@yuants/vendor-okx 0.23.25 → 0.23.26
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 +13 -136
- package/dist/account.js.map +1 -1
- package/dist/accountInfos/earning.js +15 -0
- package/dist/accountInfos/earning.js.map +1 -0
- package/dist/accountInfos/funding.js +46 -0
- package/dist/accountInfos/funding.js.map +1 -0
- package/dist/accountInfos/index.js +7 -0
- package/dist/accountInfos/index.js.map +1 -0
- package/dist/accountInfos/loan.js +46 -0
- package/dist/accountInfos/loan.js.map +1 -0
- package/dist/accountInfos/strategy.js +56 -0
- package/dist/accountInfos/strategy.js.map +1 -0
- package/dist/accountInfos/trading.js +84 -0
- package/dist/accountInfos/trading.js.map +1 -0
- package/dist/accountInfos/types.js +2 -0
- package/dist/accountInfos/types.js.map +1 -0
- package/dist/loan-account.js +3 -45
- package/dist/loan-account.js.map +1 -1
- package/dist/order-actions.js +10 -182
- package/dist/order-actions.js.map +1 -1
- package/dist/orders/cancelOrder.js +13 -0
- package/dist/orders/cancelOrder.js.map +1 -0
- package/dist/orders/modifyOrder.js +58 -0
- package/dist/orders/modifyOrder.js.map +1 -0
- package/dist/orders/submitOrder.js +107 -0
- package/dist/orders/submitOrder.js.map +1 -0
- package/dist/strategy-account.js +5 -59
- package/dist/strategy-account.js.map +1 -1
- package/lib/account.d.ts +2 -0
- package/lib/account.d.ts.map +1 -1
- package/lib/account.js +12 -136
- package/lib/account.js.map +1 -1
- package/lib/accountInfos/earning.d.ts +4 -0
- package/lib/accountInfos/earning.d.ts.map +1 -0
- package/lib/accountInfos/earning.js +19 -0
- package/lib/accountInfos/earning.js.map +1 -0
- package/lib/accountInfos/funding.d.ts +4 -0
- package/lib/accountInfos/funding.d.ts.map +1 -0
- package/lib/accountInfos/funding.js +50 -0
- package/lib/accountInfos/funding.js.map +1 -0
- package/lib/accountInfos/index.d.ts +8 -0
- package/lib/accountInfos/index.d.ts.map +1 -0
- package/lib/accountInfos/index.js +16 -0
- package/lib/accountInfos/index.js.map +1 -0
- package/lib/accountInfos/loan.d.ts +4 -0
- package/lib/accountInfos/loan.d.ts.map +1 -0
- package/lib/accountInfos/loan.js +50 -0
- package/lib/accountInfos/loan.js.map +1 -0
- package/lib/accountInfos/strategy.d.ts +4 -0
- package/lib/accountInfos/strategy.d.ts.map +1 -0
- package/lib/accountInfos/strategy.js +60 -0
- package/lib/accountInfos/strategy.js.map +1 -0
- package/lib/accountInfos/trading.d.ts +5 -0
- package/lib/accountInfos/trading.d.ts.map +1 -0
- package/lib/accountInfos/trading.js +88 -0
- package/lib/accountInfos/trading.js.map +1 -0
- package/lib/accountInfos/types.d.ts +6 -0
- package/lib/accountInfos/types.d.ts.map +1 -0
- package/lib/accountInfos/types.js +3 -0
- package/lib/accountInfos/types.js.map +1 -0
- package/lib/loan-account.js +2 -44
- package/lib/loan-account.js.map +1 -1
- package/lib/order-actions.js +8 -180
- package/lib/order-actions.js.map +1 -1
- package/lib/orders/cancelOrder.d.ts +4 -0
- package/lib/orders/cancelOrder.d.ts.map +1 -0
- package/lib/orders/cancelOrder.js +17 -0
- package/lib/orders/cancelOrder.js.map +1 -0
- package/lib/orders/modifyOrder.d.ts +4 -0
- package/lib/orders/modifyOrder.d.ts.map +1 -0
- package/lib/orders/modifyOrder.js +62 -0
- package/lib/orders/modifyOrder.js.map +1 -0
- package/lib/orders/submitOrder.d.ts +4 -0
- package/lib/orders/submitOrder.d.ts.map +1 -0
- package/lib/orders/submitOrder.js +111 -0
- package/lib/orders/submitOrder.js.map +1 -0
- package/lib/strategy-account.js +4 -58
- package/lib/strategy-account.js.map +1 -1
- package/package.json +13 -13
- package/temp/package-deps.json +29 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../src/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,yCAAoE;AACpE,+BAA2C;AAC3C,gCAAqD;AACrD,wCAA4C;AAC5C,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AC,CAAC,CAAC,KAAK,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS;QACtG,GAAG,EAAE,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;KAChD,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACtF,MAAM,GAAG,GAAG,MAAM,IAAA,oBAAc,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACrD,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,KAAI,MAAA,MAAA,GAAG,CAAC,IAAI,0CAAG,CAAC,CAAC,0CAAE,KAAK,CAAA,EAAE;QAC5C,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;KAC1B;IACD,MAAM,2BAA2B,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AACzD,CAAC,CAAC;AAjFW,QAAA,WAAW,eAiFtB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeOrder } from '../api';\nimport { productService } from '../product';\nimport { spotMarketTickers$ } from '../quote';\n\nconst mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nexport const submitOrder = async (credential: ICredential, order: IOrder): Promise<string> => {\n const [instType, instId] = decodePath(order.product_id);\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MAKER') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await postTradeOrder(credential, params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return res.data[0].ordId;\n }\n throw `Failed to submit order: ${res.code} ${res.msg}`;\n};\n"]}
|
package/lib/strategy-account.js
CHANGED
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.strategyAccountId$ = exports.accountUid$ = exports.accountConfig$ = void 0;
|
|
4
4
|
const data_account_1 = require("@yuants/data-account");
|
|
5
5
|
const protocol_1 = require("@yuants/protocol");
|
|
6
|
-
const utils_1 = require("@yuants/utils");
|
|
7
6
|
const rxjs_1 = require("rxjs");
|
|
8
7
|
const api_1 = require("./api");
|
|
8
|
+
const accountInfos_1 = require("./accountInfos");
|
|
9
9
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
10
10
|
const credential = (0, api_1.getDefaultCredential)();
|
|
11
11
|
exports.accountConfig$ = (0, rxjs_1.defer)(() => (0, api_1.getAccountConfig)(credential)).pipe((0, rxjs_1.repeat)({ delay: 10000 }), (0, rxjs_1.retry)({ delay: 10000 }), (0, rxjs_1.shareReplay)(1));
|
|
@@ -32,63 +32,9 @@ exports.strategyAccountId$ = exports.accountUid$.pipe((0, rxjs_1.map)((uid) => `
|
|
|
32
32
|
egress_token_capacity: 20,
|
|
33
33
|
egress_token_refill_interval: 4000, // 每 4 秒恢复 20 个令牌 (双倍冗余限流)
|
|
34
34
|
});
|
|
35
|
-
(0, data_account_1.provideAccountInfoService)(terminal, strategyAccountId,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
(0, api_1.getGridOrdersAlgoPending)(credential, {
|
|
39
|
-
algoOrdType: 'contract_grid',
|
|
40
|
-
}),
|
|
41
|
-
]);
|
|
42
|
-
let totalEquity = 0;
|
|
43
|
-
const positions = [];
|
|
44
|
-
const gridPositionsRes = await Promise.all(gridAlgoOrders.data.map((item) => terminal.client.requestForResponseData('OKX/QueryGridPositions', {
|
|
45
|
-
account_id: strategyAccountId,
|
|
46
|
-
algoId: item.algoId,
|
|
47
|
-
})));
|
|
48
|
-
gridPositionsRes.forEach((gridPositions, index) => {
|
|
49
|
-
var _a, _b, _c, _d;
|
|
50
|
-
let positionValuation = 0;
|
|
51
|
-
const leverage = +((_a = gridAlgoOrders.data) === null || _a === void 0 ? void 0 : _a[index].actualLever);
|
|
52
|
-
(_b = gridPositions === null || gridPositions === void 0 ? void 0 : gridPositions.data) === null || _b === void 0 ? void 0 : _b.forEach((position) => {
|
|
53
|
-
var _a, _b, _c;
|
|
54
|
-
if (+position.pos !== 0) {
|
|
55
|
-
const directionRaw = (_c = (_b = (_a = gridAlgoOrders.data) === null || _a === void 0 ? void 0 : _a[index]) === null || _b === void 0 ? void 0 : _b.direction) !== null && _c !== void 0 ? _c : '';
|
|
56
|
-
const direction = directionRaw ? directionRaw.toUpperCase() : 'LONG';
|
|
57
|
-
positions.push({
|
|
58
|
-
position_id: (0, utils_1.encodePath)(position.algoId, position.instId),
|
|
59
|
-
datasource_id: 'OKX',
|
|
60
|
-
product_id: (0, utils_1.encodePath)(position.instType, position.instId),
|
|
61
|
-
direction,
|
|
62
|
-
volume: Math.abs(+position.pos),
|
|
63
|
-
free_volume: +position.pos,
|
|
64
|
-
position_price: +position.avgPx,
|
|
65
|
-
floating_profit: +position.upl,
|
|
66
|
-
closable_price: +position.last,
|
|
67
|
-
valuation: +position.notionalUsd,
|
|
68
|
-
});
|
|
69
|
-
positionValuation += +position.notionalUsd;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
if (leverage === 0) {
|
|
73
|
-
// 实际杠杆为 0,说明没有持仓,直接把投资金额和累计盈亏算到净值里
|
|
74
|
-
totalEquity += +((_c = gridAlgoOrders.data) === null || _c === void 0 ? void 0 : _c[index].investment) + +((_d = gridAlgoOrders.data) === null || _d === void 0 ? void 0 : _d[index].totalPnl);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
// 历史提取金额不会从 investment, totalPnl 扣减
|
|
78
|
-
// 计算净值需要通过仓位的名义价值和实际杠杆计算
|
|
79
|
-
totalEquity += positionValuation / leverage;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
money: {
|
|
84
|
-
currency: 'USDT',
|
|
85
|
-
equity: totalEquity,
|
|
86
|
-
// TODO: 累计策略的可提取资金作为 free
|
|
87
|
-
free: 0,
|
|
88
|
-
},
|
|
89
|
-
positions,
|
|
90
|
-
};
|
|
91
|
-
}, { auto_refresh_interval: 5000 });
|
|
35
|
+
(0, data_account_1.provideAccountInfoService)(terminal, strategyAccountId, () => (0, accountInfos_1.getStrategyAccountInfo)(credential), {
|
|
36
|
+
auto_refresh_interval: 5000,
|
|
37
|
+
});
|
|
92
38
|
}).subscribe();
|
|
93
39
|
const sub = (0, rxjs_1.defer)(() => exports.accountUid$)
|
|
94
40
|
.pipe((0, rxjs_1.first)())
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy-account.js","sourceRoot":"","sources":["../src/strategy-account.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"strategy-account.js","sourceRoot":"","sources":["../src/strategy-account.ts"],"names":[],"mappings":";;;AAAA,uDAAmF;AACnF,+CAA4C;AAC5C,+BAA6F;AAC7F,+BAAiF;AACjF,iDAAwD;AAExD,MAAM,QAAQ,GAAG,mBAAQ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ACF,OAAO;YACL,GAAG,EAAE;gBACH,IAAI,EAAE,CAAC;gBACP,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,MAAM,IAAA,sBAAgB,EAAC,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,IAAA,wCAAyB,EAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC,IAAA,qCAAsB,EAAC,UAAU,CAAC,EAAE;QAC/F,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,MAAM,GAAG,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,mBAAW,CAAC;KACjC,IAAI,CAAC,IAAA,YAAK,GAAE,CAAC;KACb,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE;IACjB,IAAA,+BAAgB,EAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,OAAO,GAAG,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AACtF,CAAC,CAAC,CAAC;AACL,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { defer, filter, first, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';\nimport { getAccountConfig, getDefaultCredential, getGridPositions } from './api';\nimport { getStrategyAccountInfo } from './accountInfos';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\nexport const accountConfig$ = defer(() => getAccountConfig(credential)).pipe(\n repeat({ delay: 10_000 }),\n retry({ delay: 10_000 }),\n shareReplay(1),\n);\n\nexport const accountUid$ = accountConfig$.pipe(\n map((x) => x.data[0].uid),\n filter((x) => !!x),\n shareReplay(1),\n);\n\nexport const strategyAccountId$ = accountUid$.pipe(\n map((uid) => `okx/${uid}/strategy`),\n shareReplay(1),\n);\n\ndefer(async () => {\n const strategyAccountId = await firstValueFrom(strategyAccountId$);\n\n type InferPromise<T> = T extends Promise<infer U> ? U : T;\n\n terminal.server.provideService<\n { account_id: string; algoId: string },\n InferPromise<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\nconst sub = defer(() => accountUid$)\n .pipe(first())\n .subscribe((uid) => {\n addAccountMarket(terminal, { account_id: `okx/${uid}/strategy`, market_id: 'OKX' });\n });\ndefer(() => terminal.dispose$).subscribe(() => sub.unsubscribe());\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-okx",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.26",
|
|
4
4
|
"bin": "lib/cli.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
"temp"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@yuants/protocol": "0.50.
|
|
13
|
-
"@yuants/transfer": "0.2.
|
|
14
|
-
"@yuants/data-account": "0.6.
|
|
15
|
-
"@yuants/data-order": "0.3.
|
|
12
|
+
"@yuants/protocol": "0.50.4",
|
|
13
|
+
"@yuants/transfer": "0.2.33",
|
|
14
|
+
"@yuants/data-account": "0.6.14",
|
|
15
|
+
"@yuants/data-order": "0.3.12",
|
|
16
16
|
"@yuants/utils": "0.11.0",
|
|
17
|
-
"@yuants/cache": "0.
|
|
18
|
-
"@yuants/sql": "0.9.
|
|
19
|
-
"@yuants/data-series": "0.3.
|
|
20
|
-
"@yuants/data-product": "0.4.
|
|
21
|
-
"@yuants/data-ohlc": "0.4.
|
|
22
|
-
"@yuants/data-interest-rate": "0.1.
|
|
23
|
-
"@yuants/data-quote": "0.2.
|
|
24
|
-
"@yuants/data-trade": "0.1.
|
|
17
|
+
"@yuants/cache": "0.3.0",
|
|
18
|
+
"@yuants/sql": "0.9.24",
|
|
19
|
+
"@yuants/data-series": "0.3.45",
|
|
20
|
+
"@yuants/data-product": "0.4.15",
|
|
21
|
+
"@yuants/data-ohlc": "0.4.16",
|
|
22
|
+
"@yuants/data-interest-rate": "0.1.42",
|
|
23
|
+
"@yuants/data-quote": "0.2.37",
|
|
24
|
+
"@yuants/data-trade": "0.1.15",
|
|
25
25
|
"rxjs": "~7.5.6",
|
|
26
26
|
"crypto-js": "^4.2.0",
|
|
27
27
|
"ws": "~8.8.1"
|
package/temp/package-deps.json
CHANGED
|
@@ -1,50 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
"apps/vendor-okx/CHANGELOG.json": "
|
|
3
|
-
"apps/vendor-okx/CHANGELOG.md": "
|
|
2
|
+
"apps/vendor-okx/CHANGELOG.json": "010ffdab5701ba146833116295b9f94b1ef01ae7",
|
|
3
|
+
"apps/vendor-okx/CHANGELOG.md": "aa14ccfb2cc6e9c9a056b10377c5ad0277831be1",
|
|
4
4
|
"apps/vendor-okx/README.md": "ac3d1f6c4c8d73066664699b0bb1b01db02e67a2",
|
|
5
5
|
"apps/vendor-okx/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
6
6
|
"apps/vendor-okx/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
7
7
|
"apps/vendor-okx/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
8
8
|
"apps/vendor-okx/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
9
9
|
"apps/vendor-okx/etc/vendor-okx.api.md": "92c54ccd547d2ad81ca6088158ca193e85c208df",
|
|
10
|
-
"apps/vendor-okx/package.json": "
|
|
11
|
-
"apps/vendor-okx/src/account.ts": "
|
|
10
|
+
"apps/vendor-okx/package.json": "61e42c630aac1f5ae95a7966a0f6281771997b83",
|
|
11
|
+
"apps/vendor-okx/src/account.ts": "70d23dc3cf097b5bb43c07322e1a1429e89074c0",
|
|
12
|
+
"apps/vendor-okx/src/accountInfos/earning.ts": "d1afa6c128c628ebb787860c84f6cee037782fe1",
|
|
13
|
+
"apps/vendor-okx/src/accountInfos/funding.ts": "8ddb44633e8d76975b69695ad1ebcd80b0242fd2",
|
|
14
|
+
"apps/vendor-okx/src/accountInfos/index.ts": "272c4a49a94749b17d83bfb1f39a9bd932707288",
|
|
15
|
+
"apps/vendor-okx/src/accountInfos/loan.ts": "688b1f3cd8937f9b9da4a986e478c3e8efbfeebb",
|
|
16
|
+
"apps/vendor-okx/src/accountInfos/strategy.ts": "dd8a931aa9a85a416c491642a5e6663e8965244c",
|
|
17
|
+
"apps/vendor-okx/src/accountInfos/trading.ts": "9108ed4cf31b86d554db6ccff089c9176688dd06",
|
|
18
|
+
"apps/vendor-okx/src/accountInfos/types.ts": "c3c1096c3ad6849f6f679f1dfe0badb3ae876e41",
|
|
12
19
|
"apps/vendor-okx/src/api-service.ts": "9f236b61d28781eb75ef3d572e75e3b95e4e305a",
|
|
13
20
|
"apps/vendor-okx/src/api.ts": "ed9ad3c6052f0968cf612b474d9301d2316f4a04",
|
|
14
21
|
"apps/vendor-okx/src/cli.ts": "9bf6b5559a6c6f33da20e74cc6c5d702c60ec891",
|
|
15
22
|
"apps/vendor-okx/src/index.ts": "cf3479fcc512941fa3e8550ff06cbe1467bfe705",
|
|
16
23
|
"apps/vendor-okx/src/interest_rate.ts": "192ab4c5fb4cc1075bda57ba3ca6d21b4e5714a9",
|
|
17
|
-
"apps/vendor-okx/src/loan-account.ts": "
|
|
24
|
+
"apps/vendor-okx/src/loan-account.ts": "cba4bc9fa7c4f965f6a1196b4d03925abdf77aea",
|
|
18
25
|
"apps/vendor-okx/src/market-order.ts": "80c8881dc460ca03c655f513adb0653b675f28b3",
|
|
19
26
|
"apps/vendor-okx/src/ohlc.ts": "535f802ef8f3df1468d0e45ba5b7f1b8fa78940c",
|
|
20
|
-
"apps/vendor-okx/src/order-actions.ts": "
|
|
27
|
+
"apps/vendor-okx/src/order-actions.ts": "0d2348a6082cba9a125204a668cfc8bce64358e8",
|
|
21
28
|
"apps/vendor-okx/src/order.ts": "305edb35b895fa7afa187250cf08d50084c978f7",
|
|
29
|
+
"apps/vendor-okx/src/orders/cancelOrder.ts": "5c89d1860c93a0a6de113e5ae398300ec8da6cef",
|
|
30
|
+
"apps/vendor-okx/src/orders/modifyOrder.ts": "48d6df204967c831f4bee3d05429d56c02ab0f20",
|
|
31
|
+
"apps/vendor-okx/src/orders/submitOrder.ts": "dea1824cea155e41fc062c3cbe8a3f3ced7bab8f",
|
|
22
32
|
"apps/vendor-okx/src/product.ts": "2dfbe23705894e3b2d3883aa69c7a989d32ca1d9",
|
|
23
33
|
"apps/vendor-okx/src/provideOHLCFromTimeBackwardService.ts": "3a44206410b5b73683f2395d6c551549b553d7bd",
|
|
24
34
|
"apps/vendor-okx/src/provideSeriesFromTimeBackwardService.ts": "daf3c793eb4fc20e59a740bb69e50fadab5f62f0",
|
|
25
35
|
"apps/vendor-okx/src/public-api.ts": "05b9cddafd09b5c9f65ce4eaeab42832e7d60449",
|
|
26
36
|
"apps/vendor-okx/src/quote.ts": "6ebc494a6d739edfa79cab2f88576df5b0798138",
|
|
27
37
|
"apps/vendor-okx/src/services.ts": "cda765de4da97a532eb7652ea66764e9ba9afe6c",
|
|
28
|
-
"apps/vendor-okx/src/strategy-account.ts": "
|
|
38
|
+
"apps/vendor-okx/src/strategy-account.ts": "6a224521d192a69c6d9051fde87d2a95a506afae",
|
|
29
39
|
"apps/vendor-okx/src/trade.ts": "06a443dc3cd8caf016211f85599d063a1a12c63b",
|
|
30
40
|
"apps/vendor-okx/src/transfer.ts": "e2284568d755b87904160d832e25affc90f4f35c",
|
|
31
41
|
"apps/vendor-okx/src/websocket.ts": "3614db6be5dc7dba842ae4dfdd0a7c8de201b21a",
|
|
32
42
|
"apps/vendor-okx/src/ws.ts": "7aa1561c8c524dee838817eaeda5031d389ec877",
|
|
33
43
|
"apps/vendor-okx/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
|
|
34
44
|
"apps/vendor-okx/.rush/temp/shrinkwrap-deps.json": "41772be396e5468b5ef42f47388dc75c7a566c7b",
|
|
35
|
-
"libraries/protocol/temp/package-deps.json": "
|
|
36
|
-
"libraries/transfer/temp/package-deps.json": "
|
|
37
|
-
"libraries/data-account/temp/package-deps.json": "
|
|
38
|
-
"libraries/data-order/temp/package-deps.json": "
|
|
45
|
+
"libraries/protocol/temp/package-deps.json": "35bc77333a1c85db1cd130579963e8cefa00f56c",
|
|
46
|
+
"libraries/transfer/temp/package-deps.json": "708a4caf79d042cad56a39f0b00d399bca04af40",
|
|
47
|
+
"libraries/data-account/temp/package-deps.json": "1063c689ee00118b3bf78dec1fe00efe0a258db3",
|
|
48
|
+
"libraries/data-order/temp/package-deps.json": "943238fe32aa351d20da29ba160399268b01bf29",
|
|
39
49
|
"libraries/utils/temp/package-deps.json": "c58f1ca8f498315d9a0219ca8c498299a41d297b",
|
|
40
|
-
"libraries/cache/temp/package-deps.json": "
|
|
41
|
-
"libraries/sql/temp/package-deps.json": "
|
|
42
|
-
"libraries/data-series/temp/package-deps.json": "
|
|
43
|
-
"libraries/data-product/temp/package-deps.json": "
|
|
44
|
-
"libraries/data-ohlc/temp/package-deps.json": "
|
|
45
|
-
"libraries/data-interest-rate/temp/package-deps.json": "
|
|
46
|
-
"libraries/data-quote/temp/package-deps.json": "
|
|
47
|
-
"libraries/data-trade/temp/package-deps.json": "
|
|
50
|
+
"libraries/cache/temp/package-deps.json": "49789a92426969daa31f0c956bb56bd783929765",
|
|
51
|
+
"libraries/sql/temp/package-deps.json": "e3b6f24485a429fb24cacbf0d6150f55ca394706",
|
|
52
|
+
"libraries/data-series/temp/package-deps.json": "d5269fad8f63460b1b5f29ba701ad3a9457e0061",
|
|
53
|
+
"libraries/data-product/temp/package-deps.json": "0a4e14971c7dc350b84712fb16c07fefad351619",
|
|
54
|
+
"libraries/data-ohlc/temp/package-deps.json": "6e10227e1c394ad0b5a71e0f810914760e9b7956",
|
|
55
|
+
"libraries/data-interest-rate/temp/package-deps.json": "11bb199efb64628f67b1165e11d6c85dd7114a9a",
|
|
56
|
+
"libraries/data-quote/temp/package-deps.json": "752ea44d75cbe7a652ace79629c02ca92a92cf1d",
|
|
57
|
+
"libraries/data-trade/temp/package-deps.json": "3383f312b7263d86dede5a11293727746a252e5b",
|
|
48
58
|
"libraries/extension/temp/package-deps.json": "fd20507284f9fd74b4de6f9855c8cead9cc132e8",
|
|
49
59
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|
|
50
60
|
}
|