@yuants/vendor-binance 0.8.4 → 0.8.5
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/legacy_index.js +2 -16
- package/dist/legacy_index.js.map +1 -1
- package/dist/services/accounts/spot.js +6 -22
- package/dist/services/accounts/spot.js.map +1 -1
- package/dist/services/accounts/unified.js +1 -8
- package/dist/services/accounts/unified.js.map +1 -1
- package/lib/legacy_index.js +2 -16
- package/lib/legacy_index.js.map +1 -1
- package/lib/services/accounts/spot.d.ts.map +1 -1
- package/lib/services/accounts/spot.js +6 -22
- package/lib/services/accounts/spot.js.map +1 -1
- package/lib/services/accounts/unified.d.ts.map +1 -1
- package/lib/services/accounts/unified.js +1 -8
- package/lib/services/accounts/unified.js.map +1 -1
- package/package.json +2 -2
- package/temp/package-deps.json +7 -7
package/dist/legacy_index.js
CHANGED
|
@@ -175,14 +175,7 @@ else {
|
|
|
175
175
|
valuation: +v.positionAmt * (+v.entryPrice + +v.unrealizedProfit / +v.positionAmt),
|
|
176
176
|
};
|
|
177
177
|
});
|
|
178
|
-
return
|
|
179
|
-
money: {
|
|
180
|
-
currency: 'USDT',
|
|
181
|
-
equity,
|
|
182
|
-
free,
|
|
183
|
-
},
|
|
184
|
-
positions,
|
|
185
|
-
};
|
|
178
|
+
return positions;
|
|
186
179
|
}, { auto_refresh_interval: 1000 });
|
|
187
180
|
addAccountMarket(terminal, { account_id: UNIFIED_ACCOUNT_ID, market_id: 'BINANCE/UNIFIED' });
|
|
188
181
|
}
|
|
@@ -216,14 +209,7 @@ else {
|
|
|
216
209
|
return position;
|
|
217
210
|
})
|
|
218
211
|
.filter((position) => Boolean(position));
|
|
219
|
-
return
|
|
220
|
-
money: {
|
|
221
|
-
currency: 'USDT',
|
|
222
|
-
equity: +((usdtAssets === null || usdtAssets === void 0 ? void 0 : usdtAssets.free) || 0) + +((usdtAssets === null || usdtAssets === void 0 ? void 0 : usdtAssets.locked) || 0),
|
|
223
|
-
free: +((usdtAssets === null || usdtAssets === void 0 ? void 0 : usdtAssets.free) || 0),
|
|
224
|
-
},
|
|
225
|
-
positions,
|
|
226
|
-
};
|
|
212
|
+
return positions;
|
|
227
213
|
}, {
|
|
228
214
|
auto_refresh_interval: 5000,
|
|
229
215
|
});
|
package/dist/legacy_index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy_index.js","sourceRoot":"","sources":["../src/legacy_index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAa,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAU,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,wBAAwB,GAA0D,EAAE,CAAC;AAC3F,MAAM,eAAe,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;IAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAO,CAAC,CAAC,gBAAgB;IACzD,MAAM,KAAK,G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E,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAqB,QAAQ,EAAE,EAAE,EAAE,CAAC;iBACzE;gBACD,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE;oBACnD,MAAM;oBACN,OAAO,EAAE,KAAK,CAAC,QAAQ;iBACxB,CAAC,CAAC;gBACH,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE;oBAC5B,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC;iBACxE;gBACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;YAC7C,CAAC,CACF,CAAC;SACH;IACH,CAAC,CAAC,EAAE,CAAC;CACN","sourcesContent":["import { addAccountMarket, IPosition, provideAccountInfoService } from '@yuants/data-account';\nimport { IOrder, providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, map, mergeMap, repeat, retry, shareReplay, toArray } from 'rxjs';\nimport { createHash } from 'crypto';\nimport { getDefaultCredential, isApiError } from './api/client';\nimport {\n deleteUmOrder,\n getDepositAddress,\n getDepositHistory,\n getSpotAccountInfo,\n getSubAccountList,\n getUnifiedAccountBalance,\n getUnifiedUmAccount,\n getUnifiedUmOpenOrders,\n getWithdrawHistory,\n postAssetTransfer,\n postUmOrder,\n postWithdraw,\n} from './api/private-api';\nimport { getFutureOpenInterest } from './api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst _mapSymbolToOpenInterest: Record<string, { value: number; updated_at: number }> = {};\nconst getOpenInterest = async (symbol: string) => {\n const expired_at = Date.now() - 600_000; // 10min expired\n const cache = _mapSymbolToOpenInterest[symbol];\n if (cache) {\n if (cache.updated_at > expired_at) {\n return cache.value;\n }\n }\n const data = await getFutureOpenInterest({ symbol });\n const value = +data.openInterest || 0;\n _mapSymbolToOpenInterest[symbol] = { value, updated_at: Date.now() };\n return value;\n};\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 'OPEN_SHORT':\n case 'CLOSE_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 case 'MAKER':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nconst mapBinanceOrderTypeToYuants = (binanceType?: string): IOrder['order_type'] => {\n switch (binanceType) {\n case 'LIMIT':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n default:\n return 'LIMIT';\n }\n};\n\nconst mapBinanceSideToYuantsDirection = (\n side?: string,\n positionSide?: string,\n): IOrder['order_direction'] | undefined => {\n if (!side || !positionSide) {\n return undefined;\n }\n if (positionSide === 'LONG') {\n return side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (positionSide === 'SHORT') {\n return side === 'SELL' ? 'OPEN_SHORT' : 'CLOSE_SHORT';\n }\n return undefined;\n};\n\nconst deriveClientOrderId = (order: IOrder) => {\n if (order.order_id) return `${order.order_id}`;\n if (order.comment) return order.comment;\n const payload = JSON.stringify({\n account_id: order.account_id,\n product_id: order.product_id,\n order_direction: order.order_direction,\n order_type: order.order_type,\n price: order.price,\n volume: order.volume,\n });\n return `YUANTS${createHash('sha256').update(payload).digest('hex').slice(0, 24)}`;\n};\n\nconst isPublicOnly = process.env.PUBLIC_ONLY === 'true';\n\n// provideTicks(terminal, 'binance', (product_id) => {\n// const [instType, symbol] = decodePath(product_id);\n// if (instType === 'usdt-future') {\n// return combineLatest([mapSymbolToFuturePremiumIndex$, mapSymbolToFutureBookTicker$]).pipe(\n// combineLatestWith(defer(() => getOpenInterest(symbol))),\n// map(([[mapSymbolToFuturePremiumIndex, mapSymbolToFutureBookTicker], openInterestVolume]): ITick => {\n// const premiumIndex = mapSymbolToFuturePremiumIndex.get(symbol);\n// const bookTicker = mapSymbolToFutureBookTicker.get(symbol);\n// if (!premiumIndex) {\n// throw new Error(`Premium Index Not Found: ${symbol}`);\n// }\n// if (!bookTicker) {\n// throw new Error(`Book Ticker Not Found: ${symbol}`);\n// }\n// return {\n// datasource_id: 'binance',\n// product_id,\n// updated_at: Date.now(),\n// price: +premiumIndex.markPrice,\n// ask: +bookTicker.askPrice,\n// bid: +bookTicker.bidPrice,\n// interest_rate_for_long: -+premiumIndex.lastFundingRate,\n// interest_rate_for_short: +premiumIndex.lastFundingRate,\n// settlement_scheduled_at: premiumIndex.nextFundingTime,\n// open_interest: openInterestVolume,\n// };\n// }),\n// );\n// }\n// return EMPTY;\n// });\n\nif (isPublicOnly) {\n console.info('PUBLIC_ONLY=1, skip Binance legacy services');\n} else {\n const credential = getDefaultCredential();\n (async () => {\n const spotAccountInfo = await getSpotAccountInfo(credential);\n if (isApiError(spotAccountInfo)) {\n throw new Error(spotAccountInfo.msg);\n }\n const uid = spotAccountInfo.uid;\n\n const SPOT_ACCOUNT_ID = `binance/${uid}/spot/usdt`;\n const UNIFIED_ACCOUNT_ID = `binance/${uid}/unified/usdt`;\n\n {\n // unified accountInfo\n\n provideAccountInfoService(\n terminal,\n UNIFIED_ACCOUNT_ID,\n async () => {\n const [accountResult, umAccountResult] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(accountResult)) {\n throw new Error(accountResult.msg);\n }\n const usdtAssets = accountResult.find((v) => v.asset === 'USDT');\n if (!usdtAssets) {\n throw new Error('USDT not found');\n }\n if (isApiError(umAccountResult)) {\n throw new Error(umAccountResult.msg);\n }\n const usdtUmAssets = umAccountResult.assets.find((v) => v.asset === 'USDT');\n if (!usdtUmAssets) {\n throw new Error('um USDT not found');\n }\n const equity = +usdtAssets.totalWalletBalance + +usdtAssets.umUnrealizedPNL;\n const free = equity - +usdtUmAssets.initialMargin;\n\n const positions = umAccountResult.positions\n .filter((v) => +v.positionAmt !== 0)\n .map((v): IPosition => {\n return {\n position_id: `${v.symbol}/${v.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('usdt-future', v.symbol),\n direction: v.positionSide,\n volume: +v.positionAmt,\n free_volume: +v.positionAmt,\n position_price: +v.entryPrice,\n closable_price: +v.entryPrice + +v.unrealizedProfit / +v.positionAmt,\n floating_profit: +v.unrealizedProfit,\n valuation: +v.positionAmt * (+v.entryPrice + +v.unrealizedProfit / +v.positionAmt),\n };\n });\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n },\n { auto_refresh_interval: 1000 },\n );\n\n addAccountMarket(terminal, { account_id: UNIFIED_ACCOUNT_ID, market_id: 'BINANCE/UNIFIED' });\n }\n\n {\n // spot account info\n\n provideAccountInfoService(\n terminal,\n SPOT_ACCOUNT_ID,\n async () => {\n const spotAccountResult = await getSpotAccountInfo(credential, { omitZeroBalances: true });\n if (isApiError(spotAccountResult)) {\n throw new Error(spotAccountResult.msg);\n }\n const usdtAssets = spotAccountResult.balances.find((v) => v.asset === 'USDT');\n const positions = spotAccountResult.balances\n .filter((balance) => balance.asset !== 'USDT')\n .map((balance) => {\n const volume = +balance.free + +balance.locked;\n if (!volume) {\n return undefined;\n }\n const position: IPosition = {\n position_id: `spot/${balance.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('spot', `${balance.asset}USDT`),\n direction: 'LONG',\n volume,\n free_volume: +balance.free,\n position_price: 0,\n closable_price: 0,\n floating_profit: 0,\n valuation: 0,\n };\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return {\n money: {\n currency: 'USDT',\n equity: +(usdtAssets?.free || 0) + +(usdtAssets?.locked || 0),\n free: +(usdtAssets?.free || 0),\n },\n positions,\n };\n },\n {\n auto_refresh_interval: 5_000,\n },\n );\n\n addAccountMarket(terminal, { account_id: SPOT_ACCOUNT_ID, market_id: 'BINANCE/SPOT' });\n }\n\n // transfer\n {\n // spot -> unified\n const SPOT_UNIFIED_NETWORK_ID = `binance/${uid}/spot/unified`;\n addAccountTransferAddress({\n terminal,\n account_id: SPOT_ACCOUNT_ID,\n network_id: SPOT_UNIFIED_NETWORK_ID,\n currency: 'USDT',\n address: `unified`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: 'MAIN_PORTFOLIO_MARGIN',\n asset: 'USDT',\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };\n },\n },\n onEval: async (order) => {\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n\n // unified -> spot\n addAccountTransferAddress({\n terminal,\n account_id: UNIFIED_ACCOUNT_ID,\n network_id: SPOT_UNIFIED_NETWORK_ID,\n currency: 'USDT',\n address: `spot`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: 'PORTFOLIO_MARGIN_MAIN',\n asset: 'USDT',\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };\n },\n },\n onEval: async (order) => {\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n\n const subAccountsResult = await getSubAccountList(credential);\n const isMain = !isApiError(subAccountsResult);\n // main -> sub\n // TODO...\n\n // blockchain\n if (isMain) {\n const depositAddressResult = await getDepositAddress(credential, { coin: 'USDT', network: 'TRX' });\n addAccountTransferAddress({\n terminal,\n account_id: SPOT_ACCOUNT_ID,\n network_id: 'TRC20',\n currency: 'USDT',\n address: depositAddressResult.address,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postWithdraw(credential, {\n coin: 'USDT',\n network: 'TRX',\n address: order.current_rx_address!,\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'ERROR', message: transferResult.msg };\n }\n const wdId = transferResult.id;\n return { state: 'PENDING', context: wdId };\n },\n PENDING: async (order) => {\n const wdId = order.current_tx_context;\n const withdrawResult = await getWithdrawHistory(credential, { coin: 'USDT' });\n const record = withdrawResult?.find((v) => v.id === wdId);\n const txId = record?.txId;\n if (!txId) {\n return { state: 'PENDING', context: wdId };\n }\n return { state: 'COMPLETE', transaction_id: txId };\n },\n },\n onEval: async (order) => {\n const checkResult = await getDepositHistory(credential, {\n coin: 'USDT',\n txId: order.current_transaction_id,\n });\n if (checkResult?.[0]?.status !== 1) {\n return { state: 'PENDING' };\n }\n const received_amount = +checkResult[0].amount;\n return { state: 'COMPLETE', received_amount };\n },\n });\n }\n }\n\n // order related\n {\n providePendingOrdersService(\n terminal,\n UNIFIED_ACCOUNT_ID,\n async () => {\n const openOrders = await getUnifiedUmOpenOrders(credential);\n return openOrders.map((order): IOrder => {\n const order_direction =\n mapBinanceSideToYuantsDirection(order.side, order.positionSide) ?? 'OPEN_LONG';\n return {\n order_id: `${order.orderId}`,\n account_id: UNIFIED_ACCOUNT_ID,\n product_id: encodePath('usdt-future', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction,\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: new Date(order.updateTime).toISOString(),\n order_status: order.status,\n };\n });\n },\n { auto_refresh_interval: 1000 },\n );\n\n terminal.server.provideService<IOrder>(\n 'SubmitOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: UNIFIED_ACCOUNT_ID },\n },\n },\n async (msg) => {\n console.info(formatTime(Date.now()), 'SubmitOrder', msg.req);\n const order = msg.req;\n const [instType, symbol] = decodePath(order.product_id);\n if (instType === 'usdt-future') {\n const params = {\n symbol,\n side: mapOrderDirectionToSide(order.order_direction),\n positionSide: mapOrderDirectionToPosSide(order.order_direction),\n type: mapOrderTypeToOrdType(order.order_type),\n timeInForce:\n order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined,\n quantity: order.volume,\n price: order.price,\n newClientOrderId: deriveClientOrderId(order),\n };\n\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const orderResult = await postUmOrder(credential, params);\n if (isApiError(orderResult)) {\n return { res: { code: orderResult.code, message: orderResult.msg } };\n }\n return { res: { code: 0, message: 'OK', order_id: orderResult.orderId } };\n }\n return { res: { code: 400, message: `unsupported type: ${instType}` } };\n },\n );\n }\n\n {\n terminal.server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id', 'order_id', 'product_id'],\n properties: {\n account_id: { const: UNIFIED_ACCOUNT_ID },\n },\n },\n async (msg) => {\n const order = msg.req;\n if (!order.order_id) {\n return { res: { code: 400, message: 'order_id is required' } };\n }\n const [instType, symbol] = decodePath(order.product_id);\n if (instType !== 'usdt-future') {\n return { res: { code: 400, message: `unsupported type: ${instType}` } };\n }\n const cancelResult = await deleteUmOrder(credential, {\n symbol,\n orderId: order.order_id,\n });\n if (isApiError(cancelResult)) {\n return { res: { code: cancelResult.code, message: cancelResult.msg } };\n }\n return { res: { code: 0, message: 'OK' } };\n },\n );\n }\n })();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"legacy_index.js","sourceRoot":"","sources":["../src/legacy_index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAa,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAU,2BAA2B,EAAE,MAAM,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KAAK,EAAE,GAAG,EAAE,EAAE;gBACZ,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;gBACtB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;oBACnB,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC;iBAChE;gBACD,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBACxD,IAAI,QAAQ,KAAK,aAAa,EAAE;oBAC9B,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAqB,QAAQ,EAAE,EAAE,EAAE,CAAC;iBACzE;gBACD,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE;oBACnD,MAAM;oBACN,OAAO,EAAE,KAAK,CAAC,QAAQ;iBACxB,CAAC,CAAC;gBACH,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE;oBAC5B,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC;iBACxE;gBACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;YAC7C,CAAC,CACF,CAAC;SACH;IACH,CAAC,CAAC,EAAE,CAAC;CACN","sourcesContent":["import { addAccountMarket, IPosition, provideAccountInfoService } from '@yuants/data-account';\nimport { IOrder, providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { createHash } from 'crypto';\nimport { getDefaultCredential, isApiError } from './api/client';\nimport {\n deleteUmOrder,\n getDepositAddress,\n getDepositHistory,\n getSpotAccountInfo,\n getSubAccountList,\n getUnifiedAccountBalance,\n getUnifiedUmAccount,\n getUnifiedUmOpenOrders,\n getWithdrawHistory,\n postAssetTransfer,\n postUmOrder,\n postWithdraw,\n} from './api/private-api';\nimport { getFutureOpenInterest } from './api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst _mapSymbolToOpenInterest: Record<string, { value: number; updated_at: number }> = {};\nconst getOpenInterest = async (symbol: string) => {\n const expired_at = Date.now() - 600_000; // 10min expired\n const cache = _mapSymbolToOpenInterest[symbol];\n if (cache) {\n if (cache.updated_at > expired_at) {\n return cache.value;\n }\n }\n const data = await getFutureOpenInterest({ symbol });\n const value = +data.openInterest || 0;\n _mapSymbolToOpenInterest[symbol] = { value, updated_at: Date.now() };\n return value;\n};\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 'OPEN_SHORT':\n case 'CLOSE_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 case 'MAKER':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nconst mapBinanceOrderTypeToYuants = (binanceType?: string): IOrder['order_type'] => {\n switch (binanceType) {\n case 'LIMIT':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n default:\n return 'LIMIT';\n }\n};\n\nconst mapBinanceSideToYuantsDirection = (\n side?: string,\n positionSide?: string,\n): IOrder['order_direction'] | undefined => {\n if (!side || !positionSide) {\n return undefined;\n }\n if (positionSide === 'LONG') {\n return side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (positionSide === 'SHORT') {\n return side === 'SELL' ? 'OPEN_SHORT' : 'CLOSE_SHORT';\n }\n return undefined;\n};\n\nconst deriveClientOrderId = (order: IOrder) => {\n if (order.order_id) return `${order.order_id}`;\n if (order.comment) return order.comment;\n const payload = JSON.stringify({\n account_id: order.account_id,\n product_id: order.product_id,\n order_direction: order.order_direction,\n order_type: order.order_type,\n price: order.price,\n volume: order.volume,\n });\n return `YUANTS${createHash('sha256').update(payload).digest('hex').slice(0, 24)}`;\n};\n\nconst isPublicOnly = process.env.PUBLIC_ONLY === 'true';\n\n// provideTicks(terminal, 'binance', (product_id) => {\n// const [instType, symbol] = decodePath(product_id);\n// if (instType === 'usdt-future') {\n// return combineLatest([mapSymbolToFuturePremiumIndex$, mapSymbolToFutureBookTicker$]).pipe(\n// combineLatestWith(defer(() => getOpenInterest(symbol))),\n// map(([[mapSymbolToFuturePremiumIndex, mapSymbolToFutureBookTicker], openInterestVolume]): ITick => {\n// const premiumIndex = mapSymbolToFuturePremiumIndex.get(symbol);\n// const bookTicker = mapSymbolToFutureBookTicker.get(symbol);\n// if (!premiumIndex) {\n// throw new Error(`Premium Index Not Found: ${symbol}`);\n// }\n// if (!bookTicker) {\n// throw new Error(`Book Ticker Not Found: ${symbol}`);\n// }\n// return {\n// datasource_id: 'binance',\n// product_id,\n// updated_at: Date.now(),\n// price: +premiumIndex.markPrice,\n// ask: +bookTicker.askPrice,\n// bid: +bookTicker.bidPrice,\n// interest_rate_for_long: -+premiumIndex.lastFundingRate,\n// interest_rate_for_short: +premiumIndex.lastFundingRate,\n// settlement_scheduled_at: premiumIndex.nextFundingTime,\n// open_interest: openInterestVolume,\n// };\n// }),\n// );\n// }\n// return EMPTY;\n// });\n\nif (isPublicOnly) {\n console.info('PUBLIC_ONLY=1, skip Binance legacy services');\n} else {\n const credential = getDefaultCredential();\n (async () => {\n const spotAccountInfo = await getSpotAccountInfo(credential);\n if (isApiError(spotAccountInfo)) {\n throw new Error(spotAccountInfo.msg);\n }\n const uid = spotAccountInfo.uid;\n\n const SPOT_ACCOUNT_ID = `binance/${uid}/spot/usdt`;\n const UNIFIED_ACCOUNT_ID = `binance/${uid}/unified/usdt`;\n\n {\n // unified accountInfo\n\n provideAccountInfoService(\n terminal,\n UNIFIED_ACCOUNT_ID,\n async () => {\n const [accountResult, umAccountResult] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(accountResult)) {\n throw new Error(accountResult.msg);\n }\n const usdtAssets = accountResult.find((v) => v.asset === 'USDT');\n if (!usdtAssets) {\n throw new Error('USDT not found');\n }\n if (isApiError(umAccountResult)) {\n throw new Error(umAccountResult.msg);\n }\n const usdtUmAssets = umAccountResult.assets.find((v) => v.asset === 'USDT');\n if (!usdtUmAssets) {\n throw new Error('um USDT not found');\n }\n const equity = +usdtAssets.totalWalletBalance + +usdtAssets.umUnrealizedPNL;\n const free = equity - +usdtUmAssets.initialMargin;\n\n const positions = umAccountResult.positions\n .filter((v) => +v.positionAmt !== 0)\n .map((v): IPosition => {\n return {\n position_id: `${v.symbol}/${v.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('usdt-future', v.symbol),\n direction: v.positionSide,\n volume: +v.positionAmt,\n free_volume: +v.positionAmt,\n position_price: +v.entryPrice,\n closable_price: +v.entryPrice + +v.unrealizedProfit / +v.positionAmt,\n floating_profit: +v.unrealizedProfit,\n valuation: +v.positionAmt * (+v.entryPrice + +v.unrealizedProfit / +v.positionAmt),\n };\n });\n\n return positions;\n },\n { auto_refresh_interval: 1000 },\n );\n\n addAccountMarket(terminal, { account_id: UNIFIED_ACCOUNT_ID, market_id: 'BINANCE/UNIFIED' });\n }\n\n {\n // spot account info\n\n provideAccountInfoService(\n terminal,\n SPOT_ACCOUNT_ID,\n async () => {\n const spotAccountResult = await getSpotAccountInfo(credential, { omitZeroBalances: true });\n if (isApiError(spotAccountResult)) {\n throw new Error(spotAccountResult.msg);\n }\n const usdtAssets = spotAccountResult.balances.find((v) => v.asset === 'USDT');\n const positions = spotAccountResult.balances\n .filter((balance) => balance.asset !== 'USDT')\n .map((balance) => {\n const volume = +balance.free + +balance.locked;\n if (!volume) {\n return undefined;\n }\n const position: IPosition = {\n position_id: `spot/${balance.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('spot', `${balance.asset}USDT`),\n direction: 'LONG',\n volume,\n free_volume: +balance.free,\n position_price: 0,\n closable_price: 0,\n floating_profit: 0,\n valuation: 0,\n };\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return positions;\n },\n {\n auto_refresh_interval: 5_000,\n },\n );\n\n addAccountMarket(terminal, { account_id: SPOT_ACCOUNT_ID, market_id: 'BINANCE/SPOT' });\n }\n\n // transfer\n {\n // spot -> unified\n const SPOT_UNIFIED_NETWORK_ID = `binance/${uid}/spot/unified`;\n addAccountTransferAddress({\n terminal,\n account_id: SPOT_ACCOUNT_ID,\n network_id: SPOT_UNIFIED_NETWORK_ID,\n currency: 'USDT',\n address: `unified`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: 'MAIN_PORTFOLIO_MARGIN',\n asset: 'USDT',\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };\n },\n },\n onEval: async (order) => {\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n\n // unified -> spot\n addAccountTransferAddress({\n terminal,\n account_id: UNIFIED_ACCOUNT_ID,\n network_id: SPOT_UNIFIED_NETWORK_ID,\n currency: 'USDT',\n address: `spot`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: 'PORTFOLIO_MARGIN_MAIN',\n asset: 'USDT',\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };\n },\n },\n onEval: async (order) => {\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n\n const subAccountsResult = await getSubAccountList(credential);\n const isMain = !isApiError(subAccountsResult);\n // main -> sub\n // TODO...\n\n // blockchain\n if (isMain) {\n const depositAddressResult = await getDepositAddress(credential, { coin: 'USDT', network: 'TRX' });\n addAccountTransferAddress({\n terminal,\n account_id: SPOT_ACCOUNT_ID,\n network_id: 'TRC20',\n currency: 'USDT',\n address: depositAddressResult.address,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postWithdraw(credential, {\n coin: 'USDT',\n network: 'TRX',\n address: order.current_rx_address!,\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'ERROR', message: transferResult.msg };\n }\n const wdId = transferResult.id;\n return { state: 'PENDING', context: wdId };\n },\n PENDING: async (order) => {\n const wdId = order.current_tx_context;\n const withdrawResult = await getWithdrawHistory(credential, { coin: 'USDT' });\n const record = withdrawResult?.find((v) => v.id === wdId);\n const txId = record?.txId;\n if (!txId) {\n return { state: 'PENDING', context: wdId };\n }\n return { state: 'COMPLETE', transaction_id: txId };\n },\n },\n onEval: async (order) => {\n const checkResult = await getDepositHistory(credential, {\n coin: 'USDT',\n txId: order.current_transaction_id,\n });\n if (checkResult?.[0]?.status !== 1) {\n return { state: 'PENDING' };\n }\n const received_amount = +checkResult[0].amount;\n return { state: 'COMPLETE', received_amount };\n },\n });\n }\n }\n\n // order related\n {\n providePendingOrdersService(\n terminal,\n UNIFIED_ACCOUNT_ID,\n async () => {\n const openOrders = await getUnifiedUmOpenOrders(credential);\n return openOrders.map((order): IOrder => {\n const order_direction =\n mapBinanceSideToYuantsDirection(order.side, order.positionSide) ?? 'OPEN_LONG';\n return {\n order_id: `${order.orderId}`,\n account_id: UNIFIED_ACCOUNT_ID,\n product_id: encodePath('usdt-future', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction,\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: new Date(order.updateTime).toISOString(),\n order_status: order.status,\n };\n });\n },\n { auto_refresh_interval: 1000 },\n );\n\n terminal.server.provideService<IOrder>(\n 'SubmitOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: UNIFIED_ACCOUNT_ID },\n },\n },\n async (msg) => {\n console.info(formatTime(Date.now()), 'SubmitOrder', msg.req);\n const order = msg.req;\n const [instType, symbol] = decodePath(order.product_id);\n if (instType === 'usdt-future') {\n const params = {\n symbol,\n side: mapOrderDirectionToSide(order.order_direction),\n positionSide: mapOrderDirectionToPosSide(order.order_direction),\n type: mapOrderTypeToOrdType(order.order_type),\n timeInForce:\n order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined,\n quantity: order.volume,\n price: order.price,\n newClientOrderId: deriveClientOrderId(order),\n };\n\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const orderResult = await postUmOrder(credential, params);\n if (isApiError(orderResult)) {\n return { res: { code: orderResult.code, message: orderResult.msg } };\n }\n return { res: { code: 0, message: 'OK', order_id: orderResult.orderId } };\n }\n return { res: { code: 400, message: `unsupported type: ${instType}` } };\n },\n );\n }\n\n {\n terminal.server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id', 'order_id', 'product_id'],\n properties: {\n account_id: { const: UNIFIED_ACCOUNT_ID },\n },\n },\n async (msg) => {\n const order = msg.req;\n if (!order.order_id) {\n return { res: { code: 400, message: 'order_id is required' } };\n }\n const [instType, symbol] = decodePath(order.product_id);\n if (instType !== 'usdt-future') {\n return { res: { code: 400, message: `unsupported type: ${instType}` } };\n }\n const cancelResult = await deleteUmOrder(credential, {\n symbol,\n orderId: order.order_id,\n });\n if (isApiError(cancelResult)) {\n return { res: { code: cancelResult.code, message: cancelResult.msg } };\n }\n return { res: { code: 0, message: 'OK' } };\n },\n );\n }\n })();\n}\n"]}
|
|
@@ -1,44 +1,28 @@
|
|
|
1
|
+
import { makeSpotPosition } from '@yuants/data-account';
|
|
1
2
|
import { encodePath } from '@yuants/utils';
|
|
2
3
|
import { isApiError } from '../../api/client';
|
|
3
4
|
import { getSpotAccountInfo } from '../../api/private-api';
|
|
4
|
-
export const getSpotAccountInfoSnapshot = async (credential
|
|
5
|
-
var _a, _b;
|
|
5
|
+
export const getSpotAccountInfoSnapshot = async (credential) => {
|
|
6
6
|
const res = await getSpotAccountInfo(credential, { omitZeroBalances: true });
|
|
7
7
|
if (isApiError(res)) {
|
|
8
8
|
throw new Error(res.msg);
|
|
9
9
|
}
|
|
10
|
-
const usdtAsset = res.balances.find((balance) => balance.asset === 'USDT');
|
|
11
|
-
const free = +((_a = usdtAsset === null || usdtAsset === void 0 ? void 0 : usdtAsset.free) !== null && _a !== void 0 ? _a : 0);
|
|
12
|
-
const locked = +((_b = usdtAsset === null || usdtAsset === void 0 ? void 0 : usdtAsset.locked) !== null && _b !== void 0 ? _b : 0);
|
|
13
|
-
const equity = free + locked;
|
|
14
10
|
const positions = res.balances
|
|
15
|
-
.filter((balance) => balance.asset !== 'USDT')
|
|
16
11
|
.map((balance) => {
|
|
17
12
|
const volume = +balance.free + +balance.locked;
|
|
18
13
|
if (!volume)
|
|
19
14
|
return undefined;
|
|
20
|
-
const position = {
|
|
15
|
+
const position = makeSpotPosition({
|
|
21
16
|
position_id: `spot/${balance.asset}`,
|
|
22
17
|
datasource_id: 'BINANCE',
|
|
23
18
|
product_id: encodePath('spot', `${balance.asset}USDT`),
|
|
24
|
-
direction: 'LONG',
|
|
25
19
|
volume,
|
|
26
20
|
free_volume: +balance.free,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
floating_profit: 0,
|
|
30
|
-
valuation: 0,
|
|
31
|
-
};
|
|
21
|
+
closable_price: 0, // TODO: fetch price later
|
|
22
|
+
});
|
|
32
23
|
return position;
|
|
33
24
|
})
|
|
34
25
|
.filter((position) => Boolean(position));
|
|
35
|
-
return
|
|
36
|
-
money: {
|
|
37
|
-
currency: 'USDT',
|
|
38
|
-
equity,
|
|
39
|
-
free,
|
|
40
|
-
},
|
|
41
|
-
positions,
|
|
42
|
-
};
|
|
26
|
+
return positions;
|
|
43
27
|
};
|
|
44
28
|
//# sourceMappingURL=spot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAExE,MAAM,CAAC,MAAM,0BAA0B,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAC1G,MAAM,GAAG,GAAG,MAAM,kBAAkB,CAAC,UAAU,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ;SAC3B,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACf,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;QAC/C,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAC;QAC9B,MAAM,QAAQ,GAAc,gBAAgB,CAAC;YAC3C,WAAW,EAAE,QAAQ,OAAO,CAAC,KAAK,EAAE;YACpC,aAAa,EAAE,SAAS;YACxB,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,MAAM,CAAC;YACtD,MAAM;YACN,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI;YAC1B,cAAc,EAAE,CAAC,EAAE,0BAA0B;SAC9C,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,QAAQ,EAAyB,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getSpotAccountInfo, ICredential } from '../../api/private-api';\n\nexport const getSpotAccountInfoSnapshot: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const res = await getSpotAccountInfo(credential, { omitZeroBalances: true });\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n const positions = res.balances\n .map((balance) => {\n const volume = +balance.free + +balance.locked;\n if (!volume) return undefined;\n const position: IPosition = makeSpotPosition({\n position_id: `spot/${balance.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('spot', `${balance.asset}USDT`),\n volume,\n free_volume: +balance.free,\n closable_price: 0, // TODO: fetch price later\n });\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return positions;\n};\n"]}
|
|
@@ -44,13 +44,6 @@ export const getUnifiedAccountInfo = async (credential, _accountId) => {
|
|
|
44
44
|
(+position.entryPrice +
|
|
45
45
|
(+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),
|
|
46
46
|
}));
|
|
47
|
-
return
|
|
48
|
-
money: {
|
|
49
|
-
currency: 'USDT',
|
|
50
|
-
equity,
|
|
51
|
-
free,
|
|
52
|
-
},
|
|
53
|
-
positions,
|
|
54
|
-
};
|
|
47
|
+
return positions;
|
|
55
48
|
};
|
|
56
49
|
//# sourceMapping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IAEN,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\n\nexport const getUnifiedAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (\n credential,\n _accountId,\n) => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n const usdtBalance = balanceRes.find((item) => item.asset === 'USDT');\n if (!usdtBalance) {\n throw new Error('USDT balance not found');\n }\n const usdtAsset = umAccountRes.assets.find((item) => item.asset === 'USDT');\n if (!usdtAsset) {\n throw new Error('USDT asset not found in UM account');\n }\n\n const equity = +usdtBalance.totalWalletBalance + +usdtBalance.umUnrealizedPNL;\n const free = equity - +usdtAsset.initialMargin;\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('usdt-future', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: +position.positionAmt,\n free_volume: +position.positionAmt,\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n return positions;\n};\n"]}
|
package/lib/legacy_index.js
CHANGED
|
@@ -177,14 +177,7 @@ else {
|
|
|
177
177
|
valuation: +v.positionAmt * (+v.entryPrice + +v.unrealizedProfit / +v.positionAmt),
|
|
178
178
|
};
|
|
179
179
|
});
|
|
180
|
-
return
|
|
181
|
-
money: {
|
|
182
|
-
currency: 'USDT',
|
|
183
|
-
equity,
|
|
184
|
-
free,
|
|
185
|
-
},
|
|
186
|
-
positions,
|
|
187
|
-
};
|
|
180
|
+
return positions;
|
|
188
181
|
}, { auto_refresh_interval: 1000 });
|
|
189
182
|
(0, data_account_1.addAccountMarket)(terminal, { account_id: UNIFIED_ACCOUNT_ID, market_id: 'BINANCE/UNIFIED' });
|
|
190
183
|
}
|
|
@@ -218,14 +211,7 @@ else {
|
|
|
218
211
|
return position;
|
|
219
212
|
})
|
|
220
213
|
.filter((position) => Boolean(position));
|
|
221
|
-
return
|
|
222
|
-
money: {
|
|
223
|
-
currency: 'USDT',
|
|
224
|
-
equity: +((usdtAssets === null || usdtAssets === void 0 ? void 0 : usdtAssets.free) || 0) + +((usdtAssets === null || usdtAssets === void 0 ? void 0 : usdtAssets.locked) || 0),
|
|
225
|
-
free: +((usdtAssets === null || usdtAssets === void 0 ? void 0 : usdtAssets.free) || 0),
|
|
226
|
-
},
|
|
227
|
-
positions,
|
|
228
|
-
};
|
|
214
|
+
return positions;
|
|
229
215
|
}, {
|
|
230
216
|
auto_refresh_interval: 5000,
|
|
231
217
|
});
|
package/lib/legacy_index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy_index.js","sourceRoot":"","sources":["../src/legacy_index.ts"],"names":[],"mappings":";;AAAA,uDAA8F;AAC9F,mDAAyE;AACzE,+CAA4C;AAC5C,+CAA6D;AAC7D,yCAAmE;AAEnE,mCAAoC;AACpC,yCAAgE;AAChE,mDAa2B;AAC3B,iDAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,wBAAwB,GAA0D,EAAE,CAAC;AAC3F,MAAM,eAAe,GAA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;aACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;gBACZ,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;gBACtB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;oBACnB,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC;iBAChE;gBACD,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBACxD,IAAI,QAAQ,KAAK,aAAa,EAAE;oBAC9B,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAqB,QAAQ,EAAE,EAAE,EAAE,CAAC;iBACzE;gBACD,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAa,EAAC,UAAU,EAAE;oBACnD,MAAM;oBACN,OAAO,EAAE,KAAK,CAAC,QAAQ;iBACxB,CAAC,CAAC;gBACH,IAAI,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE;oBAC5B,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC;iBACxE;gBACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;YAC7C,CAAC,CACF,CAAC;SACH;IACH,CAAC,CAAC,EAAE,CAAC;CACN","sourcesContent":["import { addAccountMarket, IPosition, provideAccountInfoService } from '@yuants/data-account';\nimport { IOrder, providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, map, mergeMap, repeat, retry, shareReplay, toArray } from 'rxjs';\nimport { createHash } from 'crypto';\nimport { getDefaultCredential, isApiError } from './api/client';\nimport {\n deleteUmOrder,\n getDepositAddress,\n getDepositHistory,\n getSpotAccountInfo,\n getSubAccountList,\n getUnifiedAccountBalance,\n getUnifiedUmAccount,\n getUnifiedUmOpenOrders,\n getWithdrawHistory,\n postAssetTransfer,\n postUmOrder,\n postWithdraw,\n} from './api/private-api';\nimport { getFutureOpenInterest } from './api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst _mapSymbolToOpenInterest: Record<string, { value: number; updated_at: number }> = {};\nconst getOpenInterest = async (symbol: string) => {\n const expired_at = Date.now() - 600_000; // 10min expired\n const cache = _mapSymbolToOpenInterest[symbol];\n if (cache) {\n if (cache.updated_at > expired_at) {\n return cache.value;\n }\n }\n const data = await getFutureOpenInterest({ symbol });\n const value = +data.openInterest || 0;\n _mapSymbolToOpenInterest[symbol] = { value, updated_at: Date.now() };\n return value;\n};\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 'OPEN_SHORT':\n case 'CLOSE_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 case 'MAKER':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nconst mapBinanceOrderTypeToYuants = (binanceType?: string): IOrder['order_type'] => {\n switch (binanceType) {\n case 'LIMIT':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n default:\n return 'LIMIT';\n }\n};\n\nconst mapBinanceSideToYuantsDirection = (\n side?: string,\n positionSide?: string,\n): IOrder['order_direction'] | undefined => {\n if (!side || !positionSide) {\n return undefined;\n }\n if (positionSide === 'LONG') {\n return side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (positionSide === 'SHORT') {\n return side === 'SELL' ? 'OPEN_SHORT' : 'CLOSE_SHORT';\n }\n return undefined;\n};\n\nconst deriveClientOrderId = (order: IOrder) => {\n if (order.order_id) return `${order.order_id}`;\n if (order.comment) return order.comment;\n const payload = JSON.stringify({\n account_id: order.account_id,\n product_id: order.product_id,\n order_direction: order.order_direction,\n order_type: order.order_type,\n price: order.price,\n volume: order.volume,\n });\n return `YUANTS${createHash('sha256').update(payload).digest('hex').slice(0, 24)}`;\n};\n\nconst isPublicOnly = process.env.PUBLIC_ONLY === 'true';\n\n// provideTicks(terminal, 'binance', (product_id) => {\n// const [instType, symbol] = decodePath(product_id);\n// if (instType === 'usdt-future') {\n// return combineLatest([mapSymbolToFuturePremiumIndex$, mapSymbolToFutureBookTicker$]).pipe(\n// combineLatestWith(defer(() => getOpenInterest(symbol))),\n// map(([[mapSymbolToFuturePremiumIndex, mapSymbolToFutureBookTicker], openInterestVolume]): ITick => {\n// const premiumIndex = mapSymbolToFuturePremiumIndex.get(symbol);\n// const bookTicker = mapSymbolToFutureBookTicker.get(symbol);\n// if (!premiumIndex) {\n// throw new Error(`Premium Index Not Found: ${symbol}`);\n// }\n// if (!bookTicker) {\n// throw new Error(`Book Ticker Not Found: ${symbol}`);\n// }\n// return {\n// datasource_id: 'binance',\n// product_id,\n// updated_at: Date.now(),\n// price: +premiumIndex.markPrice,\n// ask: +bookTicker.askPrice,\n// bid: +bookTicker.bidPrice,\n// interest_rate_for_long: -+premiumIndex.lastFundingRate,\n// interest_rate_for_short: +premiumIndex.lastFundingRate,\n// settlement_scheduled_at: premiumIndex.nextFundingTime,\n// open_interest: openInterestVolume,\n// };\n// }),\n// );\n// }\n// return EMPTY;\n// });\n\nif (isPublicOnly) {\n console.info('PUBLIC_ONLY=1, skip Binance legacy services');\n} else {\n const credential = getDefaultCredential();\n (async () => {\n const spotAccountInfo = await getSpotAccountInfo(credential);\n if (isApiError(spotAccountInfo)) {\n throw new Error(spotAccountInfo.msg);\n }\n const uid = spotAccountInfo.uid;\n\n const SPOT_ACCOUNT_ID = `binance/${uid}/spot/usdt`;\n const UNIFIED_ACCOUNT_ID = `binance/${uid}/unified/usdt`;\n\n {\n // unified accountInfo\n\n provideAccountInfoService(\n terminal,\n UNIFIED_ACCOUNT_ID,\n async () => {\n const [accountResult, umAccountResult] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(accountResult)) {\n throw new Error(accountResult.msg);\n }\n const usdtAssets = accountResult.find((v) => v.asset === 'USDT');\n if (!usdtAssets) {\n throw new Error('USDT not found');\n }\n if (isApiError(umAccountResult)) {\n throw new Error(umAccountResult.msg);\n }\n const usdtUmAssets = umAccountResult.assets.find((v) => v.asset === 'USDT');\n if (!usdtUmAssets) {\n throw new Error('um USDT not found');\n }\n const equity = +usdtAssets.totalWalletBalance + +usdtAssets.umUnrealizedPNL;\n const free = equity - +usdtUmAssets.initialMargin;\n\n const positions = umAccountResult.positions\n .filter((v) => +v.positionAmt !== 0)\n .map((v): IPosition => {\n return {\n position_id: `${v.symbol}/${v.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('usdt-future', v.symbol),\n direction: v.positionSide,\n volume: +v.positionAmt,\n free_volume: +v.positionAmt,\n position_price: +v.entryPrice,\n closable_price: +v.entryPrice + +v.unrealizedProfit / +v.positionAmt,\n floating_profit: +v.unrealizedProfit,\n valuation: +v.positionAmt * (+v.entryPrice + +v.unrealizedProfit / +v.positionAmt),\n };\n });\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n },\n { auto_refresh_interval: 1000 },\n );\n\n addAccountMarket(terminal, { account_id: UNIFIED_ACCOUNT_ID, market_id: 'BINANCE/UNIFIED' });\n }\n\n {\n // spot account info\n\n provideAccountInfoService(\n terminal,\n SPOT_ACCOUNT_ID,\n async () => {\n const spotAccountResult = await getSpotAccountInfo(credential, { omitZeroBalances: true });\n if (isApiError(spotAccountResult)) {\n throw new Error(spotAccountResult.msg);\n }\n const usdtAssets = spotAccountResult.balances.find((v) => v.asset === 'USDT');\n const positions = spotAccountResult.balances\n .filter((balance) => balance.asset !== 'USDT')\n .map((balance) => {\n const volume = +balance.free + +balance.locked;\n if (!volume) {\n return undefined;\n }\n const position: IPosition = {\n position_id: `spot/${balance.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('spot', `${balance.asset}USDT`),\n direction: 'LONG',\n volume,\n free_volume: +balance.free,\n position_price: 0,\n closable_price: 0,\n floating_profit: 0,\n valuation: 0,\n };\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return {\n money: {\n currency: 'USDT',\n equity: +(usdtAssets?.free || 0) + +(usdtAssets?.locked || 0),\n free: +(usdtAssets?.free || 0),\n },\n positions,\n };\n },\n {\n auto_refresh_interval: 5_000,\n },\n );\n\n addAccountMarket(terminal, { account_id: SPOT_ACCOUNT_ID, market_id: 'BINANCE/SPOT' });\n }\n\n // transfer\n {\n // spot -> unified\n const SPOT_UNIFIED_NETWORK_ID = `binance/${uid}/spot/unified`;\n addAccountTransferAddress({\n terminal,\n account_id: SPOT_ACCOUNT_ID,\n network_id: SPOT_UNIFIED_NETWORK_ID,\n currency: 'USDT',\n address: `unified`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: 'MAIN_PORTFOLIO_MARGIN',\n asset: 'USDT',\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };\n },\n },\n onEval: async (order) => {\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n\n // unified -> spot\n addAccountTransferAddress({\n terminal,\n account_id: UNIFIED_ACCOUNT_ID,\n network_id: SPOT_UNIFIED_NETWORK_ID,\n currency: 'USDT',\n address: `spot`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: 'PORTFOLIO_MARGIN_MAIN',\n asset: 'USDT',\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };\n },\n },\n onEval: async (order) => {\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n\n const subAccountsResult = await getSubAccountList(credential);\n const isMain = !isApiError(subAccountsResult);\n // main -> sub\n // TODO...\n\n // blockchain\n if (isMain) {\n const depositAddressResult = await getDepositAddress(credential, { coin: 'USDT', network: 'TRX' });\n addAccountTransferAddress({\n terminal,\n account_id: SPOT_ACCOUNT_ID,\n network_id: 'TRC20',\n currency: 'USDT',\n address: depositAddressResult.address,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postWithdraw(credential, {\n coin: 'USDT',\n network: 'TRX',\n address: order.current_rx_address!,\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'ERROR', message: transferResult.msg };\n }\n const wdId = transferResult.id;\n return { state: 'PENDING', context: wdId };\n },\n PENDING: async (order) => {\n const wdId = order.current_tx_context;\n const withdrawResult = await getWithdrawHistory(credential, { coin: 'USDT' });\n const record = withdrawResult?.find((v) => v.id === wdId);\n const txId = record?.txId;\n if (!txId) {\n return { state: 'PENDING', context: wdId };\n }\n return { state: 'COMPLETE', transaction_id: txId };\n },\n },\n onEval: async (order) => {\n const checkResult = await getDepositHistory(credential, {\n coin: 'USDT',\n txId: order.current_transaction_id,\n });\n if (checkResult?.[0]?.status !== 1) {\n return { state: 'PENDING' };\n }\n const received_amount = +checkResult[0].amount;\n return { state: 'COMPLETE', received_amount };\n },\n });\n }\n }\n\n // order related\n {\n providePendingOrdersService(\n terminal,\n UNIFIED_ACCOUNT_ID,\n async () => {\n const openOrders = await getUnifiedUmOpenOrders(credential);\n return openOrders.map((order): IOrder => {\n const order_direction =\n mapBinanceSideToYuantsDirection(order.side, order.positionSide) ?? 'OPEN_LONG';\n return {\n order_id: `${order.orderId}`,\n account_id: UNIFIED_ACCOUNT_ID,\n product_id: encodePath('usdt-future', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction,\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: new Date(order.updateTime).toISOString(),\n order_status: order.status,\n };\n });\n },\n { auto_refresh_interval: 1000 },\n );\n\n terminal.server.provideService<IOrder>(\n 'SubmitOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: UNIFIED_ACCOUNT_ID },\n },\n },\n async (msg) => {\n console.info(formatTime(Date.now()), 'SubmitOrder', msg.req);\n const order = msg.req;\n const [instType, symbol] = decodePath(order.product_id);\n if (instType === 'usdt-future') {\n const params = {\n symbol,\n side: mapOrderDirectionToSide(order.order_direction),\n positionSide: mapOrderDirectionToPosSide(order.order_direction),\n type: mapOrderTypeToOrdType(order.order_type),\n timeInForce:\n order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined,\n quantity: order.volume,\n price: order.price,\n newClientOrderId: deriveClientOrderId(order),\n };\n\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const orderResult = await postUmOrder(credential, params);\n if (isApiError(orderResult)) {\n return { res: { code: orderResult.code, message: orderResult.msg } };\n }\n return { res: { code: 0, message: 'OK', order_id: orderResult.orderId } };\n }\n return { res: { code: 400, message: `unsupported type: ${instType}` } };\n },\n );\n }\n\n {\n terminal.server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id', 'order_id', 'product_id'],\n properties: {\n account_id: { const: UNIFIED_ACCOUNT_ID },\n },\n },\n async (msg) => {\n const order = msg.req;\n if (!order.order_id) {\n return { res: { code: 400, message: 'order_id is required' } };\n }\n const [instType, symbol] = decodePath(order.product_id);\n if (instType !== 'usdt-future') {\n return { res: { code: 400, message: `unsupported type: ${instType}` } };\n }\n const cancelResult = await deleteUmOrder(credential, {\n symbol,\n orderId: order.order_id,\n });\n if (isApiError(cancelResult)) {\n return { res: { code: cancelResult.code, message: cancelResult.msg } };\n }\n return { res: { code: 0, message: 'OK' } };\n },\n );\n }\n })();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"legacy_index.js","sourceRoot":"","sources":["../src/legacy_index.ts"],"names":[],"mappings":";;AAAA,uDAA8F;AAC9F,mDAAyE;AACzE,+CAA4C;AAC5C,+CAA6D;AAC7D,yCAAmE;AACnE,mCAAoC;AACpC,yCAAgE;AAChE,mDAa2B;AAC3B,iDAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,wBAAwB,GAA0D,EAAE,CAAC;AAC3F,MAAM,eAAe,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;IAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAO,CAAC,CAAC,gBAAgB;IACzD,MAAM,KAAK,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAC/C,IAAI,KAAK,EAAE;QACT,IAAI,KAAK,CAAC,UAAU,GAAG,UAAU,EAAE;YACjC,OAAO,KAAK,CAAC,KAAK,CAAC;SACpB;KACF;IACD,MAAM,IAAI,GAAG,MAAM,IAAA,kCAAqB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC;IACtC,wBAAwB,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IACrE,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,SAAkB,EAAE,EAAE;IACrD,QAAQ,SAAS,EAAE;QACjB,KAAK,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,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,YAAY,CAAC;gBAClD,UAAU,EAAE;oBACV,UAAU,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE;iBAC1C;aACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;gBACZ,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;gBACtB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;oBACnB,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC;iBAChE;gBACD,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBACxD,IAAI,QAAQ,KAAK,aAAa,EAAE;oBAC9B,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAqB,QAAQ,EAAE,EAAE,EAAE,CAAC;iBACzE;gBACD,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAa,EAAC,UAAU,EAAE;oBACnD,MAAM;oBACN,OAAO,EAAE,KAAK,CAAC,QAAQ;iBACxB,CAAC,CAAC;gBACH,IAAI,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE;oBAC5B,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC;iBACxE;gBACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;YAC7C,CAAC,CACF,CAAC;SACH;IACH,CAAC,CAAC,EAAE,CAAC;CACN","sourcesContent":["import { addAccountMarket, IPosition, provideAccountInfoService } from '@yuants/data-account';\nimport { IOrder, providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { createHash } from 'crypto';\nimport { getDefaultCredential, isApiError } from './api/client';\nimport {\n deleteUmOrder,\n getDepositAddress,\n getDepositHistory,\n getSpotAccountInfo,\n getSubAccountList,\n getUnifiedAccountBalance,\n getUnifiedUmAccount,\n getUnifiedUmOpenOrders,\n getWithdrawHistory,\n postAssetTransfer,\n postUmOrder,\n postWithdraw,\n} from './api/private-api';\nimport { getFutureOpenInterest } from './api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst _mapSymbolToOpenInterest: Record<string, { value: number; updated_at: number }> = {};\nconst getOpenInterest = async (symbol: string) => {\n const expired_at = Date.now() - 600_000; // 10min expired\n const cache = _mapSymbolToOpenInterest[symbol];\n if (cache) {\n if (cache.updated_at > expired_at) {\n return cache.value;\n }\n }\n const data = await getFutureOpenInterest({ symbol });\n const value = +data.openInterest || 0;\n _mapSymbolToOpenInterest[symbol] = { value, updated_at: Date.now() };\n return value;\n};\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 'OPEN_SHORT':\n case 'CLOSE_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 case 'MAKER':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nconst mapBinanceOrderTypeToYuants = (binanceType?: string): IOrder['order_type'] => {\n switch (binanceType) {\n case 'LIMIT':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n default:\n return 'LIMIT';\n }\n};\n\nconst mapBinanceSideToYuantsDirection = (\n side?: string,\n positionSide?: string,\n): IOrder['order_direction'] | undefined => {\n if (!side || !positionSide) {\n return undefined;\n }\n if (positionSide === 'LONG') {\n return side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (positionSide === 'SHORT') {\n return side === 'SELL' ? 'OPEN_SHORT' : 'CLOSE_SHORT';\n }\n return undefined;\n};\n\nconst deriveClientOrderId = (order: IOrder) => {\n if (order.order_id) return `${order.order_id}`;\n if (order.comment) return order.comment;\n const payload = JSON.stringify({\n account_id: order.account_id,\n product_id: order.product_id,\n order_direction: order.order_direction,\n order_type: order.order_type,\n price: order.price,\n volume: order.volume,\n });\n return `YUANTS${createHash('sha256').update(payload).digest('hex').slice(0, 24)}`;\n};\n\nconst isPublicOnly = process.env.PUBLIC_ONLY === 'true';\n\n// provideTicks(terminal, 'binance', (product_id) => {\n// const [instType, symbol] = decodePath(product_id);\n// if (instType === 'usdt-future') {\n// return combineLatest([mapSymbolToFuturePremiumIndex$, mapSymbolToFutureBookTicker$]).pipe(\n// combineLatestWith(defer(() => getOpenInterest(symbol))),\n// map(([[mapSymbolToFuturePremiumIndex, mapSymbolToFutureBookTicker], openInterestVolume]): ITick => {\n// const premiumIndex = mapSymbolToFuturePremiumIndex.get(symbol);\n// const bookTicker = mapSymbolToFutureBookTicker.get(symbol);\n// if (!premiumIndex) {\n// throw new Error(`Premium Index Not Found: ${symbol}`);\n// }\n// if (!bookTicker) {\n// throw new Error(`Book Ticker Not Found: ${symbol}`);\n// }\n// return {\n// datasource_id: 'binance',\n// product_id,\n// updated_at: Date.now(),\n// price: +premiumIndex.markPrice,\n// ask: +bookTicker.askPrice,\n// bid: +bookTicker.bidPrice,\n// interest_rate_for_long: -+premiumIndex.lastFundingRate,\n// interest_rate_for_short: +premiumIndex.lastFundingRate,\n// settlement_scheduled_at: premiumIndex.nextFundingTime,\n// open_interest: openInterestVolume,\n// };\n// }),\n// );\n// }\n// return EMPTY;\n// });\n\nif (isPublicOnly) {\n console.info('PUBLIC_ONLY=1, skip Binance legacy services');\n} else {\n const credential = getDefaultCredential();\n (async () => {\n const spotAccountInfo = await getSpotAccountInfo(credential);\n if (isApiError(spotAccountInfo)) {\n throw new Error(spotAccountInfo.msg);\n }\n const uid = spotAccountInfo.uid;\n\n const SPOT_ACCOUNT_ID = `binance/${uid}/spot/usdt`;\n const UNIFIED_ACCOUNT_ID = `binance/${uid}/unified/usdt`;\n\n {\n // unified accountInfo\n\n provideAccountInfoService(\n terminal,\n UNIFIED_ACCOUNT_ID,\n async () => {\n const [accountResult, umAccountResult] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(accountResult)) {\n throw new Error(accountResult.msg);\n }\n const usdtAssets = accountResult.find((v) => v.asset === 'USDT');\n if (!usdtAssets) {\n throw new Error('USDT not found');\n }\n if (isApiError(umAccountResult)) {\n throw new Error(umAccountResult.msg);\n }\n const usdtUmAssets = umAccountResult.assets.find((v) => v.asset === 'USDT');\n if (!usdtUmAssets) {\n throw new Error('um USDT not found');\n }\n const equity = +usdtAssets.totalWalletBalance + +usdtAssets.umUnrealizedPNL;\n const free = equity - +usdtUmAssets.initialMargin;\n\n const positions = umAccountResult.positions\n .filter((v) => +v.positionAmt !== 0)\n .map((v): IPosition => {\n return {\n position_id: `${v.symbol}/${v.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('usdt-future', v.symbol),\n direction: v.positionSide,\n volume: +v.positionAmt,\n free_volume: +v.positionAmt,\n position_price: +v.entryPrice,\n closable_price: +v.entryPrice + +v.unrealizedProfit / +v.positionAmt,\n floating_profit: +v.unrealizedProfit,\n valuation: +v.positionAmt * (+v.entryPrice + +v.unrealizedProfit / +v.positionAmt),\n };\n });\n\n return positions;\n },\n { auto_refresh_interval: 1000 },\n );\n\n addAccountMarket(terminal, { account_id: UNIFIED_ACCOUNT_ID, market_id: 'BINANCE/UNIFIED' });\n }\n\n {\n // spot account info\n\n provideAccountInfoService(\n terminal,\n SPOT_ACCOUNT_ID,\n async () => {\n const spotAccountResult = await getSpotAccountInfo(credential, { omitZeroBalances: true });\n if (isApiError(spotAccountResult)) {\n throw new Error(spotAccountResult.msg);\n }\n const usdtAssets = spotAccountResult.balances.find((v) => v.asset === 'USDT');\n const positions = spotAccountResult.balances\n .filter((balance) => balance.asset !== 'USDT')\n .map((balance) => {\n const volume = +balance.free + +balance.locked;\n if (!volume) {\n return undefined;\n }\n const position: IPosition = {\n position_id: `spot/${balance.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('spot', `${balance.asset}USDT`),\n direction: 'LONG',\n volume,\n free_volume: +balance.free,\n position_price: 0,\n closable_price: 0,\n floating_profit: 0,\n valuation: 0,\n };\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return positions;\n },\n {\n auto_refresh_interval: 5_000,\n },\n );\n\n addAccountMarket(terminal, { account_id: SPOT_ACCOUNT_ID, market_id: 'BINANCE/SPOT' });\n }\n\n // transfer\n {\n // spot -> unified\n const SPOT_UNIFIED_NETWORK_ID = `binance/${uid}/spot/unified`;\n addAccountTransferAddress({\n terminal,\n account_id: SPOT_ACCOUNT_ID,\n network_id: SPOT_UNIFIED_NETWORK_ID,\n currency: 'USDT',\n address: `unified`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: 'MAIN_PORTFOLIO_MARGIN',\n asset: 'USDT',\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };\n },\n },\n onEval: async (order) => {\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n\n // unified -> spot\n addAccountTransferAddress({\n terminal,\n account_id: UNIFIED_ACCOUNT_ID,\n network_id: SPOT_UNIFIED_NETWORK_ID,\n currency: 'USDT',\n address: `spot`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postAssetTransfer(credential, {\n type: 'PORTFOLIO_MARGIN_MAIN',\n asset: 'USDT',\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };\n },\n },\n onEval: async (order) => {\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n\n const subAccountsResult = await getSubAccountList(credential);\n const isMain = !isApiError(subAccountsResult);\n // main -> sub\n // TODO...\n\n // blockchain\n if (isMain) {\n const depositAddressResult = await getDepositAddress(credential, { coin: 'USDT', network: 'TRX' });\n addAccountTransferAddress({\n terminal,\n account_id: SPOT_ACCOUNT_ID,\n network_id: 'TRC20',\n currency: 'USDT',\n address: depositAddressResult.address,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postWithdraw(credential, {\n coin: 'USDT',\n network: 'TRX',\n address: order.current_rx_address!,\n amount: order.current_amount!,\n });\n if (isApiError(transferResult)) {\n return { state: 'ERROR', message: transferResult.msg };\n }\n const wdId = transferResult.id;\n return { state: 'PENDING', context: wdId };\n },\n PENDING: async (order) => {\n const wdId = order.current_tx_context;\n const withdrawResult = await getWithdrawHistory(credential, { coin: 'USDT' });\n const record = withdrawResult?.find((v) => v.id === wdId);\n const txId = record?.txId;\n if (!txId) {\n return { state: 'PENDING', context: wdId };\n }\n return { state: 'COMPLETE', transaction_id: txId };\n },\n },\n onEval: async (order) => {\n const checkResult = await getDepositHistory(credential, {\n coin: 'USDT',\n txId: order.current_transaction_id,\n });\n if (checkResult?.[0]?.status !== 1) {\n return { state: 'PENDING' };\n }\n const received_amount = +checkResult[0].amount;\n return { state: 'COMPLETE', received_amount };\n },\n });\n }\n }\n\n // order related\n {\n providePendingOrdersService(\n terminal,\n UNIFIED_ACCOUNT_ID,\n async () => {\n const openOrders = await getUnifiedUmOpenOrders(credential);\n return openOrders.map((order): IOrder => {\n const order_direction =\n mapBinanceSideToYuantsDirection(order.side, order.positionSide) ?? 'OPEN_LONG';\n return {\n order_id: `${order.orderId}`,\n account_id: UNIFIED_ACCOUNT_ID,\n product_id: encodePath('usdt-future', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction,\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: new Date(order.updateTime).toISOString(),\n order_status: order.status,\n };\n });\n },\n { auto_refresh_interval: 1000 },\n );\n\n terminal.server.provideService<IOrder>(\n 'SubmitOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: UNIFIED_ACCOUNT_ID },\n },\n },\n async (msg) => {\n console.info(formatTime(Date.now()), 'SubmitOrder', msg.req);\n const order = msg.req;\n const [instType, symbol] = decodePath(order.product_id);\n if (instType === 'usdt-future') {\n const params = {\n symbol,\n side: mapOrderDirectionToSide(order.order_direction),\n positionSide: mapOrderDirectionToPosSide(order.order_direction),\n type: mapOrderTypeToOrdType(order.order_type),\n timeInForce:\n order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined,\n quantity: order.volume,\n price: order.price,\n newClientOrderId: deriveClientOrderId(order),\n };\n\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const orderResult = await postUmOrder(credential, params);\n if (isApiError(orderResult)) {\n return { res: { code: orderResult.code, message: orderResult.msg } };\n }\n return { res: { code: 0, message: 'OK', order_id: orderResult.orderId } };\n }\n return { res: { code: 400, message: `unsupported type: ${instType}` } };\n },\n );\n }\n\n {\n terminal.server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id', 'order_id', 'product_id'],\n properties: {\n account_id: { const: UNIFIED_ACCOUNT_ID },\n },\n },\n async (msg) => {\n const order = msg.req;\n if (!order.order_id) {\n return { res: { code: 400, message: 'order_id is required' } };\n }\n const [instType, symbol] = decodePath(order.product_id);\n if (instType !== 'usdt-future') {\n return { res: { code: 400, message: `unsupported type: ${instType}` } };\n }\n const cancelResult = await deleteUmOrder(credential, {\n symbol,\n orderId: order.order_id,\n });\n if (isApiError(cancelResult)) {\n return { res: { code: cancelResult.code, message: cancelResult.msg } };\n }\n return { res: { code: 0, message: 'OK' } };\n },\n );\n }\n })();\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,
|
|
1
|
+
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAA+B,MAAM,sBAAsB,CAAC;AAGnG,OAAO,EAAsB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExE,eAAO,MAAM,0BAA0B,EAAE,8BAA8B,CAAC,WAAW,CAqBlF,CAAC"}
|
|
@@ -1,48 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSpotAccountInfoSnapshot = void 0;
|
|
4
|
+
const data_account_1 = require("@yuants/data-account");
|
|
4
5
|
const utils_1 = require("@yuants/utils");
|
|
5
6
|
const client_1 = require("../../api/client");
|
|
6
7
|
const private_api_1 = require("../../api/private-api");
|
|
7
|
-
const getSpotAccountInfoSnapshot = async (credential
|
|
8
|
-
var _a, _b;
|
|
8
|
+
const getSpotAccountInfoSnapshot = async (credential) => {
|
|
9
9
|
const res = await (0, private_api_1.getSpotAccountInfo)(credential, { omitZeroBalances: true });
|
|
10
10
|
if ((0, client_1.isApiError)(res)) {
|
|
11
11
|
throw new Error(res.msg);
|
|
12
12
|
}
|
|
13
|
-
const usdtAsset = res.balances.find((balance) => balance.asset === 'USDT');
|
|
14
|
-
const free = +((_a = usdtAsset === null || usdtAsset === void 0 ? void 0 : usdtAsset.free) !== null && _a !== void 0 ? _a : 0);
|
|
15
|
-
const locked = +((_b = usdtAsset === null || usdtAsset === void 0 ? void 0 : usdtAsset.locked) !== null && _b !== void 0 ? _b : 0);
|
|
16
|
-
const equity = free + locked;
|
|
17
13
|
const positions = res.balances
|
|
18
|
-
.filter((balance) => balance.asset !== 'USDT')
|
|
19
14
|
.map((balance) => {
|
|
20
15
|
const volume = +balance.free + +balance.locked;
|
|
21
16
|
if (!volume)
|
|
22
17
|
return undefined;
|
|
23
|
-
const position = {
|
|
18
|
+
const position = (0, data_account_1.makeSpotPosition)({
|
|
24
19
|
position_id: `spot/${balance.asset}`,
|
|
25
20
|
datasource_id: 'BINANCE',
|
|
26
21
|
product_id: (0, utils_1.encodePath)('spot', `${balance.asset}USDT`),
|
|
27
|
-
direction: 'LONG',
|
|
28
22
|
volume,
|
|
29
23
|
free_volume: +balance.free,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
floating_profit: 0,
|
|
33
|
-
valuation: 0,
|
|
34
|
-
};
|
|
24
|
+
closable_price: 0, // TODO: fetch price later
|
|
25
|
+
});
|
|
35
26
|
return position;
|
|
36
27
|
})
|
|
37
28
|
.filter((position) => Boolean(position));
|
|
38
|
-
return
|
|
39
|
-
money: {
|
|
40
|
-
currency: 'USDT',
|
|
41
|
-
equity,
|
|
42
|
-
free,
|
|
43
|
-
},
|
|
44
|
-
positions,
|
|
45
|
-
};
|
|
29
|
+
return positions;
|
|
46
30
|
};
|
|
47
31
|
exports.getSpotAccountInfoSnapshot = getSpotAccountInfoSnapshot;
|
|
48
32
|
//# sourceMappingURL=spot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmG;AACnG,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAwE;AAEjE,MAAM,0BAA0B,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAC1G,MAAM,GAAG,GAAG,MAAM,IAAA,gCAAkB,EAAC,UAAU,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ;SAC3B,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACf,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;QAC/C,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAC;QAC9B,MAAM,QAAQ,GAAc,IAAA,+BAAgB,EAAC;YAC3C,WAAW,EAAE,QAAQ,OAAO,CAAC,KAAK,EAAE;YACpC,aAAa,EAAE,SAAS;YACxB,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,MAAM,CAAC;YACtD,MAAM;YACN,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI;YAC1B,cAAc,EAAE,CAAC,EAAE,0BAA0B;SAC9C,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,QAAQ,EAAyB,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AArBW,QAAA,0BAA0B,8BAqBrC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getSpotAccountInfo, ICredential } from '../../api/private-api';\n\nexport const getSpotAccountInfoSnapshot: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const res = await getSpotAccountInfo(credential, { omitZeroBalances: true });\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n const positions = res.balances\n .map((balance) => {\n const volume = +balance.free + +balance.locked;\n if (!volume) return undefined;\n const position: IPosition = makeSpotPosition({\n position_id: `spot/${balance.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('spot', `${balance.asset}USDT`),\n volume,\n free_volume: +balance.free,\n closable_price: 0, // TODO: fetch price later\n });\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return positions;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAGjF,OAAO,EAAiD,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEnG,eAAO,MAAM,qBAAqB,EAAE,8BAA8B,CAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAGjF,OAAO,EAAiD,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEnG,eAAO,MAAM,qBAAqB,EAAE,8BAA8B,CAAC,WAAW,CAoD7E,CAAC"}
|
|
@@ -47,14 +47,7 @@ const getUnifiedAccountInfo = async (credential, _accountId) => {
|
|
|
47
47
|
(+position.entryPrice +
|
|
48
48
|
(+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),
|
|
49
49
|
}));
|
|
50
|
-
return
|
|
51
|
-
money: {
|
|
52
|
-
currency: 'USDT',
|
|
53
|
-
equity,
|
|
54
|
-
free,
|
|
55
|
-
},
|
|
56
|
-
positions,
|
|
57
|
-
};
|
|
50
|
+
return positions;
|
|
58
51
|
};
|
|
59
52
|
exports.getUnifiedAccountInfo = getUnifiedAccountInfo;
|
|
60
53
|
//# sourceMappingURL=unified.js.map
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GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAClB,WAAW,EAAE,GAAG,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,YAAY,EAAE;QAC1D,aAAa,EAAE,SAAS;QACxB,UAAU,EAAE,IAAA,kBAAU,EAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC;QACtD,SAAS,EACP,QAAQ,CAAC,YAAY,KAAK,MAAM;YAC9B,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,QAAQ,CAAC,YAAY,KAAK,OAAO;gBACnC,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,QAAQ,CAAC,YAAY,KAAK,MAAM;oBAClC,CAAC,CAAC,MAAM;oBACR,CAAC,CAAC,SAAS;QACf,MAAM,EAAE,CAAC,QAAQ,CAAC,WAAW;QAC7B,WAAW,EAAE,CAAC,QAAQ,CAAC,WAAW;QAClC,cAAc,EAAE,CAAC,QAAQ,CAAC,UAAU;QACpC,cAAc,EAAE,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,QAAQ,CAAC,gBAAgB,GAAG,CAAC,QAAQ,CAAC,WAAW;QACzF,eAAe,EAAE,CAAC,QAAQ,CAAC,gBAAgB;QAC3C,SAAS,EACP,CAAC,QAAQ,CAAC,WAAW;YACrB,CAAC,CAAC,QAAQ,CAAC,UAAU;gBACnB,CAAC,CAAC,QAAQ,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;KAC5F,CAAC,CAAC,CAAC;IAEN,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AApDW,QAAA,qBAAqB,yBAoDhC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\n\nexport const getUnifiedAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (\n credential,\n _accountId,\n) => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n const usdtBalance = balanceRes.find((item) => item.asset === 'USDT');\n if (!usdtBalance) {\n throw new Error('USDT balance not found');\n }\n const usdtAsset = umAccountRes.assets.find((item) => item.asset === 'USDT');\n if (!usdtAsset) {\n throw new Error('USDT asset not found in UM account');\n }\n\n const equity = +usdtBalance.totalWalletBalance + +usdtBalance.umUnrealizedPNL;\n const free = equity - +usdtAsset.initialMargin;\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('usdt-future', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: +position.positionAmt,\n free_volume: +position.positionAmt,\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n return positions;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-binance",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@yuants/protocol": "0.52.0",
|
|
12
|
-
"@yuants/data-account": "0.
|
|
12
|
+
"@yuants/data-account": "0.8.0",
|
|
13
13
|
"@yuants/cache": "0.3.0",
|
|
14
14
|
"@yuants/data-quote": "0.2.39",
|
|
15
15
|
"@yuants/utils": "0.11.0",
|
package/temp/package-deps.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"apps/vendor-binance/AGENTS.md": "378369925bffa237cd5e8ef459fe2bc2a141337c",
|
|
3
|
-
"apps/vendor-binance/CHANGELOG.json": "
|
|
4
|
-
"apps/vendor-binance/CHANGELOG.md": "
|
|
3
|
+
"apps/vendor-binance/CHANGELOG.json": "be006f96b97bee6a376d0b8a00dddacfcd376cd7",
|
|
4
|
+
"apps/vendor-binance/CHANGELOG.md": "2adfba8aeeeb2bfdf29fc451d18e4c004e95294e",
|
|
5
5
|
"apps/vendor-binance/README.md": "4ab94c08b3d07398aee74c3264a4f87d554d20fa",
|
|
6
6
|
"apps/vendor-binance/SESSION_NOTES.md": "de8229b25654f9be78047580112c7987990dd34a",
|
|
7
7
|
"apps/vendor-binance/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
@@ -9,21 +9,21 @@
|
|
|
9
9
|
"apps/vendor-binance/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
10
10
|
"apps/vendor-binance/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
11
11
|
"apps/vendor-binance/etc/vendor-binance.api.md": "2094b84e9b5e7503f5c42b31fffee8d7db47fe7b",
|
|
12
|
-
"apps/vendor-binance/package.json": "
|
|
12
|
+
"apps/vendor-binance/package.json": "af5e326fe093c0540c142fb5d0596b4ecdd4d55a",
|
|
13
13
|
"apps/vendor-binance/src/api/client.ts": "bce65e7525e12ac6ecfb69899f5ed2056ee80404",
|
|
14
14
|
"apps/vendor-binance/src/api/private-api.ts": "e7643bd482e4d8f4eefe39aee578e5ea52094b2b",
|
|
15
15
|
"apps/vendor-binance/src/api/public-api.ts": "04671c8732103fac9267c4133a8b96642452daa9",
|
|
16
16
|
"apps/vendor-binance/src/cli.ts": "9bf6b5559a6c6f33da20e74cc6c5d702c60ec891",
|
|
17
17
|
"apps/vendor-binance/src/index.ts": "50cef2ecce48b30f38bf67728cf1b13afadf9e69",
|
|
18
|
-
"apps/vendor-binance/src/legacy_index.ts": "
|
|
18
|
+
"apps/vendor-binance/src/legacy_index.ts": "bff1adb804a9ea3a2cd14739d54719e045d3b47b",
|
|
19
19
|
"apps/vendor-binance/src/public-data/interest_rate.ts": "5707961027cfc8be32dd40263ca075c2068535bb",
|
|
20
20
|
"apps/vendor-binance/src/public-data/ohlc.ts": "bbc2a939865537f0db0089d43b5cc1b7dff7f348",
|
|
21
21
|
"apps/vendor-binance/src/public-data/product.ts": "6fcc1e8cbcba7e5e21b821552f883ef11b7672e1",
|
|
22
22
|
"apps/vendor-binance/src/public-data/quote.ts": "be625c1719763323f152164c598ea96e73e9531c",
|
|
23
23
|
"apps/vendor-binance/src/services/account-actions-with-credential.ts": "0f53b961fc5885deaca1c5776e82a95f5acd9917",
|
|
24
24
|
"apps/vendor-binance/src/services/accounts/profile.ts": "63205996e6525d103d1829814e04f7a352e15541",
|
|
25
|
-
"apps/vendor-binance/src/services/accounts/spot.ts": "
|
|
26
|
-
"apps/vendor-binance/src/services/accounts/unified.ts": "
|
|
25
|
+
"apps/vendor-binance/src/services/accounts/spot.ts": "57ec87db6626b0138ce6ad00e5aa738918993750",
|
|
26
|
+
"apps/vendor-binance/src/services/accounts/unified.ts": "681a96fdfac79d33421ea02f3f2e40ca7bd82bc3",
|
|
27
27
|
"apps/vendor-binance/src/services/order-actions-with-credential.ts": "d7ea63781f6c4d3a47e453a48935692c3c9e761d",
|
|
28
28
|
"apps/vendor-binance/src/services/orders/cancelOrder.ts": "44b6f87bca28108e0aebe4ef469172ba0c86b402",
|
|
29
29
|
"apps/vendor-binance/src/services/orders/listOrders.ts": "b81b8de6a20de37a692a57569b93bdfb9b96a9ed",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"apps/vendor-binance/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
|
|
34
34
|
"apps/vendor-binance/.rush/temp/shrinkwrap-deps.json": "7b773443e30eca79d696c3c880b16f7ffcb15b02",
|
|
35
35
|
"libraries/protocol/temp/package-deps.json": "52d2a645608a17915da897e48a70b415312a94fb",
|
|
36
|
-
"libraries/data-account/temp/package-deps.json": "
|
|
36
|
+
"libraries/data-account/temp/package-deps.json": "459a552a5ff4304fff00dfd369bb0746bd33cf5f",
|
|
37
37
|
"libraries/cache/temp/package-deps.json": "49789a92426969daa31f0c956bb56bd783929765",
|
|
38
38
|
"libraries/data-quote/temp/package-deps.json": "33004046da19873dfe361b54e69d47dc170a66e7",
|
|
39
39
|
"libraries/utils/temp/package-deps.json": "c58f1ca8f498315d9a0219ca8c498299a41d297b",
|