@yuants/vendor-okx 0.25.1 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.js +17 -53
- package/dist/account.js.map +1 -1
- package/dist/accountInfos/uid.js +32 -0
- package/dist/accountInfos/uid.js.map +1 -0
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/order-actions-with-credential.js +5 -3
- package/dist/order-actions-with-credential.js.map +1 -1
- package/dist/order-actions.js +2 -2
- package/dist/order-actions.js.map +1 -1
- package/dist/order.js +5 -4
- package/dist/order.js.map +1 -1
- package/dist/orders/listOrders.js +34 -0
- package/dist/orders/listOrders.js.map +1 -0
- package/dist/services.js +3 -3
- package/dist/services.js.map +1 -1
- package/dist/strategy-account.js +2 -2
- package/dist/strategy-account.js.map +1 -1
- package/dist/trade.js +3 -3
- package/dist/trade.js.map +1 -1
- package/dist/transfer.js +2 -3
- package/dist/transfer.js.map +1 -1
- package/lib/account.d.ts +0 -29
- package/lib/account.d.ts.map +1 -1
- package/lib/account.js +16 -54
- package/lib/account.js.map +1 -1
- package/lib/accountInfos/uid.d.ts +15 -0
- package/lib/accountInfos/uid.d.ts.map +1 -0
- package/lib/accountInfos/uid.js +42 -0
- package/lib/accountInfos/uid.js.map +1 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/order-actions-with-credential.js +2 -0
- package/lib/order-actions-with-credential.js.map +1 -1
- package/lib/order-actions.js +2 -2
- package/lib/order-actions.js.map +1 -1
- package/lib/order.js +5 -4
- package/lib/order.js.map +1 -1
- package/lib/orders/listOrders.d.ts +4 -0
- package/lib/orders/listOrders.d.ts.map +1 -0
- package/lib/orders/listOrders.js +38 -0
- package/lib/orders/listOrders.js.map +1 -0
- package/lib/services.js +3 -3
- package/lib/services.js.map +1 -1
- package/lib/strategy-account.js +2 -2
- package/lib/strategy-account.js.map +1 -1
- package/lib/trade.js +3 -3
- package/lib/trade.js.map +1 -1
- package/lib/transfer.js +1 -2
- package/lib/transfer.js.map +1 -1
- package/package.json +3 -3
- package/temp/package-deps.json +16 -15
- package/dist/loan-account.js +0 -15
- package/dist/loan-account.js.map +0 -1
- package/lib/loan-account.d.ts +0 -2
- package/lib/loan-account.d.ts.map +0 -1
- package/lib/loan-account.js +0 -17
- package/lib/loan-account.js.map +0 -1
package/dist/account.js
CHANGED
|
@@ -1,80 +1,44 @@
|
|
|
1
|
-
import { createCache } from '@yuants/cache';
|
|
2
1
|
import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';
|
|
3
2
|
import { providePendingOrdersService } from '@yuants/data-order';
|
|
4
3
|
import { Terminal } from '@yuants/protocol';
|
|
5
|
-
import { encodePath } from '@yuants/utils';
|
|
6
4
|
import { defer } from 'rxjs';
|
|
7
|
-
import { getEarningAccountInfo, getFundingAccountInfo, getTradingAccountInfo, marketIndexTickerUSDT$, } from './accountInfos';
|
|
8
|
-
import {
|
|
5
|
+
import { getEarningAccountInfo, getFundingAccountInfo, getLoanAccountInfo, getTradingAccountInfo, marketIndexTickerUSDT$, } from './accountInfos';
|
|
6
|
+
import { getEarningAccountId, getFundingAccountId, getLoanAccountId, getTradingAccountId, } from './accountInfos/uid';
|
|
7
|
+
import { getDefaultCredential } from './api/private-api';
|
|
8
|
+
import { listOrders } from './orders/listOrders';
|
|
9
9
|
const terminal = Terminal.fromNodeEnv();
|
|
10
10
|
const credential = getDefaultCredential();
|
|
11
|
-
export const accountConfigCache = createCache(() => getAccountConfig(credential), {
|
|
12
|
-
expire: 100000,
|
|
13
|
-
swrAfter: 10000,
|
|
14
|
-
});
|
|
15
|
-
export const accountUidCache = createCache(async () => {
|
|
16
|
-
const config = await accountConfigCache.query('');
|
|
17
|
-
return config === null || config === void 0 ? void 0 : config.data[0].uid;
|
|
18
|
-
});
|
|
19
11
|
defer(async () => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return orders.data.map((x) => {
|
|
25
|
-
const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
|
|
26
|
-
const order_direction = x.side === 'buy'
|
|
27
|
-
? x.posSide === 'long'
|
|
28
|
-
? 'OPEN_LONG'
|
|
29
|
-
: 'CLOSE_SHORT'
|
|
30
|
-
: x.posSide === 'short'
|
|
31
|
-
? 'OPEN_SHORT'
|
|
32
|
-
: 'CLOSE_LONG';
|
|
33
|
-
return {
|
|
34
|
-
order_id: x.ordId,
|
|
35
|
-
account_id,
|
|
36
|
-
product_id: encodePath(x.instType, x.instId),
|
|
37
|
-
submit_at: +x.cTime,
|
|
38
|
-
filled_at: +x.fillTime,
|
|
39
|
-
order_type,
|
|
40
|
-
order_direction,
|
|
41
|
-
volume: +x.sz,
|
|
42
|
-
traded_volume: +x.accFillSz,
|
|
43
|
-
price: +x.px,
|
|
44
|
-
traded_price: +x.avgPx,
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
}, { auto_refresh_interval: 5000 });
|
|
12
|
+
const account_id = await getTradingAccountId(credential);
|
|
13
|
+
providePendingOrdersService(terminal, account_id, async () => listOrders(credential, account_id), {
|
|
14
|
+
auto_refresh_interval: 5000,
|
|
15
|
+
});
|
|
48
16
|
}).subscribe();
|
|
49
|
-
export const getTradingAccountId = async () => {
|
|
50
|
-
const uid = await accountUidCache.query('');
|
|
51
|
-
return `okx/${uid}/trading`;
|
|
52
|
-
};
|
|
53
|
-
export const getStrategyAccountId = async () => {
|
|
54
|
-
const uid = await accountUidCache.query('');
|
|
55
|
-
return `okx/${uid}/strategy`;
|
|
56
|
-
};
|
|
57
17
|
defer(async () => {
|
|
58
|
-
const tradingAccountId = await getTradingAccountId();
|
|
18
|
+
const tradingAccountId = await getTradingAccountId(credential);
|
|
59
19
|
addAccountMarket(terminal, { account_id: tradingAccountId, market_id: 'OKX' });
|
|
60
20
|
provideAccountInfoService(terminal, tradingAccountId, () => getTradingAccountInfo(credential), {
|
|
61
21
|
auto_refresh_interval: 1000,
|
|
62
22
|
});
|
|
63
23
|
}).subscribe();
|
|
64
24
|
defer(async () => {
|
|
65
|
-
const
|
|
66
|
-
const fundingAccountId = `okx/${uid}/funding/USDT`;
|
|
25
|
+
const fundingAccountId = await getFundingAccountId(credential);
|
|
67
26
|
provideAccountInfoService(terminal, fundingAccountId, () => getFundingAccountInfo(credential), {
|
|
68
27
|
auto_refresh_interval: 1000,
|
|
69
28
|
});
|
|
70
29
|
}).subscribe();
|
|
71
30
|
defer(async () => {
|
|
72
|
-
const
|
|
73
|
-
const earningAccountId = `okx/${uid}/earning/USDT`;
|
|
31
|
+
const earningAccountId = await getEarningAccountId(credential);
|
|
74
32
|
provideAccountInfoService(terminal, earningAccountId, () => getEarningAccountInfo(credential), {
|
|
75
33
|
auto_refresh_interval: 5000,
|
|
76
34
|
});
|
|
77
35
|
}).subscribe();
|
|
36
|
+
defer(async () => {
|
|
37
|
+
const loanAccountId = await getLoanAccountId(credential);
|
|
38
|
+
provideAccountInfoService(Terminal.fromNodeEnv(), loanAccountId, () => getLoanAccountInfo(credential), {
|
|
39
|
+
auto_refresh_interval: 1000,
|
|
40
|
+
});
|
|
41
|
+
}).subscribe();
|
|
78
42
|
// 导出 marketIndexTickerUSDT$ 供其他模块使用
|
|
79
43
|
export { marketIndexTickerUSDT$ };
|
|
80
44
|
//# sourceMappingURL=account.js.map
|
package/dist/account.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,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AAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE/D,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,UAAU,CAAC,EAAE;QAC7F,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC/D,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,UAAU,CAAC,EAAE;QAC7F,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACzD,yBAAyB,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE;QACrG,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,oCAAoC;AACpC,OAAO,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport {\n getEarningAccountInfo,\n getFundingAccountInfo,\n getLoanAccountInfo,\n getTradingAccountInfo,\n marketIndexTickerUSDT$,\n} from './accountInfos';\nimport {\n getEarningAccountId,\n getFundingAccountId,\n getLoanAccountId,\n getTradingAccountId,\n} from './accountInfos/uid';\nimport { getDefaultCredential } from './api/private-api';\nimport { listOrders } from './orders/listOrders';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const account_id = await getTradingAccountId(credential);\n providePendingOrdersService(terminal, account_id, async () => listOrders(credential, account_id), {\n auto_refresh_interval: 5000,\n });\n}).subscribe();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\n addAccountMarket(terminal, { account_id: tradingAccountId, market_id: 'OKX' });\n\n provideAccountInfoService(terminal, tradingAccountId, () => getTradingAccountInfo(credential), {\n auto_refresh_interval: 1000,\n });\n}).subscribe();\n\ndefer(async () => {\n const fundingAccountId = await getFundingAccountId(credential);\n\n provideAccountInfoService(terminal, fundingAccountId, () => getFundingAccountInfo(credential), {\n auto_refresh_interval: 1000,\n });\n}).subscribe();\n\ndefer(async () => {\n const earningAccountId = await getEarningAccountId(credential);\n provideAccountInfoService(terminal, earningAccountId, () => getEarningAccountInfo(credential), {\n auto_refresh_interval: 5000,\n });\n}).subscribe();\n\ndefer(async () => {\n const loanAccountId = await getLoanAccountId(credential);\n provideAccountInfoService(Terminal.fromNodeEnv(), loanAccountId, () => getLoanAccountInfo(credential), {\n auto_refresh_interval: 1000,\n });\n}).subscribe();\n\n// 导出 marketIndexTickerUSDT$ 供其他模块使用\nexport { marketIndexTickerUSDT$ };\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createCache } from '@yuants/cache';
|
|
2
|
+
import { getAccountConfig } from '../api/private-api';
|
|
3
|
+
const accountConfigCache = createCache((key) => getAccountConfig(JSON.parse(key)), {
|
|
4
|
+
expire: 100000,
|
|
5
|
+
swrAfter: 10000,
|
|
6
|
+
});
|
|
7
|
+
const accountUidCache = createCache(async (key) => {
|
|
8
|
+
const config = await accountConfigCache.query(key);
|
|
9
|
+
return config === null || config === void 0 ? void 0 : config.data[0].uid;
|
|
10
|
+
});
|
|
11
|
+
const accountIdCache = createCache(async (key) => {
|
|
12
|
+
const uid = await accountUidCache.query(key);
|
|
13
|
+
return {
|
|
14
|
+
trading: `okx/${uid}/trading`,
|
|
15
|
+
strategy: `okx/${uid}/strategy`,
|
|
16
|
+
loan: `okx/${uid}/loan/USDT`,
|
|
17
|
+
earning: `okx/${uid}/earning/USDT`,
|
|
18
|
+
funding: `okx/${uid}/funding/USDT`,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
export const getUid = async (credential) => {
|
|
22
|
+
return accountUidCache.query(JSON.stringify(credential));
|
|
23
|
+
};
|
|
24
|
+
export const getAccountIds = async (credential) => {
|
|
25
|
+
return accountIdCache.query(JSON.stringify(credential));
|
|
26
|
+
};
|
|
27
|
+
export const getTradingAccountId = async (credential) => getAccountIds(credential).then((x) => x.trading);
|
|
28
|
+
export const getStrategyAccountId = async (credential) => getAccountIds(credential).then((x) => x.strategy);
|
|
29
|
+
export const getLoanAccountId = async (credential) => getAccountIds(credential).then((x) => x.loan);
|
|
30
|
+
export const getEarningAccountId = async (credential) => getAccountIds(credential).then((x) => x.earning);
|
|
31
|
+
export const getFundingAccountId = async (credential) => getAccountIds(credential).then((x) => x.funding);
|
|
32
|
+
//# sourceMappingURL=uid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uid.js","sourceRoot":"","sources":["../../src/accountInfos/uid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAEnE,MAAM,kBAAkB,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;IACjF,MAAM,EAAE,MAAO;IACf,QAAQ,EAAE,KAAM;CACjB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAChD,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,C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K,EAAE,UAAuB,EAAE,EAAE,CAChE,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,IAAI,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE,CACnE,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE,CACnE,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getAccountConfig, ICredential } from '../api/private-api';\n\nconst accountConfigCache = createCache((key) => getAccountConfig(JSON.parse(key)), {\n expire: 100_000,\n swrAfter: 10_000,\n});\n\nconst accountUidCache = createCache(async (key) => {\n const config = await accountConfigCache.query(key);\n return config?.data[0].uid;\n});\n\nconst accountIdCache = createCache(async (key) => {\n const uid = await accountUidCache.query(key);\n return {\n trading: `okx/${uid}/trading`,\n strategy: `okx/${uid}/strategy`,\n loan: `okx/${uid}/loan/USDT`,\n earning: `okx/${uid}/earning/USDT`,\n funding: `okx/${uid}/funding/USDT`,\n };\n});\n\nexport const getUid = async (credential: ICredential) => {\n return accountUidCache.query(JSON.stringify(credential));\n};\n\nexport const getAccountIds = async (credential: ICredential) => {\n return accountIdCache.query(JSON.stringify(credential));\n};\n\nexport const getTradingAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.trading);\n\nexport const getStrategyAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.strategy);\n\nexport const getLoanAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.loan);\n\nexport const getEarningAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.earning);\n\nexport const getFundingAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.funding);\n"]}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,CAAC;AACnB,OAAO,eAAe,CAAC;AACvB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,CAAC;AACnB,OAAO,eAAe,CAAC;AACvB,OAAO,SAAS,CAAC;AACjB,OAAO,iBAAiB,CAAC;AACzB,OAAO,iCAAiC,CAAC;AACzC,OAAO,6BAA6B,CAAC;AACrC,OAAO,4BAA4B,CAAC;AACpC,OAAO,oBAAoB,CAAC;AAC5B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,YAAY,CAAC;AACpB,OAAO,oBAAoB,CAAC;AAC5B,OAAO,SAAS,CAAC;AACjB,OAAO,YAAY,CAAC","sourcesContent":["import './account';\nimport './api-service';\nimport './order';\nimport './order-actions';\nimport './order-actions-with-credential';\nimport './public-data/interest_rate';\nimport './public-data/market-order';\nimport './public-data/ohlc';\nimport './public-data/quote';\nimport './services';\nimport './strategy-account';\nimport './trade';\nimport './transfer';\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { provideOrderActionsWithCredential } from '@yuants/data-order';
|
|
2
2
|
import { Terminal } from '@yuants/protocol';
|
|
3
3
|
import { cancelOrder } from './orders/cancelOrder';
|
|
4
|
+
import { listOrders } from './orders/listOrders';
|
|
4
5
|
import { modifyOrder } from './orders/modifyOrder';
|
|
5
6
|
import { submitOrder } from './orders/submitOrder';
|
|
6
7
|
const terminal = Terminal.fromNodeEnv();
|
|
@@ -13,8 +14,9 @@ provideOrderActionsWithCredential(terminal, 'OKX', {
|
|
|
13
14
|
passphrase: { type: 'string' },
|
|
14
15
|
},
|
|
15
16
|
}, {
|
|
16
|
-
submitOrder,
|
|
17
|
-
modifyOrder,
|
|
18
|
-
cancelOrder,
|
|
17
|
+
submitOrder: submitOrder,
|
|
18
|
+
modifyOrder: modifyOrder,
|
|
19
|
+
cancelOrder: cancelOrder,
|
|
20
|
+
listOrders: listOrders,
|
|
19
21
|
});
|
|
20
22
|
//# sourceMappingURL=order-actions-with-credential.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-actions-with-credential.js","sourceRoot":"","sources":["../src/order-actions-with-credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,iCAAiC,CAC/B,QAAQ,EACR,KAAK,EACL;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;IACpD,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC/B;CACF,EACD;IACE,WAAW;
|
|
1
|
+
{"version":3,"file":"order-actions-with-credential.js","sourceRoot":"","sources":["../src/order-actions-with-credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,iCAAiC,CAC/B,QAAQ,EACR,KAAK,EACL;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;IACpD,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC/B;CACF,EACD;IACE,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,UAAU;CACvB,CACF,CAAC","sourcesContent":["import { provideOrderActionsWithCredential } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { ICredential } from './api/private-api';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { listOrders } from './orders/listOrders';\nimport { modifyOrder } from './orders/modifyOrder';\nimport { submitOrder } from './orders/submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideOrderActionsWithCredential<ICredential>(\n terminal,\n 'OKX',\n {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n {\n submitOrder: submitOrder,\n modifyOrder: modifyOrder,\n cancelOrder: cancelOrder,\n listOrders: listOrders,\n },\n);\n"]}
|
package/dist/order-actions.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Terminal } from '@yuants/protocol';
|
|
2
2
|
import { defer } from 'rxjs';
|
|
3
|
-
import { getTradingAccountId } from './account';
|
|
4
3
|
import { getDefaultCredential } from './api/private-api';
|
|
5
4
|
import { cancelOrder } from './orders/cancelOrder';
|
|
6
5
|
import { modifyOrder } from './orders/modifyOrder';
|
|
7
6
|
import { submitOrder } from './orders/submitOrder';
|
|
7
|
+
import { getTradingAccountId } from './accountInfos/uid';
|
|
8
8
|
const terminal = Terminal.fromNodeEnv();
|
|
9
9
|
const credential = getDefaultCredential();
|
|
10
10
|
defer(async () => {
|
|
11
|
-
const tradingAccountId = await getTradingAccountId();
|
|
11
|
+
const tradingAccountId = await getTradingAccountId(credential);
|
|
12
12
|
terminal.server.provideService('SubmitOrder', {
|
|
13
13
|
required: ['account_id'],
|
|
14
14
|
properties: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-actions.js","sourceRoot":"","sources":["../src/order-actions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"order-actions.js","sourceRoot":"","sources":["../src/order-actions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,oBAAoB,EAAE,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,EAAE,IAAI,EAAE,EAAE,CAAC;IAC7C,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getDefaultCredential } from './api/private-api';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { modifyOrder } from './orders/modifyOrder';\nimport { submitOrder } from './orders/submitOrder';\nimport { getTradingAccountId } from './accountInfos/uid';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\n terminal.server.provideService<IOrder, { order_id?: string }>(\n 'SubmitOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountId },\n },\n },\n async (msg) => {\n return { res: { code: 0, message: 'OK', data: await submitOrder(credential, msg.req) } };\n },\n );\n\n terminal.server.provideService<IOrder>(\n 'ModifyOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountId },\n },\n },\n async (msg) => {\n await modifyOrder(credential, msg.req);\n return { res: { code: 0, message: 'OK' } };\n },\n );\n\n terminal.server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountId },\n },\n },\n async (msg) => {\n await cancelOrder(credential, msg.req);\n return { res: { code: 0, message: 'OK' } };\n },\n );\n}).subscribe();\n"]}
|
package/dist/order.js
CHANGED
|
@@ -2,9 +2,10 @@ import { Terminal } from '@yuants/protocol';
|
|
|
2
2
|
import { writeToSQL } from '@yuants/sql';
|
|
3
3
|
import { encodePath, formatTime } from '@yuants/utils';
|
|
4
4
|
import { defer, from, map, merge, mergeMap, repeat, retry, shareReplay, Subject, tap } from 'rxjs';
|
|
5
|
-
import { getTradingAccountId } from './account';
|
|
6
5
|
import { getDefaultCredential, getTradeOrdersHistory, getTradeOrdersPending } from './api/private-api';
|
|
6
|
+
import { getTradingAccountId } from './accountInfos/uid';
|
|
7
7
|
export const order$ = new Subject();
|
|
8
|
+
const credential = getDefaultCredential();
|
|
8
9
|
order$
|
|
9
10
|
.pipe(
|
|
10
11
|
//
|
|
@@ -68,9 +69,9 @@ const makeOrder = (x, account_id) => {
|
|
|
68
69
|
};
|
|
69
70
|
};
|
|
70
71
|
(async () => {
|
|
71
|
-
const TRADING_ACCOUNT_ID = await getTradingAccountId();
|
|
72
|
-
const swapHistoryOrders = defer(() => getTradeOrdersHistory(
|
|
73
|
-
const swapPendingOrders = defer(() => getTradeOrdersPending(
|
|
72
|
+
const TRADING_ACCOUNT_ID = await getTradingAccountId(credential);
|
|
73
|
+
const swapHistoryOrders = defer(() => getTradeOrdersHistory(credential, { instType: 'SWAP' })).pipe(repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
74
|
+
const swapPendingOrders = defer(() => getTradeOrdersPending(credential, { instType: 'SWAP' })).pipe(repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
74
75
|
const ordersFromHistoryOrder$ = swapHistoryOrders.pipe(
|
|
75
76
|
//
|
|
76
77
|
mergeMap((x) => from(x.data || []).pipe(
|
package/dist/order.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACnG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[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AC,uBAAuB,EAAE,uBAAuB,CAAC;SACpD,IAAI;IACH,EAAE;IACF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACR,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CACH;SACA,SAAS,EAAE,CAAC;AACjB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, map, merge, mergeMap, repeat, retry, shareReplay, Subject, tap } from 'rxjs';\nimport { getDefaultCredential, getTradeOrdersHistory, getTradeOrdersPending } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\n\nexport const order$ = new Subject<IOrder>();\n\nconst credential = getDefaultCredential();\n\norder$\n .pipe(\n //\n // mergeMap((x) => x),\n writeToSQL({\n terminal: Terminal.fromNodeEnv(),\n tableName: '\"order\"',\n writeInterval: 1000,\n columns: [\n 'order_id',\n 'account_id',\n 'product_id',\n 'position_id',\n 'order_type',\n 'order_direction',\n 'volume',\n 'submit_at',\n 'updated_at',\n 'filled_at',\n 'price',\n 'traded_volume',\n 'traded_price',\n 'order_status',\n 'comment',\n 'profit_correction',\n 'real_profit',\n 'inferred_base_currency_price',\n ],\n conflictKeys: ['account_id', 'order_id'],\n }),\n )\n .subscribe();\n\nconst makeOrder = (\n x: {\n ordType: string;\n side: string;\n posSide: string;\n instType: string;\n instId: string;\n cTime: string;\n uTime: string;\n fillTime: string;\n sz: string;\n accFillSz: string;\n px: string;\n avgPx: string;\n state: string;\n clOrdId: string;\n ordId: string;\n },\n account_id: string,\n): IOrder => {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n const order_status = ['live', 'partially_filled'].includes(x.state)\n ? 'ACCEPTED'\n : x.state === 'filled'\n ? 'TRADED'\n : 'CANCELLED';\n return {\n order_id: x.clOrdId !== '' ? x.clOrdId : x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n created_at: formatTime(+x.cTime),\n updated_at: formatTime(+x.uTime),\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n order_status,\n };\n};\n\n(async () => {\n const TRADING_ACCOUNT_ID = await getTradingAccountId(credential);\n\n const swapHistoryOrders = defer(() => getTradeOrdersHistory(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const swapPendingOrders = defer(() => getTradeOrdersPending(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const ordersFromHistoryOrder$ = swapHistoryOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n const ordersFromPendingOrder$ = swapPendingOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n merge(ordersFromHistoryOrder$, ordersFromPendingOrder$)\n .pipe(\n //\n tap((x) => {\n order$.next(x);\n }),\n )\n .subscribe();\n})();\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { encodePath } from '@yuants/utils';
|
|
2
|
+
import { getAccountIds } from '../accountInfos/uid';
|
|
3
|
+
import { getTradeOrdersPending } from '../api/private-api';
|
|
4
|
+
export const listOrders = async (credential, account_id) => {
|
|
5
|
+
const accountIds = await getAccountIds(credential);
|
|
6
|
+
if ((accountIds === null || accountIds === void 0 ? void 0 : accountIds.trading) === account_id) {
|
|
7
|
+
const orderRes = await getTradeOrdersPending(credential, {});
|
|
8
|
+
return orderRes.data.map((x) => {
|
|
9
|
+
const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
|
|
10
|
+
const order_direction = x.side === 'buy'
|
|
11
|
+
? x.posSide === 'long'
|
|
12
|
+
? 'OPEN_LONG'
|
|
13
|
+
: 'CLOSE_SHORT'
|
|
14
|
+
: x.posSide === 'short'
|
|
15
|
+
? 'OPEN_SHORT'
|
|
16
|
+
: 'CLOSE_LONG';
|
|
17
|
+
return {
|
|
18
|
+
order_id: x.ordId,
|
|
19
|
+
account_id,
|
|
20
|
+
product_id: encodePath(x.instType, x.instId),
|
|
21
|
+
submit_at: +x.cTime,
|
|
22
|
+
filled_at: +x.fillTime,
|
|
23
|
+
order_type,
|
|
24
|
+
order_direction,
|
|
25
|
+
volume: +x.sz,
|
|
26
|
+
traded_volume: +x.accFillSz,
|
|
27
|
+
price: +x.px,
|
|
28
|
+
traded_price: +x.avgPx,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`Account ID ${account_id} not found or not a trading account`);
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=listOrders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAuB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAe,MAAM,oBAAoB,CAAC;AAExE,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAqB,EAAE;IACjG,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;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{ IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { getAccountIds, getTradingAccountId } from '../accountInfos/uid';\nimport { getTradeOrdersPending, ICredential } from '../api/private-api';\n\nexport const listOrders = async (credential: ICredential, account_id: string): Promise<IOrder[]> => {\n const accountIds = await getAccountIds(credential);\n if (accountIds?.trading === account_id) {\n const orderRes = await getTradeOrdersPending(credential, {});\n return orderRes.data.map((x) => {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n return {\n order_id: x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n };\n });\n }\n throw new Error(`Account ID ${account_id} not found or not a trading account`);\n};\n"]}
|
package/dist/services.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Terminal } from '@yuants/protocol';
|
|
2
2
|
import { defer } from 'rxjs';
|
|
3
|
-
import { getTradingAccountId } from './account';
|
|
4
3
|
import { getDefaultCredential, postGridAlgoOrder } from './api/private-api';
|
|
4
|
+
import { getTradingAccountId } from './accountInfos/uid';
|
|
5
5
|
const terminal = Terminal.fromNodeEnv();
|
|
6
|
+
const credential = getDefaultCredential();
|
|
6
7
|
defer(async () => {
|
|
7
|
-
const tradingAccountId = await getTradingAccountId();
|
|
8
|
-
const credential = getDefaultCredential();
|
|
8
|
+
const tradingAccountId = await getTradingAccountId(credential);
|
|
9
9
|
terminal.server.provideService('Grid/Algo-Order', {
|
|
10
10
|
required: ['account_id'],
|
|
11
11
|
properties: {
|
package/dist/services.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;AAE1C,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE/D,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,iBAAiB,EACjB;QACE,QAAQ,EAAE,CAAC,YAAY,CAAC;QACxB,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;SACxC;KACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,IAAI,GAAG,CAAC,GAAG,EAAE;YACX,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,GAAG,CAAC,GAAU,CAAC,CAAC;YACnE,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;SAC1D;QACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC;IACpD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getDefaultCredential, postGridAlgoOrder } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\n\n terminal.server.provideService(\n 'Grid/Algo-Order',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountId },\n },\n },\n async (msg) => {\n if (msg.req) {\n const result = await postGridAlgoOrder(credential, msg.req as any);\n return { res: { code: 0, message: 'OK', data: result } };\n }\n return { res: { code: 0, message: 'No Params' } };\n },\n );\n}).subscribe();\n"]}
|
package/dist/strategy-account.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';
|
|
2
2
|
import { Terminal } from '@yuants/protocol';
|
|
3
3
|
import { defer } from 'rxjs';
|
|
4
|
-
import { getStrategyAccountId } from './account';
|
|
5
4
|
import { getStrategyAccountInfo } from './accountInfos';
|
|
6
5
|
import { getDefaultCredential, getGridPositions } from './api/private-api';
|
|
6
|
+
import { getStrategyAccountId } from './accountInfos/uid';
|
|
7
7
|
const terminal = Terminal.fromNodeEnv();
|
|
8
8
|
const credential = getDefaultCredential();
|
|
9
9
|
defer(async () => {
|
|
10
|
-
const strategyAccountId = await getStrategyAccountId();
|
|
10
|
+
const strategyAccountId = await getStrategyAccountId(credential);
|
|
11
11
|
addAccountMarket(terminal, { account_id: strategyAccountId, market_id: 'OKX' });
|
|
12
12
|
terminal.server.provideService(`OKX/QueryGridPositions`, {
|
|
13
13
|
required: ['account_id', 'algoId'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy-account.js","sourceRoot":"","sources":["../src/strategy-account.ts"],"names":[],"mappings":"AAA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AO;YACL,GAAG,EAAE;gBACH,IAAI,EAAE,CAAC;gBACP,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,MAAM,gBAAgB,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;aACnG;SACF,CAAC;IACJ,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,4BAA4B,EAAE,IAAI,EAAE,0BAA0B;KAC/D,CACF,CAAC;IAEF,yBAAyB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC,sBAAsB,CAAC,UAAU,CAAC,EAAE;QAC/F,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getStrategyAccountInfo } from './accountInfos';\nimport { getDefaultCredential, getGridPositions } from './api/private-api';\nimport { getStrategyAccountId } from './accountInfos/uid';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const strategyAccountId = await getStrategyAccountId(credential);\n\n addAccountMarket(terminal, { account_id: strategyAccountId, market_id: 'OKX' });\n\n terminal.server.provideService<\n { account_id: string; algoId: string },\n Awaited<ReturnType<typeof getGridPositions>>\n >(\n `OKX/QueryGridPositions`,\n {\n required: ['account_id', 'algoId'],\n properties: {\n account_id: { type: 'string', const: strategyAccountId },\n algoId: { type: 'string' },\n },\n },\n async (msg) => {\n //\n return {\n res: {\n code: 0,\n message: 'OK',\n data: await getGridPositions(credential, { algoOrdType: 'contract_grid', algoId: msg.req.algoId }),\n },\n };\n },\n {\n egress_token_capacity: 20,\n egress_token_refill_interval: 4000, // 每 4 秒恢复 20 个令牌 (双倍冗余限流)\n },\n );\n\n provideAccountInfoService(terminal, strategyAccountId, () => getStrategyAccountInfo(credential), {\n auto_refresh_interval: 5000,\n });\n}).subscribe();\n"]}
|
package/dist/trade.js
CHANGED
|
@@ -2,11 +2,11 @@ import { Terminal } from '@yuants/protocol';
|
|
|
2
2
|
import { buildInsertManyIntoTableSQL, escapeSQL, requestSQL } from '@yuants/sql';
|
|
3
3
|
import { encodePath, formatTime } from '@yuants/utils';
|
|
4
4
|
import { defer, repeat, retry, tap, timeout } from 'rxjs';
|
|
5
|
-
import { getTradingAccountId } from './account';
|
|
6
5
|
import { getAccountBillsArchive, getDefaultCredential } from './api/private-api';
|
|
6
|
+
import { getTradingAccountId } from './accountInfos/uid';
|
|
7
|
+
const credential = getDefaultCredential();
|
|
7
8
|
const tradeParser = async (accountId, params) => {
|
|
8
9
|
const tradeList = [];
|
|
9
|
-
const credential = getDefaultCredential();
|
|
10
10
|
const result = await getAccountBillsArchive(credential, params);
|
|
11
11
|
const productIdToProduct = new Map();
|
|
12
12
|
const productIdSet = new Set();
|
|
@@ -131,7 +131,7 @@ const getAccountTradeWithAccountId = async (accountId) => {
|
|
|
131
131
|
}));
|
|
132
132
|
};
|
|
133
133
|
(async () => {
|
|
134
|
-
const account_id = await getTradingAccountId();
|
|
134
|
+
const account_id = await getTradingAccountId(credential);
|
|
135
135
|
console.log(formatTime(Date.now()), 'getAccountTrade', `AccountID: ${account_id}`);
|
|
136
136
|
defer(() => getAccountTradeWithAccountId(account_id))
|
|
137
137
|
.pipe(
|
package/dist/trade.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trade.js","sourceRoot":"","sources":["../src/trade.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,2BAA2B,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MA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AAU,CAAC,CAAC;SAClD,IAAI;IACH,EAAE;IACF,OAAO,CAAC,KAAM,CAAC,EAAE,aAAa;IAC9B,GAAG,CAAC;QACF,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,sBAAsB,EAAE,GAAG,CAAC,CAAC;QACrE,CAAC;KACF,CAAC,EACF,MAAM,CAAC,EAAE,KAAK,EAAE,KAAM,EAAE,CAAC,EACzB,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CACvB;SACA,SAAS,EAAE,CAAC;AACjB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { IProduct } from '@yuants/data-product';\nimport { ITrade } from '@yuants/data-trade';\nimport { Terminal } from '@yuants/protocol';\nimport { buildInsertManyIntoTableSQL, escapeSQL, requestSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, repeat, retry, tap, timeout } from 'rxjs';\nimport { getTradingAccountId } from './account';\nimport { getAccountBillsArchive, getDefaultCredential } from './api/private-api';\n\nconst tradeParser = async (accountId: string, params: Record<string, string>): Promise<ITrade[]> => {\n const tradeList: ITrade[] = [];\n const credential = getDefaultCredential();\n const result = await getAccountBillsArchive(credential, params);\n const productIdToProduct = new Map<string, IProduct>();\n const productIdSet = new Set<string>();\n if (result.code === '0' && result.data) {\n const data = result.data;\n const mapTradeIdToBillList = new Map<string, typeof data>();\n data.forEach((item) => {\n productIdSet.add(encodePath(item.instType, item.instId));\n mapTradeIdToBillList.set(item.tradeId, [...(mapTradeIdToBillList.get(item.tradeId) ?? []), item]);\n });\n if (productIdSet.size > 0) {\n const productList = await requestSQL<IProduct[]>(\n Terminal.fromNodeEnv(),\n `\n select * from product where product_id in (${Array.from(productIdSet)\n .map((productId) => escapeSQL(productId))\n .join(',')})\n `,\n );\n if (productList.length > 0) {\n productList.forEach((p) => productIdToProduct.set(p.product_id, p));\n }\n }\n mapTradeIdToBillList.forEach(async (v, tradeId) => {\n if (!((v[0].instType === 'SPOT' && v.length === 2) || v[0].instType === 'SWAP')) return;\n\n const trade: ITrade = {\n id: tradeId,\n account_id: accountId,\n product_id: '',\n direction: '',\n traded_volume: '',\n traded_price: '',\n traded_value: '',\n post_volume: '',\n fee: '',\n fee_currency: '',\n created_at: '0',\n };\n\n v.forEach((bill) => {\n trade.created_at = Math.max(Number(trade.created_at), Number(bill.ts)).toString();\n trade.product_id = encodePath(bill.instType, bill.instId);\n trade.traded_price = bill.px;\n if (bill.instType === 'SWAP') {\n if (bill.subType === '1') trade.direction = 'OPEN_LONG';\n if (bill.subType === '2') trade.direction = 'CLOSE_LONG';\n if (bill.subType === '3') trade.direction = 'OPEN_LONG';\n if (bill.subType === '4') trade.direction = 'OPEN_SHORT';\n if (bill.subType === '5') trade.direction = 'CLOSE_LONG';\n if (bill.subType === '6') trade.direction = 'CLOSE_SHORT';\n trade.traded_volume = bill.sz;\n trade.traded_value = (Number(bill.sz) * Number(bill.px)).toString();\n }\n if (bill.instType === 'SPOT') {\n if (bill.subType === '1') {\n if (bill.ccy !== 'USDT') {\n trade.direction = 'OPEN_LONG';\n } else {\n trade.direction = 'CLOSE_LONG';\n }\n }\n\n if (bill.ccy !== 'USDT') {\n trade.traded_volume = bill.sz;\n }\n if (bill.ccy === 'USDT') {\n trade.traded_value = bill.sz;\n }\n }\n // fee\n if (bill.fee !== '0') {\n trade.fee = Math.abs(Number(bill.fee)).toString();\n trade.fee_currency = bill.ccy;\n }\n });\n trade.created_at = formatTime(Number(trade.created_at));\n if (productIdToProduct.has(trade.product_id)) {\n trade.traded_value = (\n +trade.traded_value * +(productIdToProduct.get(trade.product_id)?.value_scale ?? 1)\n ).toString();\n } else {\n throw new Error(`Not Found Product With Product Id: ${trade.product_id}`);\n }\n tradeList.push(trade);\n });\n }\n return tradeList;\n};\n\nconst getAccountTradeWithAccountId = async (accountId: string) => {\n const currentTrade = await requestSQL<ITrade[]>(\n Terminal.fromNodeEnv(),\n `\n select * from trade where account_id=${escapeSQL(accountId)} order by created_at desc limit 1;\n `,\n );\n const params: Record<string, string> = {\n type: '2',\n begin: (new Date().getTime() - 1000 * 60 * 60 * 24 * 30 * 3).toString(),\n };\n if (currentTrade.length === 1) {\n params['begin'] = new Date(currentTrade[0].created_at ?? 0).getTime().toString();\n }\n console.log(formatTime(Date.now()), 'getAccountTrade', `params: ${JSON.stringify(params)}`);\n const tradeList = await tradeParser(accountId, params);\n console.log(formatTime(Date.now()), 'getAccountTrade', `tradeList: ${JSON.stringify(tradeList)}`);\n await requestSQL(\n Terminal.fromNodeEnv(),\n buildInsertManyIntoTableSQL(tradeList, 'trade', {\n columns: [\n 'id',\n 'account_id',\n 'product_id',\n 'traded_volume',\n 'traded_value',\n 'traded_price',\n 'direction',\n 'fee',\n 'fee_currency',\n 'created_at',\n ],\n conflictKeys: ['id'],\n }),\n );\n};\n\n(async () => {\n const account_id = await getTradingAccountId();\n console.log(formatTime(Date.now()), 'getAccountTrade', `AccountID: ${account_id}`);\n defer(() => getAccountTradeWithAccountId(account_id))\n .pipe(\n //\n timeout(10_000), // 超时设定:10 秒\n tap({\n error: (err) => {\n console.error(formatTime(Date.now()), 'getAccountTradeError', err);\n },\n }),\n repeat({ delay: 30_000 }),\n retry({ delay: 5000 }),\n )\n .subscribe();\n})();\n"]}
|
|
1
|
+
{"version":3,"file":"trade.js","sourceRoot":"","sources":["../src/trade.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,2BAA2B,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,sBAAsB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Aa;IAC9B,GAAG,CAAC;QACF,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,sBAAsB,EAAE,GAAG,CAAC,CAAC;QACrE,CAAC;KACF,CAAC,EACF,MAAM,CAAC,EAAE,KAAK,EAAE,KAAM,EAAE,CAAC,EACzB,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CACvB;SACA,SAAS,EAAE,CAAC;AACjB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { IProduct } from '@yuants/data-product';\nimport { ITrade } from '@yuants/data-trade';\nimport { Terminal } from '@yuants/protocol';\nimport { buildInsertManyIntoTableSQL, escapeSQL, requestSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, repeat, retry, tap, timeout } from 'rxjs';\nimport { getAccountBillsArchive, getDefaultCredential } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\n\nconst credential = getDefaultCredential();\n\nconst tradeParser = async (accountId: string, params: Record<string, string>): Promise<ITrade[]> => {\n const tradeList: ITrade[] = [];\n const result = await getAccountBillsArchive(credential, params);\n const productIdToProduct = new Map<string, IProduct>();\n const productIdSet = new Set<string>();\n if (result.code === '0' && result.data) {\n const data = result.data;\n const mapTradeIdToBillList = new Map<string, typeof data>();\n data.forEach((item) => {\n productIdSet.add(encodePath(item.instType, item.instId));\n mapTradeIdToBillList.set(item.tradeId, [...(mapTradeIdToBillList.get(item.tradeId) ?? []), item]);\n });\n if (productIdSet.size > 0) {\n const productList = await requestSQL<IProduct[]>(\n Terminal.fromNodeEnv(),\n `\n select * from product where product_id in (${Array.from(productIdSet)\n .map((productId) => escapeSQL(productId))\n .join(',')})\n `,\n );\n if (productList.length > 0) {\n productList.forEach((p) => productIdToProduct.set(p.product_id, p));\n }\n }\n mapTradeIdToBillList.forEach(async (v, tradeId) => {\n if (!((v[0].instType === 'SPOT' && v.length === 2) || v[0].instType === 'SWAP')) return;\n\n const trade: ITrade = {\n id: tradeId,\n account_id: accountId,\n product_id: '',\n direction: '',\n traded_volume: '',\n traded_price: '',\n traded_value: '',\n post_volume: '',\n fee: '',\n fee_currency: '',\n created_at: '0',\n };\n\n v.forEach((bill) => {\n trade.created_at = Math.max(Number(trade.created_at), Number(bill.ts)).toString();\n trade.product_id = encodePath(bill.instType, bill.instId);\n trade.traded_price = bill.px;\n if (bill.instType === 'SWAP') {\n if (bill.subType === '1') trade.direction = 'OPEN_LONG';\n if (bill.subType === '2') trade.direction = 'CLOSE_LONG';\n if (bill.subType === '3') trade.direction = 'OPEN_LONG';\n if (bill.subType === '4') trade.direction = 'OPEN_SHORT';\n if (bill.subType === '5') trade.direction = 'CLOSE_LONG';\n if (bill.subType === '6') trade.direction = 'CLOSE_SHORT';\n trade.traded_volume = bill.sz;\n trade.traded_value = (Number(bill.sz) * Number(bill.px)).toString();\n }\n if (bill.instType === 'SPOT') {\n if (bill.subType === '1') {\n if (bill.ccy !== 'USDT') {\n trade.direction = 'OPEN_LONG';\n } else {\n trade.direction = 'CLOSE_LONG';\n }\n }\n\n if (bill.ccy !== 'USDT') {\n trade.traded_volume = bill.sz;\n }\n if (bill.ccy === 'USDT') {\n trade.traded_value = bill.sz;\n }\n }\n // fee\n if (bill.fee !== '0') {\n trade.fee = Math.abs(Number(bill.fee)).toString();\n trade.fee_currency = bill.ccy;\n }\n });\n trade.created_at = formatTime(Number(trade.created_at));\n if (productIdToProduct.has(trade.product_id)) {\n trade.traded_value = (\n +trade.traded_value * +(productIdToProduct.get(trade.product_id)?.value_scale ?? 1)\n ).toString();\n } else {\n throw new Error(`Not Found Product With Product Id: ${trade.product_id}`);\n }\n tradeList.push(trade);\n });\n }\n return tradeList;\n};\n\nconst getAccountTradeWithAccountId = async (accountId: string) => {\n const currentTrade = await requestSQL<ITrade[]>(\n Terminal.fromNodeEnv(),\n `\n select * from trade where account_id=${escapeSQL(accountId)} order by created_at desc limit 1;\n `,\n );\n const params: Record<string, string> = {\n type: '2',\n begin: (new Date().getTime() - 1000 * 60 * 60 * 24 * 30 * 3).toString(),\n };\n if (currentTrade.length === 1) {\n params['begin'] = new Date(currentTrade[0].created_at ?? 0).getTime().toString();\n }\n console.log(formatTime(Date.now()), 'getAccountTrade', `params: ${JSON.stringify(params)}`);\n const tradeList = await tradeParser(accountId, params);\n console.log(formatTime(Date.now()), 'getAccountTrade', `tradeList: ${JSON.stringify(tradeList)}`);\n await requestSQL(\n Terminal.fromNodeEnv(),\n buildInsertManyIntoTableSQL(tradeList, 'trade', {\n columns: [\n 'id',\n 'account_id',\n 'product_id',\n 'traded_volume',\n 'traded_value',\n 'traded_price',\n 'direction',\n 'fee',\n 'fee_currency',\n 'created_at',\n ],\n conflictKeys: ['id'],\n }),\n );\n};\n\n(async () => {\n const account_id = await getTradingAccountId(credential);\n console.log(formatTime(Date.now()), 'getAccountTrade', `AccountID: ${account_id}`);\n defer(() => getAccountTradeWithAccountId(account_id))\n .pipe(\n //\n timeout(10_000), // 超时设定:10 秒\n tap({\n error: (err) => {\n console.error(formatTime(Date.now()), 'getAccountTradeError', err);\n },\n }),\n repeat({ delay: 30_000 }),\n retry({ delay: 5000 }),\n )\n .subscribe();\n})();\n"]}
|
package/dist/transfer.js
CHANGED
|
@@ -3,13 +3,12 @@ import { Terminal } from '@yuants/protocol';
|
|
|
3
3
|
import { addAccountTransferAddress } from '@yuants/transfer';
|
|
4
4
|
import { formatTime } from '@yuants/utils';
|
|
5
5
|
import { defer } from 'rxjs';
|
|
6
|
-
import {
|
|
7
|
-
import { getAssetCurrencies, getAssetDepositAddress, getAssetDepositHistory, getAssetWithdrawalHistory, getDefaultCredential, getSubAccountList, postAssetTransfer, postAssetWithdrawal, postFinanceSavingsPurchaseRedempt, } from './api/private-api';
|
|
6
|
+
import { getAccountConfig, getAssetCurrencies, getAssetDepositAddress, getAssetDepositHistory, getAssetWithdrawalHistory, getDefaultCredential, getSubAccountList, postAssetTransfer, postAssetWithdrawal, postFinanceSavingsPurchaseRedempt, } from './api/private-api';
|
|
8
7
|
const terminal = Terminal.fromNodeEnv();
|
|
9
8
|
const credential = getDefaultCredential();
|
|
10
9
|
const cacheOfAssetCurrencies = createCache(() => getAssetCurrencies(credential), { expire: 3600000 });
|
|
11
10
|
defer(async () => {
|
|
12
|
-
const account_config = await
|
|
11
|
+
const account_config = await getAccountConfig(credential);
|
|
13
12
|
if (!account_config)
|
|
14
13
|
throw new Error('Failed to get account config');
|
|
15
14
|
console.info(formatTime(Date.now()), 'AccountConfig', JSON.stringify(account_config));
|