@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/transfer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,iCAAiC,GAClC,MAAM,mBAAmB,CAAC;AAE3B,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;AAE1C,MAAM,sBAAsB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAQ,EAAE,CAAC,CAAC;AAEvG,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,cAAc,GAAG,MAAM,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC1D,IAAI,CAAC,cAA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BACxB,QAAQ;gBACR,UAAU,EAAE,kBAAkB;gBAC9B,UAAU,EAAE,sBAAsB,CAAC,GAAG,CAAC;gBACvC,QAAQ,EAAE,MAAM;gBAChB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;wBACpB,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE;4BACzD,IAAI,EAAE,GAAG;4BACT,GAAG,EAAE,MAAM;4BACX,GAAG,EAAE,GAAG,KAAK,CAAC,cAAc,EAAE;4BAC9B,IAAI,EAAE,GAAG;4BACT,EAAE,EAAE,GAAG;yBACR,CAAC,CAAC;wBACH,IAAI,cAAc,CAAC,IAAI,KAAK,GAAG,EAAE;4BAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,GAAG,EAAE,CAAC;yBACvD;wBACD,MAAM,cAAc,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;wBACtD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;oBAC/C,CAAC;iBACF;gBACD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBACtB,oFAAoF;oBACpF,qGAAqG;oBACrG,uDAAuD;oBACvD,0BAA0B;oBAC1B,wDAAwD;oBACxD,IAAI;oBACJ,mEAAmE;oBACnE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC;gBACtE,CAAC;aACF,CAAC,CAAC;SACJ;KACF;AACH,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { formatTime } from '@yuants/utils';\nimport { defer } from 'rxjs';\nimport { accountConfigCache } from './account';\nimport {\n getAssetCurrencies,\n getAssetDepositAddress,\n getAssetDepositHistory,\n getAssetWithdrawalHistory,\n getDefaultCredential,\n getSubAccountList,\n postAssetTransfer,\n postAssetWithdrawal,\n postFinanceSavingsPurchaseRedempt,\n} from './api/private-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credential = getDefaultCredential();\n\nconst cacheOfAssetCurrencies = createCache(() => getAssetCurrencies(credential), { expire: 3600_000 });\n\ndefer(async () => {\n const account_config = await accountConfigCache.query('');\n if (!account_config) throw new Error('Failed to get account config');\n console.info(formatTime(Date.now()), 'AccountConfig', JSON.stringify(account_config));\n const { mainUid, uid } = account_config.data[0];\n const isMainAccount = mainUid === uid;\n\n const TRADING_ACCOUNT_ID = `okx/${uid}/trading`;\n const FUNDING_ACCOUNT_ID = `okx/${uid}/funding/USDT`;\n const EARNING_ACCOUNT_ID = `okx/${uid}/earning/USDT`;\n\n // BLOCK_CHAIN: only available for main account\n if (isMainAccount) {\n const depositAddressRes = await getAssetDepositAddress(credential, { ccy: 'USDT' });\n console.info(formatTime(Date.now()), 'DepositAddress', JSON.stringify(depositAddressRes.data));\n const addresses = depositAddressRes.data.filter((v) => v.chain === 'USDT-TRC20' && v.to === '6');\n for (const address of addresses) {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: 'TRC20',\n currency: 'USDT',\n address: address.addr,\n onApply: {\n INIT: async (order) => {\n if (\n !order.current_amount ||\n order.current_amount < 3 // 最小提币额度\n ) {\n return { state: 'ERROR', message: 'Amount too small' };\n }\n const res = await cacheOfAssetCurrencies.query('');\n const theRes = res?.data?.find((x) => x.ccy === 'USDT' && x.chain === 'USDT-TRC20');\n const _fee = theRes?.minFee;\n if (!_fee) return { state: 'ERROR', message: 'Currency Info not found, cannot get fee' };\n const fee = +_fee;\n const amt = Math.floor(order.current_amount - fee);\n const transferResult = await postAssetWithdrawal(credential, {\n amt: `${amt}`,\n ccy: 'USDT',\n chain: 'USDT-TRC20',\n fee: `${fee}`,\n dest: '4', // 链上提币\n toAddr: order.current_rx_address!,\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const wdId = transferResult.data[0]?.wdId;\n return { state: 'AWAIT_TX_ID', context: wdId };\n },\n AWAIT_TX_ID: async (transferOrder) => {\n const wdId = transferOrder.current_tx_context;\n const withdrawalHistory = await getAssetWithdrawalHistory(credential, { wdId });\n const txId = withdrawalHistory.data?.[0]?.txId;\n if (!txId) {\n return { state: 'AWAIT_TX_ID', context: wdId };\n }\n return { state: 'COMPLETE', transaction_id: txId };\n },\n },\n onEval: async (transferOrder) => {\n const checkResult = await getAssetDepositHistory(credential, {\n ccy: 'USDT',\n txId: transferOrder.current_transaction_id,\n type: '4',\n });\n\n if (checkResult.code !== '0') {\n return {\n state: 'INIT',\n };\n }\n\n if (checkResult.data[0].state !== '2') {\n return { state: 'PENDING' };\n }\n const received_amount = +checkResult.data[0].amt;\n return { state: 'COMPLETE', received_amount };\n },\n });\n }\n }\n\n // Funding-Trading\n {\n const FUNDING_TRADING_NETWORK_ID = `OKX/${uid}/Funding-Trading`;\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: FUNDING_TRADING_NETWORK_ID,\n currency: 'USDT',\n address: 'funding',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: '0',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '18',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n addAccountTransferAddress({\n terminal,\n account_id: TRADING_ACCOUNT_ID,\n network_id: FUNDING_TRADING_NETWORK_ID,\n currency: 'USDT',\n address: 'trading',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: '0',\n ccy: order.currency,\n amt: `${order.current_amount}`,\n from: '18',\n to: '6',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n }\n // Funding-Earning\n {\n const FUNDING_EARNING_NETWORK_ID = `OKX/${uid}/Funding-Earning`;\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: FUNDING_EARNING_NETWORK_ID,\n currency: 'USDT',\n address: 'funding',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postFinanceSavingsPurchaseRedempt(credential, {\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n side: 'purchase',\n rate: '0.01',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: 'ok' };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n addAccountTransferAddress({\n terminal,\n account_id: EARNING_ACCOUNT_ID,\n network_id: FUNDING_EARNING_NETWORK_ID,\n currency: 'USDT',\n address: 'earning',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postFinanceSavingsPurchaseRedempt(credential, {\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n side: 'redempt',\n rate: '0.01',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: 'ok' };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n }\n\n // SubAccount\n {\n const getSubAccountNetworkId = (subUid: string) => `OKX/${mainUid}/SubAccount/${subUid}`;\n if (isMainAccount) {\n const subAcctsRes = await getSubAccountList(credential);\n for (const item of subAcctsRes.data || []) {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: getSubAccountNetworkId(item.uid),\n currency: 'USDT',\n address: 'main',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: '1',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '6',\n subAcct: item.subAcct,\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (order) => {\n // ISSUE: OKX API Issue: transId is incorrect or transId does not match with ‘ type’\n // const checkResult = await client.getAssetTransferState({ transId: order.current_transaction_id });\n // const received_amount = checkResult?.data?.[0]?.amt;\n // if (!received_amount) {\n // return { state: 'INIT', message: checkResult.msg };\n // }\n // return { state: 'COMPLETE', received_amount: +received_amount };\n\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n }\n }\n // SubAccount API\n else {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: getSubAccountNetworkId(uid),\n currency: 'USDT',\n address: 'sub',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: '3',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '6',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (order) => {\n // ISSUE: OKX API Issue: transId is incorrect or transId does not match with ‘ type’\n // const checkResult = await client.getAssetTransferState({ transId: order.current_transaction_id });\n // const received_amount = checkResult?.data?.[0]?.amt;\n // if (!received_amount) {\n // return { state: 'INIT', message: checkResult.msg };\n // }\n // return { state: 'COMPLETE', received_amount: +received_amount };\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n }\n }\n}).subscribe();\n"]}
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"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H,IAAI,cAAc,CAAC,IAAI,KAAK,GAAG,EAAE;4BAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,GAAG,EAAE,CAAC;yBACvD;wBACD,MAAM,cAAc,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;wBACtD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;oBAC/C,CAAC;iBACF;gBACD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBACtB,oFAAoF;oBACpF,qGAAqG;oBACrG,uDAAuD;oBACvD,0BAA0B;oBAC1B,wDAAwD;oBACxD,IAAI;oBACJ,mEAAmE;oBACnE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC;gBACtE,CAAC;aACF,CAAC,CAAC;SACJ;KACF;AACH,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { formatTime } from '@yuants/utils';\nimport { defer } from 'rxjs';\nimport {\n getAccountConfig,\n getAssetCurrencies,\n getAssetDepositAddress,\n getAssetDepositHistory,\n getAssetWithdrawalHistory,\n getDefaultCredential,\n getSubAccountList,\n postAssetTransfer,\n postAssetWithdrawal,\n postFinanceSavingsPurchaseRedempt,\n} from './api/private-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credential = getDefaultCredential();\n\nconst cacheOfAssetCurrencies = createCache(() => getAssetCurrencies(credential), { expire: 3600_000 });\n\ndefer(async () => {\n const account_config = await getAccountConfig(credential);\n if (!account_config) throw new Error('Failed to get account config');\n console.info(formatTime(Date.now()), 'AccountConfig', JSON.stringify(account_config));\n const { mainUid, uid } = account_config.data[0];\n const isMainAccount = mainUid === uid;\n\n const TRADING_ACCOUNT_ID = `okx/${uid}/trading`;\n const FUNDING_ACCOUNT_ID = `okx/${uid}/funding/USDT`;\n const EARNING_ACCOUNT_ID = `okx/${uid}/earning/USDT`;\n\n // BLOCK_CHAIN: only available for main account\n if (isMainAccount) {\n const depositAddressRes = await getAssetDepositAddress(credential, { ccy: 'USDT' });\n console.info(formatTime(Date.now()), 'DepositAddress', JSON.stringify(depositAddressRes.data));\n const addresses = depositAddressRes.data.filter((v) => v.chain === 'USDT-TRC20' && v.to === '6');\n for (const address of addresses) {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: 'TRC20',\n currency: 'USDT',\n address: address.addr,\n onApply: {\n INIT: async (order) => {\n if (\n !order.current_amount ||\n order.current_amount < 3 // 最小提币额度\n ) {\n return { state: 'ERROR', message: 'Amount too small' };\n }\n const res = await cacheOfAssetCurrencies.query('');\n const theRes = res?.data?.find((x) => x.ccy === 'USDT' && x.chain === 'USDT-TRC20');\n const _fee = theRes?.minFee;\n if (!_fee) return { state: 'ERROR', message: 'Currency Info not found, cannot get fee' };\n const fee = +_fee;\n const amt = Math.floor(order.current_amount - fee);\n const transferResult = await postAssetWithdrawal(credential, {\n amt: `${amt}`,\n ccy: 'USDT',\n chain: 'USDT-TRC20',\n fee: `${fee}`,\n dest: '4', // 链上提币\n toAddr: order.current_rx_address!,\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const wdId = transferResult.data[0]?.wdId;\n return { state: 'AWAIT_TX_ID', context: wdId };\n },\n AWAIT_TX_ID: async (transferOrder) => {\n const wdId = transferOrder.current_tx_context;\n const withdrawalHistory = await getAssetWithdrawalHistory(credential, { wdId });\n const txId = withdrawalHistory.data?.[0]?.txId;\n if (!txId) {\n return { state: 'AWAIT_TX_ID', context: wdId };\n }\n return { state: 'COMPLETE', transaction_id: txId };\n },\n },\n onEval: async (transferOrder) => {\n const checkResult = await getAssetDepositHistory(credential, {\n ccy: 'USDT',\n txId: transferOrder.current_transaction_id,\n type: '4',\n });\n\n if (checkResult.code !== '0') {\n return {\n state: 'INIT',\n };\n }\n\n if (checkResult.data[0].state !== '2') {\n return { state: 'PENDING' };\n }\n const received_amount = +checkResult.data[0].amt;\n return { state: 'COMPLETE', received_amount };\n },\n });\n }\n }\n\n // Funding-Trading\n {\n const FUNDING_TRADING_NETWORK_ID = `OKX/${uid}/Funding-Trading`;\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: FUNDING_TRADING_NETWORK_ID,\n currency: 'USDT',\n address: 'funding',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: '0',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '18',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n addAccountTransferAddress({\n terminal,\n account_id: TRADING_ACCOUNT_ID,\n network_id: FUNDING_TRADING_NETWORK_ID,\n currency: 'USDT',\n address: 'trading',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: '0',\n ccy: order.currency,\n amt: `${order.current_amount}`,\n from: '18',\n to: '6',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n }\n // Funding-Earning\n {\n const FUNDING_EARNING_NETWORK_ID = `OKX/${uid}/Funding-Earning`;\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: FUNDING_EARNING_NETWORK_ID,\n currency: 'USDT',\n address: 'funding',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postFinanceSavingsPurchaseRedempt(credential, {\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n side: 'purchase',\n rate: '0.01',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: 'ok' };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n addAccountTransferAddress({\n terminal,\n account_id: EARNING_ACCOUNT_ID,\n network_id: FUNDING_EARNING_NETWORK_ID,\n currency: 'USDT',\n address: 'earning',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postFinanceSavingsPurchaseRedempt(credential, {\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n side: 'redempt',\n rate: '0.01',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: 'ok' };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n }\n\n // SubAccount\n {\n const getSubAccountNetworkId = (subUid: string) => `OKX/${mainUid}/SubAccount/${subUid}`;\n if (isMainAccount) {\n const subAcctsRes = await getSubAccountList(credential);\n for (const item of subAcctsRes.data || []) {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: getSubAccountNetworkId(item.uid),\n currency: 'USDT',\n address: 'main',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: '1',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '6',\n subAcct: item.subAcct,\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (order) => {\n // ISSUE: OKX API Issue: transId is incorrect or transId does not match with ‘ type’\n // const checkResult = await client.getAssetTransferState({ transId: order.current_transaction_id });\n // const received_amount = checkResult?.data?.[0]?.amt;\n // if (!received_amount) {\n // return { state: 'INIT', message: checkResult.msg };\n // }\n // return { state: 'COMPLETE', received_amount: +received_amount };\n\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n }\n }\n // SubAccount API\n else {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: getSubAccountNetworkId(uid),\n currency: 'USDT',\n address: 'sub',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: '3',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '6',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (order) => {\n // ISSUE: OKX API Issue: transId is incorrect or transId does not match with ‘ type’\n // const checkResult = await client.getAssetTransferState({ transId: order.current_transaction_id });\n // const received_amount = checkResult?.data?.[0]?.amt;\n // if (!received_amount) {\n // return { state: 'INIT', message: checkResult.msg };\n // }\n // return { state: 'COMPLETE', received_amount: +received_amount };\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n }\n }\n}).subscribe();\n"]}
|
package/lib/account.d.ts
CHANGED
|
@@ -1,32 +1,3 @@
|
|
|
1
1
|
import { marketIndexTickerUSDT$ } from './accountInfos';
|
|
2
|
-
export declare const accountConfigCache: import("@yuants/cache").ICache<{
|
|
3
|
-
code: string;
|
|
4
|
-
data: {
|
|
5
|
-
acctLv: string;
|
|
6
|
-
autoLoan: boolean;
|
|
7
|
-
ctIsoMode: string;
|
|
8
|
-
greeksType: string;
|
|
9
|
-
level: string;
|
|
10
|
-
levelTmp: string;
|
|
11
|
-
mgnIsoMode: string;
|
|
12
|
-
posMode: string;
|
|
13
|
-
spotOffsetType: string;
|
|
14
|
-
uid: string;
|
|
15
|
-
label: string;
|
|
16
|
-
roleType: string;
|
|
17
|
-
traderInsts: unknown[];
|
|
18
|
-
spotRoleType: string;
|
|
19
|
-
spotTraderInsts: unknown[];
|
|
20
|
-
opAuth: string;
|
|
21
|
-
kycLv: string;
|
|
22
|
-
ip: string;
|
|
23
|
-
perm: string;
|
|
24
|
-
mainUid: string;
|
|
25
|
-
}[];
|
|
26
|
-
msg: string;
|
|
27
|
-
}>;
|
|
28
|
-
export declare const accountUidCache: import("@yuants/cache").ICache<string>;
|
|
29
|
-
export declare const getTradingAccountId: () => Promise<string>;
|
|
30
|
-
export declare const getStrategyAccountId: () => Promise<string>;
|
|
31
2
|
export { marketIndexTickerUSDT$ };
|
|
32
3
|
//# sourceMappingURL=account.d.ts.map
|
package/lib/account.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAqDxB,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
package/lib/account.js
CHANGED
|
@@ -1,84 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.marketIndexTickerUSDT$ =
|
|
4
|
-
const cache_1 = require("@yuants/cache");
|
|
3
|
+
exports.marketIndexTickerUSDT$ = void 0;
|
|
5
4
|
const data_account_1 = require("@yuants/data-account");
|
|
6
5
|
const data_order_1 = require("@yuants/data-order");
|
|
7
6
|
const protocol_1 = require("@yuants/protocol");
|
|
8
|
-
const utils_1 = require("@yuants/utils");
|
|
9
7
|
const rxjs_1 = require("rxjs");
|
|
10
8
|
const accountInfos_1 = require("./accountInfos");
|
|
11
9
|
Object.defineProperty(exports, "marketIndexTickerUSDT$", { enumerable: true, get: function () { return accountInfos_1.marketIndexTickerUSDT$; } });
|
|
10
|
+
const uid_1 = require("./accountInfos/uid");
|
|
12
11
|
const private_api_1 = require("./api/private-api");
|
|
12
|
+
const listOrders_1 = require("./orders/listOrders");
|
|
13
13
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
14
14
|
const credential = (0, private_api_1.getDefaultCredential)();
|
|
15
|
-
exports.accountConfigCache = (0, cache_1.createCache)(() => (0, private_api_1.getAccountConfig)(credential), {
|
|
16
|
-
expire: 100000,
|
|
17
|
-
swrAfter: 10000,
|
|
18
|
-
});
|
|
19
|
-
exports.accountUidCache = (0, cache_1.createCache)(async () => {
|
|
20
|
-
const config = await exports.accountConfigCache.query('');
|
|
21
|
-
return config === null || config === void 0 ? void 0 : config.data[0].uid;
|
|
22
|
-
});
|
|
23
15
|
(0, rxjs_1.defer)(async () => {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return orders.data.map((x) => {
|
|
29
|
-
const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
|
|
30
|
-
const order_direction = x.side === 'buy'
|
|
31
|
-
? x.posSide === 'long'
|
|
32
|
-
? 'OPEN_LONG'
|
|
33
|
-
: 'CLOSE_SHORT'
|
|
34
|
-
: x.posSide === 'short'
|
|
35
|
-
? 'OPEN_SHORT'
|
|
36
|
-
: 'CLOSE_LONG';
|
|
37
|
-
return {
|
|
38
|
-
order_id: x.ordId,
|
|
39
|
-
account_id,
|
|
40
|
-
product_id: (0, utils_1.encodePath)(x.instType, x.instId),
|
|
41
|
-
submit_at: +x.cTime,
|
|
42
|
-
filled_at: +x.fillTime,
|
|
43
|
-
order_type,
|
|
44
|
-
order_direction,
|
|
45
|
-
volume: +x.sz,
|
|
46
|
-
traded_volume: +x.accFillSz,
|
|
47
|
-
price: +x.px,
|
|
48
|
-
traded_price: +x.avgPx,
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
}, { auto_refresh_interval: 5000 });
|
|
16
|
+
const account_id = await (0, uid_1.getTradingAccountId)(credential);
|
|
17
|
+
(0, data_order_1.providePendingOrdersService)(terminal, account_id, async () => (0, listOrders_1.listOrders)(credential, account_id), {
|
|
18
|
+
auto_refresh_interval: 5000,
|
|
19
|
+
});
|
|
52
20
|
}).subscribe();
|
|
53
|
-
const getTradingAccountId = async () => {
|
|
54
|
-
const uid = await exports.accountUidCache.query('');
|
|
55
|
-
return `okx/${uid}/trading`;
|
|
56
|
-
};
|
|
57
|
-
exports.getTradingAccountId = getTradingAccountId;
|
|
58
|
-
const getStrategyAccountId = async () => {
|
|
59
|
-
const uid = await exports.accountUidCache.query('');
|
|
60
|
-
return `okx/${uid}/strategy`;
|
|
61
|
-
};
|
|
62
|
-
exports.getStrategyAccountId = getStrategyAccountId;
|
|
63
21
|
(0, rxjs_1.defer)(async () => {
|
|
64
|
-
const tradingAccountId = await (0,
|
|
22
|
+
const tradingAccountId = await (0, uid_1.getTradingAccountId)(credential);
|
|
65
23
|
(0, data_account_1.addAccountMarket)(terminal, { account_id: tradingAccountId, market_id: 'OKX' });
|
|
66
24
|
(0, data_account_1.provideAccountInfoService)(terminal, tradingAccountId, () => (0, accountInfos_1.getTradingAccountInfo)(credential), {
|
|
67
25
|
auto_refresh_interval: 1000,
|
|
68
26
|
});
|
|
69
27
|
}).subscribe();
|
|
70
28
|
(0, rxjs_1.defer)(async () => {
|
|
71
|
-
const
|
|
72
|
-
const fundingAccountId = `okx/${uid}/funding/USDT`;
|
|
29
|
+
const fundingAccountId = await (0, uid_1.getFundingAccountId)(credential);
|
|
73
30
|
(0, data_account_1.provideAccountInfoService)(terminal, fundingAccountId, () => (0, accountInfos_1.getFundingAccountInfo)(credential), {
|
|
74
31
|
auto_refresh_interval: 1000,
|
|
75
32
|
});
|
|
76
33
|
}).subscribe();
|
|
77
34
|
(0, rxjs_1.defer)(async () => {
|
|
78
|
-
const
|
|
79
|
-
const earningAccountId = `okx/${uid}/earning/USDT`;
|
|
35
|
+
const earningAccountId = await (0, uid_1.getEarningAccountId)(credential);
|
|
80
36
|
(0, data_account_1.provideAccountInfoService)(terminal, earningAccountId, () => (0, accountInfos_1.getEarningAccountInfo)(credential), {
|
|
81
37
|
auto_refresh_interval: 5000,
|
|
82
38
|
});
|
|
83
39
|
}).subscribe();
|
|
40
|
+
(0, rxjs_1.defer)(async () => {
|
|
41
|
+
const loanAccountId = await (0, uid_1.getLoanAccountId)(credential);
|
|
42
|
+
(0, data_account_1.provideAccountInfoService)(protocol_1.Terminal.fromNodeEnv(), loanAccountId, () => (0, accountInfos_1.getLoanAccountInfo)(credential), {
|
|
43
|
+
auto_refresh_interval: 1000,
|
|
44
|
+
});
|
|
45
|
+
}).subscribe();
|
|
84
46
|
//# sourceMappingURL=account.js.map
|
package/lib/account.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;AAAA,uDAAmF;AACnF,mDAAiE;AACjE,+CAA4C;AAC5C,+BAA6B;AAC7B,iDAMwB;AAqDf,uGAtDP,qCAAsB,OAsDO;AApD/B,4CAK4B;AAC5B,mDAAyD;AACzD,oDAAiD;AAEjD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,UAAU,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAAU,CAAC,CAAC;IACzD,IAAA,wCAA2B,EAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,IAAA,uBAAU,EAAC,UAAU,EAAE,UAAU,CAAC,EAAE;QAChG,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM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rG,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,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,15 @@
|
|
|
1
|
+
import { ICredential } from '../api/private-api';
|
|
2
|
+
export declare const getUid: (credential: ICredential) => Promise<string | undefined>;
|
|
3
|
+
export declare const getAccountIds: (credential: ICredential) => Promise<{
|
|
4
|
+
trading: string;
|
|
5
|
+
strategy: string;
|
|
6
|
+
loan: string;
|
|
7
|
+
earning: string;
|
|
8
|
+
funding: string;
|
|
9
|
+
} | undefined>;
|
|
10
|
+
export declare const getTradingAccountId: (credential: ICredential) => Promise<string>;
|
|
11
|
+
export declare const getStrategyAccountId: (credential: ICredential) => Promise<string>;
|
|
12
|
+
export declare const getLoanAccountId: (credential: ICredential) => Promise<string>;
|
|
13
|
+
export declare const getEarningAccountId: (credential: ICredential) => Promise<string>;
|
|
14
|
+
export declare const getFundingAccountId: (credential: ICredential) => Promise<string>;
|
|
15
|
+
//# sourceMappingURL=uid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uid.d.ts","sourceRoot":"","sources":["../../src/accountInfos/uid.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAuBnE,eAAO,MAAM,MAAM,eAAsB,WAAW,gCAEnD,CAAC;AAEF,eAAO,MAAM,aAAa,eAAsB,WAAW;;;;;;cAE1D,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC;AAEpD,eAAO,MAAM,oBAAoB,eAAsB,WAAW,oBACd,CAAC;AAErD,eAAO,MAAM,gBAAgB,eAAsB,WAAW,oBACd,CAAC;AAEjD,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC;AAEpD,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFundingAccountId = exports.getEarningAccountId = exports.getLoanAccountId = exports.getStrategyAccountId = exports.getTradingAccountId = exports.getAccountIds = exports.getUid = void 0;
|
|
4
|
+
const cache_1 = require("@yuants/cache");
|
|
5
|
+
const private_api_1 = require("../api/private-api");
|
|
6
|
+
const accountConfigCache = (0, cache_1.createCache)((key) => (0, private_api_1.getAccountConfig)(JSON.parse(key)), {
|
|
7
|
+
expire: 100000,
|
|
8
|
+
swrAfter: 10000,
|
|
9
|
+
});
|
|
10
|
+
const accountUidCache = (0, cache_1.createCache)(async (key) => {
|
|
11
|
+
const config = await accountConfigCache.query(key);
|
|
12
|
+
return config === null || config === void 0 ? void 0 : config.data[0].uid;
|
|
13
|
+
});
|
|
14
|
+
const accountIdCache = (0, cache_1.createCache)(async (key) => {
|
|
15
|
+
const uid = await accountUidCache.query(key);
|
|
16
|
+
return {
|
|
17
|
+
trading: `okx/${uid}/trading`,
|
|
18
|
+
strategy: `okx/${uid}/strategy`,
|
|
19
|
+
loan: `okx/${uid}/loan/USDT`,
|
|
20
|
+
earning: `okx/${uid}/earning/USDT`,
|
|
21
|
+
funding: `okx/${uid}/funding/USDT`,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
const getUid = async (credential) => {
|
|
25
|
+
return accountUidCache.query(JSON.stringify(credential));
|
|
26
|
+
};
|
|
27
|
+
exports.getUid = getUid;
|
|
28
|
+
const getAccountIds = async (credential) => {
|
|
29
|
+
return accountIdCache.query(JSON.stringify(credential));
|
|
30
|
+
};
|
|
31
|
+
exports.getAccountIds = getAccountIds;
|
|
32
|
+
const getTradingAccountId = async (credential) => (0, exports.getAccountIds)(credential).then((x) => x.trading);
|
|
33
|
+
exports.getTradingAccountId = getTradingAccountId;
|
|
34
|
+
const getStrategyAccountId = async (credential) => (0, exports.getAccountIds)(credential).then((x) => x.strategy);
|
|
35
|
+
exports.getStrategyAccountId = getStrategyAccountId;
|
|
36
|
+
const getLoanAccountId = async (credential) => (0, exports.getAccountIds)(credential).then((x) => x.loan);
|
|
37
|
+
exports.getLoanAccountId = getLoanAccountId;
|
|
38
|
+
const getEarningAccountId = async (credential) => (0, exports.getAccountIds)(credential).then((x) => x.earning);
|
|
39
|
+
exports.getEarningAccountId = getEarningAccountId;
|
|
40
|
+
const getFundingAccountId = async (credential) => (0, exports.getAccountIds)(credential).then((x) => x.funding);
|
|
41
|
+
exports.getFundingAccountId = getFundingAccountId;
|
|
42
|
+
//# sourceMappingURL=uid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uid.js","sourceRoot":"","sources":["../../src/accountInfos/uid.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,oDAAmE;AAEnE,MAAM,kBAAkB,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,8BAAgB,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;IACjF,MAAM,EAAE,MAAO;IACf,QAAQ,EAAE,KAAM;CACjB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,IAAA,mBAAW,EAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAChD,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnD,OAAO,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;AAC7B,CAAC,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,IAAA,mBAAW,EAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAC/C,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO;QACL,OAAO,EAAE,OAAO,GAAG,UAAU;QAC7B,QAAQ,EAAE,OAAO,GAAG,WAAW;QAC/B,IAAI,EAAE,OAAO,GAAG,YAAY;QAC5B,OAAO,EAAE,OAAO,GAAG,eAAe;QAClC,OAAO,EAAE,OAAO,GAAG,eAAe;KACnC,CAAC;AACJ,CAAC,CAAC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EAAE,EAAE,CACnE,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC;AADvC,QAAA,mBAAmB,uBACoB","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/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,CAAC;AACnB,OAAO,eAAe,CAAC;AACvB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","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"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qBAAmB;AACnB,yBAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qBAAmB;AACnB,yBAAuB;AACvB,mBAAiB;AACjB,2BAAyB;AACzB,2CAAyC;AACzC,uCAAqC;AACrC,sCAAoC;AACpC,8BAA4B;AAC5B,+BAA6B;AAC7B,sBAAoB;AACpB,8BAA4B;AAC5B,mBAAiB;AACjB,sBAAoB","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"]}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const data_order_1 = require("@yuants/data-order");
|
|
4
4
|
const protocol_1 = require("@yuants/protocol");
|
|
5
5
|
const cancelOrder_1 = require("./orders/cancelOrder");
|
|
6
|
+
const listOrders_1 = require("./orders/listOrders");
|
|
6
7
|
const modifyOrder_1 = require("./orders/modifyOrder");
|
|
7
8
|
const submitOrder_1 = require("./orders/submitOrder");
|
|
8
9
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
@@ -18,5 +19,6 @@ const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
|
18
19
|
submitOrder: submitOrder_1.submitOrder,
|
|
19
20
|
modifyOrder: modifyOrder_1.modifyOrder,
|
|
20
21
|
cancelOrder: cancelOrder_1.cancelOrder,
|
|
22
|
+
listOrders: listOrders_1.listOrders,
|
|
21
23
|
});
|
|
22
24
|
//# 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,mDAAuE;AACvE,+CAA4C;AAE5C,sDAAmD;AACnD,sDAAmD;AACnD,sDAAmD;AAEnD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,8CAAiC,EAC/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,mDAAuE;AACvE,+CAA4C;AAE5C,sDAAmD;AACnD,oDAAiD;AACjD,sDAAmD;AACnD,sDAAmD;AAEnD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,8CAAiC,EAC/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,yBAAW;IACxB,WAAW,EAAE,yBAAW;IACxB,WAAW,EAAE,yBAAW;IACxB,UAAU,EAAE,uBAAU;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/lib/order-actions.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const protocol_1 = require("@yuants/protocol");
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
|
-
const account_1 = require("./account");
|
|
6
5
|
const private_api_1 = require("./api/private-api");
|
|
7
6
|
const cancelOrder_1 = require("./orders/cancelOrder");
|
|
8
7
|
const modifyOrder_1 = require("./orders/modifyOrder");
|
|
9
8
|
const submitOrder_1 = require("./orders/submitOrder");
|
|
9
|
+
const uid_1 = require("./accountInfos/uid");
|
|
10
10
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
11
11
|
const credential = (0, private_api_1.getDefaultCredential)();
|
|
12
12
|
(0, rxjs_1.defer)(async () => {
|
|
13
|
-
const tradingAccountId = await (0,
|
|
13
|
+
const tradingAccountId = await (0, uid_1.getTradingAccountId)(credential);
|
|
14
14
|
terminal.server.provideService('SubmitOrder', {
|
|
15
15
|
required: ['account_id'],
|
|
16
16
|
properties: {
|
package/lib/order-actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-actions.js","sourceRoot":"","sources":["../src/order-actions.ts"],"names":[],"mappings":";;AACA,+CAA4C;AAC5C,+BAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"order-actions.js","sourceRoot":"","sources":["../src/order-actions.ts"],"names":[],"mappings":";;AACA,+CAA4C;AAC5C,+BAA6B;AAC7B,mDAAyD;AACzD,sDAAmD;AACnD,sDAAmD;AACnD,sDAAmD;AACnD,4CAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAAU,CAAC,CAAC;IAC/D,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,aAAa,EACb;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,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,IAAA,yBAAW,EAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;IAC3F,CAAC,CACF,CAAC;IAEF,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,aAAa,EACb;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,MAAM,IAAA,yBAAW,EAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QACvC,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;IAC7C,CAAC,CACF,CAAC;IAEF,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,aAAa,EACb;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,MAAM,IAAA,yBAAW,EAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QACvC,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,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/lib/order.js
CHANGED
|
@@ -5,9 +5,10 @@ const protocol_1 = require("@yuants/protocol");
|
|
|
5
5
|
const sql_1 = require("@yuants/sql");
|
|
6
6
|
const utils_1 = require("@yuants/utils");
|
|
7
7
|
const rxjs_1 = require("rxjs");
|
|
8
|
-
const account_1 = require("./account");
|
|
9
8
|
const private_api_1 = require("./api/private-api");
|
|
9
|
+
const uid_1 = require("./accountInfos/uid");
|
|
10
10
|
exports.order$ = new rxjs_1.Subject();
|
|
11
|
+
const credential = (0, private_api_1.getDefaultCredential)();
|
|
11
12
|
exports.order$
|
|
12
13
|
.pipe(
|
|
13
14
|
//
|
|
@@ -71,9 +72,9 @@ const makeOrder = (x, account_id) => {
|
|
|
71
72
|
};
|
|
72
73
|
};
|
|
73
74
|
(async () => {
|
|
74
|
-
const TRADING_ACCOUNT_ID = await (0,
|
|
75
|
-
const swapHistoryOrders = (0, rxjs_1.defer)(() => (0, private_api_1.getTradeOrdersHistory)(
|
|
76
|
-
const swapPendingOrders = (0, rxjs_1.defer)(() => (0, private_api_1.getTradeOrdersPending)(
|
|
75
|
+
const TRADING_ACCOUNT_ID = await (0, uid_1.getTradingAccountId)(credential);
|
|
76
|
+
const swapHistoryOrders = (0, rxjs_1.defer)(() => (0, private_api_1.getTradeOrdersHistory)(credential, { instType: 'SWAP' })).pipe((0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
|
|
77
|
+
const swapPendingOrders = (0, rxjs_1.defer)(() => (0, private_api_1.getTradeOrdersPending)(credential, { instType: 'SWAP' })).pipe((0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
|
|
77
78
|
const ordersFromHistoryOrder$ = swapHistoryOrders.pipe(
|
|
78
79
|
//
|
|
79
80
|
(0, rxjs_1.mergeMap)((x) => (0, rxjs_1.from)(x.data || []).pipe(
|
package/lib/order.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAAmG;AACnG,
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAAmG;AACnG,mDAAuG;AACvG,4CAAyD;AAE5C,QAAA,MAAM,GAAG,IAAI,cAAO,EAAU,CAAC;AAE5C,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,cAAM;KACH,IAAI;AACH,EAAE;AACF,sBAAsB;AACtB,IAAA,gBAAU,EAAC;IACT,QAAQ,EAAE,mBAAQ,CAAC,WAAW,EAAE;IAChC,SAAS,EAAE,SAAS;IACpB,aAAa,EAAE,IAAI;IACnB,OAAO,EAAE;QACP,UAAU;QACV,YAAY;QACZ,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,iBAAiB;QACjB,QAAQ;QACR,WAAW;QACX,YAAY;QACZ,WAAW;QACX,OAAO;QACP,eAAe;QACf,cAAc;QACd,cAAc;QACd,SAAS;QACT,mBAAmB;QACnB,aAAa;QACb,8BAA8B;KAC/B;IACD,YAAY,EAAE,CAAC,YAAY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,kBAAkB,CAAC,CAAC,CAC7C,CACF,CACF,CAAC;IAEF,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,IAAI;IACpD,EAAE;IACF,IAAA,eAAQ,EAAC,CAAC,CAAC,EAAE,EAAE,CACb,IAAA,WAAI,EAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI;IACrB,EAAE;IACF,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAC7C,CACF,CACF,CAAC;IAEF,IAAA,YAAK,EAAC,uBAAuB,EAAE,uBAAuB,CAAC;SACpD,IAAI;IACH,EAAE;IACF,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE;QACR,cAAM,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 @@
|
|
|
1
|
+
{"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAExE,eAAO,MAAM,UAAU,eAAsB,WAAW,cAAc,MAAM,KAAG,QAAQ,MAAM,EAAE,CA+B9F,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listOrders = void 0;
|
|
4
|
+
const utils_1 = require("@yuants/utils");
|
|
5
|
+
const uid_1 = require("../accountInfos/uid");
|
|
6
|
+
const private_api_1 = require("../api/private-api");
|
|
7
|
+
const listOrders = async (credential, account_id) => {
|
|
8
|
+
const accountIds = await (0, uid_1.getAccountIds)(credential);
|
|
9
|
+
if ((accountIds === null || accountIds === void 0 ? void 0 : accountIds.trading) === account_id) {
|
|
10
|
+
const orderRes = await (0, private_api_1.getTradeOrdersPending)(credential, {});
|
|
11
|
+
return orderRes.data.map((x) => {
|
|
12
|
+
const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
|
|
13
|
+
const order_direction = x.side === 'buy'
|
|
14
|
+
? x.posSide === 'long'
|
|
15
|
+
? 'OPEN_LONG'
|
|
16
|
+
: 'CLOSE_SHORT'
|
|
17
|
+
: x.posSide === 'short'
|
|
18
|
+
? 'OPEN_SHORT'
|
|
19
|
+
: 'CLOSE_LONG';
|
|
20
|
+
return {
|
|
21
|
+
order_id: x.ordId,
|
|
22
|
+
account_id,
|
|
23
|
+
product_id: (0, utils_1.encodePath)(x.instType, x.instId),
|
|
24
|
+
submit_at: +x.cTime,
|
|
25
|
+
filled_at: +x.fillTime,
|
|
26
|
+
order_type,
|
|
27
|
+
order_direction,
|
|
28
|
+
volume: +x.sz,
|
|
29
|
+
traded_volume: +x.accFillSz,
|
|
30
|
+
price: +x.px,
|
|
31
|
+
traded_price: +x.avgPx,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`Account ID ${account_id} not found or not a trading account`);
|
|
36
|
+
};
|
|
37
|
+
exports.listOrders = listOrders;
|
|
38
|
+
//# sourceMappingURL=listOrders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,6CAAyE;AACzE,oDAAwE;AAEjE,MAAM,UAAU,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAqB,EAAE;IACjG,MAAM,UAAU,GAAG,MAAM,IAAA,mBAAa,EAAC,UAAU,CAAC,CAAC;IACnD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,MAAK,UAAU,EAAE;QACtC,MAAM,QAAQ,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7B,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;YAEnG,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;gBACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM;oBACpB,CAAC,CAAC,WAAW;oBACb,CAAC,CAAC,aAAa;gBACjB,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO;oBACvB,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,YAAY,CAAC;YACnB,OAAO;gBACL,QAAQ,EAAE,CAAC,CAAC,KAAK;gBACjB,UAAU;gBACV,UAAU,EAAE,IAAA,kBAAU,EAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;gBAC5C,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK;gBACnB,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;gBACtB,UAAU;gBACV,eAAe;gBACf,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;gBACb,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS;gBAC3B,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;gBACZ,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;IACD,MAAM,IAAI,KAAK,CAAC,cAAc,UAAU,qCAAqC,CAAC,CAAC;AACjF,CAAC,CAAC;AA/BW,QAAA,UAAU,cA+BrB","sourcesContent":["import { 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/lib/services.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const protocol_1 = require("@yuants/protocol");
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
|
-
const account_1 = require("./account");
|
|
6
5
|
const private_api_1 = require("./api/private-api");
|
|
6
|
+
const uid_1 = require("./accountInfos/uid");
|
|
7
7
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
8
|
+
const credential = (0, private_api_1.getDefaultCredential)();
|
|
8
9
|
(0, rxjs_1.defer)(async () => {
|
|
9
|
-
const tradingAccountId = await (0,
|
|
10
|
-
const credential = (0, private_api_1.getDefaultCredential)();
|
|
10
|
+
const tradingAccountId = await (0, uid_1.getTradingAccountId)(credential);
|
|
11
11
|
terminal.server.provideService('Grid/Algo-Order', {
|
|
12
12
|
required: ['account_id'],
|
|
13
13
|
properties: {
|
package/lib/services.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAC5C,+BAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAC5C,+BAA6B;AAC7B,mDAA4E;AAC5E,4CAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,IAAA,yBAAmB,EAAC,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,IAAA,+BAAiB,EAAC,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"]}
|