@yuants/vendor-aster 0.7.25 → 0.7.27
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/api/private-api.js +6 -0
- package/dist/api/private-api.js.map +1 -1
- package/dist/services/accounts/spot.js +6 -3
- package/dist/services/accounts/spot.js.map +1 -1
- package/lib/api/private-api.d.ts +22 -0
- package/lib/api/private-api.d.ts.map +1 -1
- package/lib/api/private-api.js +7 -1
- package/lib/api/private-api.js.map +1 -1
- package/lib/services/accounts/spot.d.ts.map +1 -1
- package/lib/services/accounts/spot.js +5 -2
- package/lib/services/accounts/spot.js.map +1 -1
- package/package.json +3 -3
- package/temp/package-deps.json +7 -7
package/dist/api/private-api.js
CHANGED
|
@@ -48,6 +48,12 @@ const createSpotApi = createApi('https://sapi.asterdex.com');
|
|
|
48
48
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data
|
|
49
49
|
*/
|
|
50
50
|
export const getFApiV4Account = createFutureApi('GET', '/fapi/v4/account');
|
|
51
|
+
/**
|
|
52
|
+
* 用户持仓风险V2 (USER_DATA)
|
|
53
|
+
*
|
|
54
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data
|
|
55
|
+
*/
|
|
56
|
+
export const getFApiV2PositionRisk = createFutureApi('GET', '/fapi/v2/positionRisk');
|
|
51
57
|
export const getFApiV2Balance = createFutureApi('GET', '/fapi/v2/balance');
|
|
52
58
|
export const postFApiV1Order = createFutureApi('POST', '/fapi/v1/order');
|
|
53
59
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QA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G,eAAe,CAa7C,KAAK,EAAE,kBAAkB,CAAC,CAAC;AAE7B,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAmB5C,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE5B;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAKhD,KAAK,EAAE,qBAAqB,CAAC,CAAC;AAEhC;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAK7C,KAAK,EAAE,oBAAoB,CAAC,CAAC;AAE/B,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAO9C,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AAE9B;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAe1C,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAE5B;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAO9C,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAazC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAO3C,QAAQ,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { encodeHex, HmacSHA256, newError } from '@yuants/utils';\n\nimport { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\n\nconst MetricsAsterApiCallCounter = GlobalPrometheusRegistry.counter(\n 'aster_api_call',\n 'Number of aster api call',\n);\nconst terminal = Terminal.fromNodeEnv();\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nexport interface IAsterFutureOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n updateTime: number;\n avgPrice: string;\n reduceOnly?: boolean;\n closePosition?: boolean;\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n workingType?: string;\n priceProtect?: boolean;\n origType?: string;\n stopPrice?: string;\n symbol: string;\n}\n\nexport interface IAsterSpotOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n cummulativeQuoteQty?: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n stopPrice?: string;\n icebergQty?: string;\n time: number;\n updateTime: number;\n isWorking?: boolean;\n avgPrice?: string;\n symbol: string;\n}\n\nconst request = async <T>(\n credential: ICredential,\n method: string,\n baseURL: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const url = new URL(baseURL);\n url.pathname = endpoint;\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined) continue;\n url.searchParams.set(key, `${value}`);\n }\n\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = encodeHex(\n await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n\n console.info(url.toString());\n MetricsAsterApiCallCounter.labels({ path: url.pathname, terminal_id: terminal.terminal_id }).inc();\n const response = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n });\n\n const resText = await response.text();\n\n try {\n const res = JSON.parse(resText);\n\n if (res.code && res.code !== 0) {\n throw resText;\n }\n return res;\n } catch (e) {\n throw newError(\n 'ASTER_API_ERROR',\n {\n status: response.status,\n statusText: response.statusText,\n resText,\n params,\n },\n e,\n );\n }\n};\n\nconst createApi =\n (baseURL: string) =>\n <TReq, TRes>(method: string, endpoint: string) =>\n (credential: ICredential, params: TReq) =>\n request<TRes>(credential, method, baseURL, endpoint, params);\n\nconst createFutureApi = createApi('https://fapi.asterdex.com');\nconst createSpotApi = createApi('https://sapi.asterdex.com');\n\n/**\n * 获取账户信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data\n */\nexport const getFApiV4Account = createFutureApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n updateTime: number;\n totalInitialMargin: string;\n totalMaintMargin: string;\n totalWalletBalance: string;\n totalUnrealizedProfit: string;\n totalMarginBalance: string;\n totalPositionInitialMargin: string;\n totalOpenOrderInitialMargin: string;\n totalCrossWalletBalance: string;\n totalCrossUnPnl: string;\n availableBalance: string;\n maxWithdrawAmount: string;\n assets: {\n asset: string;\n walletBalance: string;\n unrealizedProfit: string;\n marginBalance: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n maxWithdrawAmount: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n availableBalance: string;\n marginAvailable: boolean;\n updateTime: number;\n }[];\n positions: {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n isolated: boolean;\n entryPrice: string;\n maxNotional: string;\n positionSide: 'BOTH' | 'LONG' | 'SHORT';\n positionAmt: string;\n notional: string;\n isolatedWallet: string;\n updateTime: number;\n }[];\n }\n>('GET', '/fapi/v4/account');\n\nexport const getFApiV2Balance = createFutureApi<\n {},\n {\n accountAlias: string; // 账户唯一识别码\n asset: string; // 资产\n balance: string; // 总余额\n crossWalletBalance: string; // 全仓余额\n crossUnPnl: string; // 全仓持仓未实现盈亏\n availableBalance: string; // 下单可用余额\n maxWithdrawAmount: string; // 最大可转出余额\n marginAvailable: boolean; // 是否可用作联合保证金\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/balance');\n\nexport const postFApiV1Order = createFutureApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n type:\n | 'MARKET'\n | 'LIMIT'\n | 'STOP'\n | 'STOP_MARKET'\n | 'TAKE_PROFIT'\n | 'TAKE_PROFIT_MARKET'\n | 'TRAILING_STOP_MARKET';\n reduceOnly?: 'true' | 'false';\n quantity?: number;\n price?: number;\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX' | 'HIDDEN';\n },\n {}\n>('POST', '/fapi/v1/order');\n\n/**\n * 查询当前挂单 (永续)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766\n */\nexport const getFApiV1OpenOrders = createFutureApi<\n {\n symbol?: string;\n },\n IAsterFutureOpenOrder[]\n>('GET', '/fapi/v1/openOrders');\n\n/**\n * 查询当前挂单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234\n */\nexport const getApiV1OpenOrders = createSpotApi<\n {\n symbol?: string;\n },\n IAsterSpotOpenOrder[]\n>('GET', '/api/v1/openOrders');\n\nexport const deleteFApiV1Order = createFutureApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/fapi/v1/order');\n\n/**\n * 获取账户信息 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getApiV1Account = createSpotApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n canBurnAsset: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n }\n>('GET', '/api/v1/account');\n\n/**\n * 获取最新价格\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC\n */\nexport const getApiV1TickerPrice = createSpotApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createSpotApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX';\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n },\n {\n orderId: number; // 系统的订单ID\n }\n>('POST', '/api/v1/order');\n\n/**\n * 取消有效订单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074\n */\nexport const deleteApiV1Order = createSpotApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/api/v1/order');\n"]}
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,wBAAwB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEtE,MAAM,0BAA0B,GAAG,wBAAwB,CAAC,OAAO,CACjE,gBAAgB,EAChB,0BAA0B,CAC3B,CAAC;AACF,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAkDxC,MAAM,OAAO,GAAG,KAAK,EACnB,UAAuB,EACvB,MAAc,EACd,OAAe,EACf,QAAgB,EAChB,SAAc,EAAE,EACJ,EAAE;IACd,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;KACvC;IAED,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,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,MAAM,cAAc,GAAG,aAAa,CAazC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAO3C,QAAQ,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { encodeHex, HmacSHA256, newError } from '@yuants/utils';\n\nimport { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\n\nconst MetricsAsterApiCallCounter = GlobalPrometheusRegistry.counter(\n 'aster_api_call',\n 'Number of aster api call',\n);\nconst terminal = Terminal.fromNodeEnv();\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nexport interface IAsterFutureOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n updateTime: number;\n avgPrice: string;\n reduceOnly?: boolean;\n closePosition?: boolean;\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n workingType?: string;\n priceProtect?: boolean;\n origType?: string;\n stopPrice?: string;\n symbol: string;\n}\n\nexport interface IAsterSpotOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n cummulativeQuoteQty?: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n stopPrice?: string;\n icebergQty?: string;\n time: number;\n updateTime: number;\n isWorking?: boolean;\n avgPrice?: string;\n symbol: string;\n}\n\nconst request = async <T>(\n credential: ICredential,\n method: string,\n baseURL: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const url = new URL(baseURL);\n url.pathname = endpoint;\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined) continue;\n url.searchParams.set(key, `${value}`);\n }\n\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = encodeHex(\n await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n\n console.info(url.toString());\n MetricsAsterApiCallCounter.labels({ path: url.pathname, terminal_id: terminal.terminal_id }).inc();\n const response = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n });\n\n const resText = await response.text();\n\n try {\n const res = JSON.parse(resText);\n\n if (res.code && res.code !== 0) {\n throw resText;\n }\n return res;\n } catch (e) {\n throw newError(\n 'ASTER_API_ERROR',\n {\n status: response.status,\n statusText: response.statusText,\n resText,\n params,\n },\n e,\n );\n }\n};\n\nconst createApi =\n (baseURL: string) =>\n <TReq, TRes>(method: string, endpoint: string) =>\n (credential: ICredential, params: TReq) =>\n request<TRes>(credential, method, baseURL, endpoint, params);\n\nconst createFutureApi = createApi('https://fapi.asterdex.com');\nconst createSpotApi = createApi('https://sapi.asterdex.com');\n\n/**\n * 获取账户信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data\n */\nexport const getFApiV4Account = createFutureApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n updateTime: number;\n totalInitialMargin: string;\n totalMaintMargin: string;\n totalWalletBalance: string;\n totalUnrealizedProfit: string;\n totalMarginBalance: string;\n totalPositionInitialMargin: string;\n totalOpenOrderInitialMargin: string;\n totalCrossWalletBalance: string;\n totalCrossUnPnl: string;\n availableBalance: string;\n maxWithdrawAmount: string;\n assets: {\n asset: string;\n walletBalance: string;\n unrealizedProfit: string;\n marginBalance: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n maxWithdrawAmount: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n availableBalance: string;\n marginAvailable: boolean;\n updateTime: number;\n }[];\n positions: {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n isolated: boolean;\n entryPrice: string;\n maxNotional: string;\n positionSide: 'BOTH' | 'LONG' | 'SHORT';\n positionAmt: string;\n notional: string;\n isolatedWallet: string;\n updateTime: number;\n }[];\n }\n>('GET', '/fapi/v4/account');\n\n/**\n * 用户持仓风险V2 (USER_DATA)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data\n */\nexport const getFApiV2PositionRisk = createFutureApi<\n {\n symbol?: string;\n },\n {\n entryPrice: string;\n marginType: string;\n isAutoAddMargin: string;\n isolatedMargin: string;\n leverage: string;\n liquidationPrice: string;\n markPrice: string;\n maxNotionalValue: string;\n positionAmt: string;\n symbol: string;\n unRealizedProfit: string;\n positionSide: string;\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/positionRisk');\n\nexport const getFApiV2Balance = createFutureApi<\n {},\n {\n accountAlias: string; // 账户唯一识别码\n asset: string; // 资产\n balance: string; // 总余额\n crossWalletBalance: string; // 全仓余额\n crossUnPnl: string; // 全仓持仓未实现盈亏\n availableBalance: string; // 下单可用余额\n maxWithdrawAmount: string; // 最大可转出余额\n marginAvailable: boolean; // 是否可用作联合保证金\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/balance');\n\nexport const postFApiV1Order = createFutureApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n type:\n | 'MARKET'\n | 'LIMIT'\n | 'STOP'\n | 'STOP_MARKET'\n | 'TAKE_PROFIT'\n | 'TAKE_PROFIT_MARKET'\n | 'TRAILING_STOP_MARKET';\n reduceOnly?: 'true' | 'false';\n quantity?: number;\n price?: number;\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX' | 'HIDDEN';\n },\n {}\n>('POST', '/fapi/v1/order');\n\n/**\n * 查询当前挂单 (永续)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766\n */\nexport const getFApiV1OpenOrders = createFutureApi<\n {\n symbol?: string;\n },\n IAsterFutureOpenOrder[]\n>('GET', '/fapi/v1/openOrders');\n\n/**\n * 查询当前挂单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234\n */\nexport const getApiV1OpenOrders = createSpotApi<\n {\n symbol?: string;\n },\n IAsterSpotOpenOrder[]\n>('GET', '/api/v1/openOrders');\n\nexport const deleteFApiV1Order = createFutureApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/fapi/v1/order');\n\n/**\n * 获取账户信息 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getApiV1Account = createSpotApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n canBurnAsset: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n }\n>('GET', '/api/v1/account');\n\n/**\n * 获取最新价格\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC\n */\nexport const getApiV1TickerPrice = createSpotApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createSpotApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX';\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n },\n {\n orderId: number; // 系统的订单ID\n }\n>('POST', '/api/v1/order');\n\n/**\n * 取消有效订单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074\n */\nexport const deleteApiV1Order = createSpotApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/api/v1/order');\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createCache } from '@yuants/cache';
|
|
2
2
|
import { makeSpotPosition } from '@yuants/data-account';
|
|
3
3
|
import { encodePath } from '@yuants/utils';
|
|
4
|
-
import { getApiV1Account, getApiV1TickerPrice, getFApiV4Account } from '../../api/private-api';
|
|
4
|
+
import { getApiV1Account, getApiV1TickerPrice, getFApiV2PositionRisk, getFApiV4Account, } from '../../api/private-api';
|
|
5
5
|
import { listProducts } from '../markets/product';
|
|
6
6
|
// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko
|
|
7
7
|
const asBNBPrice = createCache(() => fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')
|
|
@@ -21,12 +21,13 @@ const spotProductMapCache = createCache(async () => {
|
|
|
21
21
|
return map;
|
|
22
22
|
}, { expire: 86400000 });
|
|
23
23
|
export const getPositions = async (credential) => {
|
|
24
|
-
var _a, _b, _c, _d, _e;
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
25
25
|
const positions = [];
|
|
26
|
-
const [x, prices, prep, spotProductMap] = await Promise.all([
|
|
26
|
+
const [x, prices, prep, positionRisk, spotProductMap] = await Promise.all([
|
|
27
27
|
getApiV1Account(credential, {}),
|
|
28
28
|
getApiV1TickerPrice(credential, {}),
|
|
29
29
|
getFApiV4Account(credential, {}),
|
|
30
|
+
getFApiV2PositionRisk(credential, {}),
|
|
30
31
|
spotProductMapCache.query(''),
|
|
31
32
|
]);
|
|
32
33
|
const resolvedSpotProductMap = spotProductMap !== null && spotProductMap !== void 0 ? spotProductMap : new Map();
|
|
@@ -79,6 +80,8 @@ export const getPositions = async (credential) => {
|
|
|
79
80
|
position_price: +p.entryPrice,
|
|
80
81
|
closable_price: Math.abs(+p.notional / +p.positionAmt),
|
|
81
82
|
floating_profit: +p.unrealizedProfit,
|
|
83
|
+
// TODO: optimize find performance
|
|
84
|
+
liquidation_price: (_f = positionRisk.find((r) => r.symbol === p.symbol)) === null || _f === void 0 ? void 0 : _f.liquidationPrice,
|
|
82
85
|
valuation: Math.abs(+p.notional),
|
|
83
86
|
});
|
|
84
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qFAAqF;AACrF,MAAM,UAAU,GAAG,WAAW,CAC5B,GAAG,EAAE,CACH,KAAK,CAAC,yFAAyF,CAAC;KAC7F,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;KACzB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,GAAa,CAAC,EAC9D;IACE,MAAM,EAAE,KAAM,EAAE,WAAW;CAC5B,CACF,CAAC;AAEF,MAAM,mBA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AC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,0CAAE,gBAAgB;YACpF,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport {\n getApiV1Account,\n getApiV1TickerPrice,\n getFApiV2PositionRisk,\n getFApiV4Account,\n ICredential,\n} from '../../api/private-api';\nimport { listProducts } from '../markets/product';\n\n// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko\nconst asBNBPrice = createCache(\n () =>\n fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')\n .then((res) => res.json())\n .then((data) => data['astherus-staked-bnb'].usd as number),\n {\n expire: 60_000, // 1 minute\n },\n);\n\nconst spotProductMapCache = createCache(\n async () => {\n const products = await listProducts();\n const map = new Map<string, string>();\n for (const product of products) {\n const [, instType] = product.product_id.split('/');\n if (instType === 'SPOT') {\n map.set(product.base_currency, product.product_id);\n }\n }\n return map;\n },\n { expire: 86_400_000 },\n);\n\nexport const getPositions = async (credential: ICredential) => {\n const positions: IPosition[] = [];\n const [x, prices, prep, positionRisk, spotProductMap] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n getFApiV2PositionRisk(credential, {}),\n spotProductMapCache.query(''),\n ]);\n\n const resolvedSpotProductMap = spotProductMap ?? new Map<string, string>();\n\n for (const b of x.balances) {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n positions.push(\n makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: resolvedSpotProductMap.get(b.asset) ?? encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n }),\n );\n }\n\n for (const b of prep.assets) {\n if (+b.walletBalance === 0) continue;\n let thePrice = 0;\n if (b.asset === 'USDT') {\n thePrice = 1;\n } else if (b.asset === 'ASBNB') {\n const _p = await asBNBPrice.query('').catch(() => 0);\n if (_p) {\n thePrice = _p;\n }\n } else {\n thePrice = +(prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0);\n }\n\n positions.push(\n makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: thePrice,\n }),\n );\n }\n\n for (const p of prep.positions) {\n if (+p.positionAmt === 0) continue;\n positions.push({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n // TODO: optimize find performance\n liquidation_price: positionRisk.find((r) => r.symbol === p.symbol)?.liquidationPrice,\n valuation: Math.abs(+p.notional),\n });\n }\n\n return positions;\n};\n"]}
|
package/lib/api/private-api.d.ts
CHANGED
|
@@ -99,6 +99,28 @@ export declare const getFApiV4Account: (credential: ICredential, params: {}) =>
|
|
|
99
99
|
updateTime: number;
|
|
100
100
|
}[];
|
|
101
101
|
}>;
|
|
102
|
+
/**
|
|
103
|
+
* 用户持仓风险V2 (USER_DATA)
|
|
104
|
+
*
|
|
105
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data
|
|
106
|
+
*/
|
|
107
|
+
export declare const getFApiV2PositionRisk: (credential: ICredential, params: {
|
|
108
|
+
symbol?: string | undefined;
|
|
109
|
+
}) => Promise<{
|
|
110
|
+
entryPrice: string;
|
|
111
|
+
marginType: string;
|
|
112
|
+
isAutoAddMargin: string;
|
|
113
|
+
isolatedMargin: string;
|
|
114
|
+
leverage: string;
|
|
115
|
+
liquidationPrice: string;
|
|
116
|
+
markPrice: string;
|
|
117
|
+
maxNotionalValue: string;
|
|
118
|
+
positionAmt: string;
|
|
119
|
+
symbol: string;
|
|
120
|
+
unRealizedProfit: string;
|
|
121
|
+
positionSide: string;
|
|
122
|
+
updateTime: number;
|
|
123
|
+
}[]>;
|
|
102
124
|
export declare const getFApiV2Balance: (credential: ICredential, params: {}) => Promise<{
|
|
103
125
|
accountAlias: string;
|
|
104
126
|
asset: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-api.d.ts","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,MAA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
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteApiV1Order = exports.postApiV1Order = exports.getApiV1TickerPrice = exports.getApiV1Account = exports.deleteFApiV1Order = exports.getApiV1OpenOrders = exports.getFApiV1OpenOrders = exports.postFApiV1Order = exports.getFApiV2Balance = exports.getFApiV4Account = void 0;
|
|
3
|
+
exports.deleteApiV1Order = exports.postApiV1Order = exports.getApiV1TickerPrice = exports.getApiV1Account = exports.deleteFApiV1Order = exports.getApiV1OpenOrders = exports.getFApiV1OpenOrders = exports.postFApiV1Order = exports.getFApiV2Balance = exports.getFApiV2PositionRisk = exports.getFApiV4Account = void 0;
|
|
4
4
|
const utils_1 = require("@yuants/utils");
|
|
5
5
|
const protocol_1 = require("@yuants/protocol");
|
|
6
6
|
const MetricsAsterApiCallCounter = protocol_1.GlobalPrometheusRegistry.counter('aster_api_call', 'Number of aster api call');
|
|
@@ -51,6 +51,12 @@ const createSpotApi = createApi('https://sapi.asterdex.com');
|
|
|
51
51
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data
|
|
52
52
|
*/
|
|
53
53
|
exports.getFApiV4Account = createFutureApi('GET', '/fapi/v4/account');
|
|
54
|
+
/**
|
|
55
|
+
* 用户持仓风险V2 (USER_DATA)
|
|
56
|
+
*
|
|
57
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data
|
|
58
|
+
*/
|
|
59
|
+
exports.getFApiV2PositionRisk = createFutureApi('GET', '/fapi/v2/positionRisk');
|
|
54
60
|
exports.getFApiV2Balance = createFutureApi('GET', '/fapi/v2/balance');
|
|
55
61
|
exports.postFApiV1Order = createFutureApi('POST', '/fapi/v1/order');
|
|
56
62
|
/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AAC,CAAC;AAEhB,QAAA,gBAAgB,GAAG,eAAe,CAa7C,KAAK,EAAE,kBAAkB,CAAC,CAAC;AAEhB,QAAA,eAAe,GAAG,eAAe,CAmB5C,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE5B;;;;GAIG;AACU,QAAA,mBAAmB,GAAG,eAAe,CAKhD,KAAK,EAAE,qBAAqB,CAAC,CAAC;AAEhC;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,aAAa,CAK7C,KAAK,EAAE,oBAAoB,CAAC,CAAC;AAElB,QAAA,iBAAiB,GAAG,eAAe,CAO9C,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AAE9B;;;;GAIG;AACU,QAAA,eAAe,GAAG,aAAa,CAe1C,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAE5B;;;GAGG;AACU,QAAA,mBAAmB,GAAG,aAAa,CAO9C,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEpB,QAAA,cAAc,GAAG,aAAa,CAazC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3B;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,aAAa,CAO3C,QAAQ,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { encodeHex, HmacSHA256, newError } from '@yuants/utils';\n\nimport { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\n\nconst MetricsAsterApiCallCounter = GlobalPrometheusRegistry.counter(\n 'aster_api_call',\n 'Number of aster api call',\n);\nconst terminal = Terminal.fromNodeEnv();\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nexport interface IAsterFutureOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n updateTime: number;\n avgPrice: string;\n reduceOnly?: boolean;\n closePosition?: boolean;\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n workingType?: string;\n priceProtect?: boolean;\n origType?: string;\n stopPrice?: string;\n symbol: string;\n}\n\nexport interface IAsterSpotOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n cummulativeQuoteQty?: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n stopPrice?: string;\n icebergQty?: string;\n time: number;\n updateTime: number;\n isWorking?: boolean;\n avgPrice?: string;\n symbol: string;\n}\n\nconst request = async <T>(\n credential: ICredential,\n method: string,\n baseURL: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const url = new URL(baseURL);\n url.pathname = endpoint;\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined) continue;\n url.searchParams.set(key, `${value}`);\n }\n\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = encodeHex(\n await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n\n console.info(url.toString());\n MetricsAsterApiCallCounter.labels({ path: url.pathname, terminal_id: terminal.terminal_id }).inc();\n const response = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n });\n\n const resText = await response.text();\n\n try {\n const res = JSON.parse(resText);\n\n if (res.code && res.code !== 0) {\n throw resText;\n }\n return res;\n } catch (e) {\n throw newError(\n 'ASTER_API_ERROR',\n {\n status: response.status,\n statusText: response.statusText,\n resText,\n params,\n },\n e,\n );\n }\n};\n\nconst createApi =\n (baseURL: string) =>\n <TReq, TRes>(method: string, endpoint: string) =>\n (credential: ICredential, params: TReq) =>\n request<TRes>(credential, method, baseURL, endpoint, params);\n\nconst createFutureApi = createApi('https://fapi.asterdex.com');\nconst createSpotApi = createApi('https://sapi.asterdex.com');\n\n/**\n * 获取账户信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data\n */\nexport const getFApiV4Account = createFutureApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n updateTime: number;\n totalInitialMargin: string;\n totalMaintMargin: string;\n totalWalletBalance: string;\n totalUnrealizedProfit: string;\n totalMarginBalance: string;\n totalPositionInitialMargin: string;\n totalOpenOrderInitialMargin: string;\n totalCrossWalletBalance: string;\n totalCrossUnPnl: string;\n availableBalance: string;\n maxWithdrawAmount: string;\n assets: {\n asset: string;\n walletBalance: string;\n unrealizedProfit: string;\n marginBalance: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n maxWithdrawAmount: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n availableBalance: string;\n marginAvailable: boolean;\n updateTime: number;\n }[];\n positions: {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n isolated: boolean;\n entryPrice: string;\n maxNotional: string;\n positionSide: 'BOTH' | 'LONG' | 'SHORT';\n positionAmt: string;\n notional: string;\n isolatedWallet: string;\n updateTime: number;\n }[];\n }\n>('GET', '/fapi/v4/account');\n\nexport const getFApiV2Balance = createFutureApi<\n {},\n {\n accountAlias: string; // 账户唯一识别码\n asset: string; // 资产\n balance: string; // 总余额\n crossWalletBalance: string; // 全仓余额\n crossUnPnl: string; // 全仓持仓未实现盈亏\n availableBalance: string; // 下单可用余额\n maxWithdrawAmount: string; // 最大可转出余额\n marginAvailable: boolean; // 是否可用作联合保证金\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/balance');\n\nexport const postFApiV1Order = createFutureApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n type:\n | 'MARKET'\n | 'LIMIT'\n | 'STOP'\n | 'STOP_MARKET'\n | 'TAKE_PROFIT'\n | 'TAKE_PROFIT_MARKET'\n | 'TRAILING_STOP_MARKET';\n reduceOnly?: 'true' | 'false';\n quantity?: number;\n price?: number;\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX' | 'HIDDEN';\n },\n {}\n>('POST', '/fapi/v1/order');\n\n/**\n * 查询当前挂单 (永续)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766\n */\nexport const getFApiV1OpenOrders = createFutureApi<\n {\n symbol?: string;\n },\n IAsterFutureOpenOrder[]\n>('GET', '/fapi/v1/openOrders');\n\n/**\n * 查询当前挂单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234\n */\nexport const getApiV1OpenOrders = createSpotApi<\n {\n symbol?: string;\n },\n IAsterSpotOpenOrder[]\n>('GET', '/api/v1/openOrders');\n\nexport const deleteFApiV1Order = createFutureApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/fapi/v1/order');\n\n/**\n * 获取账户信息 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getApiV1Account = createSpotApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n canBurnAsset: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n }\n>('GET', '/api/v1/account');\n\n/**\n * 获取最新价格\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC\n */\nexport const getApiV1TickerPrice = createSpotApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createSpotApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX';\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n },\n {\n orderId: number; // 系统的订单ID\n }\n>('POST', '/api/v1/order');\n\n/**\n * 取消有效订单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074\n */\nexport const deleteApiV1Order = createSpotApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/api/v1/order');\n"]}
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":";;;AAAA,yCAAgE;AAEhE,+CAAsE;AAEtE,MAAM,0BAA0B,GAAG,mCAAwB,CAAC,OAAO,CACjE,gBAAgB,EAChB,0BAA0B,CAC3B,CAAC;AACF,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAkDxC,MAAM,OAAO,GAAG,KAAK,EACnB,UAAuB,EACvB,MAAc,EACd,OAAe,EACf,QAAgB,EAChB,SAAc,EAAE,EACJ,EAAE;IACd,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;KACvC;IAED,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;IAC7C,MAAM,SAAS,GAAG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,EAAE,EAAE,CACxC,OAAO,CAAO,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEjE,MAAM,eAAe,GAAG,SAAS,CAAC,2BAA2B,CAAC,CAAC;AAC/D,MAAM,aAAa,GAAG,SAAS,CAAC,2BAA2B,CAAC,CAAC;AAE7D;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,eAAe,CAqD7C,KAAK,EAAE,kBAAkB,CAAC,CAAC;AAE7B;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,eAAe,CAmBlD,KAAK,EAAE,uBAAuB,CAAC,CAAC;AAErB,QAAA,gBAAgB,GAAG,eAAe,CAa7C,KAAK,EAAE,kBAAkB,CAAC,CAAC;AAEhB,QAAA,eAAe,GAAG,eAAe,CAmB5C,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE5B;;;;GAIG;AACU,QAAA,mBAAmB,GAAG,eAAe,CAKhD,KAAK,EAAE,qBAAqB,CAAC,CAAC;AAEhC;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,aAAa,CAK7C,KAAK,EAAE,oBAAoB,CAAC,CAAC;AAElB,QAAA,iBAAiB,GAAG,eAAe,CAO9C,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AAE9B;;;;GAIG;AACU,QAAA,eAAe,GAAG,aAAa,CAe1C,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAE5B;;;GAGG;AACU,QAAA,mBAAmB,GAAG,aAAa,CAO9C,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEpB,QAAA,cAAc,GAAG,aAAa,CAazC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3B;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,aAAa,CAO3C,QAAQ,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { encodeHex, HmacSHA256, newError } from '@yuants/utils';\n\nimport { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\n\nconst MetricsAsterApiCallCounter = GlobalPrometheusRegistry.counter(\n 'aster_api_call',\n 'Number of aster api call',\n);\nconst terminal = Terminal.fromNodeEnv();\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nexport interface IAsterFutureOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n updateTime: number;\n avgPrice: string;\n reduceOnly?: boolean;\n closePosition?: boolean;\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n workingType?: string;\n priceProtect?: boolean;\n origType?: string;\n stopPrice?: string;\n symbol: string;\n}\n\nexport interface IAsterSpotOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n cummulativeQuoteQty?: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n stopPrice?: string;\n icebergQty?: string;\n time: number;\n updateTime: number;\n isWorking?: boolean;\n avgPrice?: string;\n symbol: string;\n}\n\nconst request = async <T>(\n credential: ICredential,\n method: string,\n baseURL: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const url = new URL(baseURL);\n url.pathname = endpoint;\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined) continue;\n url.searchParams.set(key, `${value}`);\n }\n\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = encodeHex(\n await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n\n console.info(url.toString());\n MetricsAsterApiCallCounter.labels({ path: url.pathname, terminal_id: terminal.terminal_id }).inc();\n const response = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n });\n\n const resText = await response.text();\n\n try {\n const res = JSON.parse(resText);\n\n if (res.code && res.code !== 0) {\n throw resText;\n }\n return res;\n } catch (e) {\n throw newError(\n 'ASTER_API_ERROR',\n {\n status: response.status,\n statusText: response.statusText,\n resText,\n params,\n },\n e,\n );\n }\n};\n\nconst createApi =\n (baseURL: string) =>\n <TReq, TRes>(method: string, endpoint: string) =>\n (credential: ICredential, params: TReq) =>\n request<TRes>(credential, method, baseURL, endpoint, params);\n\nconst createFutureApi = createApi('https://fapi.asterdex.com');\nconst createSpotApi = createApi('https://sapi.asterdex.com');\n\n/**\n * 获取账户信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data\n */\nexport const getFApiV4Account = createFutureApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n updateTime: number;\n totalInitialMargin: string;\n totalMaintMargin: string;\n totalWalletBalance: string;\n totalUnrealizedProfit: string;\n totalMarginBalance: string;\n totalPositionInitialMargin: string;\n totalOpenOrderInitialMargin: string;\n totalCrossWalletBalance: string;\n totalCrossUnPnl: string;\n availableBalance: string;\n maxWithdrawAmount: string;\n assets: {\n asset: string;\n walletBalance: string;\n unrealizedProfit: string;\n marginBalance: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n maxWithdrawAmount: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n availableBalance: string;\n marginAvailable: boolean;\n updateTime: number;\n }[];\n positions: {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n isolated: boolean;\n entryPrice: string;\n maxNotional: string;\n positionSide: 'BOTH' | 'LONG' | 'SHORT';\n positionAmt: string;\n notional: string;\n isolatedWallet: string;\n updateTime: number;\n }[];\n }\n>('GET', '/fapi/v4/account');\n\n/**\n * 用户持仓风险V2 (USER_DATA)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data\n */\nexport const getFApiV2PositionRisk = createFutureApi<\n {\n symbol?: string;\n },\n {\n entryPrice: string;\n marginType: string;\n isAutoAddMargin: string;\n isolatedMargin: string;\n leverage: string;\n liquidationPrice: string;\n markPrice: string;\n maxNotionalValue: string;\n positionAmt: string;\n symbol: string;\n unRealizedProfit: string;\n positionSide: string;\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/positionRisk');\n\nexport const getFApiV2Balance = createFutureApi<\n {},\n {\n accountAlias: string; // 账户唯一识别码\n asset: string; // 资产\n balance: string; // 总余额\n crossWalletBalance: string; // 全仓余额\n crossUnPnl: string; // 全仓持仓未实现盈亏\n availableBalance: string; // 下单可用余额\n maxWithdrawAmount: string; // 最大可转出余额\n marginAvailable: boolean; // 是否可用作联合保证金\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/balance');\n\nexport const postFApiV1Order = createFutureApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n type:\n | 'MARKET'\n | 'LIMIT'\n | 'STOP'\n | 'STOP_MARKET'\n | 'TAKE_PROFIT'\n | 'TAKE_PROFIT_MARKET'\n | 'TRAILING_STOP_MARKET';\n reduceOnly?: 'true' | 'false';\n quantity?: number;\n price?: number;\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX' | 'HIDDEN';\n },\n {}\n>('POST', '/fapi/v1/order');\n\n/**\n * 查询当前挂单 (永续)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766\n */\nexport const getFApiV1OpenOrders = createFutureApi<\n {\n symbol?: string;\n },\n IAsterFutureOpenOrder[]\n>('GET', '/fapi/v1/openOrders');\n\n/**\n * 查询当前挂单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234\n */\nexport const getApiV1OpenOrders = createSpotApi<\n {\n symbol?: string;\n },\n IAsterSpotOpenOrder[]\n>('GET', '/api/v1/openOrders');\n\nexport const deleteFApiV1Order = createFutureApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/fapi/v1/order');\n\n/**\n * 获取账户信息 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getApiV1Account = createSpotApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n canBurnAsset: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n }\n>('GET', '/api/v1/account');\n\n/**\n * 获取最新价格\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC\n */\nexport const getApiV1TickerPrice = createSpotApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createSpotApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX';\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n },\n {\n orderId: number; // 系统的订单ID\n }\n>('POST', '/api/v1/order');\n\n/**\n * 取消有效订单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074\n */\nexport const deleteApiV1Order = createSpotApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/api/v1/order');\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAEnE,OAAO,
|
|
1
|
+
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAKL,WAAW,EACZ,MAAM,uBAAuB,CAAC;AA6B/B,eAAO,MAAM,YAAY,eAAsB,WAAW,yBAuEzD,CAAC"}
|
|
@@ -24,12 +24,13 @@ const spotProductMapCache = (0, cache_1.createCache)(async () => {
|
|
|
24
24
|
return map;
|
|
25
25
|
}, { expire: 86400000 });
|
|
26
26
|
const getPositions = async (credential) => {
|
|
27
|
-
var _a, _b, _c, _d, _e;
|
|
27
|
+
var _a, _b, _c, _d, _e, _f;
|
|
28
28
|
const positions = [];
|
|
29
|
-
const [x, prices, prep, spotProductMap] = await Promise.all([
|
|
29
|
+
const [x, prices, prep, positionRisk, spotProductMap] = await Promise.all([
|
|
30
30
|
(0, private_api_1.getApiV1Account)(credential, {}),
|
|
31
31
|
(0, private_api_1.getApiV1TickerPrice)(credential, {}),
|
|
32
32
|
(0, private_api_1.getFApiV4Account)(credential, {}),
|
|
33
|
+
(0, private_api_1.getFApiV2PositionRisk)(credential, {}),
|
|
33
34
|
spotProductMapCache.query(''),
|
|
34
35
|
]);
|
|
35
36
|
const resolvedSpotProductMap = spotProductMap !== null && spotProductMap !== void 0 ? spotProductMap : new Map();
|
|
@@ -82,6 +83,8 @@ const getPositions = async (credential) => {
|
|
|
82
83
|
position_price: +p.entryPrice,
|
|
83
84
|
closable_price: Math.abs(+p.notional / +p.positionAmt),
|
|
84
85
|
floating_profit: +p.unrealizedProfit,
|
|
86
|
+
// TODO: optimize find performance
|
|
87
|
+
liquidation_price: (_f = positionRisk.find((r) => r.symbol === p.symbol)) === null || _f === void 0 ? void 0 : _f.liquidationPrice,
|
|
85
88
|
valuation: Math.abs(+p.notional),
|
|
86
89
|
});
|
|
87
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,uDAAmE;AACnE,yCAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,uDAAmE;AACnE,yCAA2C;AAC3C,uDAM+B;AAC/B,gDAAkD;AAElD,qFAAqF;AACrF,MAAM,UAAU,GAAG,IAAA,mBAAW,EAC5B,GAAG,EAAE,CACH,KAAK,CAAC,yFAAyF,CAAC;KAC7F,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;KACzB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,GAAa,CAAC,EAC9D;IACE,MAAM,EAAE,KAAM,EAAE,WAAW;CAC5B,CACF,CAAC;AAEF,MAAM,mBAAmB,GAAG,IAAA,mBAAW,EACrC,KAAK,IAAI,EAAE;IACT,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAY,GAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnD,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;SACpD;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAE,MAAM,EAAE,QAAU,EAAE,CACvB,CAAC;AAEK,MAAM,YAAY,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;;IAC5D,MAA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,MAAM;YACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACjD,aAAa,EAAE,OAAO;YACtB,SAAS,EAAE,CAAC,CAAC,YAAY,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;YAC/F,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;YAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;YACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;YACpC,kCAAkC;YAClC,iBAAiB,EAAE,MAAA,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,0CAAE,gBAAgB;YACpF,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAvEW,QAAA,YAAY,gBAuEvB","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport {\n getApiV1Account,\n getApiV1TickerPrice,\n getFApiV2PositionRisk,\n getFApiV4Account,\n ICredential,\n} from '../../api/private-api';\nimport { listProducts } from '../markets/product';\n\n// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko\nconst asBNBPrice = createCache(\n () =>\n fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')\n .then((res) => res.json())\n .then((data) => data['astherus-staked-bnb'].usd as number),\n {\n expire: 60_000, // 1 minute\n },\n);\n\nconst spotProductMapCache = createCache(\n async () => {\n const products = await listProducts();\n const map = new Map<string, string>();\n for (const product of products) {\n const [, instType] = product.product_id.split('/');\n if (instType === 'SPOT') {\n map.set(product.base_currency, product.product_id);\n }\n }\n return map;\n },\n { expire: 86_400_000 },\n);\n\nexport const getPositions = async (credential: ICredential) => {\n const positions: IPosition[] = [];\n const [x, prices, prep, positionRisk, spotProductMap] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n getFApiV2PositionRisk(credential, {}),\n spotProductMapCache.query(''),\n ]);\n\n const resolvedSpotProductMap = spotProductMap ?? new Map<string, string>();\n\n for (const b of x.balances) {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n positions.push(\n makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: resolvedSpotProductMap.get(b.asset) ?? encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n }),\n );\n }\n\n for (const b of prep.assets) {\n if (+b.walletBalance === 0) continue;\n let thePrice = 0;\n if (b.asset === 'USDT') {\n thePrice = 1;\n } else if (b.asset === 'ASBNB') {\n const _p = await asBNBPrice.query('').catch(() => 0);\n if (_p) {\n thePrice = _p;\n }\n } else {\n thePrice = +(prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0);\n }\n\n positions.push(\n makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: thePrice,\n }),\n );\n }\n\n for (const p of prep.positions) {\n if (+p.positionAmt === 0) continue;\n positions.push({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n // TODO: optimize find performance\n liquidation_price: positionRisk.find((r) => r.symbol === p.symbol)?.liquidationPrice,\n valuation: Math.abs(+p.notional),\n });\n }\n\n return positions;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-aster",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.27",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@yuants/protocol": "0.53.2",
|
|
12
12
|
"@yuants/cache": "0.3.3",
|
|
13
|
-
"@yuants/data-account": "0.
|
|
13
|
+
"@yuants/data-account": "0.10.0",
|
|
14
14
|
"@yuants/utils": "0.14.0",
|
|
15
15
|
"@yuants/data-series": "0.3.51",
|
|
16
16
|
"@yuants/sql": "0.9.30",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@yuants/data-interest-rate": "0.1.48",
|
|
21
21
|
"@yuants/transfer": "0.2.39",
|
|
22
22
|
"@yuants/data-quote": "0.2.43",
|
|
23
|
-
"@yuants/exchange": "0.
|
|
23
|
+
"@yuants/exchange": "0.5.0",
|
|
24
24
|
"rxjs": "~7.5.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
package/temp/package-deps.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"apps/vendor-aster/AGENTS.md": "dcd006d19a5c3b73081525d7c0afea68cd6d058b",
|
|
3
|
-
"apps/vendor-aster/CHANGELOG.json": "
|
|
4
|
-
"apps/vendor-aster/CHANGELOG.md": "
|
|
3
|
+
"apps/vendor-aster/CHANGELOG.json": "bf9ca2050c7d935fe9c9e9ea071bd8bedc415599",
|
|
4
|
+
"apps/vendor-aster/CHANGELOG.md": "f7a2ff01b60136ba89fdf32570ea2eab10cf8a3f",
|
|
5
5
|
"apps/vendor-aster/SESSION_NOTES.md": "d91f7a251d148fab1715b6da62395455edcb3b93",
|
|
6
6
|
"apps/vendor-aster/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
7
7
|
"apps/vendor-aster/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
8
8
|
"apps/vendor-aster/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
9
|
-
"apps/vendor-aster/package.json": "
|
|
10
|
-
"apps/vendor-aster/src/api/private-api.ts": "
|
|
9
|
+
"apps/vendor-aster/package.json": "c959d3b9dd6bd07f25e2510eae50a9ba72fbf1ac",
|
|
10
|
+
"apps/vendor-aster/src/api/private-api.ts": "b3288706373f8917be480210f8f02074890d5b34",
|
|
11
11
|
"apps/vendor-aster/src/api/public-api.ts": "ced2ae976ee7a74a5c1fe704b2c5fb2e25f13ab7",
|
|
12
12
|
"apps/vendor-aster/src/index.ts": "509ef4c18ec2deb8a6e11ed5682334433cb2bcb2",
|
|
13
13
|
"apps/vendor-aster/src/services/accounts/profile.ts": "fc57e7d2c865790dd257c043c8dd5cf5c641b7fd",
|
|
14
|
-
"apps/vendor-aster/src/services/accounts/spot.ts": "
|
|
14
|
+
"apps/vendor-aster/src/services/accounts/spot.ts": "49d045e5daae100ce9919ebd84723506806060ea",
|
|
15
15
|
"apps/vendor-aster/src/services/exchange.ts": "71a555ceec0d84b6f12a9c2002834676f1370d51",
|
|
16
16
|
"apps/vendor-aster/src/services/markets/interest_rate.ts": "8512bb506f3d66b16aceb9d153d1b3a4671de5ef",
|
|
17
17
|
"apps/vendor-aster/src/services/markets/product.ts": "cae86f69c6f019747ebad07569ed2bc862a78ac6",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"apps/vendor-aster/.rush/temp/shrinkwrap-deps.json": "5ded440ffb547a8aa495353d5b13c1fd1b164b4a",
|
|
24
24
|
"libraries/protocol/temp/package-deps.json": "0bd43721e96039b52d7b59c834dc6df45cf75e3f",
|
|
25
25
|
"libraries/cache/temp/package-deps.json": "a4afa15e6462983f9d3735d31dc1ed8a683fb4dc",
|
|
26
|
-
"libraries/data-account/temp/package-deps.json": "
|
|
26
|
+
"libraries/data-account/temp/package-deps.json": "3ee766acef866410612b60dfc1012082c9c24556",
|
|
27
27
|
"libraries/utils/temp/package-deps.json": "6d58e9b325e8d16de8a878c32010f626b12a01da",
|
|
28
28
|
"libraries/data-series/temp/package-deps.json": "c89ebffe302757903aa54eff78f76cb855486b8c",
|
|
29
29
|
"libraries/sql/temp/package-deps.json": "4a9a7ec55f04b20459e664e81e76fa74b6c77b39",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"libraries/data-interest-rate/temp/package-deps.json": "cef1e1cb0116ad593c24635684e0cbf03488d67c",
|
|
34
34
|
"libraries/transfer/temp/package-deps.json": "36c58299bd6c841c5ba7252d71881a881570d08c",
|
|
35
35
|
"libraries/data-quote/temp/package-deps.json": "34d079eab44d2bf65e07b112ac2099c6e92a015e",
|
|
36
|
-
"libraries/exchange/temp/package-deps.json": "
|
|
36
|
+
"libraries/exchange/temp/package-deps.json": "d40288d0530bc7e63246f234bdffa10a497776b1",
|
|
37
37
|
"libraries/extension/temp/package-deps.json": "9569c553c2f9a7d50b70d8f101fc2d3825aaccb9",
|
|
38
38
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|
|
39
39
|
}
|