@yuants/vendor-gate 0.4.20 → 0.4.22
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.map +1 -1
- package/dist/services/accounts/unified.js +53 -7
- package/dist/services/accounts/unified.js.map +1 -1
- package/dist/services/exchange.js +3 -16
- package/dist/services/exchange.js.map +1 -1
- package/lib/api/private-api.d.ts +1 -0
- package/lib/api/private-api.d.ts.map +1 -1
- package/lib/api/private-api.js.map +1 -1
- package/lib/services/accounts/unified.d.ts.map +1 -1
- package/lib/services/accounts/unified.js +53 -7
- package/lib/services/accounts/unified.js.map +1 -1
- package/lib/services/exchange.js +3 -16
- package/lib/services/exchange.js.map +1 -1
- package/package.json +1 -1
- package/temp/package-deps.json +7 -9
- package/dist/services/accounts/future.js +0 -44
- package/dist/services/accounts/future.js.map +0 -1
- package/dist/services/accounts/spot.js +0 -20
- package/dist/services/accounts/spot.js.map +0 -1
- package/lib/services/accounts/future.d.ts +0 -5
- package/lib/services/accounts/future.d.ts.map +0 -1
- package/lib/services/accounts/future.js +0 -49
- package/lib/services/accounts/future.js.map +0 -1
- package/lib/services/accounts/spot.d.ts +0 -3
- package/lib/services/accounts/spot.d.ts.map +0 -1
- package/lib/services/accounts/spot.js +0 -24
- package/lib/services/accounts/spot.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI/C,MAAM,WAAW,GAAG,CAClB,UAAuB,EACvB,MAAkB,EAClB,IAAY,EACZ,MAAmB,EACnB,EAAE,CAAC,cAAc,CAAY,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,UAAuB,EAStB,EAAE,CAAC,WAAW,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M,CAAC,CAAC","sourcesContent":["import type { GateParams, HttpMethod, IGateCredential } from './http-client';\nimport { requestPrivate } from './http-client';\n\nexport type ICredential = IGateCredential;\n\nconst callPrivate = <TResponse>(\n credential: ICredential,\n method: HttpMethod,\n path: string,\n params?: GateParams,\n) => requestPrivate<TResponse>(credential, method, path, params);\n\n/**\n * 获取用户账户信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF\n */\nexport const getAccountDetail = (\n credential: ICredential,\n): Promise<{\n user_id: number;\n ip_whitelist: string[];\n currency_pairs: string[];\n key: {\n mode: number;\n };\n tier: number;\n}> => callPrivate(credential, 'GET', '/account/detail');\n\nexport const getUnifiedAccounts = (\n credential: ICredential,\n params?: { currency?: string },\n): Promise<{\n user_id: string;\n refresh_time: number;\n locket: boolean;\n balances: Record<\n string,\n {\n available: string;\n freeze: string;\n borrowed: string;\n negative_liab: string;\n futures_pos_liab: string;\n equity: string;\n total_freeze: string;\n total_liab: string;\n spot_in_use: string;\n }\n >;\n total: string;\n borrowed: string;\n total_initial_margin: string;\n total_margin_balance: string;\n total_maintenance_margin: string;\n total_initial_margin_rate: string;\n total_maintenance_margin_rate: string;\n total_avail_margin: string;\n unified_account_total: string;\n unified_account_total_liab: string;\n unified_account_total_equity: string;\n leverage: string;\n spot_order_loss: string;\n spot_hedge: boolean;\n}> => callPrivate(credential, 'GET', '/unified/accounts', params);\n\n/**\n * 获取用户仓位列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E4%BB%93%E4%BD%8D%E5%88%97%E8%A1%A8\n */\nexport const getFuturePositions = (\n credential: ICredential,\n quote_currency: string,\n params?: { holding?: boolean; limit?: number; offset?: number },\n): Promise<\n {\n user: number;\n contract: string;\n size: number;\n leverage: string;\n risk_limit: string;\n leverage_max: string;\n maintenance_rate: string;\n value: string;\n margin: string;\n entry_price: string;\n mark_price: string;\n unrealised_pnl: string;\n realised_pnl: string;\n mode: string;\n }[]\n> => callPrivate(credential, 'GET', `/futures/${quote_currency}/positions`, params);\n\n/**\n * 查询合约订单列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%90%88%E7%BA%A6%E8%AE%A2%E5%8D%95%E5%88%97%E8%A1%A8\n */\nexport const getFuturesOrders = (\n credential: ICredential,\n settle: string,\n params: {\n contract?: string;\n status: string;\n limit?: number;\n offset?: number;\n last_id?: number;\n },\n): Promise<\n {\n id: string;\n contract: string;\n create_time: number;\n size: number;\n price: string;\n is_close: boolean;\n fill_price: string;\n left?: number;\n status?: string;\n text: string;\n }[]\n> => callPrivate(credential, 'GET', `/futures/${settle}/orders`, params);\n\n/**\n * 获取合约账号\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%90%88%E7%BA%A6%E8%B4%A6%E5%8F%B7\n */\nexport const getFuturesAccounts = (\n credential: ICredential,\n settle: string,\n): Promise<{\n user: number;\n currency: string;\n total: string;\n unrealised_pnl: string;\n position_margin: string;\n order_margin: string;\n available: string;\n point: string;\n bonus: string;\n in_dual_mode: boolean;\n enable_evolved_classic: boolean;\n history: {\n dnw: string;\n pnl: string;\n fee: string;\n refr: string;\n fund: string;\n point_dnw: string;\n point_fee: string;\n point_refr: string;\n bonus_dnw: string;\n bonus_offset: string;\n };\n}> => callPrivate(credential, 'GET', `/futures/${settle}/accounts`);\n\n/**\n * 合约交易下单\n *\n * 下单时指定的是合约张数 size ,而非币的数量,每一张合约对应的币的数量是合约详情接口里返回的 quanto_multiplier\n *\n * 0 成交的订单在撤单 10 分钟之后无法再获取到,会提到订单不存在\n *\n * 设置 reduce_only 为 true 可以防止在减仓的时候穿仓\n *\n * 单仓模式下,如果需要平仓,需要设置 size 为 0 ,close 为 true\n *\n * 双仓模式下,平仓需要使用 auto_size 来设置平仓方向,并同时设置 reduce_only 为 true,size 为 0\n *\n * 设置 stp_act 决定使用限制用户自成交的策略,详细用法参考body参数stp_act\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E4%BA%A4%E6%98%93%E4%B8%8B%E5%8D%95\n */\nexport const postFutureOrders = (\n credential: ICredential,\n settle: string,\n params: {\n contract: string;\n size: number;\n iceberg?: number;\n price?: string;\n close?: boolean;\n reduce_only?: boolean;\n tif?: string;\n text?: string;\n auto_size?: string;\n stp_act?: string;\n },\n): Promise<{\n label?: string;\n message?: string;\n detail?: string;\n id: number;\n user: number;\n contract: string;\n create_time: number;\n size: number;\n iceberg: number;\n left: number;\n price: string;\n fill_price: string;\n mkfr: string;\n tkfr: string;\n tif: string;\n refu: number;\n is_reduce_only: boolean;\n is_close: boolean;\n is_liq: boolean;\n text: string;\n status: string;\n finish_time: number;\n finish_as: string;\n stp_id: number;\n stp_act: string;\n amend_text: string;\n}> => callPrivate(credential, 'POST', `/futures/${settle}/orders`, params);\n\n/**\n * 撤销单个订单\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%92%A4%E9%94%80%E5%8D%95%E4%B8%AA%E8%AE%A2%E5%8D%95-2\n */\nexport const deleteFutureOrders = (credential: ICredential, settle: string, order_id: string): Promise<{}> =>\n callPrivate(credential, 'DELETE', `/futures/${settle}/orders/${order_id}`);\n\n/**\n * 提现\n *\n * POST /withdrawals\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%8F%90%E7%8E%B0\n */\nexport const postWithdrawals = (\n credential: ICredential,\n params: {\n withdraw_order_id?: string;\n amount: string;\n currency: string;\n address?: string;\n memo?: string;\n chain: string;\n },\n): Promise<{\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n}> => callPrivate(credential, 'POST', '/withdrawals', params);\n\n/**\n * 获取币种充值地址\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%B8%81%E7%A7%8D%E5%85%85%E5%80%BC%E5%9C%B0%E5%9D%80\n */\nexport const getDepositAddress = (\n credential: ICredential,\n params: {\n currency: string;\n },\n): Promise<{\n currency: string;\n address: string;\n multichain_addresses: {\n chain: string;\n address: string;\n payment_id: string;\n payment_name: string;\n obtain_failed: boolean;\n }[];\n}> => callPrivate(credential, 'GET', '/wallet/deposit_address', params);\n\n/**\n * 创建新的子账户\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E5%AD%90%E8%B4%A6%E6%88%B7\n */\nexport const getSubAccountList = (\n credential: ICredential,\n params?: {\n type?: string;\n },\n): Promise<\n {\n remark: string;\n login_name: string;\n password: string;\n email: string;\n state: number;\n type: number;\n user_id: number;\n create_time: number;\n }[]\n> => callPrivate(credential, 'GET', '/sub_accounts', params);\n\n/**\n * 获取充值记录\n *\n * 记录查询时间范围不允许超过 30 天\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%85%85%E5%80%BC%E8%AE%B0%E5%BD%95\n */\nexport const getDepositHistory = (\n credential: ICredential,\n params?: {\n currency?: string;\n from?: number;\n to?: number;\n limit?: number;\n offset?: number;\n },\n): Promise<\n {\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n }[]\n> => callPrivate(credential, 'GET', '/wallet/deposits', params);\n\n/**\n * 获取提现记录\n *\n * 记录查询时间范围不允许超过 30 天\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%B8%81%E7%A7%8D%E5%85%85%E5%80%BC%E5%9C%B0%E5%9D%80\n */\nexport const getWithdrawalHistory = (\n credential: ICredential,\n params?: {\n currency?: string;\n from?: number;\n to?: number;\n limit?: number;\n offset?: number;\n },\n): Promise<\n {\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n }[]\n> => callPrivate(credential, 'GET', '/wallet/withdrawals', params);\n\n/**\n * 获取现货交易账户列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%8E%B0%E8%B4%A7%E4%BA%A4%E6%98%93%E8%B4%A6%E6%88%B7%E5%88%97%E8%A1%A8\n */\nexport const getSpotAccounts = (\n credential: ICredential,\n params?: {\n currency?: string;\n },\n): Promise<\n {\n currency: string;\n available: string;\n locked: string;\n update_id: string;\n }[]\n> => callPrivate(credential, 'GET', '/spot/accounts', params);\n\n/**\n * 交易账户互转\n *\n * POST /wallet/transfers\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E4%BA%A4%E6%98%93%E8%B4%A6%E6%88%B7%E4%BA%92%E8%BD%AC\n */\nexport const postWalletTransfer = (\n credential: ICredential,\n params: {\n currency: string;\n from: string;\n to: string;\n amount: string;\n currency_pair?: string;\n settle?: string;\n },\n): Promise<{\n tx_id: string;\n}> => callPrivate(credential, 'POST', '/wallet/transfers', params);\n\n/**\n * 获取统一账户最多可转出\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E7%BB%9F%E4%B8%80%E8%B4%A6%E6%88%B7%E6%9C%80%E5%A4%9A%E5%8F%AF%E8%BD%AC%E5%87%BA\n */\nexport const getUnifiedTransferable = (\n credential: ICredential,\n params: {\n currency: string;\n },\n): Promise<{\n currency: string;\n amount: string;\n}> => callPrivate(credential, 'GET', `/unified/transferable`, params);\n"]}
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI/C,MAAM,WAAW,GAAG,CAClB,UAAuB,EACvB,MAAkB,E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AAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,UAAuB,EACvB,MAEC,EAIA,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,uBAAuB,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import type { GateParams, HttpMethod, IGateCredential } from './http-client';\nimport { requestPrivate } from './http-client';\n\nexport type ICredential = IGateCredential;\n\nconst callPrivate = <TResponse>(\n credential: ICredential,\n method: HttpMethod,\n path: string,\n params?: GateParams,\n) => requestPrivate<TResponse>(credential, method, path, params);\n\n/**\n * 获取用户账户信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF\n */\nexport const getAccountDetail = (\n credential: ICredential,\n): Promise<{\n user_id: number;\n ip_whitelist: string[];\n currency_pairs: string[];\n key: {\n mode: number;\n };\n tier: number;\n}> => callPrivate(credential, 'GET', '/account/detail');\n\nexport const getUnifiedAccounts = (\n credential: ICredential,\n params?: { currency?: string },\n): Promise<{\n user_id: string;\n refresh_time: number;\n locket: boolean;\n balances: Record<\n string,\n {\n available: string;\n freeze: string;\n borrowed: string;\n negative_liab: string;\n futures_pos_liab: string;\n equity: string;\n total_freeze: string;\n total_liab: string;\n spot_in_use: string;\n }\n >;\n total: string;\n borrowed: string;\n total_initial_margin: string;\n total_margin_balance: string;\n total_maintenance_margin: string;\n total_initial_margin_rate: string;\n total_maintenance_margin_rate: string;\n total_avail_margin: string;\n unified_account_total: string;\n unified_account_total_liab: string;\n unified_account_total_equity: string;\n leverage: string;\n spot_order_loss: string;\n spot_hedge: boolean;\n}> => callPrivate(credential, 'GET', '/unified/accounts', params);\n\n/**\n * 获取用户仓位列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E4%BB%93%E4%BD%8D%E5%88%97%E8%A1%A8\n */\nexport const getFuturePositions = (\n credential: ICredential,\n quote_currency: string,\n params?: { holding?: boolean; limit?: number; offset?: number },\n): Promise<\n {\n user: number;\n contract: string;\n size: number;\n leverage: string;\n risk_limit: string;\n leverage_max: string;\n maintenance_rate: string;\n value: string;\n margin: string;\n entry_price: string;\n mark_price: string;\n unrealised_pnl: string;\n realised_pnl: string;\n mode: string;\n liq_price: string;\n }[]\n> => callPrivate(credential, 'GET', `/futures/${quote_currency}/positions`, params);\n\n/**\n * 查询合约订单列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%90%88%E7%BA%A6%E8%AE%A2%E5%8D%95%E5%88%97%E8%A1%A8\n */\nexport const getFuturesOrders = (\n credential: ICredential,\n settle: string,\n params: {\n contract?: string;\n status: string;\n limit?: number;\n offset?: number;\n last_id?: number;\n },\n): Promise<\n {\n id: string;\n contract: string;\n create_time: number;\n size: number;\n price: string;\n is_close: boolean;\n fill_price: string;\n left?: number;\n status?: string;\n text: string;\n }[]\n> => callPrivate(credential, 'GET', `/futures/${settle}/orders`, params);\n\n/**\n * 获取合约账号\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%90%88%E7%BA%A6%E8%B4%A6%E5%8F%B7\n */\nexport const getFuturesAccounts = (\n credential: ICredential,\n settle: string,\n): Promise<{\n user: number;\n currency: string;\n total: string;\n unrealised_pnl: string;\n position_margin: string;\n order_margin: string;\n available: string;\n point: string;\n bonus: string;\n in_dual_mode: boolean;\n enable_evolved_classic: boolean;\n history: {\n dnw: string;\n pnl: string;\n fee: string;\n refr: string;\n fund: string;\n point_dnw: string;\n point_fee: string;\n point_refr: string;\n bonus_dnw: string;\n bonus_offset: string;\n };\n}> => callPrivate(credential, 'GET', `/futures/${settle}/accounts`);\n\n/**\n * 合约交易下单\n *\n * 下单时指定的是合约张数 size ,而非币的数量,每一张合约对应的币的数量是合约详情接口里返回的 quanto_multiplier\n *\n * 0 成交的订单在撤单 10 分钟之后无法再获取到,会提到订单不存在\n *\n * 设置 reduce_only 为 true 可以防止在减仓的时候穿仓\n *\n * 单仓模式下,如果需要平仓,需要设置 size 为 0 ,close 为 true\n *\n * 双仓模式下,平仓需要使用 auto_size 来设置平仓方向,并同时设置 reduce_only 为 true,size 为 0\n *\n * 设置 stp_act 决定使用限制用户自成交的策略,详细用法参考body参数stp_act\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E4%BA%A4%E6%98%93%E4%B8%8B%E5%8D%95\n */\nexport const postFutureOrders = (\n credential: ICredential,\n settle: string,\n params: {\n contract: string;\n size: number;\n iceberg?: number;\n price?: string;\n close?: boolean;\n reduce_only?: boolean;\n tif?: string;\n text?: string;\n auto_size?: string;\n stp_act?: string;\n },\n): Promise<{\n label?: string;\n message?: string;\n detail?: string;\n id: number;\n user: number;\n contract: string;\n create_time: number;\n size: number;\n iceberg: number;\n left: number;\n price: string;\n fill_price: string;\n mkfr: string;\n tkfr: string;\n tif: string;\n refu: number;\n is_reduce_only: boolean;\n is_close: boolean;\n is_liq: boolean;\n text: string;\n status: string;\n finish_time: number;\n finish_as: string;\n stp_id: number;\n stp_act: string;\n amend_text: string;\n}> => callPrivate(credential, 'POST', `/futures/${settle}/orders`, params);\n\n/**\n * 撤销单个订单\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%92%A4%E9%94%80%E5%8D%95%E4%B8%AA%E8%AE%A2%E5%8D%95-2\n */\nexport const deleteFutureOrders = (credential: ICredential, settle: string, order_id: string): Promise<{}> =>\n callPrivate(credential, 'DELETE', `/futures/${settle}/orders/${order_id}`);\n\n/**\n * 提现\n *\n * POST /withdrawals\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%8F%90%E7%8E%B0\n */\nexport const postWithdrawals = (\n credential: ICredential,\n params: {\n withdraw_order_id?: string;\n amount: string;\n currency: string;\n address?: string;\n memo?: string;\n chain: string;\n },\n): Promise<{\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n}> => callPrivate(credential, 'POST', '/withdrawals', params);\n\n/**\n * 获取币种充值地址\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%B8%81%E7%A7%8D%E5%85%85%E5%80%BC%E5%9C%B0%E5%9D%80\n */\nexport const getDepositAddress = (\n credential: ICredential,\n params: {\n currency: string;\n },\n): Promise<{\n currency: string;\n address: string;\n multichain_addresses: {\n chain: string;\n address: string;\n payment_id: string;\n payment_name: string;\n obtain_failed: boolean;\n }[];\n}> => callPrivate(credential, 'GET', '/wallet/deposit_address', params);\n\n/**\n * 创建新的子账户\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E5%AD%90%E8%B4%A6%E6%88%B7\n */\nexport const getSubAccountList = (\n credential: ICredential,\n params?: {\n type?: string;\n },\n): Promise<\n {\n remark: string;\n login_name: string;\n password: string;\n email: string;\n state: number;\n type: number;\n user_id: number;\n create_time: number;\n }[]\n> => callPrivate(credential, 'GET', '/sub_accounts', params);\n\n/**\n * 获取充值记录\n *\n * 记录查询时间范围不允许超过 30 天\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%85%85%E5%80%BC%E8%AE%B0%E5%BD%95\n */\nexport const getDepositHistory = (\n credential: ICredential,\n params?: {\n currency?: string;\n from?: number;\n to?: number;\n limit?: number;\n offset?: number;\n },\n): Promise<\n {\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n }[]\n> => callPrivate(credential, 'GET', '/wallet/deposits', params);\n\n/**\n * 获取提现记录\n *\n * 记录查询时间范围不允许超过 30 天\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%B8%81%E7%A7%8D%E5%85%85%E5%80%BC%E5%9C%B0%E5%9D%80\n */\nexport const getWithdrawalHistory = (\n credential: ICredential,\n params?: {\n currency?: string;\n from?: number;\n to?: number;\n limit?: number;\n offset?: number;\n },\n): Promise<\n {\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n }[]\n> => callPrivate(credential, 'GET', '/wallet/withdrawals', params);\n\n/**\n * 获取现货交易账户列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%8E%B0%E8%B4%A7%E4%BA%A4%E6%98%93%E8%B4%A6%E6%88%B7%E5%88%97%E8%A1%A8\n */\nexport const getSpotAccounts = (\n credential: ICredential,\n params?: {\n currency?: string;\n },\n): Promise<\n {\n currency: string;\n available: string;\n locked: string;\n update_id: string;\n }[]\n> => callPrivate(credential, 'GET', '/spot/accounts', params);\n\n/**\n * 交易账户互转\n *\n * POST /wallet/transfers\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E4%BA%A4%E6%98%93%E8%B4%A6%E6%88%B7%E4%BA%92%E8%BD%AC\n */\nexport const postWalletTransfer = (\n credential: ICredential,\n params: {\n currency: string;\n from: string;\n to: string;\n amount: string;\n currency_pair?: string;\n settle?: string;\n },\n): Promise<{\n tx_id: string;\n}> => callPrivate(credential, 'POST', '/wallet/transfers', params);\n\n/**\n * 获取统一账户最多可转出\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E7%BB%9F%E4%B8%80%E8%B4%A6%E6%88%B7%E6%9C%80%E5%A4%9A%E5%8F%AF%E8%BD%AC%E5%87%BA\n */\nexport const getUnifiedTransferable = (\n credential: ICredential,\n params: {\n currency: string;\n },\n): Promise<{\n currency: string;\n amount: string;\n}> => callPrivate(credential, 'GET', `/unified/transferable`, params);\n"]}
|
|
@@ -1,19 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getSpotTickers } from '../../api/public-api';
|
|
3
|
-
import { loadFuturePositions } from './future';
|
|
1
|
+
import { createCache } from '@yuants/cache';
|
|
4
2
|
import { encodePath } from '@yuants/utils';
|
|
3
|
+
import { getUnifiedAccounts, getFuturePositions } from '../../api/private-api';
|
|
4
|
+
import { getSpotTickers } from '../../api/public-api';
|
|
5
|
+
import { listProducts } from '../markets/product';
|
|
6
|
+
const spotProductMapCache = createCache(async () => {
|
|
7
|
+
const products = await listProducts();
|
|
8
|
+
const map = new Map();
|
|
9
|
+
for (const product of products !== null && products !== void 0 ? products : []) {
|
|
10
|
+
const [, instType] = product.product_id.split('/');
|
|
11
|
+
if (instType === 'SPOT') {
|
|
12
|
+
map.set(product.base_currency, product.product_id);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return map;
|
|
16
|
+
}, { expire: 86400000 });
|
|
17
|
+
const loadFuturePositions = async (credential) => {
|
|
18
|
+
const positions = [];
|
|
19
|
+
const positionsRes = await getFuturePositions(credential, 'usdt');
|
|
20
|
+
for (const position of Array.isArray(positionsRes) ? positionsRes : []) {
|
|
21
|
+
if (!(Math.abs(position.size) > 0))
|
|
22
|
+
continue;
|
|
23
|
+
const product_id = encodePath('GATE', 'FUTURE', position.contract);
|
|
24
|
+
const volume = Math.abs(position.size);
|
|
25
|
+
const closable_price = Number(position.mark_price);
|
|
26
|
+
const valuation = volume * closable_price;
|
|
27
|
+
positions.push({
|
|
28
|
+
datasource_id: 'GATE',
|
|
29
|
+
position_id: `${position.contract}-${position.leverage}-${position.mode}`,
|
|
30
|
+
product_id,
|
|
31
|
+
direction: position.mode === 'dual_long'
|
|
32
|
+
? 'LONG'
|
|
33
|
+
: position.mode === 'dual_short'
|
|
34
|
+
? 'SHORT'
|
|
35
|
+
: position.size > 0
|
|
36
|
+
? 'LONG'
|
|
37
|
+
: 'SHORT',
|
|
38
|
+
volume,
|
|
39
|
+
free_volume: Math.abs(position.size),
|
|
40
|
+
position_price: Number(position.entry_price),
|
|
41
|
+
closable_price,
|
|
42
|
+
floating_profit: Number(position.unrealised_pnl),
|
|
43
|
+
liquidation_price: position.liq_price,
|
|
44
|
+
valuation,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return positions;
|
|
48
|
+
};
|
|
5
49
|
export const getUnifiedAccountInfo = async (credential) => {
|
|
6
50
|
var _a;
|
|
7
|
-
const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([
|
|
51
|
+
const [futurePositions, unifiedAccount, spotTickers, spotProductMap] = await Promise.all([
|
|
8
52
|
loadFuturePositions(credential),
|
|
9
53
|
getUnifiedAccounts(credential, {}),
|
|
10
54
|
getSpotTickers({}),
|
|
55
|
+
spotProductMapCache.query('').catch(() => undefined),
|
|
11
56
|
]);
|
|
57
|
+
const resolvedSpotProductMap = spotProductMap !== null && spotProductMap !== void 0 ? spotProductMap : new Map();
|
|
12
58
|
const balances = (_a = unifiedAccount === null || unifiedAccount === void 0 ? void 0 : unifiedAccount.balances) !== null && _a !== void 0 ? _a : {};
|
|
13
59
|
const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];
|
|
14
60
|
const spotPositions = Object.keys(balances)
|
|
15
61
|
.map((currency) => {
|
|
16
|
-
var _a, _b;
|
|
62
|
+
var _a, _b, _c;
|
|
17
63
|
let currency_pair = `${currency}_USDT`;
|
|
18
64
|
if (currency === 'SOL2') {
|
|
19
65
|
currency_pair = 'SOL_USDT';
|
|
@@ -28,9 +74,9 @@ export const getUnifiedAccountInfo = async (credential) => {
|
|
|
28
74
|
if (Math.abs(volume) === 0)
|
|
29
75
|
return undefined;
|
|
30
76
|
return {
|
|
31
|
-
datasource_id: '
|
|
77
|
+
datasource_id: 'GATE',
|
|
32
78
|
position_id: currency,
|
|
33
|
-
product_id: encodePath('GATE', 'SPOT', currency),
|
|
79
|
+
product_id: (_c = resolvedSpotProductMap.get(currency)) !== null && _c !== void 0 ? _c : encodePath('GATE', 'SPOT', currency),
|
|
34
80
|
direction: 'LONG',
|
|
35
81
|
volume,
|
|
36
82
|
free_volume: volume,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,mBAAmB,GAAG,WAAW,CACrC,KAAK,IAAI,EAAE;IACT,MAAM,QAAQ,GAAG,MAAM,YAAY,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,KAAK,MAAM,OAAO,IAAI,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,EAAE;QACpC,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;AAEF,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAClF,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,Y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AAM,CAAC,aAAa,KAAK,aAAa,CAAC,0CAAE,IAAI,KAAI,CAAC,CAAC,CAAC;QACjG,MAAM,MAAM,GAAG,MAAM,CAAC,CAAA,MAAA,QAAQ,CAAC,QAAQ,CAAC,0CAAE,SAAS,KAAI,CAAC,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC7C,OAAO;YACL,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,MAAA,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,mCAAI,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;YACxF,SAAS,EAAE,MAAM;YACjB,MAAM;YACN,WAAW,EAAE,MAAM;YACnB,cAAc;YACd,cAAc,EAAE,cAAc;YAC9B,eAAe,EAAE,cAAc,GAAG,MAAM;YACxC,SAAS,EAAE,cAAc,GAAG,MAAM;SACtB,CAAC;IACjB,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,IAAI,EAAqB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,eAAe,EAAE,GAAG,aAAa,CAAC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport type { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getUnifiedAccounts, getFuturePositions, ICredential } from '../../api/private-api';\nimport { getSpotTickers } from '../../api/public-api';\nimport { listProducts } from '../markets/product';\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\nconst loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n const positionsRes = await getFuturePositions(credential, 'usdt');\n\n for (const position of Array.isArray(positionsRes) ? positionsRes : []) {\n if (!(Math.abs(position.size) > 0)) continue;\n\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price;\n positions.push({\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n liquidation_price: position.liq_price,\n valuation,\n });\n }\n\n return positions;\n};\n\nexport const getUnifiedAccountInfo = async (credential: ICredential) => {\n const [futurePositions, unifiedAccount, spotTickers, spotProductMap] = await Promise.all([\n loadFuturePositions(credential),\n getUnifiedAccounts(credential, {}),\n getSpotTickers({}),\n spotProductMapCache.query('').catch(() => undefined),\n ]);\n\n const resolvedSpotProductMap = spotProductMap ?? new Map<string, string>();\n const balances = unifiedAccount?.balances ?? {};\n const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];\n const spotPositions: IPosition[] = Object.keys(balances)\n .map((currency) => {\n let currency_pair = `${currency}_USDT`;\n if (currency === 'SOL2') {\n currency_pair = 'SOL_USDT';\n }\n if (currency === 'GTSOL') {\n currency_pair = 'SOL_USDT';\n }\n const closable_price =\n currency === 'USDT'\n ? 1\n : Number(spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)?.last || 0);\n const volume = Number(balances[currency]?.available || 0);\n if (Math.abs(volume) === 0) return undefined;\n return {\n datasource_id: 'GATE',\n position_id: currency,\n product_id: resolvedSpotProductMap.get(currency) ?? encodePath('GATE', 'SPOT', currency),\n direction: 'LONG',\n volume,\n free_volume: volume,\n closable_price,\n position_price: closable_price,\n floating_profit: closable_price * volume,\n valuation: closable_price * volume,\n } as IPosition;\n })\n .filter((item): item is IPosition => !!item);\n\n return [...futurePositions, ...spotPositions];\n};\n"]}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { provideExchangeServices } from '@yuants/exchange';
|
|
2
2
|
import { Terminal } from '@yuants/protocol';
|
|
3
|
-
import { decodePath } from '@yuants/utils';
|
|
4
3
|
import { getCredentialId } from './accounts/profile';
|
|
5
4
|
import { getUnifiedAccountInfo } from './accounts/unified';
|
|
6
5
|
import { cancelOrder } from './orders/cancelOrder';
|
|
7
6
|
import { submitOrder } from './orders/submitOrder';
|
|
8
|
-
import { getFutureAccountInfo } from './accounts/future';
|
|
9
7
|
import { listOrders, getOrdersByProductId } from './orders/listOrders';
|
|
10
8
|
import { listProducts } from './markets/product';
|
|
11
9
|
const terminal = Terminal.fromNodeEnv();
|
|
@@ -22,10 +20,7 @@ provideExchangeServices(terminal, {
|
|
|
22
20
|
getCredentialId,
|
|
23
21
|
listProducts,
|
|
24
22
|
getPositions: async function (credential) {
|
|
25
|
-
const
|
|
26
|
-
// getFutureAccountInfo(credential),
|
|
27
|
-
getUnifiedAccountInfo(credential),
|
|
28
|
-
]);
|
|
23
|
+
const unifiedPositions = await getUnifiedAccountInfo(credential);
|
|
29
24
|
return [...unifiedPositions];
|
|
30
25
|
},
|
|
31
26
|
getOrders: async function (credential) {
|
|
@@ -36,16 +31,8 @@ provideExchangeServices(terminal, {
|
|
|
36
31
|
return [...umOrders];
|
|
37
32
|
},
|
|
38
33
|
getPositionsByProductId: async function (credential, product_id) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
// const positions = await getSpotAccountInfoSnapshot(credential);
|
|
42
|
-
// return positions.filter((position) => position.product_id === product_id);
|
|
43
|
-
// }
|
|
44
|
-
if (instType === 'FUTURE') {
|
|
45
|
-
const positions = await getFutureAccountInfo(credential);
|
|
46
|
-
return positions.filter((position) => position.product_id === product_id);
|
|
47
|
-
}
|
|
48
|
-
throw new Error(`Unsupported instType: ${instType}`);
|
|
34
|
+
const positions = await getUnifiedAccountInfo(credential);
|
|
35
|
+
return positions.filter((position) => position.product_id === product_id);
|
|
49
36
|
},
|
|
50
37
|
getOrdersByProductId,
|
|
51
38
|
submitOrder,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,uBAAuB,CAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,MAAM;IACZ,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;QACtC,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC/B;KACF;IACD,eAAe;IACf,YAAY;IACZ,YAAY,EAAE,KAAK,WAAW,UAAuB;QACnD,MAAM,gBAAgB,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAAC,CAAC;QACjE,OAAO,CAAC,GAAG,gBAAgB,CAAC,CAAC;IAC/B,CAAC;IACD,SAAS,EAAE,KAAK,WAAW,UAAuB;QAChD,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACnC,UAAU,CAAC,UAAU,CAAC;YACtB,gCAAgC;SACjC,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;IACvB,CAAC;IACD,uBAAuB,EAAE,KAAK,WAC5B,UAAuB,EACvB,UAAkB;QAElB,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAAC,CAAC;QAC1D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IAC5E,CAAC;IACD,oBAAoB;IACpB,WAAW;IACX,WAAW,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,WAAW;CACZ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { getCredentialId } from './accounts/profile';\nimport { getUnifiedAccountInfo } from './accounts/unified';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { submitOrder } from './orders/submitOrder';\nimport { ICredential } from '../api/private-api';\nimport { listOrders, getOrdersByProductId } from './orders/listOrders';\nimport { listProducts } from './markets/product';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'GATE',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: async function (credential: ICredential): Promise<IPosition[]> {\n const unifiedPositions = await getUnifiedAccountInfo(credential);\n return [...unifiedPositions];\n },\n getOrders: async function (credential: ICredential): Promise<IOrder[]> {\n const [umOrders] = await Promise.all([\n listOrders(credential),\n // listSpotOrders(credential),\n ]);\n return [...umOrders];\n },\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const positions = await getUnifiedAccountInfo(credential);\n return positions.filter((position) => position.product_id === product_id);\n },\n getOrdersByProductId,\n submitOrder,\n modifyOrder: () => {\n throw new Error('Not implemented');\n },\n cancelOrder,\n});\n"]}
|
package/lib/api/private-api.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-api.d.ts","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,eAAe,EAAE,MAAM,eAAe,CAAC;AAG7E,oBAAY,WAAW,GAAG,eAAe,CAAC;AAS1C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,eACf,WAAW,KACtB,QAAQ;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,GAAG,EAAE;QACH,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,EAAE,MAAM,CAAC;CACd,CAAsD,CAAC;AAExD,eAAO,MAAM,kBAAkB,eACjB,WAAW,WACd;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7B,QAAQ;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OACR,MAAM,EACN;QACE,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,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WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,uBAAuB,EAAE,MAAM,CAAC,CAAC;AARzD,QAAA,sBAAsB,0BAQmC","sourcesContent":["import type { GateParams, HttpMethod, IGateCredential } from './http-client';\nimport { requestPrivate } from './http-client';\n\nexport type ICredential = IGateCredential;\n\nconst callPrivate = <TResponse>(\n credential: ICredential,\n method: HttpMethod,\n path: string,\n params?: GateParams,\n) => requestPrivate<TResponse>(credential, method, path, params);\n\n/**\n * 获取用户账户信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF\n */\nexport const getAccountDetail = (\n credential: ICredential,\n): Promise<{\n user_id: number;\n ip_whitelist: string[];\n currency_pairs: string[];\n key: {\n mode: number;\n };\n tier: number;\n}> => callPrivate(credential, 'GET', '/account/detail');\n\nexport const getUnifiedAccounts = (\n credential: ICredential,\n params?: { currency?: string },\n): Promise<{\n user_id: string;\n refresh_time: number;\n locket: boolean;\n balances: Record<\n string,\n {\n available: string;\n freeze: string;\n borrowed: string;\n negative_liab: string;\n futures_pos_liab: string;\n equity: string;\n total_freeze: string;\n total_liab: string;\n spot_in_use: string;\n }\n >;\n total: string;\n borrowed: string;\n total_initial_margin: string;\n total_margin_balance: string;\n total_maintenance_margin: string;\n total_initial_margin_rate: string;\n total_maintenance_margin_rate: string;\n total_avail_margin: string;\n unified_account_total: string;\n unified_account_total_liab: string;\n unified_account_total_equity: string;\n leverage: string;\n spot_order_loss: string;\n spot_hedge: boolean;\n}> => callPrivate(credential, 'GET', '/unified/accounts', params);\n\n/**\n * 获取用户仓位列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E4%BB%93%E4%BD%8D%E5%88%97%E8%A1%A8\n */\nexport const getFuturePositions = (\n credential: ICredential,\n quote_currency: string,\n params?: { holding?: boolean; limit?: number; offset?: number },\n): Promise<\n {\n user: number;\n contract: string;\n size: number;\n leverage: string;\n risk_limit: string;\n leverage_max: string;\n maintenance_rate: string;\n value: string;\n margin: string;\n entry_price: string;\n mark_price: string;\n unrealised_pnl: string;\n realised_pnl: string;\n mode: string;\n }[]\n> => callPrivate(credential, 'GET', `/futures/${quote_currency}/positions`, params);\n\n/**\n * 查询合约订单列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%90%88%E7%BA%A6%E8%AE%A2%E5%8D%95%E5%88%97%E8%A1%A8\n */\nexport const getFuturesOrders = (\n credential: ICredential,\n settle: string,\n params: {\n contract?: string;\n status: string;\n limit?: number;\n offset?: number;\n last_id?: number;\n },\n): Promise<\n {\n id: string;\n contract: string;\n create_time: number;\n size: number;\n price: string;\n is_close: boolean;\n fill_price: string;\n left?: number;\n status?: string;\n text: string;\n }[]\n> => callPrivate(credential, 'GET', `/futures/${settle}/orders`, params);\n\n/**\n * 获取合约账号\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%90%88%E7%BA%A6%E8%B4%A6%E5%8F%B7\n */\nexport const getFuturesAccounts = (\n credential: ICredential,\n settle: string,\n): Promise<{\n user: number;\n currency: string;\n total: string;\n unrealised_pnl: string;\n position_margin: string;\n order_margin: string;\n available: string;\n point: string;\n bonus: string;\n in_dual_mode: boolean;\n enable_evolved_classic: boolean;\n history: {\n dnw: string;\n pnl: string;\n fee: string;\n refr: string;\n fund: string;\n point_dnw: string;\n point_fee: string;\n point_refr: string;\n bonus_dnw: string;\n bonus_offset: string;\n };\n}> => callPrivate(credential, 'GET', `/futures/${settle}/accounts`);\n\n/**\n * 合约交易下单\n *\n * 下单时指定的是合约张数 size ,而非币的数量,每一张合约对应的币的数量是合约详情接口里返回的 quanto_multiplier\n *\n * 0 成交的订单在撤单 10 分钟之后无法再获取到,会提到订单不存在\n *\n * 设置 reduce_only 为 true 可以防止在减仓的时候穿仓\n *\n * 单仓模式下,如果需要平仓,需要设置 size 为 0 ,close 为 true\n *\n * 双仓模式下,平仓需要使用 auto_size 来设置平仓方向,并同时设置 reduce_only 为 true,size 为 0\n *\n * 设置 stp_act 决定使用限制用户自成交的策略,详细用法参考body参数stp_act\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E4%BA%A4%E6%98%93%E4%B8%8B%E5%8D%95\n */\nexport const postFutureOrders = (\n credential: ICredential,\n settle: string,\n params: {\n contract: string;\n size: number;\n iceberg?: number;\n price?: string;\n close?: boolean;\n reduce_only?: boolean;\n tif?: string;\n text?: string;\n auto_size?: string;\n stp_act?: string;\n },\n): Promise<{\n label?: string;\n message?: string;\n detail?: string;\n id: number;\n user: number;\n contract: string;\n create_time: number;\n size: number;\n iceberg: number;\n left: number;\n price: string;\n fill_price: string;\n mkfr: string;\n tkfr: string;\n tif: string;\n refu: number;\n is_reduce_only: boolean;\n is_close: boolean;\n is_liq: boolean;\n text: string;\n status: string;\n finish_time: number;\n finish_as: string;\n stp_id: number;\n stp_act: string;\n amend_text: string;\n}> => callPrivate(credential, 'POST', `/futures/${settle}/orders`, params);\n\n/**\n * 撤销单个订单\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%92%A4%E9%94%80%E5%8D%95%E4%B8%AA%E8%AE%A2%E5%8D%95-2\n */\nexport const deleteFutureOrders = (credential: ICredential, settle: string, order_id: string): Promise<{}> =>\n callPrivate(credential, 'DELETE', `/futures/${settle}/orders/${order_id}`);\n\n/**\n * 提现\n *\n * POST /withdrawals\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%8F%90%E7%8E%B0\n */\nexport const postWithdrawals = (\n credential: ICredential,\n params: {\n withdraw_order_id?: string;\n amount: string;\n currency: string;\n address?: string;\n memo?: string;\n chain: string;\n },\n): Promise<{\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n}> => callPrivate(credential, 'POST', '/withdrawals', params);\n\n/**\n * 获取币种充值地址\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%B8%81%E7%A7%8D%E5%85%85%E5%80%BC%E5%9C%B0%E5%9D%80\n */\nexport const getDepositAddress = (\n credential: ICredential,\n params: {\n currency: string;\n },\n): Promise<{\n currency: string;\n address: string;\n multichain_addresses: {\n chain: string;\n address: string;\n payment_id: string;\n payment_name: string;\n obtain_failed: boolean;\n }[];\n}> => callPrivate(credential, 'GET', '/wallet/deposit_address', params);\n\n/**\n * 创建新的子账户\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E5%AD%90%E8%B4%A6%E6%88%B7\n */\nexport const getSubAccountList = (\n credential: ICredential,\n params?: {\n type?: string;\n },\n): Promise<\n {\n remark: string;\n login_name: string;\n password: string;\n email: string;\n state: number;\n type: number;\n user_id: number;\n create_time: number;\n }[]\n> => callPrivate(credential, 'GET', '/sub_accounts', params);\n\n/**\n * 获取充值记录\n *\n * 记录查询时间范围不允许超过 30 天\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%85%85%E5%80%BC%E8%AE%B0%E5%BD%95\n */\nexport const getDepositHistory = (\n credential: ICredential,\n params?: {\n currency?: string;\n from?: number;\n to?: number;\n limit?: number;\n offset?: number;\n },\n): Promise<\n {\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n }[]\n> => callPrivate(credential, 'GET', '/wallet/deposits', params);\n\n/**\n * 获取提现记录\n *\n * 记录查询时间范围不允许超过 30 天\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%B8%81%E7%A7%8D%E5%85%85%E5%80%BC%E5%9C%B0%E5%9D%80\n */\nexport const getWithdrawalHistory = (\n credential: ICredential,\n params?: {\n currency?: string;\n from?: number;\n to?: number;\n limit?: number;\n offset?: number;\n },\n): Promise<\n {\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n }[]\n> => callPrivate(credential, 'GET', '/wallet/withdrawals', params);\n\n/**\n * 获取现货交易账户列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%8E%B0%E8%B4%A7%E4%BA%A4%E6%98%93%E8%B4%A6%E6%88%B7%E5%88%97%E8%A1%A8\n */\nexport const getSpotAccounts = (\n credential: ICredential,\n params?: {\n currency?: string;\n },\n): Promise<\n {\n currency: string;\n available: string;\n locked: string;\n update_id: string;\n }[]\n> => callPrivate(credential, 'GET', '/spot/accounts', params);\n\n/**\n * 交易账户互转\n *\n * POST /wallet/transfers\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E4%BA%A4%E6%98%93%E8%B4%A6%E6%88%B7%E4%BA%92%E8%BD%AC\n */\nexport const postWalletTransfer = (\n credential: ICredential,\n params: {\n currency: string;\n from: string;\n to: string;\n amount: string;\n currency_pair?: string;\n settle?: string;\n },\n): Promise<{\n tx_id: string;\n}> => callPrivate(credential, 'POST', '/wallet/transfers', params);\n\n/**\n * 获取统一账户最多可转出\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E7%BB%9F%E4%B8%80%E8%B4%A6%E6%88%B7%E6%9C%80%E5%A4%9A%E5%8F%AF%E8%BD%AC%E5%87%BA\n */\nexport const getUnifiedTransferable = (\n credential: ICredential,\n params: {\n currency: string;\n },\n): Promise<{\n currency: string;\n amount: string;\n}> => callPrivate(credential, 'GET', `/unified/transferable`, params);\n"]}
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":";;;AACA,+CAA+C;A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wBAsBkC;AAEnE;;;;GAIG;AACI,MAAM,eAAe,GAAG,CAC7B,UAAuB,EACvB,MAEC,EAQD,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;AAZjD,QAAA,eAAe,mBAYkC;AAE9D;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAChC,UAAuB,EACvB,MAOC,EAGA,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,CAAC,CAAC;AAZtD,QAAA,kBAAkB,sBAYoC;AAEnE;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,CACpC,UAAuB,EACvB,MAEC,EAIA,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,uBAAuB,EAAE,MAAM,CAAC,CAAC;AARzD,QAAA,sBAAsB,0BAQmC","sourcesContent":["import type { GateParams, HttpMethod, IGateCredential } from './http-client';\nimport { requestPrivate } from './http-client';\n\nexport type ICredential = IGateCredential;\n\nconst callPrivate = <TResponse>(\n credential: ICredential,\n method: HttpMethod,\n path: string,\n params?: GateParams,\n) => requestPrivate<TResponse>(credential, method, path, params);\n\n/**\n * 获取用户账户信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF\n */\nexport const getAccountDetail = (\n credential: ICredential,\n): Promise<{\n user_id: number;\n ip_whitelist: string[];\n currency_pairs: string[];\n key: {\n mode: number;\n };\n tier: number;\n}> => callPrivate(credential, 'GET', '/account/detail');\n\nexport const getUnifiedAccounts = (\n credential: ICredential,\n params?: { currency?: string },\n): Promise<{\n user_id: string;\n refresh_time: number;\n locket: boolean;\n balances: Record<\n string,\n {\n available: string;\n freeze: string;\n borrowed: string;\n negative_liab: string;\n futures_pos_liab: string;\n equity: string;\n total_freeze: string;\n total_liab: string;\n spot_in_use: string;\n }\n >;\n total: string;\n borrowed: string;\n total_initial_margin: string;\n total_margin_balance: string;\n total_maintenance_margin: string;\n total_initial_margin_rate: string;\n total_maintenance_margin_rate: string;\n total_avail_margin: string;\n unified_account_total: string;\n unified_account_total_liab: string;\n unified_account_total_equity: string;\n leverage: string;\n spot_order_loss: string;\n spot_hedge: boolean;\n}> => callPrivate(credential, 'GET', '/unified/accounts', params);\n\n/**\n * 获取用户仓位列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E4%BB%93%E4%BD%8D%E5%88%97%E8%A1%A8\n */\nexport const getFuturePositions = (\n credential: ICredential,\n quote_currency: string,\n params?: { holding?: boolean; limit?: number; offset?: number },\n): Promise<\n {\n user: number;\n contract: string;\n size: number;\n leverage: string;\n risk_limit: string;\n leverage_max: string;\n maintenance_rate: string;\n value: string;\n margin: string;\n entry_price: string;\n mark_price: string;\n unrealised_pnl: string;\n realised_pnl: string;\n mode: string;\n liq_price: string;\n }[]\n> => callPrivate(credential, 'GET', `/futures/${quote_currency}/positions`, params);\n\n/**\n * 查询合约订单列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%90%88%E7%BA%A6%E8%AE%A2%E5%8D%95%E5%88%97%E8%A1%A8\n */\nexport const getFuturesOrders = (\n credential: ICredential,\n settle: string,\n params: {\n contract?: string;\n status: string;\n limit?: number;\n offset?: number;\n last_id?: number;\n },\n): Promise<\n {\n id: string;\n contract: string;\n create_time: number;\n size: number;\n price: string;\n is_close: boolean;\n fill_price: string;\n left?: number;\n status?: string;\n text: string;\n }[]\n> => callPrivate(credential, 'GET', `/futures/${settle}/orders`, params);\n\n/**\n * 获取合约账号\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%90%88%E7%BA%A6%E8%B4%A6%E5%8F%B7\n */\nexport const getFuturesAccounts = (\n credential: ICredential,\n settle: string,\n): Promise<{\n user: number;\n currency: string;\n total: string;\n unrealised_pnl: string;\n position_margin: string;\n order_margin: string;\n available: string;\n point: string;\n bonus: string;\n in_dual_mode: boolean;\n enable_evolved_classic: boolean;\n history: {\n dnw: string;\n pnl: string;\n fee: string;\n refr: string;\n fund: string;\n point_dnw: string;\n point_fee: string;\n point_refr: string;\n bonus_dnw: string;\n bonus_offset: string;\n };\n}> => callPrivate(credential, 'GET', `/futures/${settle}/accounts`);\n\n/**\n * 合约交易下单\n *\n * 下单时指定的是合约张数 size ,而非币的数量,每一张合约对应的币的数量是合约详情接口里返回的 quanto_multiplier\n *\n * 0 成交的订单在撤单 10 分钟之后无法再获取到,会提到订单不存在\n *\n * 设置 reduce_only 为 true 可以防止在减仓的时候穿仓\n *\n * 单仓模式下,如果需要平仓,需要设置 size 为 0 ,close 为 true\n *\n * 双仓模式下,平仓需要使用 auto_size 来设置平仓方向,并同时设置 reduce_only 为 true,size 为 0\n *\n * 设置 stp_act 决定使用限制用户自成交的策略,详细用法参考body参数stp_act\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E4%BA%A4%E6%98%93%E4%B8%8B%E5%8D%95\n */\nexport const postFutureOrders = (\n credential: ICredential,\n settle: string,\n params: {\n contract: string;\n size: number;\n iceberg?: number;\n price?: string;\n close?: boolean;\n reduce_only?: boolean;\n tif?: string;\n text?: string;\n auto_size?: string;\n stp_act?: string;\n },\n): Promise<{\n label?: string;\n message?: string;\n detail?: string;\n id: number;\n user: number;\n contract: string;\n create_time: number;\n size: number;\n iceberg: number;\n left: number;\n price: string;\n fill_price: string;\n mkfr: string;\n tkfr: string;\n tif: string;\n refu: number;\n is_reduce_only: boolean;\n is_close: boolean;\n is_liq: boolean;\n text: string;\n status: string;\n finish_time: number;\n finish_as: string;\n stp_id: number;\n stp_act: string;\n amend_text: string;\n}> => callPrivate(credential, 'POST', `/futures/${settle}/orders`, params);\n\n/**\n * 撤销单个订单\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%92%A4%E9%94%80%E5%8D%95%E4%B8%AA%E8%AE%A2%E5%8D%95-2\n */\nexport const deleteFutureOrders = (credential: ICredential, settle: string, order_id: string): Promise<{}> =>\n callPrivate(credential, 'DELETE', `/futures/${settle}/orders/${order_id}`);\n\n/**\n * 提现\n *\n * POST /withdrawals\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%8F%90%E7%8E%B0\n */\nexport const postWithdrawals = (\n credential: ICredential,\n params: {\n withdraw_order_id?: string;\n amount: string;\n currency: string;\n address?: string;\n memo?: string;\n chain: string;\n },\n): Promise<{\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n}> => callPrivate(credential, 'POST', '/withdrawals', params);\n\n/**\n * 获取币种充值地址\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%B8%81%E7%A7%8D%E5%85%85%E5%80%BC%E5%9C%B0%E5%9D%80\n */\nexport const getDepositAddress = (\n credential: ICredential,\n params: {\n currency: string;\n },\n): Promise<{\n currency: string;\n address: string;\n multichain_addresses: {\n chain: string;\n address: string;\n payment_id: string;\n payment_name: string;\n obtain_failed: boolean;\n }[];\n}> => callPrivate(credential, 'GET', '/wallet/deposit_address', params);\n\n/**\n * 创建新的子账户\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E5%AD%90%E8%B4%A6%E6%88%B7\n */\nexport const getSubAccountList = (\n credential: ICredential,\n params?: {\n type?: string;\n },\n): Promise<\n {\n remark: string;\n login_name: string;\n password: string;\n email: string;\n state: number;\n type: number;\n user_id: number;\n create_time: number;\n }[]\n> => callPrivate(credential, 'GET', '/sub_accounts', params);\n\n/**\n * 获取充值记录\n *\n * 记录查询时间范围不允许超过 30 天\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%85%85%E5%80%BC%E8%AE%B0%E5%BD%95\n */\nexport const getDepositHistory = (\n credential: ICredential,\n params?: {\n currency?: string;\n from?: number;\n to?: number;\n limit?: number;\n offset?: number;\n },\n): Promise<\n {\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n }[]\n> => callPrivate(credential, 'GET', '/wallet/deposits', params);\n\n/**\n * 获取提现记录\n *\n * 记录查询时间范围不允许超过 30 天\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E5%B8%81%E7%A7%8D%E5%85%85%E5%80%BC%E5%9C%B0%E5%9D%80\n */\nexport const getWithdrawalHistory = (\n credential: ICredential,\n params?: {\n currency?: string;\n from?: number;\n to?: number;\n limit?: number;\n offset?: number;\n },\n): Promise<\n {\n id: string;\n txid: string;\n withdraw_order_id: string;\n timestamp: number;\n amount: string;\n currency: string;\n address: string;\n memo: string;\n status: string;\n chain: string;\n }[]\n> => callPrivate(credential, 'GET', '/wallet/withdrawals', params);\n\n/**\n * 获取现货交易账户列表\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E7%8E%B0%E8%B4%A7%E4%BA%A4%E6%98%93%E8%B4%A6%E6%88%B7%E5%88%97%E8%A1%A8\n */\nexport const getSpotAccounts = (\n credential: ICredential,\n params?: {\n currency?: string;\n },\n): Promise<\n {\n currency: string;\n available: string;\n locked: string;\n update_id: string;\n }[]\n> => callPrivate(credential, 'GET', '/spot/accounts', params);\n\n/**\n * 交易账户互转\n *\n * POST /wallet/transfers\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E4%BA%A4%E6%98%93%E8%B4%A6%E6%88%B7%E4%BA%92%E8%BD%AC\n */\nexport const postWalletTransfer = (\n credential: ICredential,\n params: {\n currency: string;\n from: string;\n to: string;\n amount: string;\n currency_pair?: string;\n settle?: string;\n },\n): Promise<{\n tx_id: string;\n}> => callPrivate(credential, 'POST', '/wallet/transfers', params);\n\n/**\n * 获取统一账户最多可转出\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E7%BB%9F%E4%B8%80%E8%B4%A6%E6%88%B7%E6%9C%80%E5%A4%9A%E5%8F%AF%E8%BD%AC%E5%87%BA\n */\nexport const getUnifiedTransferable = (\n credential: ICredential,\n params: {\n currency: string;\n },\n): Promise<{\n currency: string;\n amount: string;\n}> => callPrivate(credential, 'GET', `/unified/transferable`, params);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAuD5F,eAAO,MAAM,qBAAqB,eAAsB,WAAW,yBA0ClE,CAAC"}
|
|
@@ -1,22 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getUnifiedAccountInfo = void 0;
|
|
4
|
+
const cache_1 = require("@yuants/cache");
|
|
5
|
+
const utils_1 = require("@yuants/utils");
|
|
4
6
|
const private_api_1 = require("../../api/private-api");
|
|
5
7
|
const public_api_1 = require("../../api/public-api");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
+
const product_1 = require("../markets/product");
|
|
9
|
+
const spotProductMapCache = (0, cache_1.createCache)(async () => {
|
|
10
|
+
const products = await (0, product_1.listProducts)();
|
|
11
|
+
const map = new Map();
|
|
12
|
+
for (const product of products !== null && products !== void 0 ? products : []) {
|
|
13
|
+
const [, instType] = product.product_id.split('/');
|
|
14
|
+
if (instType === 'SPOT') {
|
|
15
|
+
map.set(product.base_currency, product.product_id);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return map;
|
|
19
|
+
}, { expire: 86400000 });
|
|
20
|
+
const loadFuturePositions = async (credential) => {
|
|
21
|
+
const positions = [];
|
|
22
|
+
const positionsRes = await (0, private_api_1.getFuturePositions)(credential, 'usdt');
|
|
23
|
+
for (const position of Array.isArray(positionsRes) ? positionsRes : []) {
|
|
24
|
+
if (!(Math.abs(position.size) > 0))
|
|
25
|
+
continue;
|
|
26
|
+
const product_id = (0, utils_1.encodePath)('GATE', 'FUTURE', position.contract);
|
|
27
|
+
const volume = Math.abs(position.size);
|
|
28
|
+
const closable_price = Number(position.mark_price);
|
|
29
|
+
const valuation = volume * closable_price;
|
|
30
|
+
positions.push({
|
|
31
|
+
datasource_id: 'GATE',
|
|
32
|
+
position_id: `${position.contract}-${position.leverage}-${position.mode}`,
|
|
33
|
+
product_id,
|
|
34
|
+
direction: position.mode === 'dual_long'
|
|
35
|
+
? 'LONG'
|
|
36
|
+
: position.mode === 'dual_short'
|
|
37
|
+
? 'SHORT'
|
|
38
|
+
: position.size > 0
|
|
39
|
+
? 'LONG'
|
|
40
|
+
: 'SHORT',
|
|
41
|
+
volume,
|
|
42
|
+
free_volume: Math.abs(position.size),
|
|
43
|
+
position_price: Number(position.entry_price),
|
|
44
|
+
closable_price,
|
|
45
|
+
floating_profit: Number(position.unrealised_pnl),
|
|
46
|
+
liquidation_price: position.liq_price,
|
|
47
|
+
valuation,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return positions;
|
|
51
|
+
};
|
|
8
52
|
const getUnifiedAccountInfo = async (credential) => {
|
|
9
53
|
var _a;
|
|
10
|
-
const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([
|
|
11
|
-
|
|
54
|
+
const [futurePositions, unifiedAccount, spotTickers, spotProductMap] = await Promise.all([
|
|
55
|
+
loadFuturePositions(credential),
|
|
12
56
|
(0, private_api_1.getUnifiedAccounts)(credential, {}),
|
|
13
57
|
(0, public_api_1.getSpotTickers)({}),
|
|
58
|
+
spotProductMapCache.query('').catch(() => undefined),
|
|
14
59
|
]);
|
|
60
|
+
const resolvedSpotProductMap = spotProductMap !== null && spotProductMap !== void 0 ? spotProductMap : new Map();
|
|
15
61
|
const balances = (_a = unifiedAccount === null || unifiedAccount === void 0 ? void 0 : unifiedAccount.balances) !== null && _a !== void 0 ? _a : {};
|
|
16
62
|
const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];
|
|
17
63
|
const spotPositions = Object.keys(balances)
|
|
18
64
|
.map((currency) => {
|
|
19
|
-
var _a, _b;
|
|
65
|
+
var _a, _b, _c;
|
|
20
66
|
let currency_pair = `${currency}_USDT`;
|
|
21
67
|
if (currency === 'SOL2') {
|
|
22
68
|
currency_pair = 'SOL_USDT';
|
|
@@ -31,9 +77,9 @@ const getUnifiedAccountInfo = async (credential) => {
|
|
|
31
77
|
if (Math.abs(volume) === 0)
|
|
32
78
|
return undefined;
|
|
33
79
|
return {
|
|
34
|
-
datasource_id: '
|
|
80
|
+
datasource_id: 'GATE',
|
|
35
81
|
position_id: currency,
|
|
36
|
-
product_id: (0, utils_1.encodePath)('GATE', 'SPOT', currency),
|
|
82
|
+
product_id: (_c = resolvedSpotProductMap.get(currency)) !== null && _c !== void 0 ? _c : (0, utils_1.encodePath)('GATE', 'SPOT', currency),
|
|
37
83
|
direction: 'LONG',
|
|
38
84
|
volume,
|
|
39
85
|
free_volume: volume,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,yCAA2C;AAC3C,uDAA4F;AAC5F,qDAAsD;AACtD,gDAAkD;AAElD,MAAM,mBAA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,EAAE,cAAc,GAAG,MAAM;YACxC,SAAS,EAAE,cAAc,GAAG,MAAM;SACtB,CAAC;IACjB,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,IAAI,EAAqB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,eAAe,EAAE,GAAG,aAAa,CAAC,CAAC;AAChD,CAAC,CAAC;AA1CW,QAAA,qBAAqB,yBA0ChC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport type { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getUnifiedAccounts, getFuturePositions, ICredential } from '../../api/private-api';\nimport { getSpotTickers } from '../../api/public-api';\nimport { listProducts } from '../markets/product';\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\nconst loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n const positionsRes = await getFuturePositions(credential, 'usdt');\n\n for (const position of Array.isArray(positionsRes) ? positionsRes : []) {\n if (!(Math.abs(position.size) > 0)) continue;\n\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price;\n positions.push({\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n liquidation_price: position.liq_price,\n valuation,\n });\n }\n\n return positions;\n};\n\nexport const getUnifiedAccountInfo = async (credential: ICredential) => {\n const [futurePositions, unifiedAccount, spotTickers, spotProductMap] = await Promise.all([\n loadFuturePositions(credential),\n getUnifiedAccounts(credential, {}),\n getSpotTickers({}),\n spotProductMapCache.query('').catch(() => undefined),\n ]);\n\n const resolvedSpotProductMap = spotProductMap ?? new Map<string, string>();\n const balances = unifiedAccount?.balances ?? {};\n const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];\n const spotPositions: IPosition[] = Object.keys(balances)\n .map((currency) => {\n let currency_pair = `${currency}_USDT`;\n if (currency === 'SOL2') {\n currency_pair = 'SOL_USDT';\n }\n if (currency === 'GTSOL') {\n currency_pair = 'SOL_USDT';\n }\n const closable_price =\n currency === 'USDT'\n ? 1\n : Number(spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)?.last || 0);\n const volume = Number(balances[currency]?.available || 0);\n if (Math.abs(volume) === 0) return undefined;\n return {\n datasource_id: 'GATE',\n position_id: currency,\n product_id: resolvedSpotProductMap.get(currency) ?? encodePath('GATE', 'SPOT', currency),\n direction: 'LONG',\n volume,\n free_volume: volume,\n closable_price,\n position_price: closable_price,\n floating_profit: closable_price * volume,\n valuation: closable_price * volume,\n } as IPosition;\n })\n .filter((item): item is IPosition => !!item);\n\n return [...futurePositions, ...spotPositions];\n};\n"]}
|
package/lib/services/exchange.js
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const exchange_1 = require("@yuants/exchange");
|
|
4
4
|
const protocol_1 = require("@yuants/protocol");
|
|
5
|
-
const utils_1 = require("@yuants/utils");
|
|
6
5
|
const profile_1 = require("./accounts/profile");
|
|
7
6
|
const unified_1 = require("./accounts/unified");
|
|
8
7
|
const cancelOrder_1 = require("./orders/cancelOrder");
|
|
9
8
|
const submitOrder_1 = require("./orders/submitOrder");
|
|
10
|
-
const future_1 = require("./accounts/future");
|
|
11
9
|
const listOrders_1 = require("./orders/listOrders");
|
|
12
10
|
const product_1 = require("./markets/product");
|
|
13
11
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
@@ -24,10 +22,7 @@ const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
|
24
22
|
getCredentialId: profile_1.getCredentialId,
|
|
25
23
|
listProducts: product_1.listProducts,
|
|
26
24
|
getPositions: async function (credential) {
|
|
27
|
-
const
|
|
28
|
-
// getFutureAccountInfo(credential),
|
|
29
|
-
(0, unified_1.getUnifiedAccountInfo)(credential),
|
|
30
|
-
]);
|
|
25
|
+
const unifiedPositions = await (0, unified_1.getUnifiedAccountInfo)(credential);
|
|
31
26
|
return [...unifiedPositions];
|
|
32
27
|
},
|
|
33
28
|
getOrders: async function (credential) {
|
|
@@ -38,16 +33,8 @@ const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
|
38
33
|
return [...umOrders];
|
|
39
34
|
},
|
|
40
35
|
getPositionsByProductId: async function (credential, product_id) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
// const positions = await getSpotAccountInfoSnapshot(credential);
|
|
44
|
-
// return positions.filter((position) => position.product_id === product_id);
|
|
45
|
-
// }
|
|
46
|
-
if (instType === 'FUTURE') {
|
|
47
|
-
const positions = await (0, future_1.getFutureAccountInfo)(credential);
|
|
48
|
-
return positions.filter((position) => position.product_id === product_id);
|
|
49
|
-
}
|
|
50
|
-
throw new Error(`Unsupported instType: ${instType}`);
|
|
36
|
+
const positions = await (0, unified_1.getUnifiedAccountInfo)(credential);
|
|
37
|
+
return positions.filter((position) => position.product_id === product_id);
|
|
51
38
|
},
|
|
52
39
|
getOrdersByProductId: listOrders_1.getOrdersByProductId,
|
|
53
40
|
submitOrder: submitOrder_1.submitOrder,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2D;AAC3D,+CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],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E,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,WAAW,EAAX,yBAAW;CACZ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { getCredentialId } from './accounts/profile';\nimport { getUnifiedAccountInfo } from './accounts/unified';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { submitOrder } from './orders/submitOrder';\nimport { ICredential } from '../api/private-api';\nimport { listOrders, getOrdersByProductId } from './orders/listOrders';\nimport { listProducts } from './markets/product';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'GATE',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: async function (credential: ICredential): Promise<IPosition[]> {\n const unifiedPositions = await getUnifiedAccountInfo(credential);\n return [...unifiedPositions];\n },\n getOrders: async function (credential: ICredential): Promise<IOrder[]> {\n const [umOrders] = await Promise.all([\n listOrders(credential),\n // listSpotOrders(credential),\n ]);\n return [...umOrders];\n },\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const positions = await getUnifiedAccountInfo(credential);\n return positions.filter((position) => position.product_id === product_id);\n },\n getOrdersByProductId,\n submitOrder,\n modifyOrder: () => {\n throw new Error('Not implemented');\n },\n cancelOrder,\n});\n"]}
|
package/package.json
CHANGED
package/temp/package-deps.json
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"apps/vendor-gate/AGENTS.md": "59be8d734f8a91ae5f7377e7c688f1fccb8641b7",
|
|
3
|
-
"apps/vendor-gate/CHANGELOG.json": "
|
|
4
|
-
"apps/vendor-gate/CHANGELOG.md": "
|
|
3
|
+
"apps/vendor-gate/CHANGELOG.json": "86d6e1579d351260d0e37f088a56ca2e7dc6ca21",
|
|
4
|
+
"apps/vendor-gate/CHANGELOG.md": "4fb526cd75cb5663817076309a6eda52be6ca866",
|
|
5
5
|
"apps/vendor-gate/README.md": "ea5ee3a61cd87d9104d729902dfaccac9b9913e0",
|
|
6
|
-
"apps/vendor-gate/SESSION_NOTES.md": "
|
|
6
|
+
"apps/vendor-gate/SESSION_NOTES.md": "eefeaa9e02b039bde7180b6a479fc3fa0e72321c",
|
|
7
7
|
"apps/vendor-gate/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
8
8
|
"apps/vendor-gate/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
9
9
|
"apps/vendor-gate/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
10
10
|
"apps/vendor-gate/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
11
11
|
"apps/vendor-gate/etc/vendor-gate.api.md": "970682cd589432de553cc5cee2a0abe73814a515",
|
|
12
|
-
"apps/vendor-gate/package.json": "
|
|
12
|
+
"apps/vendor-gate/package.json": "ae7c38bee258902f03b64afd2b12cdff3d45729a",
|
|
13
13
|
"apps/vendor-gate/src/api/http-client.ts": "97e0e70454c6072f388f90442ec4afabe6feb93b",
|
|
14
|
-
"apps/vendor-gate/src/api/private-api.ts": "
|
|
14
|
+
"apps/vendor-gate/src/api/private-api.ts": "d8e7c486135bce076f691dd247d0e2eb40543fa5",
|
|
15
15
|
"apps/vendor-gate/src/api/public-api.ts": "ee1a246a8833a7d9bb06e829b09a3bd80e0d86bf",
|
|
16
16
|
"apps/vendor-gate/src/api/rate-limiter.ts": "047c51029ffcaf98190cfd04d96816bbced5fa7c",
|
|
17
17
|
"apps/vendor-gate/src/index.ts": "31888627bccab532d55bd91833d80c72a4afae9b",
|
|
18
|
-
"apps/vendor-gate/src/services/accounts/future.ts": "4e762c193fe8ae4dbe3ae15d45b03bdf0a0fb8c8",
|
|
19
18
|
"apps/vendor-gate/src/services/accounts/profile.ts": "4132c7c3d9760b9a6694d5b3eae7e8b2847fe6c1",
|
|
20
|
-
"apps/vendor-gate/src/services/accounts/
|
|
21
|
-
"apps/vendor-gate/src/services/accounts/unified.ts": "f49b87a161553fd2abcce20ec76f8df3ae98c2bc",
|
|
19
|
+
"apps/vendor-gate/src/services/accounts/unified.ts": "8baba2c3f726d9733f8afbc860d9225d75ed3bd6",
|
|
22
20
|
"apps/vendor-gate/src/services/default-credential.ts": "b9ffa157b818148450bfaaf4851597e91901190c",
|
|
23
|
-
"apps/vendor-gate/src/services/exchange.ts": "
|
|
21
|
+
"apps/vendor-gate/src/services/exchange.ts": "3a8fbaecaf7ea0c5a03f3a61f21fb8d2d4588394",
|
|
24
22
|
"apps/vendor-gate/src/services/markets/interest-rate.ts": "e669eb1d664448f309bb062907b273157d1c111e",
|
|
25
23
|
"apps/vendor-gate/src/services/markets/product.ts": "217bf64b307adca4c251333462b75f73d0d85e83",
|
|
26
24
|
"apps/vendor-gate/src/services/markets/quote.ts": "1624d58b9c607ae01300de292de3ed49a2f2e037",
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { encodePath } from '@yuants/utils';
|
|
2
|
-
import { getFuturePositions, getFuturesAccounts } from '../../api/private-api';
|
|
3
|
-
import { productCache } from '../markets/product';
|
|
4
|
-
export const loadFuturePositions = async (credential) => {
|
|
5
|
-
var _a;
|
|
6
|
-
const positions = [];
|
|
7
|
-
const positionsRes = await getFuturePositions(credential, 'usdt');
|
|
8
|
-
for (const position of Array.isArray(positionsRes) ? positionsRes : []) {
|
|
9
|
-
if (!(Math.abs(position.size) > 0))
|
|
10
|
-
continue;
|
|
11
|
-
const product_id = encodePath('GATE', 'FUTURE', position.contract);
|
|
12
|
-
const theProduct = await productCache.query(product_id);
|
|
13
|
-
const volume = Math.abs(position.size);
|
|
14
|
-
const closable_price = Number(position.mark_price);
|
|
15
|
-
const valuation = volume * closable_price * ((_a = theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) !== null && _a !== void 0 ? _a : 1);
|
|
16
|
-
positions.push({
|
|
17
|
-
datasource_id: 'GATE',
|
|
18
|
-
position_id: `${position.contract}-${position.leverage}-${position.mode}`,
|
|
19
|
-
product_id,
|
|
20
|
-
direction: position.mode === 'dual_long'
|
|
21
|
-
? 'LONG'
|
|
22
|
-
: position.mode === 'dual_short'
|
|
23
|
-
? 'SHORT'
|
|
24
|
-
: position.size > 0
|
|
25
|
-
? 'LONG'
|
|
26
|
-
: 'SHORT',
|
|
27
|
-
volume,
|
|
28
|
-
free_volume: Math.abs(position.size),
|
|
29
|
-
position_price: Number(position.entry_price),
|
|
30
|
-
closable_price,
|
|
31
|
-
floating_profit: Number(position.unrealised_pnl),
|
|
32
|
-
valuation,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return positions;
|
|
36
|
-
};
|
|
37
|
-
export const getFutureAccountInfo = async (credential) => {
|
|
38
|
-
const [positions, rawAccount] = await Promise.all([
|
|
39
|
-
loadFuturePositions(credential),
|
|
40
|
-
getFuturesAccounts(credential, 'usdt'),
|
|
41
|
-
]);
|
|
42
|
-
return positions;
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=future.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;;IACzF,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAAC,UAAU,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,CAAC;YAC5C,cAAc;YACd,eAAe,EAAE,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC;YAChD,SAAS;SACV,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IACpE,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,mBAAmB,CAAC,UAAU,CAAC;QAC/B,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import type { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { productCache } from '../markets/product';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n const positionsRes = await getFuturePositions(credential, 'usdt');\n\n for (const position of Array.isArray(positionsRes) ? positionsRes : []) {\n if (!(Math.abs(position.size) > 0)) continue;\n\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = await productCache.query(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n positions.push({\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n });\n }\n\n return positions;\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n return positions;\n};\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { makeSpotPosition } from '@yuants/data-account';
|
|
2
|
-
import { getSpotAccounts } from '../../api/private-api';
|
|
3
|
-
import { encodePath } from '@yuants/utils';
|
|
4
|
-
export const getSpotAccountInfo = async (credential) => {
|
|
5
|
-
const res = await getSpotAccounts(credential);
|
|
6
|
-
if (!Array.isArray(res)) {
|
|
7
|
-
throw new Error('Failed to load spot balances');
|
|
8
|
-
}
|
|
9
|
-
return res.map((item) => {
|
|
10
|
-
return makeSpotPosition({
|
|
11
|
-
datasource_id: 'GATE',
|
|
12
|
-
position_id: item.currency,
|
|
13
|
-
product_id: encodePath('GATE', 'SPOT', `${item.currency}`),
|
|
14
|
-
volume: Number(item.available),
|
|
15
|
-
free_volume: Number(item.available),
|
|
16
|
-
closable_price: 1, // TODO: use real price
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=spot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAe,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,OAAO,gBAAgB,CAAC;YACtB,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,IAAI,CAAC,QAAQ;YAC1B,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1D,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YACnC,cAAc,EAAE,CAAC,EAAE,uBAAuB;SAC3C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccounts, ICredential } from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\nexport const getSpotAccountInfo = async (credential: ICredential) => {\n const res = await getSpotAccounts(credential);\n if (!Array.isArray(res)) {\n throw new Error('Failed to load spot balances');\n }\n return res.map((item) => {\n return makeSpotPosition({\n datasource_id: 'GATE',\n position_id: item.currency,\n product_id: encodePath('GATE', 'SPOT', `${item.currency}`),\n volume: Number(item.available),\n free_volume: Number(item.available),\n closable_price: 1, // TODO: use real price\n });\n });\n};\n"]}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { IPosition } from '@yuants/data-account';
|
|
2
|
-
import { ICredential } from '../../api/private-api';
|
|
3
|
-
export declare const loadFuturePositions: (credential: ICredential) => Promise<IPosition[]>;
|
|
4
|
-
export declare const getFutureAccountInfo: (credential: ICredential) => Promise<IPosition[]>;
|
|
5
|
-
//# sourceMappingURL=future.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG5F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAkCtF,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAsB,WAAW,yBAOjE,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFutureAccountInfo = exports.loadFuturePositions = void 0;
|
|
4
|
-
const utils_1 = require("@yuants/utils");
|
|
5
|
-
const private_api_1 = require("../../api/private-api");
|
|
6
|
-
const product_1 = require("../markets/product");
|
|
7
|
-
const loadFuturePositions = async (credential) => {
|
|
8
|
-
var _a;
|
|
9
|
-
const positions = [];
|
|
10
|
-
const positionsRes = await (0, private_api_1.getFuturePositions)(credential, 'usdt');
|
|
11
|
-
for (const position of Array.isArray(positionsRes) ? positionsRes : []) {
|
|
12
|
-
if (!(Math.abs(position.size) > 0))
|
|
13
|
-
continue;
|
|
14
|
-
const product_id = (0, utils_1.encodePath)('GATE', 'FUTURE', position.contract);
|
|
15
|
-
const theProduct = await product_1.productCache.query(product_id);
|
|
16
|
-
const volume = Math.abs(position.size);
|
|
17
|
-
const closable_price = Number(position.mark_price);
|
|
18
|
-
const valuation = volume * closable_price * ((_a = theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) !== null && _a !== void 0 ? _a : 1);
|
|
19
|
-
positions.push({
|
|
20
|
-
datasource_id: 'GATE',
|
|
21
|
-
position_id: `${position.contract}-${position.leverage}-${position.mode}`,
|
|
22
|
-
product_id,
|
|
23
|
-
direction: position.mode === 'dual_long'
|
|
24
|
-
? 'LONG'
|
|
25
|
-
: position.mode === 'dual_short'
|
|
26
|
-
? 'SHORT'
|
|
27
|
-
: position.size > 0
|
|
28
|
-
? 'LONG'
|
|
29
|
-
: 'SHORT',
|
|
30
|
-
volume,
|
|
31
|
-
free_volume: Math.abs(position.size),
|
|
32
|
-
position_price: Number(position.entry_price),
|
|
33
|
-
closable_price,
|
|
34
|
-
floating_profit: Number(position.unrealised_pnl),
|
|
35
|
-
valuation,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return positions;
|
|
39
|
-
};
|
|
40
|
-
exports.loadFuturePositions = loadFuturePositions;
|
|
41
|
-
const getFutureAccountInfo = async (credential) => {
|
|
42
|
-
const [positions, rawAccount] = await Promise.all([
|
|
43
|
-
(0, exports.loadFuturePositions)(credential),
|
|
44
|
-
(0, private_api_1.getFuturesAccounts)(credential, 'usdt'),
|
|
45
|
-
]);
|
|
46
|
-
return positions;
|
|
47
|
-
};
|
|
48
|
-
exports.getFutureAccountInfo = getFutureAccountInfo;
|
|
49
|
-
//# sourceMappingURL=future.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,uDAA4F;AAC5F,gDAAkD;AAE3C,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;;IACzF,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,MAAM,IAAA,gCAAkB,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAElE,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE;QACtE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAAE,SAAS;QAE7C,MAAM,UAAU,GAAG,IAAA,kBAAU,EAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnE,MAAM,UAAU,GAAG,MAAM,sBAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,cAAc,GAAG,MAAM,C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account';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { productCache } from '../markets/product';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n const positionsRes = await getFuturePositions(credential, 'usdt');\n\n for (const position of Array.isArray(positionsRes) ? positionsRes : []) {\n if (!(Math.abs(position.size) > 0)) continue;\n\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = await productCache.query(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n positions.push({\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n });\n }\n\n return positions;\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n return positions;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGrE,eAAO,MAAM,kBAAkB,eAAsB,WAAW,wDAe/D,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpotAccountInfo = void 0;
|
|
4
|
-
const data_account_1 = require("@yuants/data-account");
|
|
5
|
-
const private_api_1 = require("../../api/private-api");
|
|
6
|
-
const utils_1 = require("@yuants/utils");
|
|
7
|
-
const getSpotAccountInfo = async (credential) => {
|
|
8
|
-
const res = await (0, private_api_1.getSpotAccounts)(credential);
|
|
9
|
-
if (!Array.isArray(res)) {
|
|
10
|
-
throw new Error('Failed to load spot balances');
|
|
11
|
-
}
|
|
12
|
-
return res.map((item) => {
|
|
13
|
-
return (0, data_account_1.makeSpotPosition)({
|
|
14
|
-
datasource_id: 'GATE',
|
|
15
|
-
position_id: item.currency,
|
|
16
|
-
product_id: (0, utils_1.encodePath)('GATE', 'SPOT', `${item.currency}`),
|
|
17
|
-
volume: Number(item.available),
|
|
18
|
-
free_volume: Number(item.available),
|
|
19
|
-
closable_price: 1, // TODO: use real price
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
exports.getSpotAccountInfo = getSpotAccountInfo;
|
|
24
|
-
//# sourceMappingURL=spot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAwD;AACxD,uDAAqE;AACrE,yCAA2C;AAEpC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,MAAM,IAAA,6BAAe,EAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,OAAO,IAAA,+BAAgB,EAAC;YACtB,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,IAAI,CAAC,QAAQ;YAC1B,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1D,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YACnC,cAAc,EAAE,CAAC,EAAE,uBAAuB;SAC3C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B","sourcesContent":["import { makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccounts, ICredential } from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\nexport const getSpotAccountInfo = async (credential: ICredential) => {\n const res = await getSpotAccounts(credential);\n if (!Array.isArray(res)) {\n throw new Error('Failed to load spot balances');\n }\n return res.map((item) => {\n return makeSpotPosition({\n datasource_id: 'GATE',\n position_id: item.currency,\n product_id: encodePath('GATE', 'SPOT', `${item.currency}`),\n volume: Number(item.available),\n free_volume: Number(item.available),\n closable_price: 1, // TODO: use real price\n });\n });\n};\n"]}
|