diff --git a/README.md b/README.md index e971639..4b08052 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,20 @@ [1]: https://www.npmjs.com/package/gateio-api +Public spot tickers: + +```javascript +const { WebsocketClient } = require('gateio-api'); +const ws = new WebsocketClient(); +ws.subscribe({ topic: 'spot.tickers', payload: ['BTC_USDT'] }, 'spotV4'); +``` + +`WebsocketClient` handles what a raw WebSocket does not: + +- reconnect +- heartbeat +- resubscribe + Updated & performant JavaScript & Node.js SDK for the Gate.com (gate.io) REST APIs and WebSockets: - Professional, robust & performant Gate.com SDK with extensive production use in live trading environments. diff --git a/docs/endpointFunctionList.md b/docs/endpointFunctionList.md index 8f776c5..fb80a38 100644 --- a/docs/endpointFunctionList.md +++ b/docs/endpointFunctionList.md @@ -49,465 +49,465 @@ This table includes all endpoints from the official Exchange API docs and corres | Function | AUTH | HTTP Method | Endpoint | | -------- | :------: | :------: | -------- | -| [getSystemMaintenanceStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L718) | | GET | `/v1/public/system_info` | -| [listAnnouncementArticles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L722) | | POST | `/ann/list_article` | -| [submitWithdrawal()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L741) | :closed_lock_with_key: | POST | `/withdrawals` | -| [submitSpotMainAccountTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L755) | :closed_lock_with_key: | POST | `/withdrawals/push` | -| [cancelWithdrawal()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L771) | :closed_lock_with_key: | DELETE | `/withdrawals/{withdrawal_id}` | -| [getCurrencyChains()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L788) | | GET | `/wallet/currency_chains` | -| [createDepositAddress()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L798) | :closed_lock_with_key: | GET | `/wallet/deposit_address` | -| [getWithdrawalRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L812) | :closed_lock_with_key: | GET | `/wallet/withdrawals` | -| [getDepositRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L826) | :closed_lock_with_key: | GET | `/wallet/deposits` | -| [submitTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L845) | :closed_lock_with_key: | POST | `/wallet/transfers` | -| [getTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L857) | :closed_lock_with_key: | GET | `/wallet/transfers` | -| [submitMainSubTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L869) | :closed_lock_with_key: | POST | `/wallet/sub_account_transfers` | -| [getMainSubTransfers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L883) | :closed_lock_with_key: | GET | `/wallet/sub_account_transfers` | -| [submitSubToSubTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L897) | :closed_lock_with_key: | POST | `/wallet/sub_account_to_sub_account` | -| [getTransferStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L912) | :closed_lock_with_key: | GET | `/wallet/order_status` | -| [getWithdrawalStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L928) | :closed_lock_with_key: | GET | `/wallet/withdraw_status` | -| [getSubBalance()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L940) | :closed_lock_with_key: | GET | `/wallet/sub_account_balances` | -| [getSubMarginBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L952) | :closed_lock_with_key: | GET | `/wallet/sub_account_margin_balances` | -| [getSubFuturesBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L964) | :closed_lock_with_key: | GET | `/wallet/sub_account_futures_balances` | -| [getSubCrossMarginBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L977) | :closed_lock_with_key: | GET | `/wallet/sub_account_cross_margin_balances` | -| [getSavedAddresses()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L989) | :closed_lock_with_key: | GET | `/wallet/saved_address` | -| [getTradingFees()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L999) | :closed_lock_with_key: | GET | `/wallet/fee` | -| [getBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1020) | :closed_lock_with_key: | GET | `/wallet/total_balance` | -| [getSmallBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1029) | :closed_lock_with_key: | GET | `/wallet/small_balance` | -| [convertSmallBalance()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1039) | :closed_lock_with_key: | POST | `/wallet/small_balance` | -| [getSmallBalanceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1052) | :closed_lock_with_key: | GET | `/wallet/small_balance_history` | -| [getPushOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1064) | :closed_lock_with_key: | GET | `/wallet/push` | -| [getLowCapExchangeList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1073) | :closed_lock_with_key: | GET | `/wallet/getLowCapExchangeList` | -| [createSubAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1088) | :closed_lock_with_key: | POST | `/sub_accounts` | -| [getSubAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1099) | :closed_lock_with_key: | GET | `/sub_accounts` | -| [getSubAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1109) | :closed_lock_with_key: | GET | `/sub_accounts/{user_id}` | -| [createSubAccountApiKey()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1119) | :closed_lock_with_key: | POST | `/sub_accounts/{user_id}/keys` | -| [getSubAccountApiKeys()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1132) | :closed_lock_with_key: | GET | `/sub_accounts/{user_id}/keys` | -| [updateSubAccountApiKey()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1146) | :closed_lock_with_key: | PUT | `/sub_accounts/{user_id}/keys/{key}` | -| [deleteSubAccountApiKey()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1157) | :closed_lock_with_key: | DELETE | `/sub_accounts/{user_id}/keys/{key}` | -| [getSubAccountApiKey()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1172) | :closed_lock_with_key: | GET | `/sub_accounts/{user_id}/keys/{key}` | -| [lockSubAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1187) | :closed_lock_with_key: | POST | `/sub_accounts/{user_id}/lock` | -| [unlockSubAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1197) | :closed_lock_with_key: | POST | `/sub_accounts/{user_id}/unlock` | -| [getSubAccountMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1211) | :closed_lock_with_key: | GET | `/sub_accounts/unified_mode` | -| [getUnifiedAccountInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1230) | :closed_lock_with_key: | GET | `/unified/accounts` | -| [getUnifiedMaxBorrow()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1246) | :closed_lock_with_key: | GET | `/unified/borrowable` | -| [getUnifiedMaxTransferable()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1262) | :closed_lock_with_key: | GET | `/unified/transferable` | -| [getUnifiedMaxTransferables()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1277) | :closed_lock_with_key: | GET | `/unified/transferables` | -| [getUnifiedBatchMaxBorrowable()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1286) | :closed_lock_with_key: | GET | `/unified/batch_borrowable` | -| [submitUnifiedBorrowOrRepay()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1304) | :closed_lock_with_key: | POST | `/unified/loans` | -| [getUnifiedLoans()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1316) | :closed_lock_with_key: | GET | `/unified/loans` | -| [getUnifiedLoanRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1326) | :closed_lock_with_key: | GET | `/unified/loan_records` | -| [getUnifiedInterestRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1338) | :closed_lock_with_key: | GET | `/unified/interest_records` | -| [getUnifiedRiskUnitDetails()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1349) | :closed_lock_with_key: | GET | `/unified/risk_units` | -| [setUnifiedAccountMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1361) | :closed_lock_with_key: | PUT | `/unified/unified_mode` | -| [getUnifiedAccountMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1370) | :closed_lock_with_key: | GET | `/unified/unified_mode` | -| [getUnifiedEstimateRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1382) | :closed_lock_with_key: | GET | `/unified/estimate_rate` | -| [getUnifiedCurrencyDiscountTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1393) | | GET | `/unified/currency_discount_tiers` | -| [getLoanMarginTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1405) | | GET | `/unified/loan_margin_tiers` | -| [portfolioMarginCalculate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1422) | | POST | `/unified/portfolio_calculator` | -| [setUserLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1436) | :closed_lock_with_key: | POST | `/unified/leverage/user_setting` | -| [getUserCurrencyLeverageConfig()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1450) | :closed_lock_with_key: | GET | `/unified/leverage/user_currency_config` | -| [getUserCurrencyLeverageSettings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1464) | :closed_lock_with_key: | GET | `/unified/leverage/user_currency_setting` | -| [updateUserCurrencyLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1479) | :closed_lock_with_key: | POST | `/unified/leverage/user_currency_setting` | -| [getUnifiedLoanCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1494) | :closed_lock_with_key: | GET | `/unified/currencies` | -| [getHistoricalLendingRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1506) | :closed_lock_with_key: | GET | `/unified/history_loan_rate` | -| [submitUnifiedLoanRepay()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1512) | :closed_lock_with_key: | POST | `/unified/loans/repay` | -| [getEstimatedQuickRepayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1519) | :closed_lock_with_key: | GET | `/unified/estimated_quick_repayment` | -| [createQuickRepayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1526) | :closed_lock_with_key: | POST | `/unified/quick_repayment` | -| [setUnifiedDeltaNeutral()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1537) | :closed_lock_with_key: | POST | `/unified/delta_neutral` | -| [getUnifiedDeltaNeutral()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1546) | :closed_lock_with_key: | GET | `/unified/delta_neutral` | -| [getSpotCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1566) | | GET | `/spot/currencies` | -| [getSpotCurrency()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1576) | | GET | `/spot/currencies/{currency}` | -| [getSpotCurrencyPairs()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1585) | | GET | `/spot/currency_pairs` | -| [getSpotCurrencyPair()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1595) | | GET | `/spot/currency_pairs/{currency_pair}` | -| [getSpotTicker()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1609) | | GET | `/spot/tickers` | -| [getSpotOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1624) | | GET | `/spot/order_book` | -| [getSpotRpiOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1636) | | GET | `/spot/rpi_order_book` | -| [getSpotTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1649) | | GET | `/spot/trades` | -| [getSpotCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1661) | | GET | `/spot/candlesticks` | -| [getSpotFeeRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1673) | :closed_lock_with_key: | GET | `/spot/fee` | -| [getSpotBatchFeeRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1682) | :closed_lock_with_key: | GET | `/spot/batch_fee` | -| [getSpotAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1694) | :closed_lock_with_key: | GET | `/spot/accounts` | -| [getSpotAccountBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1706) | :closed_lock_with_key: | GET | `/spot/account_book` | -| [submitSpotBatchOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1725) | :closed_lock_with_key: | POST | `/spot/batch_orders` | -| [getSpotOpenOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1752) | :closed_lock_with_key: | GET | `/spot/open_orders` | -| [submitSpotClosePosCrossDisabled()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1768) | :closed_lock_with_key: | POST | `/spot/cross_liquidate_orders` | -| [submitSpotOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1784) | :closed_lock_with_key: | POST | `/spot/orders` | -| [getSpotOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1801) | :closed_lock_with_key: | GET | `/spot/orders` | -| [cancelSpotOpenOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1816) | :closed_lock_with_key: | DELETE | `/spot/orders` | -| [batchCancelSpotOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1845) | :closed_lock_with_key: | POST | `/spot/cancel_batch_orders` | -| [getSpotOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1870) | :closed_lock_with_key: | GET | `/spot/orders/{order_id}` | -| [updateSpotOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1887) | :closed_lock_with_key: | PATCH | `/spot/orders/{order_id}` | -| [cancelSpotOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1915) | :closed_lock_with_key: | DELETE | `/spot/orders/{order_id}` | -| [getSpotTradingHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1944) | :closed_lock_with_key: | GET | `/spot/my_trades` | -| [submitSpotCountdownOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1973) | :closed_lock_with_key: | POST | `/spot/countdown_cancel_all` | -| [batchUpdateSpotOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1992) | :closed_lock_with_key: | POST | `/spot/amend_batch_orders` | -| [getSpotInsuranceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2019) | :closed_lock_with_key: | GET | `/spot/insurance_history` | -| [submitSpotPriceTriggerOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2033) | :closed_lock_with_key: | POST | `/spot/price_orders` | -| [getSpotAutoOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2045) | :closed_lock_with_key: | GET | `/spot/price_orders` | -| [cancelAllOpenSpotOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2057) | :closed_lock_with_key: | DELETE | `/spot/price_orders` | -| [getPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2070) | :closed_lock_with_key: | GET | `/spot/price_orders/{order_id}` | -| [cancelSpotTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2082) | :closed_lock_with_key: | DELETE | `/spot/price_orders/{order_id}` | -| [getSpotPovOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2096) | :closed_lock_with_key: | GET | `/spot/pov_orders` | -| [createSpotPovOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2108) | :closed_lock_with_key: | POST | `/spot/pov_orders` | -| [cancelSpotPovOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2120) | :closed_lock_with_key: | DELETE | `/spot/pov_orders` | -| [getSpotPovOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2134) | :closed_lock_with_key: | GET | `/spot/pov_orders/{order_id}` | -| [cancelSpotPovOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2146) | :closed_lock_with_key: | DELETE | `/spot/pov_orders/{order_id}` | -| [setCollateralCurrency()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2158) | :closed_lock_with_key: | POST | `/unified/collateral_currencies` | -| [getMarginAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2179) | :closed_lock_with_key: | GET | `/margin/accounts` | -| [getMarginBalanceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2193) | :closed_lock_with_key: | GET | `/margin/account_book` | -| [getFundingAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2211) | :closed_lock_with_key: | GET | `/margin/funding_accounts` | -| [updateAutoRepaymentSetting()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2229) | :closed_lock_with_key: | POST | `/margin/auto_repay` | -| [getAutoRepaymentSetting()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2240) | :closed_lock_with_key: | GET | `/margin/auto_repay` | -| [getMarginTransferableAmount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2254) | :closed_lock_with_key: | GET | `/margin/transferable` | -| [getCrossMarginCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2271) | | GET | `/margin/cross/currencies` | -| [getCrossMarginCurrency()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2282) | | GET | `/margin/cross/currencies/{currency}` | -| [getCrossMarginAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2294) | :closed_lock_with_key: | GET | `/margin/cross/accounts` | -| [getCrossMarginAccountHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2307) | :closed_lock_with_key: | GET | `/margin/cross/account_book` | -| [submitCrossMarginBorrowLoan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2324) | :closed_lock_with_key: | POST | `/margin/cross/loans` | -| [getCrossMarginBorrowHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2339) | :closed_lock_with_key: | GET | `/margin/cross/loans` | -| [getCrossMarginBorrowLoan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2352) | :closed_lock_with_key: | GET | `/margin/cross/loans/{loan_id}` | -| [submitCrossMarginRepayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2367) | :closed_lock_with_key: | POST | `/margin/cross/repayments` | -| [getCrossMarginRepayments()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2383) | :closed_lock_with_key: | GET | `/margin/cross/repayments` | -| [getCrossMarginInterestRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2396) | :closed_lock_with_key: | GET | `/margin/cross/interest_records` | -| [getCrossMarginTransferableAmount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2412) | :closed_lock_with_key: | GET | `/margin/cross/transferable` | -| [getEstimatedInterestRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2428) | :closed_lock_with_key: | GET | `/margin/cross/estimate_rate` | -| [getCrossMarginBorrowableAmount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2442) | :closed_lock_with_key: | GET | `/margin/cross/borrowable` | -| [getMarginUserLoanTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2455) | :closed_lock_with_key: | GET | `/margin/user/loan_margin_tiers` | -| [getMarginPublicLoanTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2471) | | GET | `/margin/loan_margin_tiers` | -| [setMarginUserLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2487) | :closed_lock_with_key: | POST | `/margin/leverage/user_market_setting` | -| [getMarginUserAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2504) | :closed_lock_with_key: | GET | `/margin/user/account` | -| [getLendingMarkets()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2519) | | GET | `/margin/uni/currency_pairs` | -| [getLendingMarket()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2534) | | GET | `/margin/uni/currency_pairs/{currency_pair}` | -| [getEstimatedInterestRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2546) | :closed_lock_with_key: | GET | `/margin/uni/estimate_rate` | -| [submitMarginUNIBorrowOrRepay()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2556) | :closed_lock_with_key: | POST | `/margin/uni/loans` | -| [getMarginUNILoans()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2572) | :closed_lock_with_key: | GET | `/margin/uni/loans` | -| [getMarginUNILoanRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2582) | :closed_lock_with_key: | GET | `/margin/uni/loan_records` | -| [getMarginUNIInterestRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2594) | :closed_lock_with_key: | GET | `/margin/uni/interest_records` | -| [getMarginUNIMaxBorrow()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2606) | :closed_lock_with_key: | GET | `/margin/uni/borrowable` | -| [getFlashSwapCurrencyPairs()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2622) | | GET | `/flash_swap/currency_pairs` | -| [submitFlashSwapOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2638) | :closed_lock_with_key: | POST | `/flash_swap/orders` | -| [getFlashSwapOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2650) | :closed_lock_with_key: | GET | `/flash_swap/orders` | -| [getFlashSwapOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2662) | :closed_lock_with_key: | GET | `/flash_swap/orders/{order_id}` | -| [submitFlashSwapOrderPreview()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2672) | :closed_lock_with_key: | POST | `/flash_swap/orders/preview` | -| [getFuturesContracts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2689) | | GET | `/futures/{settle}/contracts` | -| [getFuturesContract()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2704) | | GET | `/futures/{settle}/contracts/{contract}` | -| [listFuturesADLRiskStates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2711) | | GET | `/futures/{settle}/adl_risk_states` | -| [getFuturesOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2725) | | GET | `/futures/{settle}/order_book` | -| [getFuturesRpiOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2741) | | GET | `/futures/{settle}/rpi_order_book` | -| [getFuturesTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2754) | | GET | `/futures/{settle}/trades` | -| [getFuturesCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2769) | | GET | `/futures/{settle}/candlesticks` | -| [getPremiumIndexKLines()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2782) | | GET | `/futures/{settle}/premium_index` | -| [getFuturesTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2795) | | GET | `/futures/{settle}/tickers` | -| [getFundingRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2812) | | GET | `/futures/{settle}/funding_rate` | -| [getBatchFundingRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2828) | | POST | `/futures/{settle}/funding_rates` | -| [getFuturesInsuranceBalanceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2846) | | GET | `/futures/{settle}/insurance` | -| [getFuturesStats()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2865) | | GET | `/futures/{settle}/contract_stats` | -| [getIndexConstituents()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2876) | | GET | `/futures/{settle}/index_constituents/{index}` | -| [getLiquidationHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2893) | | GET | `/futures/{settle}/liq_orders` | -| [getRiskLimitTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2910) | | GET | `/futures/{settle}/risk_limit_tiers` | -| [getFuturesAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2923) | :closed_lock_with_key: | GET | `/futures/{settle}/accounts` | -| [getFuturesAccountBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2937) | :closed_lock_with_key: | GET | `/futures/{settle}/account_book` | -| [getFuturesPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2950) | :closed_lock_with_key: | GET | `/futures/{settle}/positions` | -| [getFuturesPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2965) | :closed_lock_with_key: | GET | `/futures/{settle}/positions/{contract}` | -| [updateFuturesMargin()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2982) | :closed_lock_with_key: | POST | `/futures/{settle}/positions/{contract}/margin` | -| [updateFuturesLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3010) | :closed_lock_with_key: | POST | `/futures/{settle}/positions/{contract}/leverage` | -| [getFuturesContractLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3030) | :closed_lock_with_key: | GET | `/futures/{settle}/get_leverage/{contract}` | -| [updateFuturesPositionMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3046) | :closed_lock_with_key: | POST | `/futures/{settle}/positions/cross_mode` | -| [updatePositionRiskLimit()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3063) | :closed_lock_with_key: | POST | `/futures/{settle}/positions/{contract}/risk_limit` | -| [updateFuturesDualMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3083) | :closed_lock_with_key: | POST | `/futures/{settle}/dual_mode` | -| [getDualModePosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3099) | :closed_lock_with_key: | GET | `/futures/{settle}/dual_comp/positions/{contract}` | -| [updateDualModePositionMargin()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3114) | :closed_lock_with_key: | POST | `/futures/{settle}/dual_comp/positions/{contract}/margin` | -| [updateDualModePositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3130) | :closed_lock_with_key: | POST | `/futures/{settle}/dual_comp/positions/{contract}/leverage` | -| [updateDualModePositionRiskLimit()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3154) | :closed_lock_with_key: | POST | `/futures/{settle}/dual_comp/positions/{contract}/risk_limit` | -| [submitFuturesOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3181) | :closed_lock_with_key: | POST | `/futures/{settle}/orders` | -| [getFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3202) | :closed_lock_with_key: | GET | `/futures/{settle}/orders` | -| [cancelAllFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3217) | :closed_lock_with_key: | DELETE | `/futures/{settle}/orders` | -| [getFuturesOrdersByTimeRange()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3237) | :closed_lock_with_key: | GET | `/futures/{settle}/orders_timerange` | -| [submitFuturesBatchOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3260) | :closed_lock_with_key: | POST | `/futures/{settle}/batch_orders` | -| [getFuturesOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3285) | :closed_lock_with_key: | GET | `/futures/{settle}/orders/{order_id}` | -| [cancelFuturesOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3302) | :closed_lock_with_key: | DELETE | `/futures/{settle}/orders/{order_id}` | -| [updateFuturesOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3327) | :closed_lock_with_key: | PUT | `/futures/{settle}/orders/{order_id}` | -| [getFuturesTradingHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3348) | :closed_lock_with_key: | GET | `/futures/{settle}/my_trades` | -| [getFuturesTradingHistoryByTimeRange()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3363) | :closed_lock_with_key: | GET | `/futures/{settle}/my_trades_timerange` | -| [getFuturesPositionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3376) | :closed_lock_with_key: | GET | `/futures/{settle}/position_close` | -| [getFuturesLiquidationHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3389) | :closed_lock_with_key: | GET | `/futures/{settle}/liquidates` | -| [getFuturesAutoDeleveragingHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3402) | :closed_lock_with_key: | GET | `/futures/{settle}/auto_deleverages` | -| [setFuturesOrderCancelCountdown()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3419) | :closed_lock_with_key: | POST | `/futures/{settle}/countdown_cancel_all` | -| [getFuturesUserTradingFees()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3436) | :closed_lock_with_key: | GET | `/futures/{settle}/fee` | -| [batchCancelFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3454) | :closed_lock_with_key: | POST | `/futures/{settle}/batch_cancel_orders` | -| [batchUpdateFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3481) | :closed_lock_with_key: | POST | `/futures/{settle}/batch_amend_orders` | -| [getRiskLimitTable()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3503) | | GET | `/futures/{settle}/risk_limit_table` | -| [submitFuturesPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3516) | :closed_lock_with_key: | POST | `/futures/{settle}/price_orders` | -| [getFuturesAutoOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3529) | :closed_lock_with_key: | GET | `/futures/{settle}/price_orders` | -| [cancelAllOpenFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3542) | :closed_lock_with_key: | DELETE | `/futures/{settle}/price_orders` | -| [getFuturesPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3558) | :closed_lock_with_key: | GET | `/futures/{settle}/price_orders/{order_id}` | -| [cancelFuturesPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3573) | :closed_lock_with_key: | DELETE | `/futures/{settle}/price_orders/{order_id}` | -| [updateFuturesPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3591) | :closed_lock_with_key: | PUT | `/futures/{settle}/price_orders/amend/{order_id}` | -| [createTrailOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3609) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/trail/create` | -| [terminateTrailOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3627) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/trail/stop` | -| [batchTerminateTrailOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3640) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/trail/stop_all` | -| [getTrailOrderList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3655) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/trail/list` | -| [getTrailOrderDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3668) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/trail/detail` | -| [updateTrailOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3686) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/trail/update` | -| [getTrailOrderChangeLog()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3699) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/trail/change_log` | -| [createChaseOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3712) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/chase/create` | -| [stopChaseOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3722) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/chase/stop` | -| [stopAllChaseOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3732) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/chase/stop_all` | -| [getChaseOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3744) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/chase/list` | -| [getChaseOrderDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3752) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/chase/detail` | -| [getFuturesPositionCloseHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3761) | :closed_lock_with_key: | GET | `/futures/{settle}/position_close_history` | -| [getFuturesInsuranceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3770) | :closed_lock_with_key: | GET | `/futures/{settle}/insurance` | -| [getAllDeliveryContracts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3787) | | GET | `/delivery/{settle}/contracts` | -| [getDeliveryContract()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3799) | | GET | `/delivery/{settle}/contracts/{contract}` | -| [getDeliveryOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3814) | | GET | `/delivery/{settle}/order_book` | -| [getDeliveryTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3827) | | GET | `/delivery/{settle}/trades` | -| [getDeliveryCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3841) | | GET | `/delivery/{settle}/candlesticks` | -| [getDeliveryTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3852) | | GET | `/delivery/{settle}/tickers` | -| [getDeliveryInsuranceBalanceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3869) | | GET | `/delivery/{settle}/insurance` | -| [getDeliveryAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3888) | :closed_lock_with_key: | GET | `/delivery/{settle}/accounts` | -| [getDeliveryBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3899) | :closed_lock_with_key: | GET | `/delivery/{settle}/account_book` | -| [getDeliveryPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3910) | :closed_lock_with_key: | GET | `/delivery/{settle}/positions` | -| [getDeliveryPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3920) | :closed_lock_with_key: | GET | `/delivery/{settle}/positions/{contract}` | -| [updateDeliveryMargin()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3935) | :closed_lock_with_key: | POST | `/delivery/{settle}/positions/{contract}/margin` | -| [updateDeliveryLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3953) | :closed_lock_with_key: | POST | `/delivery/{settle}/positions/{contract}/leverage` | -| [updateDeliveryRiskLimit()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3971) | :closed_lock_with_key: | POST | `/delivery/{settle}/positions/{contract}/risk_limit` | -| [submitDeliveryOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3991) | :closed_lock_with_key: | POST | `/delivery/{settle}/orders` | -| [getDeliveryOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4006) | :closed_lock_with_key: | GET | `/delivery/{settle}/orders` | -| [cancelAllDeliveryOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4019) | :closed_lock_with_key: | DELETE | `/delivery/{settle}/orders` | -| [getDeliveryOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4038) | :closed_lock_with_key: | GET | `/delivery/{settle}/orders/{order_id}` | -| [cancelDeliveryOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4053) | :closed_lock_with_key: | DELETE | `/delivery/{settle}/orders/{order_id}` | -| [getDeliveryTradingHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4068) | :closed_lock_with_key: | GET | `/delivery/{settle}/my_trades` | -| [getDeliveryClosedPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4081) | :closed_lock_with_key: | GET | `/delivery/{settle}/position_close` | -| [getDeliveryLiquidationHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4094) | :closed_lock_with_key: | GET | `/delivery/{settle}/liquidates` | -| [getDeliverySettlementHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4107) | :closed_lock_with_key: | GET | `/delivery/{settle}/settlements` | -| [submitDeliveryTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4120) | :closed_lock_with_key: | POST | `/delivery/{settle}/price_orders` | -| [getDeliveryAutoOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4135) | :closed_lock_with_key: | GET | `/delivery/{settle}/price_orders` | -| [cancelAllOpenDeliveryOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4148) | :closed_lock_with_key: | DELETE | `/delivery/{settle}/price_orders` | -| [getDeliveryTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4164) | :closed_lock_with_key: | GET | `/delivery/{settle}/price_orders/{order_id}` | -| [cancelTriggeredDeliveryOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4179) | :closed_lock_with_key: | DELETE | `/delivery/{settle}/price_orders/{order_id}` | -| [getOptionsUnderlyings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4198) | | GET | `/options/underlyings` | -| [getOptionsExpirationTimes()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4208) | | GET | `/options/expirations` | -| [getOptionsContracts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4218) | | GET | `/options/contracts` | -| [getOptionsContract()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4231) | | GET | `/options/contracts/{contract}` | -| [getOptionsSettlementHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4241) | | GET | `/options/settlements` | -| [getOptionsContractSettlement()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4253) | | GET | `/options/settlements/{contract}` | -| [getOptionsMySettlements()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4268) | :closed_lock_with_key: | GET | `/options/my_settlements` | -| [getOptionsOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4282) | | GET | `/options/order_book` | -| [getOptionsTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4294) | | GET | `/options/tickers` | -| [getOptionsUnderlyingTicker()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4308) | | GET | `/options/underlying/tickers/{underlying}` | -| [getOptionsCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4322) | | GET | `/options/candlesticks` | -| [getOptionsUnderlyingCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4332) | | GET | `/options/underlying/candlesticks` | -| [getOptionsTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4344) | | GET | `/options/trades` | -| [getOptionsAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4355) | :closed_lock_with_key: | GET | `/options/accounts` | -| [getOptionsAccountChange()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4365) | :closed_lock_with_key: | GET | `/options/account_book` | -| [getOptionsPositionsUnderlying()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4377) | :closed_lock_with_key: | GET | `/options/positions` | -| [getOptionsPositionContract()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4389) | :closed_lock_with_key: | GET | `/options/positions/{contract}` | -| [getOptionsLiquidation()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4401) | :closed_lock_with_key: | GET | `/options/position_close` | -| [submitOptionsOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4414) | :closed_lock_with_key: | POST | `/options/orders` | -| [getOptionsOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4426) | :closed_lock_with_key: | GET | `/options/orders` | -| [cancelAllOpenOptionsOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4438) | :closed_lock_with_key: | DELETE | `/options/orders` | -| [getOptionsOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4452) | :closed_lock_with_key: | GET | `/options/orders/{order_id}` | -| [amendOptionsOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4464) | :closed_lock_with_key: | PUT | `/options/orders/{order_id}` | -| [cancelOptionsOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4479) | :closed_lock_with_key: | DELETE | `/options/orders/{order_id}` | -| [submitOptionsCountdownCancel()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4498) | :closed_lock_with_key: | POST | `/options/countdown_cancel_all` | -| [getOptionsPersonalHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4514) | :closed_lock_with_key: | GET | `/options/my_trades` | -| [setOptionsMMPSettings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4526) | :closed_lock_with_key: | POST | `/options/mmp` | -| [getOptionsMMPSettings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4538) | :closed_lock_with_key: | GET | `/options/mmp` | -| [resetOptionsMMPSettings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4550) | :closed_lock_with_key: | POST | `/options/mmp/reset` | -| [getLendingCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4566) | | GET | `/earn/uni/currencies` | -| [getLendingCurrency()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4576) | | GET | `/earn/uni/currencies/{currency}` | -| [submitLendOrRedeemOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4586) | :closed_lock_with_key: | POST | `/earn/uni/lends` | -| [getLendingOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4596) | :closed_lock_with_key: | GET | `/earn/uni/lends` | -| [updateLendingOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4608) | :closed_lock_with_key: | PATCH | `/earn/uni/lends` | -| [getLendingRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4621) | :closed_lock_with_key: | GET | `/earn/uni/lend_records` | -| [getLendingTotalInterest()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4634) | :closed_lock_with_key: | GET | `/earn/uni/interests/{currency}` | -| [getLendingInterestRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4647) | :closed_lock_with_key: | GET | `/earn/uni/interest_records` | -| [updateInterestReinvestment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4660) | :closed_lock_with_key: | PUT | `/earn/uni/interest_reinvest` | -| [getLendingInterestStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4676) | :closed_lock_with_key: | GET | `/earn/uni/interest_status/{currency}` | -| [getLendingAnnualizedTrendChart()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4691) | :closed_lock_with_key: | GET | `/earn/uni/chart` | -| [getLendingEstimatedRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4699) | :closed_lock_with_key: | GET | `/earn/uni/rate` | -| [submitMultiLoanOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4716) | :closed_lock_with_key: | POST | `/loan/multi_collateral/orders` | -| [getMultiLoanOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4728) | :closed_lock_with_key: | GET | `/loan/multi_collateral/orders` | -| [getMultiLoanOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4740) | :closed_lock_with_key: | GET | `/loan/multi_collateral/orders/{order_id}` | -| [repayMultiLoan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4750) | :closed_lock_with_key: | POST | `/loan/multi_collateral/repay` | -| [getMultiLoanRepayRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4760) | :closed_lock_with_key: | GET | `/loan/multi_collateral/repay` | -| [updateMultiLoan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4772) | :closed_lock_with_key: | POST | `/loan/multi_collateral/mortgage` | -| [getMultiLoanAdjustmentRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4784) | :closed_lock_with_key: | GET | `/loan/multi_collateral/mortgage` | -| [getMultiLoanCurrencyQuota()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4796) | :closed_lock_with_key: | GET | `/loan/multi_collateral/currency_quota` | -| [getMultiLoanSupportedCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4808) | | GET | `/loan/multi_collateral/currencies` | -| [getMultiLoanRatio()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4817) | | GET | `/loan/multi_collateral/ltv` | -| [getMultiLoanFixedRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4826) | | GET | `/loan/multi_collateral/fixed_rate` | -| [getMultiLoanCurrentRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4839) | | GET | `/loan/multi_collateral/current_rate` | -| [getDualInvestmentProducts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4863) | | GET | `/earn/dual/investment_plan` | -| [getDualInvestmentOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4874) | :closed_lock_with_key: | GET | `/earn/dual/orders` | -| [submitDualInvestmentOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4886) | :closed_lock_with_key: | POST | `/earn/dual/orders` | -| [getDualOrderRefundPreview()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4895) | :closed_lock_with_key: | GET | `/earn/dual/order-refund-preview` | -| [submitDualOrderRefund()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4904) | :closed_lock_with_key: | POST | `/earn/dual/order-refund` | -| [updateDualOrderReinvest()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4913) | :closed_lock_with_key: | POST | `/earn/dual/modify-order-reinvest` | -| [getDualProjectRecommend()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4924) | :closed_lock_with_key: | GET | `/earn/dual/project-recommend` | -| [getDualStockInvestmentPlans()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4935) | | GET | `/earn/dual/stock/investment_plan` | -| [getDualStockProjectRecommend()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4947) | | GET | `/earn/dual/stock/project-recommend` | -| [getDualStockOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4956) | :closed_lock_with_key: | GET | `/earn/dual/stock/orders` | -| [submitDualStockOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4968) | :closed_lock_with_key: | POST | `/earn/dual/stock/orders` | -| [getDualStockBalance()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4977) | :closed_lock_with_key: | GET | `/earn/dual/stock/balance` | -| [getDualStockOrderRefundPreview()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4984) | :closed_lock_with_key: | GET | `/earn/dual/stock/order-refund-preview` | -| [submitDualStockOrderRefund()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4993) | :closed_lock_with_key: | POST | `/earn/dual/stock/order-refund` | -| [updateDualStockOrderReinvest()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5002) | :closed_lock_with_key: | POST | `/earn/dual/stock/modify-order-reinvest` | -| [getEarnFixedTermProducts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5013) | | GET | `/earn/fixed-term/product` | -| [getEarnFixedTermProductsByAsset()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5022) | | GET | `/earn/fixed-term/product/{asset}/list` | -| [createEarnFixedTermLend()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5032) | :closed_lock_with_key: | POST | `/earn/fixed-term/user/lend` | -| [getEarnFixedTermLends()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5041) | :closed_lock_with_key: | GET | `/earn/fixed-term/user/lend` | -| [createEarnFixedTermPreRedeem()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5050) | :closed_lock_with_key: | POST | `/earn/fixed-term/user/pre-redeem` | -| [getEarnFixedTermHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5061) | :closed_lock_with_key: | GET | `/earn/fixed-term/user/history` | -| [createAutoInvestPlan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5070) | :closed_lock_with_key: | POST | `/earn/autoinvest/plans/create` | -| [updateAutoInvestPlan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5079) | :closed_lock_with_key: | POST | `/earn/autoinvest/plans/update` | -| [stopAutoInvestPlan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5086) | :closed_lock_with_key: | POST | `/earn/autoinvest/plans/stop` | -| [addAutoInvestPlanPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5093) | :closed_lock_with_key: | POST | `/earn/autoinvest/plans/add_position` | -| [getAutoInvestCoins()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5104) | :closed_lock_with_key: | GET | `/earn/autoinvest/coins` | -| [getAutoInvestMinAmount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5113) | :closed_lock_with_key: | POST | `/earn/autoinvest/min_invest_amount` | -| [getAutoInvestPlanRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5124) | :closed_lock_with_key: | GET | `/earn/autoinvest/plans/records` | -| [getAutoInvestOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5133) | :closed_lock_with_key: | GET | `/earn/autoinvest/orders` | -| [getAutoInvestConfig()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5142) | :closed_lock_with_key: | GET | `/earn/autoinvest/config` | -| [getAutoInvestPlanDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5149) | :closed_lock_with_key: | GET | `/earn/autoinvest/plans/detail` | -| [getAutoInvestPlans()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5158) | :closed_lock_with_key: | GET | `/earn/autoinvest/plans/list_info` | -| [getStakingCoins()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5170) | :closed_lock_with_key: | GET | `/earn/staking/coins` | -| [submitStakingSwap()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5183) | :closed_lock_with_key: | POST | `/earn/staking/swap` | -| [getAccountDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5202) | :closed_lock_with_key: | GET | `/account/detail` | -| [getAccountRateLimit()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5211) | :closed_lock_with_key: | GET | `/account/rate_limit` | -| [createStpGroup()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5221) | :closed_lock_with_key: | POST | `/account/stp_groups` | -| [getStpGroups()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5231) | :closed_lock_with_key: | GET | `/account/stp_groups` | -| [getStpGroupUsers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5241) | :closed_lock_with_key: | GET | `/account/stp_groups/{stp_id}/users` | -| [addUsersToStpGroup()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5251) | :closed_lock_with_key: | POST | `/account/stp_groups/{stp_id}/users` | -| [deleteUserFromStpGroup()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5267) | :closed_lock_with_key: | DELETE | `/account/stp_groups/{stp_id}/users` | -| [setGTDeduction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5285) | :closed_lock_with_key: | POST | `/account/debit_fee` | -| [getGTDeduction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5296) | :closed_lock_with_key: | GET | `/account/debit_fee` | -| [getAccountMainKeys()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5305) | :closed_lock_with_key: | GET | `/account/main_keys` | -| [getAgencyTransactionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5321) | :closed_lock_with_key: | GET | `/rebate/agency/transaction_history` | -| [getAgencyCommissionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5334) | :closed_lock_with_key: | GET | `/rebate/agency/commission_history` | -| [getPartnerTransactionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5348) | :closed_lock_with_key: | GET | `/rebate/partner/transaction_history` | -| [getPartnerCommissionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5363) | :closed_lock_with_key: | GET | `/rebate/partner/commission_history` | -| [getPartnerSubordinateList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5386) | :closed_lock_with_key: | GET | `/rebate/partner/sub_list` | -| [getPartnerAgentDataAggregated()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5396) | :closed_lock_with_key: | GET | `/rebate/partner/data/aggregated` | -| [getBrokerCommissionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5409) | :closed_lock_with_key: | GET | `/rebate/broker/commission_history` | -| [getBrokerTransactionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5422) | :closed_lock_with_key: | GET | `/rebate/broker/transaction_history` | -| [getUserRebateInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5431) | :closed_lock_with_key: | GET | `/rebate/user/info` | -| [createOTCQuote()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5466) | :closed_lock_with_key: | POST | `/otc/quote` | -| [createOTCFiatOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5478) | :closed_lock_with_key: | POST | `/otc/order/create` | -| [createOTCStablecoinOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5492) | :closed_lock_with_key: | POST | `/otc/stable_coin/order/create` | -| [getOTCBankList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5501) | :closed_lock_with_key: | GET | `/otc/bank/list` | -| [getOTCBankListLegacy()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5508) | :closed_lock_with_key: | GET | `/otc/bank_list` | -| [createOTCUploadPreUpload()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5512) | :closed_lock_with_key: | POST | `/otc/upload/pre_upload` | -| [createOTCBank()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5521) | :closed_lock_with_key: | POST | `/otc/bank/create` | -| [deleteOTCBank()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5535) | :closed_lock_with_key: | POST | `/otc/bank/delete` | -| [setDefaultOTCBank()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5542) | :closed_lock_with_key: | POST | `/otc/bank/set_default` | -| [getOTCBankSupplementChecklist()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5549) | :closed_lock_with_key: | GET | `/otc/bank/bank_supplement_checklist` | -| [submitOTCBankPersonalSupplement()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5558) | :closed_lock_with_key: | POST | `/otc/order/paid` | -| [submitOTCBankEnterpriseSupplement()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5577) | :closed_lock_with_key: | POST | `/otc/order/paid` | -| [markOTCOrderAsPaid()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5613) | :closed_lock_with_key: | POST | `/otc/order/paid` | -| [cancelOTCOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5627) | :closed_lock_with_key: | POST | `/otc/order/cancel` | -| [getOTCFiatOrderList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5639) | :closed_lock_with_key: | GET | `/otc/order/list` | -| [getOTCStablecoinOrderList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5653) | :closed_lock_with_key: | GET | `/otc/stable_coin/order/list` | -| [getOTCFiatOrderDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5667) | :closed_lock_with_key: | GET | `/otc/order/detail` | -| [getP2PMerchantUserInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5681) | :closed_lock_with_key: | POST | `/p2p/merchant/account/get_user_info` | -| [getP2PMerchantCounterpartyUserInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5690) | :closed_lock_with_key: | POST | `/p2p/merchant/account/get_counterparty_user_info` | -| [getP2PMerchantMyselfPayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5702) | :closed_lock_with_key: | POST | `/p2p/merchant/account/get_myself_payment` | -| [getP2PMerchantSpotBalance()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5715) | :closed_lock_with_key: | POST | `/p2p/merchant/account/set_merchant_work_hours` | -| [setP2PMerchantWorkHours()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5724) | :closed_lock_with_key: | POST | `/p2p/merchant/account/set_merchant_work_hours` | -| [getP2PMerchantPendingTransactionList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5735) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/get_pending_transaction_list` | -| [getP2PMerchantCompletedTransactionList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5747) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/get_completed_transaction_list` | -| [getP2PMerchantTransactionDetails()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5759) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/get_transaction_details` | -| [confirmP2PMerchantPayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5771) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/confirm-payment` | -| [confirmP2PMerchantReceipt()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5782) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/confirm-receipt` | -| [cancelP2PMerchantTransaction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5793) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/cancel` | -| [placeP2PMerchantBizPushOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5804) | :closed_lock_with_key: | POST | `/p2p/merchant/books/place_biz_push_order` | -| [updateP2PMerchantAdsStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5815) | :closed_lock_with_key: | POST | `/p2p/merchant/books/ads_update_status` | -| [getP2PMerchantAdsDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5828) | :closed_lock_with_key: | POST | `/p2p/merchant/books/ads_detail` | -| [getP2PMerchantMyAdsList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5837) | :closed_lock_with_key: | POST | `/p2p/merchant/books/my_ads_list` | -| [getP2PMerchantAdsList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5848) | :closed_lock_with_key: | POST | `/p2p/merchant/books/ads_list` | -| [getP2PMerchantChatsList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5857) | :closed_lock_with_key: | POST | `/p2p/merchant/chat/get_chats_list` | -| [sendP2PMerchantChatMessage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5868) | :closed_lock_with_key: | POST | `/p2p/merchant/chat/send_chat_message` | -| [uploadP2PMerchantChatFile()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5879) | :closed_lock_with_key: | POST | `/p2p/merchant/chat/upload_chat_file` | -| [getCrossExSymbols()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5902) | | GET | `/crossex/rule/symbols` | -| [getCrossExRiskLimits()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5914) | | GET | `/crossex/rule/risk_limits` | -| [getCrossExTransferCoins()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5928) | | GET | `/crossex/transfers/coin` | -| [createCrossExTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5942) | :closed_lock_with_key: | POST | `/crossex/transfers` | -| [getCrossExTransferHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5956) | :closed_lock_with_key: | GET | `/crossex/transfers` | -| [createCrossExOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5973) | :closed_lock_with_key: | POST | `/crossex/orders` | -| [cancelBatchCrossExOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5987) | :closed_lock_with_key: | POST | `/crossex/batch_cancel_orders` | -| [cancelCrossExOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6001) | :closed_lock_with_key: | DELETE | `/crossex/orders/{order_id}` | -| [modifyCrossExOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6014) | :closed_lock_with_key: | PUT | `/crossex/orders/{order_id}` | -| [getCrossExOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6029) | :closed_lock_with_key: | GET | `/crossex/orders/{order_id}` | -| [createCrossExConvertQuote()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6041) | :closed_lock_with_key: | POST | `/crossex/convert/quote` | -| [createCrossExConvertOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6055) | :closed_lock_with_key: | POST | `/crossex/convert/orders` | -| [updateCrossExAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6069) | :closed_lock_with_key: | PUT | `/crossex/accounts` | -| [getCrossExAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6083) | :closed_lock_with_key: | GET | `/crossex/accounts` | -| [setCrossExPositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6095) | :closed_lock_with_key: | POST | `/crossex/positions/leverage` | -| [getCrossExPositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6109) | :closed_lock_with_key: | GET | `/crossex/positions/leverage` | -| [setCrossExMarginPositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6123) | :closed_lock_with_key: | POST | `/crossex/margin_positions/leverage` | -| [getCrossExMarginPositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6139) | :closed_lock_with_key: | GET | `/crossex/margin_positions/leverage` | -| [closeCrossExPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6153) | :closed_lock_with_key: | POST | `/crossex/position` | -| [updateCrossExPositionsMargin()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6159) | :closed_lock_with_key: | POST | `/crossex/positions/margin` | -| [getCrossExInterestRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6173) | :closed_lock_with_key: | GET | `/crossex/interest_rate` | -| [getCrossExFeeRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6186) | :closed_lock_with_key: | GET | `/crossex/fee` | -| [getCrossExPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6198) | :closed_lock_with_key: | GET | `/crossex/positions` | -| [getCrossExSecurityPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6212) | :closed_lock_with_key: | GET | `/crossex/security_positions` | -| [getCrossExMarginPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6226) | :closed_lock_with_key: | GET | `/crossex/margin_positions` | -| [getCrossExAdlRank()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6240) | :closed_lock_with_key: | GET | `/crossex/adl_rank` | -| [getCrossExOpenOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6252) | :closed_lock_with_key: | GET | `/crossex/open_orders` | -| [getCrossExHistoryOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6266) | :closed_lock_with_key: | GET | `/crossex/history_orders` | -| [getCrossExHistoryPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6280) | :closed_lock_with_key: | GET | `/crossex/history_positions` | -| [getCrossExHistoryMarginPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6294) | :closed_lock_with_key: | GET | `/crossex/history_margin_positions` | -| [getCrossExHistoryMarginInterests()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6308) | :closed_lock_with_key: | GET | `/crossex/history_margin_interests` | -| [getCrossExHistoryTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6322) | :closed_lock_with_key: | GET | `/crossex/history_trades` | -| [getCrossExAccountBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6338) | :closed_lock_with_key: | GET | `/crossex/account_book` | -| [getCrossExCoinDiscountRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6352) | :closed_lock_with_key: | GET | `/crossex/coin_discount_rate` | -| [getCrossExMarketTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6366) | | GET | `/crossex/market/tickers` | -| [getCrossExMarketFundingInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6380) | | GET | `/crossex/market/funding_info` | -| [getAlphaAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6398) | :closed_lock_with_key: | GET | `/alpha/accounts` | -| [getAlphaAccountBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6410) | :closed_lock_with_key: | GET | `/alpha/account_book` | -| [createAlphaQuote()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6424) | :closed_lock_with_key: | POST | `/alpha/quote` | -| [createAlphaOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6436) | :closed_lock_with_key: | POST | `/alpha/orders` | -| [getAlphaOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6448) | :closed_lock_with_key: | GET | `/alpha/orders` | -| [getAlphaOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6460) | :closed_lock_with_key: | GET | `/alpha/order` | -| [getAlphaCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6472) | | GET | `/alpha/currencies` | -| [getAlphaTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6484) | | GET | `/alpha/tickers` | -| [getTradFiMT5Account()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6490) | :closed_lock_with_key: | GET | `/tradfi/users/mt5-account` | -| [getTradFiSymbolCategories()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6494) | | GET | `/tradfi/symbols/categories` | -| [getTradFiSymbols()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6500) | | GET | `/tradfi/symbols` | -| [getTradFiSymbolCommissions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6512) | :closed_lock_with_key: | GET | `/tradfi/symbols/commissions` | -| [getTradFiSymbolDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6518) | :closed_lock_with_key: | GET | `/tradfi/symbols/detail` | -| [getTradFiKlines()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6533) | | GET | `/tradfi/symbols/{symbol}/klines` | -| [getTradFiTicker()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6540) | | GET | `/tradfi/symbols/{symbol}/tickers` | -| [createTradFiUser()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6544) | :closed_lock_with_key: | POST | `/tradfi/users` | -| [getTradFiAssets()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6548) | :closed_lock_with_key: | GET | `/tradfi/users/assets` | -| [createTradFiTransaction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6552) | :closed_lock_with_key: | POST | `/tradfi/transactions` | -| [getTradFiTransactions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6558) | :closed_lock_with_key: | GET | `/tradfi/transactions` | -| [createTradFiOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6564) | :closed_lock_with_key: | POST | `/tradfi/orders` | -| [getTradFiOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6570) | :closed_lock_with_key: | GET | `/tradfi/orders` | -| [modifyTradFiOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6574) | :closed_lock_with_key: | PUT | `/tradfi/orders/{orderId}` | -| [cancelTradFiOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6581) | :closed_lock_with_key: | DELETE | `/tradfi/orders/{orderId}` | -| [getTradFiOrderHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6585) | :closed_lock_with_key: | GET | `/tradfi/orders/history` | -| [getTradFiPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6591) | :closed_lock_with_key: | GET | `/tradfi/positions` | -| [modifyTradFiPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6597) | :closed_lock_with_key: | PUT | `/tradfi/positions/{positionId}` | -| [closeTradFiPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6606) | :closed_lock_with_key: | POST | `/tradfi/positions/{positionId}/close` | -| [getTradFiPositionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6615) | :closed_lock_with_key: | GET | `/tradfi/positions/history` | -| [getTradFiOrderLog()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6624) | :closed_lock_with_key: | GET | `/tradfi/orders/log/{log_id}` | -| [getStockUserAssets()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6638) | :closed_lock_with_key: | GET | `/stock/users/assets` | -| [getStockSymbols()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6650) | | GET | `/stock/symbols` | -| [getStockSymbolDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6662) | :closed_lock_with_key: | GET | `/stock/symbols/detail` | -| [getStockOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6674) | | GET | `/stock/market/{symbol}/orderbook` | -| [getStockOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6684) | :closed_lock_with_key: | GET | `/stock/orders` | -| [createStockOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6698) | :closed_lock_with_key: | POST | `/stock/orders` | -| [cancelAllStockOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6709) | :closed_lock_with_key: | DELETE | `/stock/orders` | -| [getStockOrderHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6719) | :closed_lock_with_key: | GET | `/stock/orders/history` | -| [updateStockOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6732) | :closed_lock_with_key: | PUT | `/stock/orders/{orderId}` | -| [cancelStockOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6745) | :closed_lock_with_key: | DELETE | `/stock/orders/{orderId}` | -| [getStockPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6757) | :closed_lock_with_key: | GET | `/stock/positions` | -| [closeStockPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6769) | :closed_lock_with_key: | POST | `/stock/positions/close` | -| [getStockTransactions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6781) | :closed_lock_with_key: | GET | `/stock/transactions` | -| [createStockTransaction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6795) | :closed_lock_with_key: | POST | `/stock/transactions` | -| [getStockExchanges()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6806) | | GET | `/stock/exchanges` | -| [getStockFeeRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6817) | | GET | `/stock/fee-rate` | +| [getSystemMaintenanceStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L719) | | GET | `/v1/public/system_info` | +| [listAnnouncementArticles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L723) | | POST | `/ann/list_article` | +| [submitWithdrawal()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L745) | :closed_lock_with_key: | POST | `/withdrawals` | +| [submitSpotMainAccountTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L759) | :closed_lock_with_key: | POST | `/withdrawals/push` | +| [cancelWithdrawal()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L775) | :closed_lock_with_key: | DELETE | `/withdrawals/{withdrawal_id}` | +| [getCurrencyChains()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L792) | | GET | `/wallet/currency_chains` | +| [createDepositAddress()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L802) | :closed_lock_with_key: | GET | `/wallet/deposit_address` | +| [getWithdrawalRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L818) | :closed_lock_with_key: | GET | `/wallet/withdrawals` | +| [getDepositRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L832) | :closed_lock_with_key: | GET | `/wallet/deposits` | +| [submitTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L851) | :closed_lock_with_key: | POST | `/wallet/transfers` | +| [getTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L863) | :closed_lock_with_key: | GET | `/wallet/transfers` | +| [submitMainSubTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L878) | :closed_lock_with_key: | POST | `/wallet/sub_account_transfers` | +| [getMainSubTransfers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L892) | :closed_lock_with_key: | GET | `/wallet/sub_account_transfers` | +| [submitSubToSubTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L906) | :closed_lock_with_key: | POST | `/wallet/sub_account_to_sub_account` | +| [getTransferStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L921) | :closed_lock_with_key: | GET | `/wallet/order_status` | +| [getWithdrawalStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L937) | :closed_lock_with_key: | GET | `/wallet/withdraw_status` | +| [getSubBalance()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L949) | :closed_lock_with_key: | GET | `/wallet/sub_account_balances` | +| [getSubMarginBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L961) | :closed_lock_with_key: | GET | `/wallet/sub_account_margin_balances` | +| [getSubFuturesBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L973) | :closed_lock_with_key: | GET | `/wallet/sub_account_futures_balances` | +| [getSubCrossMarginBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L986) | :closed_lock_with_key: | GET | `/wallet/sub_account_cross_margin_balances` | +| [getSavedAddresses()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L998) | :closed_lock_with_key: | GET | `/wallet/saved_address` | +| [getTradingFees()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1008) | :closed_lock_with_key: | GET | `/wallet/fee` | +| [getBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1029) | :closed_lock_with_key: | GET | `/wallet/total_balance` | +| [getSmallBalances()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1038) | :closed_lock_with_key: | GET | `/wallet/small_balance` | +| [convertSmallBalance()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1048) | :closed_lock_with_key: | POST | `/wallet/small_balance` | +| [getSmallBalanceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1061) | :closed_lock_with_key: | GET | `/wallet/small_balance_history` | +| [getPushOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1073) | :closed_lock_with_key: | GET | `/wallet/push` | +| [getLowCapExchangeList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1082) | :closed_lock_with_key: | GET | `/wallet/getLowCapExchangeList` | +| [createSubAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1097) | :closed_lock_with_key: | POST | `/sub_accounts` | +| [getSubAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1108) | :closed_lock_with_key: | GET | `/sub_accounts` | +| [getSubAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1118) | :closed_lock_with_key: | GET | `/sub_accounts/{user_id}` | +| [createSubAccountApiKey()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1128) | :closed_lock_with_key: | POST | `/sub_accounts/{user_id}/keys` | +| [getSubAccountApiKeys()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1141) | :closed_lock_with_key: | GET | `/sub_accounts/{user_id}/keys` | +| [updateSubAccountApiKey()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1155) | :closed_lock_with_key: | PUT | `/sub_accounts/{user_id}/keys/{key}` | +| [deleteSubAccountApiKey()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1166) | :closed_lock_with_key: | DELETE | `/sub_accounts/{user_id}/keys/{key}` | +| [getSubAccountApiKey()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1181) | :closed_lock_with_key: | GET | `/sub_accounts/{user_id}/keys/{key}` | +| [lockSubAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1196) | :closed_lock_with_key: | POST | `/sub_accounts/{user_id}/lock` | +| [unlockSubAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1206) | :closed_lock_with_key: | POST | `/sub_accounts/{user_id}/unlock` | +| [getSubAccountMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1220) | :closed_lock_with_key: | GET | `/sub_accounts/unified_mode` | +| [getUnifiedAccountInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1239) | :closed_lock_with_key: | GET | `/unified/accounts` | +| [getUnifiedMaxBorrow()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1255) | :closed_lock_with_key: | GET | `/unified/borrowable` | +| [getUnifiedMaxTransferable()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1271) | :closed_lock_with_key: | GET | `/unified/transferable` | +| [getUnifiedMaxTransferables()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1286) | :closed_lock_with_key: | GET | `/unified/transferables` | +| [getUnifiedBatchMaxBorrowable()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1295) | :closed_lock_with_key: | GET | `/unified/batch_borrowable` | +| [submitUnifiedBorrowOrRepay()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1313) | :closed_lock_with_key: | POST | `/unified/loans` | +| [getUnifiedLoans()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1325) | :closed_lock_with_key: | GET | `/unified/loans` | +| [getUnifiedLoanRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1335) | :closed_lock_with_key: | GET | `/unified/loan_records` | +| [getUnifiedInterestRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1347) | :closed_lock_with_key: | GET | `/unified/interest_records` | +| [getUnifiedRiskUnitDetails()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1358) | :closed_lock_with_key: | GET | `/unified/risk_units` | +| [setUnifiedAccountMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1370) | :closed_lock_with_key: | PUT | `/unified/unified_mode` | +| [getUnifiedAccountMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1379) | :closed_lock_with_key: | GET | `/unified/unified_mode` | +| [getUnifiedEstimateRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1391) | :closed_lock_with_key: | GET | `/unified/estimate_rate` | +| [getUnifiedCurrencyDiscountTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1402) | | GET | `/unified/currency_discount_tiers` | +| [getLoanMarginTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1414) | | GET | `/unified/loan_margin_tiers` | +| [portfolioMarginCalculate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1431) | | POST | `/unified/portfolio_calculator` | +| [setUserLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1445) | :closed_lock_with_key: | POST | `/unified/leverage/user_setting` | +| [getUserCurrencyLeverageConfig()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1459) | :closed_lock_with_key: | GET | `/unified/leverage/user_currency_config` | +| [getUserCurrencyLeverageSettings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1473) | :closed_lock_with_key: | GET | `/unified/leverage/user_currency_setting` | +| [updateUserCurrencyLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1488) | :closed_lock_with_key: | POST | `/unified/leverage/user_currency_setting` | +| [getUnifiedLoanCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1503) | :closed_lock_with_key: | GET | `/unified/currencies` | +| [getHistoricalLendingRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1515) | :closed_lock_with_key: | GET | `/unified/history_loan_rate` | +| [submitUnifiedLoanRepay()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1521) | :closed_lock_with_key: | POST | `/unified/loans/repay` | +| [getEstimatedQuickRepayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1528) | :closed_lock_with_key: | GET | `/unified/estimated_quick_repayment` | +| [createQuickRepayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1535) | :closed_lock_with_key: | POST | `/unified/quick_repayment` | +| [setUnifiedDeltaNeutral()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1546) | :closed_lock_with_key: | POST | `/unified/delta_neutral` | +| [getUnifiedDeltaNeutral()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1555) | :closed_lock_with_key: | GET | `/unified/delta_neutral` | +| [getSpotCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1575) | | GET | `/spot/currencies` | +| [getSpotCurrency()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1585) | | GET | `/spot/currencies/{currency}` | +| [getSpotCurrencyPairs()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1594) | | GET | `/spot/currency_pairs` | +| [getSpotCurrencyPair()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1604) | | GET | `/spot/currency_pairs/{currency_pair}` | +| [getSpotTicker()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1618) | | GET | `/spot/tickers` | +| [getSpotOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1633) | | GET | `/spot/order_book` | +| [getSpotRpiOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1645) | | GET | `/spot/rpi_order_book` | +| [getSpotTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1658) | | GET | `/spot/trades` | +| [getSpotCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1670) | | GET | `/spot/candlesticks` | +| [getSpotFeeRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1682) | :closed_lock_with_key: | GET | `/spot/fee` | +| [getSpotBatchFeeRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1691) | :closed_lock_with_key: | GET | `/spot/batch_fee` | +| [getSpotAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1703) | :closed_lock_with_key: | GET | `/spot/accounts` | +| [getSpotAccountBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1715) | :closed_lock_with_key: | GET | `/spot/account_book` | +| [submitSpotBatchOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1734) | :closed_lock_with_key: | POST | `/spot/batch_orders` | +| [getSpotOpenOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1761) | :closed_lock_with_key: | GET | `/spot/open_orders` | +| [submitSpotClosePosCrossDisabled()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1777) | :closed_lock_with_key: | POST | `/spot/cross_liquidate_orders` | +| [submitSpotOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1793) | :closed_lock_with_key: | POST | `/spot/orders` | +| [getSpotOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1810) | :closed_lock_with_key: | GET | `/spot/orders` | +| [cancelSpotOpenOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1825) | :closed_lock_with_key: | DELETE | `/spot/orders` | +| [batchCancelSpotOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1854) | :closed_lock_with_key: | POST | `/spot/cancel_batch_orders` | +| [getSpotOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1879) | :closed_lock_with_key: | GET | `/spot/orders/{order_id}` | +| [updateSpotOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1896) | :closed_lock_with_key: | PATCH | `/spot/orders/{order_id}` | +| [cancelSpotOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1924) | :closed_lock_with_key: | DELETE | `/spot/orders/{order_id}` | +| [getSpotTradingHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1953) | :closed_lock_with_key: | GET | `/spot/my_trades` | +| [submitSpotCountdownOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L1982) | :closed_lock_with_key: | POST | `/spot/countdown_cancel_all` | +| [batchUpdateSpotOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2001) | :closed_lock_with_key: | POST | `/spot/amend_batch_orders` | +| [getSpotInsuranceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2028) | :closed_lock_with_key: | GET | `/spot/insurance_history` | +| [submitSpotPriceTriggerOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2042) | :closed_lock_with_key: | POST | `/spot/price_orders` | +| [getSpotAutoOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2054) | :closed_lock_with_key: | GET | `/spot/price_orders` | +| [cancelAllOpenSpotOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2066) | :closed_lock_with_key: | DELETE | `/spot/price_orders` | +| [getPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2079) | :closed_lock_with_key: | GET | `/spot/price_orders/{order_id}` | +| [cancelSpotTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2091) | :closed_lock_with_key: | DELETE | `/spot/price_orders/{order_id}` | +| [getSpotPovOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2105) | :closed_lock_with_key: | GET | `/spot/pov_orders` | +| [createSpotPovOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2117) | :closed_lock_with_key: | POST | `/spot/pov_orders` | +| [cancelSpotPovOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2129) | :closed_lock_with_key: | DELETE | `/spot/pov_orders` | +| [getSpotPovOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2143) | :closed_lock_with_key: | GET | `/spot/pov_orders/{order_id}` | +| [cancelSpotPovOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2155) | :closed_lock_with_key: | DELETE | `/spot/pov_orders/{order_id}` | +| [setCollateralCurrency()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2167) | :closed_lock_with_key: | POST | `/unified/collateral_currencies` | +| [getMarginAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2188) | :closed_lock_with_key: | GET | `/margin/accounts` | +| [getMarginBalanceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2202) | :closed_lock_with_key: | GET | `/margin/account_book` | +| [getFundingAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2220) | :closed_lock_with_key: | GET | `/margin/funding_accounts` | +| [updateAutoRepaymentSetting()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2238) | :closed_lock_with_key: | POST | `/margin/auto_repay` | +| [getAutoRepaymentSetting()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2249) | :closed_lock_with_key: | GET | `/margin/auto_repay` | +| [getMarginTransferableAmount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2263) | :closed_lock_with_key: | GET | `/margin/transferable` | +| [getCrossMarginCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2280) | | GET | `/margin/cross/currencies` | +| [getCrossMarginCurrency()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2291) | | GET | `/margin/cross/currencies/{currency}` | +| [getCrossMarginAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2303) | :closed_lock_with_key: | GET | `/margin/cross/accounts` | +| [getCrossMarginAccountHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2316) | :closed_lock_with_key: | GET | `/margin/cross/account_book` | +| [submitCrossMarginBorrowLoan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2333) | :closed_lock_with_key: | POST | `/margin/cross/loans` | +| [getCrossMarginBorrowHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2348) | :closed_lock_with_key: | GET | `/margin/cross/loans` | +| [getCrossMarginBorrowLoan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2361) | :closed_lock_with_key: | GET | `/margin/cross/loans/{loan_id}` | +| [submitCrossMarginRepayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2376) | :closed_lock_with_key: | POST | `/margin/cross/repayments` | +| [getCrossMarginRepayments()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2392) | :closed_lock_with_key: | GET | `/margin/cross/repayments` | +| [getCrossMarginInterestRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2405) | :closed_lock_with_key: | GET | `/margin/cross/interest_records` | +| [getCrossMarginTransferableAmount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2421) | :closed_lock_with_key: | GET | `/margin/cross/transferable` | +| [getEstimatedInterestRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2437) | :closed_lock_with_key: | GET | `/margin/cross/estimate_rate` | +| [getCrossMarginBorrowableAmount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2451) | :closed_lock_with_key: | GET | `/margin/cross/borrowable` | +| [getMarginUserLoanTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2464) | :closed_lock_with_key: | GET | `/margin/user/loan_margin_tiers` | +| [getMarginPublicLoanTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2480) | | GET | `/margin/loan_margin_tiers` | +| [setMarginUserLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2496) | :closed_lock_with_key: | POST | `/margin/leverage/user_market_setting` | +| [getMarginUserAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2513) | :closed_lock_with_key: | GET | `/margin/user/account` | +| [getLendingMarkets()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2528) | | GET | `/margin/uni/currency_pairs` | +| [getLendingMarket()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2543) | | GET | `/margin/uni/currency_pairs/{currency_pair}` | +| [getEstimatedInterestRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2555) | :closed_lock_with_key: | GET | `/margin/uni/estimate_rate` | +| [submitMarginUNIBorrowOrRepay()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2565) | :closed_lock_with_key: | POST | `/margin/uni/loans` | +| [getMarginUNILoans()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2581) | :closed_lock_with_key: | GET | `/margin/uni/loans` | +| [getMarginUNILoanRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2591) | :closed_lock_with_key: | GET | `/margin/uni/loan_records` | +| [getMarginUNIInterestRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2603) | :closed_lock_with_key: | GET | `/margin/uni/interest_records` | +| [getMarginUNIMaxBorrow()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2615) | :closed_lock_with_key: | GET | `/margin/uni/borrowable` | +| [getFlashSwapCurrencyPairs()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2631) | | GET | `/flash_swap/currency_pairs` | +| [submitFlashSwapOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2647) | :closed_lock_with_key: | POST | `/flash_swap/orders` | +| [getFlashSwapOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2659) | :closed_lock_with_key: | GET | `/flash_swap/orders` | +| [getFlashSwapOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2671) | :closed_lock_with_key: | GET | `/flash_swap/orders/{order_id}` | +| [submitFlashSwapOrderPreview()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2681) | :closed_lock_with_key: | POST | `/flash_swap/orders/preview` | +| [getFuturesContracts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2698) | | GET | `/futures/{settle}/contracts` | +| [getFuturesContract()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2713) | | GET | `/futures/{settle}/contracts/{contract}` | +| [listFuturesADLRiskStates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2720) | | GET | `/futures/{settle}/adl_risk_states` | +| [getFuturesOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2734) | | GET | `/futures/{settle}/order_book` | +| [getFuturesRpiOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2750) | | GET | `/futures/{settle}/rpi_order_book` | +| [getFuturesTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2763) | | GET | `/futures/{settle}/trades` | +| [getFuturesCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2778) | | GET | `/futures/{settle}/candlesticks` | +| [getPremiumIndexKLines()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2791) | | GET | `/futures/{settle}/premium_index` | +| [getFuturesTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2804) | | GET | `/futures/{settle}/tickers` | +| [getFundingRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2821) | | GET | `/futures/{settle}/funding_rate` | +| [getBatchFundingRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2837) | | POST | `/futures/{settle}/funding_rates` | +| [getFuturesInsuranceBalanceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2855) | | GET | `/futures/{settle}/insurance` | +| [getFuturesStats()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2874) | | GET | `/futures/{settle}/contract_stats` | +| [getIndexConstituents()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2885) | | GET | `/futures/{settle}/index_constituents/{index}` | +| [getLiquidationHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2902) | | GET | `/futures/{settle}/liq_orders` | +| [getRiskLimitTiers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2919) | | GET | `/futures/{settle}/risk_limit_tiers` | +| [getFuturesAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2932) | :closed_lock_with_key: | GET | `/futures/{settle}/accounts` | +| [getFuturesAccountBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2946) | :closed_lock_with_key: | GET | `/futures/{settle}/account_book` | +| [getFuturesPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2959) | :closed_lock_with_key: | GET | `/futures/{settle}/positions` | +| [getFuturesPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2974) | :closed_lock_with_key: | GET | `/futures/{settle}/positions/{contract}` | +| [updateFuturesMargin()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L2991) | :closed_lock_with_key: | POST | `/futures/{settle}/positions/{contract}/margin` | +| [updateFuturesLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3019) | :closed_lock_with_key: | POST | `/futures/{settle}/positions/{contract}/leverage` | +| [getFuturesContractLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3039) | :closed_lock_with_key: | GET | `/futures/{settle}/get_leverage/{contract}` | +| [updateFuturesPositionMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3055) | :closed_lock_with_key: | POST | `/futures/{settle}/positions/cross_mode` | +| [updatePositionRiskLimit()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3072) | :closed_lock_with_key: | POST | `/futures/{settle}/positions/{contract}/risk_limit` | +| [updateFuturesDualMode()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3092) | :closed_lock_with_key: | POST | `/futures/{settle}/dual_mode` | +| [getDualModePosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3108) | :closed_lock_with_key: | GET | `/futures/{settle}/dual_comp/positions/{contract}` | +| [updateDualModePositionMargin()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3123) | :closed_lock_with_key: | POST | `/futures/{settle}/dual_comp/positions/{contract}/margin` | +| [updateDualModePositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3139) | :closed_lock_with_key: | POST | `/futures/{settle}/dual_comp/positions/{contract}/leverage` | +| [updateDualModePositionRiskLimit()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3163) | :closed_lock_with_key: | POST | `/futures/{settle}/dual_comp/positions/{contract}/risk_limit` | +| [submitFuturesOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3190) | :closed_lock_with_key: | POST | `/futures/{settle}/orders` | +| [getFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3211) | :closed_lock_with_key: | GET | `/futures/{settle}/orders` | +| [cancelAllFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3226) | :closed_lock_with_key: | DELETE | `/futures/{settle}/orders` | +| [getFuturesOrdersByTimeRange()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3246) | :closed_lock_with_key: | GET | `/futures/{settle}/orders_timerange` | +| [submitFuturesBatchOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3269) | :closed_lock_with_key: | POST | `/futures/{settle}/batch_orders` | +| [getFuturesOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3294) | :closed_lock_with_key: | GET | `/futures/{settle}/orders/{order_id}` | +| [cancelFuturesOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3311) | :closed_lock_with_key: | DELETE | `/futures/{settle}/orders/{order_id}` | +| [updateFuturesOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3336) | :closed_lock_with_key: | PUT | `/futures/{settle}/orders/{order_id}` | +| [getFuturesTradingHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3357) | :closed_lock_with_key: | GET | `/futures/{settle}/my_trades` | +| [getFuturesTradingHistoryByTimeRange()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3372) | :closed_lock_with_key: | GET | `/futures/{settle}/my_trades_timerange` | +| [getFuturesPositionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3385) | :closed_lock_with_key: | GET | `/futures/{settle}/position_close` | +| [getFuturesLiquidationHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3398) | :closed_lock_with_key: | GET | `/futures/{settle}/liquidates` | +| [getFuturesAutoDeleveragingHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3411) | :closed_lock_with_key: | GET | `/futures/{settle}/auto_deleverages` | +| [setFuturesOrderCancelCountdown()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3428) | :closed_lock_with_key: | POST | `/futures/{settle}/countdown_cancel_all` | +| [getFuturesUserTradingFees()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3445) | :closed_lock_with_key: | GET | `/futures/{settle}/fee` | +| [batchCancelFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3463) | :closed_lock_with_key: | POST | `/futures/{settle}/batch_cancel_orders` | +| [batchUpdateFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3490) | :closed_lock_with_key: | POST | `/futures/{settle}/batch_amend_orders` | +| [getRiskLimitTable()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3512) | | GET | `/futures/{settle}/risk_limit_table` | +| [submitFuturesPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3525) | :closed_lock_with_key: | POST | `/futures/{settle}/price_orders` | +| [getFuturesAutoOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3538) | :closed_lock_with_key: | GET | `/futures/{settle}/price_orders` | +| [cancelAllOpenFuturesOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3551) | :closed_lock_with_key: | DELETE | `/futures/{settle}/price_orders` | +| [getFuturesPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3567) | :closed_lock_with_key: | GET | `/futures/{settle}/price_orders/{order_id}` | +| [cancelFuturesPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3582) | :closed_lock_with_key: | DELETE | `/futures/{settle}/price_orders/{order_id}` | +| [updateFuturesPriceTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3600) | :closed_lock_with_key: | PUT | `/futures/{settle}/price_orders/amend/{order_id}` | +| [createTrailOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3618) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/trail/create` | +| [terminateTrailOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3636) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/trail/stop` | +| [batchTerminateTrailOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3649) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/trail/stop_all` | +| [getTrailOrderList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3664) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/trail/list` | +| [getTrailOrderDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3677) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/trail/detail` | +| [updateTrailOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3695) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/trail/update` | +| [getTrailOrderChangeLog()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3708) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/trail/change_log` | +| [createChaseOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3721) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/chase/create` | +| [stopChaseOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3731) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/chase/stop` | +| [stopAllChaseOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3741) | :closed_lock_with_key: | POST | `/futures/{settle}/autoorder/v1/chase/stop_all` | +| [getChaseOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3753) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/chase/list` | +| [getChaseOrderDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3761) | :closed_lock_with_key: | GET | `/futures/{settle}/autoorder/v1/chase/detail` | +| [getFuturesPositionCloseHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3770) | :closed_lock_with_key: | GET | `/futures/{settle}/position_close_history` | +| [getFuturesInsuranceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3779) | :closed_lock_with_key: | GET | `/futures/{settle}/insurance` | +| [getAllDeliveryContracts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3796) | | GET | `/delivery/{settle}/contracts` | +| [getDeliveryContract()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3808) | | GET | `/delivery/{settle}/contracts/{contract}` | +| [getDeliveryOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3823) | | GET | `/delivery/{settle}/order_book` | +| [getDeliveryTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3836) | | GET | `/delivery/{settle}/trades` | +| [getDeliveryCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3850) | | GET | `/delivery/{settle}/candlesticks` | +| [getDeliveryTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3861) | | GET | `/delivery/{settle}/tickers` | +| [getDeliveryInsuranceBalanceHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3878) | | GET | `/delivery/{settle}/insurance` | +| [getDeliveryAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3897) | :closed_lock_with_key: | GET | `/delivery/{settle}/accounts` | +| [getDeliveryBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3908) | :closed_lock_with_key: | GET | `/delivery/{settle}/account_book` | +| [getDeliveryPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3919) | :closed_lock_with_key: | GET | `/delivery/{settle}/positions` | +| [getDeliveryPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3929) | :closed_lock_with_key: | GET | `/delivery/{settle}/positions/{contract}` | +| [updateDeliveryMargin()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3944) | :closed_lock_with_key: | POST | `/delivery/{settle}/positions/{contract}/margin` | +| [updateDeliveryLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3962) | :closed_lock_with_key: | POST | `/delivery/{settle}/positions/{contract}/leverage` | +| [updateDeliveryRiskLimit()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L3980) | :closed_lock_with_key: | POST | `/delivery/{settle}/positions/{contract}/risk_limit` | +| [submitDeliveryOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4000) | :closed_lock_with_key: | POST | `/delivery/{settle}/orders` | +| [getDeliveryOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4015) | :closed_lock_with_key: | GET | `/delivery/{settle}/orders` | +| [cancelAllDeliveryOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4028) | :closed_lock_with_key: | DELETE | `/delivery/{settle}/orders` | +| [getDeliveryOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4047) | :closed_lock_with_key: | GET | `/delivery/{settle}/orders/{order_id}` | +| [cancelDeliveryOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4062) | :closed_lock_with_key: | DELETE | `/delivery/{settle}/orders/{order_id}` | +| [getDeliveryTradingHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4077) | :closed_lock_with_key: | GET | `/delivery/{settle}/my_trades` | +| [getDeliveryClosedPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4090) | :closed_lock_with_key: | GET | `/delivery/{settle}/position_close` | +| [getDeliveryLiquidationHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4103) | :closed_lock_with_key: | GET | `/delivery/{settle}/liquidates` | +| [getDeliverySettlementHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4116) | :closed_lock_with_key: | GET | `/delivery/{settle}/settlements` | +| [submitDeliveryTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4129) | :closed_lock_with_key: | POST | `/delivery/{settle}/price_orders` | +| [getDeliveryAutoOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4144) | :closed_lock_with_key: | GET | `/delivery/{settle}/price_orders` | +| [cancelAllOpenDeliveryOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4157) | :closed_lock_with_key: | DELETE | `/delivery/{settle}/price_orders` | +| [getDeliveryTriggeredOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4173) | :closed_lock_with_key: | GET | `/delivery/{settle}/price_orders/{order_id}` | +| [cancelTriggeredDeliveryOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4188) | :closed_lock_with_key: | DELETE | `/delivery/{settle}/price_orders/{order_id}` | +| [getOptionsUnderlyings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4207) | | GET | `/options/underlyings` | +| [getOptionsExpirationTimes()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4217) | | GET | `/options/expirations` | +| [getOptionsContracts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4227) | | GET | `/options/contracts` | +| [getOptionsContract()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4240) | | GET | `/options/contracts/{contract}` | +| [getOptionsSettlementHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4250) | | GET | `/options/settlements` | +| [getOptionsContractSettlement()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4262) | | GET | `/options/settlements/{contract}` | +| [getOptionsMySettlements()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4277) | :closed_lock_with_key: | GET | `/options/my_settlements` | +| [getOptionsOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4291) | | GET | `/options/order_book` | +| [getOptionsTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4303) | | GET | `/options/tickers` | +| [getOptionsUnderlyingTicker()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4317) | | GET | `/options/underlying/tickers/{underlying}` | +| [getOptionsCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4331) | | GET | `/options/candlesticks` | +| [getOptionsUnderlyingCandles()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4341) | | GET | `/options/underlying/candlesticks` | +| [getOptionsTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4353) | | GET | `/options/trades` | +| [getOptionsAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4364) | :closed_lock_with_key: | GET | `/options/accounts` | +| [getOptionsAccountChange()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4374) | :closed_lock_with_key: | GET | `/options/account_book` | +| [getOptionsPositionsUnderlying()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4386) | :closed_lock_with_key: | GET | `/options/positions` | +| [getOptionsPositionContract()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4398) | :closed_lock_with_key: | GET | `/options/positions/{contract}` | +| [getOptionsLiquidation()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4410) | :closed_lock_with_key: | GET | `/options/position_close` | +| [submitOptionsOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4423) | :closed_lock_with_key: | POST | `/options/orders` | +| [getOptionsOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4435) | :closed_lock_with_key: | GET | `/options/orders` | +| [cancelAllOpenOptionsOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4447) | :closed_lock_with_key: | DELETE | `/options/orders` | +| [getOptionsOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4461) | :closed_lock_with_key: | GET | `/options/orders/{order_id}` | +| [amendOptionsOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4473) | :closed_lock_with_key: | PUT | `/options/orders/{order_id}` | +| [cancelOptionsOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4488) | :closed_lock_with_key: | DELETE | `/options/orders/{order_id}` | +| [submitOptionsCountdownCancel()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4507) | :closed_lock_with_key: | POST | `/options/countdown_cancel_all` | +| [getOptionsPersonalHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4523) | :closed_lock_with_key: | GET | `/options/my_trades` | +| [setOptionsMMPSettings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4535) | :closed_lock_with_key: | POST | `/options/mmp` | +| [getOptionsMMPSettings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4547) | :closed_lock_with_key: | GET | `/options/mmp` | +| [resetOptionsMMPSettings()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4559) | :closed_lock_with_key: | POST | `/options/mmp/reset` | +| [getLendingCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4575) | | GET | `/earn/uni/currencies` | +| [getLendingCurrency()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4585) | | GET | `/earn/uni/currencies/{currency}` | +| [submitLendOrRedeemOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4595) | :closed_lock_with_key: | POST | `/earn/uni/lends` | +| [getLendingOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4605) | :closed_lock_with_key: | GET | `/earn/uni/lends` | +| [updateLendingOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4617) | :closed_lock_with_key: | PATCH | `/earn/uni/lends` | +| [getLendingRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4630) | :closed_lock_with_key: | GET | `/earn/uni/lend_records` | +| [getLendingTotalInterest()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4643) | :closed_lock_with_key: | GET | `/earn/uni/interests/{currency}` | +| [getLendingInterestRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4656) | :closed_lock_with_key: | GET | `/earn/uni/interest_records` | +| [updateInterestReinvestment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4669) | :closed_lock_with_key: | PUT | `/earn/uni/interest_reinvest` | +| [getLendingInterestStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4685) | :closed_lock_with_key: | GET | `/earn/uni/interest_status/{currency}` | +| [getLendingAnnualizedTrendChart()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4700) | :closed_lock_with_key: | GET | `/earn/uni/chart` | +| [getLendingEstimatedRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4708) | :closed_lock_with_key: | GET | `/earn/uni/rate` | +| [submitMultiLoanOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4725) | :closed_lock_with_key: | POST | `/loan/multi_collateral/orders` | +| [getMultiLoanOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4737) | :closed_lock_with_key: | GET | `/loan/multi_collateral/orders` | +| [getMultiLoanOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4749) | :closed_lock_with_key: | GET | `/loan/multi_collateral/orders/{order_id}` | +| [repayMultiLoan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4759) | :closed_lock_with_key: | POST | `/loan/multi_collateral/repay` | +| [getMultiLoanRepayRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4769) | :closed_lock_with_key: | GET | `/loan/multi_collateral/repay` | +| [updateMultiLoan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4781) | :closed_lock_with_key: | POST | `/loan/multi_collateral/mortgage` | +| [getMultiLoanAdjustmentRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4793) | :closed_lock_with_key: | GET | `/loan/multi_collateral/mortgage` | +| [getMultiLoanCurrencyQuota()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4805) | :closed_lock_with_key: | GET | `/loan/multi_collateral/currency_quota` | +| [getMultiLoanSupportedCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4817) | | GET | `/loan/multi_collateral/currencies` | +| [getMultiLoanRatio()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4826) | | GET | `/loan/multi_collateral/ltv` | +| [getMultiLoanFixedRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4835) | | GET | `/loan/multi_collateral/fixed_rate` | +| [getMultiLoanCurrentRates()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4848) | | GET | `/loan/multi_collateral/current_rate` | +| [getDualInvestmentProducts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4872) | | GET | `/earn/dual/investment_plan` | +| [getDualInvestmentOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4883) | :closed_lock_with_key: | GET | `/earn/dual/orders` | +| [submitDualInvestmentOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4895) | :closed_lock_with_key: | POST | `/earn/dual/orders` | +| [getDualOrderRefundPreview()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4904) | :closed_lock_with_key: | GET | `/earn/dual/order-refund-preview` | +| [submitDualOrderRefund()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4913) | :closed_lock_with_key: | POST | `/earn/dual/order-refund` | +| [updateDualOrderReinvest()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4922) | :closed_lock_with_key: | POST | `/earn/dual/modify-order-reinvest` | +| [getDualProjectRecommend()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4933) | :closed_lock_with_key: | GET | `/earn/dual/project-recommend` | +| [getDualStockInvestmentPlans()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4944) | | GET | `/earn/dual/stock/investment_plan` | +| [getDualStockProjectRecommend()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4956) | | GET | `/earn/dual/stock/project-recommend` | +| [getDualStockOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4965) | :closed_lock_with_key: | GET | `/earn/dual/stock/orders` | +| [submitDualStockOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4977) | :closed_lock_with_key: | POST | `/earn/dual/stock/orders` | +| [getDualStockBalance()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4986) | :closed_lock_with_key: | GET | `/earn/dual/stock/balance` | +| [getDualStockOrderRefundPreview()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L4993) | :closed_lock_with_key: | GET | `/earn/dual/stock/order-refund-preview` | +| [submitDualStockOrderRefund()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5002) | :closed_lock_with_key: | POST | `/earn/dual/stock/order-refund` | +| [updateDualStockOrderReinvest()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5011) | :closed_lock_with_key: | POST | `/earn/dual/stock/modify-order-reinvest` | +| [getEarnFixedTermProducts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5022) | | GET | `/earn/fixed-term/product` | +| [getEarnFixedTermProductsByAsset()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5031) | | GET | `/earn/fixed-term/product/{asset}/list` | +| [createEarnFixedTermLend()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5041) | :closed_lock_with_key: | POST | `/earn/fixed-term/user/lend` | +| [getEarnFixedTermLends()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5050) | :closed_lock_with_key: | GET | `/earn/fixed-term/user/lend` | +| [createEarnFixedTermPreRedeem()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5059) | :closed_lock_with_key: | POST | `/earn/fixed-term/user/pre-redeem` | +| [getEarnFixedTermHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5070) | :closed_lock_with_key: | GET | `/earn/fixed-term/user/history` | +| [createAutoInvestPlan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5079) | :closed_lock_with_key: | POST | `/earn/autoinvest/plans/create` | +| [updateAutoInvestPlan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5088) | :closed_lock_with_key: | POST | `/earn/autoinvest/plans/update` | +| [stopAutoInvestPlan()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5095) | :closed_lock_with_key: | POST | `/earn/autoinvest/plans/stop` | +| [addAutoInvestPlanPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5102) | :closed_lock_with_key: | POST | `/earn/autoinvest/plans/add_position` | +| [getAutoInvestCoins()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5113) | :closed_lock_with_key: | GET | `/earn/autoinvest/coins` | +| [getAutoInvestMinAmount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5122) | :closed_lock_with_key: | POST | `/earn/autoinvest/min_invest_amount` | +| [getAutoInvestPlanRecords()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5133) | :closed_lock_with_key: | GET | `/earn/autoinvest/plans/records` | +| [getAutoInvestOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5142) | :closed_lock_with_key: | GET | `/earn/autoinvest/orders` | +| [getAutoInvestConfig()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5151) | :closed_lock_with_key: | GET | `/earn/autoinvest/config` | +| [getAutoInvestPlanDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5158) | :closed_lock_with_key: | GET | `/earn/autoinvest/plans/detail` | +| [getAutoInvestPlans()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5167) | :closed_lock_with_key: | GET | `/earn/autoinvest/plans/list_info` | +| [getStakingCoins()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5179) | :closed_lock_with_key: | GET | `/earn/staking/coins` | +| [submitStakingSwap()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5192) | :closed_lock_with_key: | POST | `/earn/staking/swap` | +| [getAccountDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5211) | :closed_lock_with_key: | GET | `/account/detail` | +| [getAccountRateLimit()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5220) | :closed_lock_with_key: | GET | `/account/rate_limit` | +| [createStpGroup()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5230) | :closed_lock_with_key: | POST | `/account/stp_groups` | +| [getStpGroups()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5240) | :closed_lock_with_key: | GET | `/account/stp_groups` | +| [getStpGroupUsers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5250) | :closed_lock_with_key: | GET | `/account/stp_groups/{stp_id}/users` | +| [addUsersToStpGroup()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5260) | :closed_lock_with_key: | POST | `/account/stp_groups/{stp_id}/users` | +| [deleteUserFromStpGroup()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5276) | :closed_lock_with_key: | DELETE | `/account/stp_groups/{stp_id}/users` | +| [setGTDeduction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5294) | :closed_lock_with_key: | POST | `/account/debit_fee` | +| [getGTDeduction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5305) | :closed_lock_with_key: | GET | `/account/debit_fee` | +| [getAccountMainKeys()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5314) | :closed_lock_with_key: | GET | `/account/main_keys` | +| [getAgencyTransactionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5330) | :closed_lock_with_key: | GET | `/rebate/agency/transaction_history` | +| [getAgencyCommissionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5343) | :closed_lock_with_key: | GET | `/rebate/agency/commission_history` | +| [getPartnerTransactionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5357) | :closed_lock_with_key: | GET | `/rebate/partner/transaction_history` | +| [getPartnerCommissionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5372) | :closed_lock_with_key: | GET | `/rebate/partner/commission_history` | +| [getPartnerSubordinateList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5395) | :closed_lock_with_key: | GET | `/rebate/partner/sub_list` | +| [getPartnerAgentDataAggregated()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5405) | :closed_lock_with_key: | GET | `/rebate/partner/data/aggregated` | +| [getBrokerCommissionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5418) | :closed_lock_with_key: | GET | `/rebate/broker/commission_history` | +| [getBrokerTransactionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5431) | :closed_lock_with_key: | GET | `/rebate/broker/transaction_history` | +| [getUserRebateInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5440) | :closed_lock_with_key: | GET | `/rebate/user/info` | +| [createOTCQuote()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5475) | :closed_lock_with_key: | POST | `/otc/quote` | +| [createOTCFiatOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5487) | :closed_lock_with_key: | POST | `/otc/order/create` | +| [createOTCStablecoinOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5501) | :closed_lock_with_key: | POST | `/otc/stable_coin/order/create` | +| [getOTCBankList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5510) | :closed_lock_with_key: | GET | `/otc/bank/list` | +| [getOTCBankListLegacy()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5517) | :closed_lock_with_key: | GET | `/otc/bank_list` | +| [createOTCUploadPreUpload()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5521) | :closed_lock_with_key: | POST | `/otc/upload/pre_upload` | +| [createOTCBank()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5530) | :closed_lock_with_key: | POST | `/otc/bank/create` | +| [deleteOTCBank()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5544) | :closed_lock_with_key: | POST | `/otc/bank/delete` | +| [setDefaultOTCBank()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5551) | :closed_lock_with_key: | POST | `/otc/bank/set_default` | +| [getOTCBankSupplementChecklist()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5558) | :closed_lock_with_key: | GET | `/otc/bank/bank_supplement_checklist` | +| [submitOTCBankPersonalSupplement()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5567) | :closed_lock_with_key: | POST | `/otc/order/paid` | +| [submitOTCBankEnterpriseSupplement()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5586) | :closed_lock_with_key: | POST | `/otc/order/paid` | +| [markOTCOrderAsPaid()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5622) | :closed_lock_with_key: | POST | `/otc/order/paid` | +| [cancelOTCOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5636) | :closed_lock_with_key: | POST | `/otc/order/cancel` | +| [getOTCFiatOrderList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5648) | :closed_lock_with_key: | GET | `/otc/order/list` | +| [getOTCStablecoinOrderList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5662) | :closed_lock_with_key: | GET | `/otc/stable_coin/order/list` | +| [getOTCFiatOrderDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5676) | :closed_lock_with_key: | GET | `/otc/order/detail` | +| [getP2PMerchantUserInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5690) | :closed_lock_with_key: | POST | `/p2p/merchant/account/get_user_info` | +| [getP2PMerchantCounterpartyUserInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5699) | :closed_lock_with_key: | POST | `/p2p/merchant/account/get_counterparty_user_info` | +| [getP2PMerchantMyselfPayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5711) | :closed_lock_with_key: | POST | `/p2p/merchant/account/get_myself_payment` | +| [getP2PMerchantSpotBalance()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5724) | :closed_lock_with_key: | POST | `/p2p/merchant/account/set_merchant_work_hours` | +| [setP2PMerchantWorkHours()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5733) | :closed_lock_with_key: | POST | `/p2p/merchant/account/set_merchant_work_hours` | +| [getP2PMerchantPendingTransactionList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5744) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/get_pending_transaction_list` | +| [getP2PMerchantCompletedTransactionList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5756) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/get_completed_transaction_list` | +| [getP2PMerchantTransactionDetails()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5768) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/get_transaction_details` | +| [confirmP2PMerchantPayment()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5780) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/confirm-payment` | +| [confirmP2PMerchantReceipt()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5791) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/confirm-receipt` | +| [cancelP2PMerchantTransaction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5802) | :closed_lock_with_key: | POST | `/p2p/merchant/transaction/cancel` | +| [placeP2PMerchantBizPushOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5813) | :closed_lock_with_key: | POST | `/p2p/merchant/books/place_biz_push_order` | +| [updateP2PMerchantAdsStatus()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5824) | :closed_lock_with_key: | POST | `/p2p/merchant/books/ads_update_status` | +| [getP2PMerchantAdsDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5837) | :closed_lock_with_key: | POST | `/p2p/merchant/books/ads_detail` | +| [getP2PMerchantMyAdsList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5846) | :closed_lock_with_key: | POST | `/p2p/merchant/books/my_ads_list` | +| [getP2PMerchantAdsList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5857) | :closed_lock_with_key: | POST | `/p2p/merchant/books/ads_list` | +| [getP2PMerchantChatsList()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5866) | :closed_lock_with_key: | POST | `/p2p/merchant/chat/get_chats_list` | +| [sendP2PMerchantChatMessage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5877) | :closed_lock_with_key: | POST | `/p2p/merchant/chat/send_chat_message` | +| [uploadP2PMerchantChatFile()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5888) | :closed_lock_with_key: | POST | `/p2p/merchant/chat/upload_chat_file` | +| [getCrossExSymbols()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5911) | | GET | `/crossex/rule/symbols` | +| [getCrossExRiskLimits()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5923) | | GET | `/crossex/rule/risk_limits` | +| [getCrossExTransferCoins()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5937) | | GET | `/crossex/transfers/coin` | +| [createCrossExTransfer()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5951) | :closed_lock_with_key: | POST | `/crossex/transfers` | +| [getCrossExTransferHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5965) | :closed_lock_with_key: | GET | `/crossex/transfers` | +| [createCrossExOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5982) | :closed_lock_with_key: | POST | `/crossex/orders` | +| [cancelBatchCrossExOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L5996) | :closed_lock_with_key: | POST | `/crossex/batch_cancel_orders` | +| [cancelCrossExOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6010) | :closed_lock_with_key: | DELETE | `/crossex/orders/{order_id}` | +| [modifyCrossExOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6023) | :closed_lock_with_key: | PUT | `/crossex/orders/{order_id}` | +| [getCrossExOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6038) | :closed_lock_with_key: | GET | `/crossex/orders/{order_id}` | +| [createCrossExConvertQuote()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6050) | :closed_lock_with_key: | POST | `/crossex/convert/quote` | +| [createCrossExConvertOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6064) | :closed_lock_with_key: | POST | `/crossex/convert/orders` | +| [updateCrossExAccount()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6078) | :closed_lock_with_key: | PUT | `/crossex/accounts` | +| [getCrossExAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6092) | :closed_lock_with_key: | GET | `/crossex/accounts` | +| [setCrossExPositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6104) | :closed_lock_with_key: | POST | `/crossex/positions/leverage` | +| [getCrossExPositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6118) | :closed_lock_with_key: | GET | `/crossex/positions/leverage` | +| [setCrossExMarginPositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6132) | :closed_lock_with_key: | POST | `/crossex/margin_positions/leverage` | +| [getCrossExMarginPositionLeverage()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6148) | :closed_lock_with_key: | GET | `/crossex/margin_positions/leverage` | +| [closeCrossExPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6162) | :closed_lock_with_key: | POST | `/crossex/position` | +| [updateCrossExPositionsMargin()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6168) | :closed_lock_with_key: | POST | `/crossex/positions/margin` | +| [getCrossExInterestRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6182) | :closed_lock_with_key: | GET | `/crossex/interest_rate` | +| [getCrossExFeeRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6195) | :closed_lock_with_key: | GET | `/crossex/fee` | +| [getCrossExPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6207) | :closed_lock_with_key: | GET | `/crossex/positions` | +| [getCrossExSecurityPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6221) | :closed_lock_with_key: | GET | `/crossex/security_positions` | +| [getCrossExMarginPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6235) | :closed_lock_with_key: | GET | `/crossex/margin_positions` | +| [getCrossExAdlRank()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6249) | :closed_lock_with_key: | GET | `/crossex/adl_rank` | +| [getCrossExOpenOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6261) | :closed_lock_with_key: | GET | `/crossex/open_orders` | +| [getCrossExHistoryOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6275) | :closed_lock_with_key: | GET | `/crossex/history_orders` | +| [getCrossExHistoryPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6289) | :closed_lock_with_key: | GET | `/crossex/history_positions` | +| [getCrossExHistoryMarginPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6303) | :closed_lock_with_key: | GET | `/crossex/history_margin_positions` | +| [getCrossExHistoryMarginInterests()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6317) | :closed_lock_with_key: | GET | `/crossex/history_margin_interests` | +| [getCrossExHistoryTrades()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6331) | :closed_lock_with_key: | GET | `/crossex/history_trades` | +| [getCrossExAccountBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6347) | :closed_lock_with_key: | GET | `/crossex/account_book` | +| [getCrossExCoinDiscountRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6361) | :closed_lock_with_key: | GET | `/crossex/coin_discount_rate` | +| [getCrossExMarketTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6375) | | GET | `/crossex/market/tickers` | +| [getCrossExMarketFundingInfo()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6389) | | GET | `/crossex/market/funding_info` | +| [getAlphaAccounts()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6407) | :closed_lock_with_key: | GET | `/alpha/accounts` | +| [getAlphaAccountBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6419) | :closed_lock_with_key: | GET | `/alpha/account_book` | +| [createAlphaQuote()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6433) | :closed_lock_with_key: | POST | `/alpha/quote` | +| [createAlphaOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6445) | :closed_lock_with_key: | POST | `/alpha/orders` | +| [getAlphaOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6457) | :closed_lock_with_key: | GET | `/alpha/orders` | +| [getAlphaOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6469) | :closed_lock_with_key: | GET | `/alpha/order` | +| [getAlphaCurrencies()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6481) | | GET | `/alpha/currencies` | +| [getAlphaTickers()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6493) | | GET | `/alpha/tickers` | +| [getTradFiMT5Account()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6499) | :closed_lock_with_key: | GET | `/tradfi/users/mt5-account` | +| [getTradFiSymbolCategories()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6503) | | GET | `/tradfi/symbols/categories` | +| [getTradFiSymbols()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6509) | | GET | `/tradfi/symbols` | +| [getTradFiSymbolCommissions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6521) | :closed_lock_with_key: | GET | `/tradfi/symbols/commissions` | +| [getTradFiSymbolDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6527) | :closed_lock_with_key: | GET | `/tradfi/symbols/detail` | +| [getTradFiKlines()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6542) | | GET | `/tradfi/symbols/{symbol}/klines` | +| [getTradFiTicker()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6549) | | GET | `/tradfi/symbols/{symbol}/tickers` | +| [createTradFiUser()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6553) | :closed_lock_with_key: | POST | `/tradfi/users` | +| [getTradFiAssets()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6557) | :closed_lock_with_key: | GET | `/tradfi/users/assets` | +| [createTradFiTransaction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6561) | :closed_lock_with_key: | POST | `/tradfi/transactions` | +| [getTradFiTransactions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6567) | :closed_lock_with_key: | GET | `/tradfi/transactions` | +| [createTradFiOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6573) | :closed_lock_with_key: | POST | `/tradfi/orders` | +| [getTradFiOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6579) | :closed_lock_with_key: | GET | `/tradfi/orders` | +| [modifyTradFiOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6583) | :closed_lock_with_key: | PUT | `/tradfi/orders/{orderId}` | +| [cancelTradFiOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6590) | :closed_lock_with_key: | DELETE | `/tradfi/orders/{orderId}` | +| [getTradFiOrderHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6594) | :closed_lock_with_key: | GET | `/tradfi/orders/history` | +| [getTradFiPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6600) | :closed_lock_with_key: | GET | `/tradfi/positions` | +| [modifyTradFiPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6606) | :closed_lock_with_key: | PUT | `/tradfi/positions/{positionId}` | +| [closeTradFiPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6615) | :closed_lock_with_key: | POST | `/tradfi/positions/{positionId}/close` | +| [getTradFiPositionHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6624) | :closed_lock_with_key: | GET | `/tradfi/positions/history` | +| [getTradFiOrderLog()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6633) | :closed_lock_with_key: | GET | `/tradfi/orders/log/{log_id}` | +| [getStockUserAssets()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6647) | :closed_lock_with_key: | GET | `/stock/users/assets` | +| [getStockSymbols()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6659) | | GET | `/stock/symbols` | +| [getStockSymbolDetail()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6671) | :closed_lock_with_key: | GET | `/stock/symbols/detail` | +| [getStockOrderBook()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6683) | | GET | `/stock/market/{symbol}/orderbook` | +| [getStockOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6693) | :closed_lock_with_key: | GET | `/stock/orders` | +| [createStockOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6707) | :closed_lock_with_key: | POST | `/stock/orders` | +| [cancelAllStockOrders()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6718) | :closed_lock_with_key: | DELETE | `/stock/orders` | +| [getStockOrderHistory()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6728) | :closed_lock_with_key: | GET | `/stock/orders/history` | +| [updateStockOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6741) | :closed_lock_with_key: | PUT | `/stock/orders/{orderId}` | +| [cancelStockOrder()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6754) | :closed_lock_with_key: | DELETE | `/stock/orders/{orderId}` | +| [getStockPositions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6766) | :closed_lock_with_key: | GET | `/stock/positions` | +| [closeStockPosition()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6778) | :closed_lock_with_key: | POST | `/stock/positions/close` | +| [getStockTransactions()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6790) | :closed_lock_with_key: | GET | `/stock/transactions` | +| [createStockTransaction()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6804) | :closed_lock_with_key: | POST | `/stock/transactions` | +| [getStockExchanges()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6815) | | GET | `/stock/exchanges` | +| [getStockFeeRate()](https://github.com/sieblyio/gateio-api/blob/master/src/RestClient.ts#L6826) | | GET | `/stock/fee-rate` | # WebsocketAPIClient.ts diff --git a/llms.txt b/llms.txt index 7471790..cc48ae3 100644 --- a/llms.txt +++ b/llms.txt @@ -296,605 +296,1040 @@ export interface WsStoredState { /** To reauthenticate on the WS API, which channel do we send to? */ ================ -File: src/lib/logger.ts +File: src/lib/BaseWSClient.ts ================ -export type LogParams = null | any; +import EventEmitter from 'events'; +import WebSocket from 'isomorphic-ws'; ⋮---- -// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { + WebsocketClientOptions, + WSClientConfigurableOptions, +} from '../types/websockets/client.js'; +import { WsOperation } from '../types/websockets/requests.js'; +import { WS_LOGGER_CATEGORY } from '../WebsocketClient.js'; +import { DefaultLogger } from './logger.js'; +import { isMessageEvent, MessageEventLike } from './requestUtils.js'; +import { checkWebCryptoAPISupported } from './webCryptoAPI.js'; +import { + safeTerminateWs, + WsTopicRequest, + WsTopicRequestOrStringTopic, +} from './websocket/websocket-util.js'; +import { WsStore } from './websocket/WsStore.js'; +import { + WSConnectedResult, + WsConnectionStateEnum, +} from './websocket/WsStore.types.js'; ⋮---- -// console.log(_params); +interface WSClientEventMap { + /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */ + open: (evt: { + wsKey: WsKey; + event: any; + wsUrl: string; + ws: WebSocket; + }) => void /** Reconnecting a dropped connection */; + reconnect: (evt: { wsKey: WsKey; event: any }) => void; + /** Successfully reconnected a connection that dropped */ + reconnected: (evt: { + wsKey: WsKey; + event: any; + wsUrl: string; + ws: WebSocket; + }) => void; + /** Connection closed */ + close: (evt: { wsKey: WsKey; event: any }) => void; + /** Received reply to websocket command (e.g. after subscribing to topics) */ + response: (response: any & { wsKey: WsKey }) => void; + /** Received data for topic */ + update: (response: any & { wsKey: WsKey }) => void; + /** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */ + exception: (response: any & { wsKey: WsKey }) => void; + error: (response: any & { wsKey: WsKey }) => void; + /** Confirmation that a connection successfully authenticated */ + authenticated: (event: { wsKey: WsKey; event: any }) => void; +} ⋮---- -export type DefaultLogger = typeof DefaultLogger; - -================ -File: src/lib/misc-util.ts -================ -export function neverGuard(x: never, msg: string): Error +/** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */ +⋮---- +}) => void /** Reconnecting a dropped connection */; +⋮---- +/** Successfully reconnected a connection that dropped */ +⋮---- +/** Connection closed */ +⋮---- +/** Received reply to websocket command (e.g. after subscribing to topics) */ +⋮---- +/** Received data for topic */ +⋮---- +/** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */ +⋮---- +/** Confirmation that a connection successfully authenticated */ +⋮---- +export interface EmittableEvent { + eventType: 'response' | 'update' | 'exception' | 'authenticated'; + event: TEvent; +} +⋮---- +// Type safety for on and emit handlers: https://stackoverflow.com/a/61609010/880837 +export interface BaseWebsocketClient { + on>( + event: U, + listener: WSClientEventMap[U], + ): this; -================ -File: src/lib/webCryptoAPI.ts -================ -import { neverGuard } from './misc-util.js'; + emit>( + event: U, + ...args: Parameters[U]> + ): boolean; +} ⋮---- -function bufferToB64(buffer: ArrayBuffer): string +on>( + event: U, + listener: WSClientEventMap[U], + ): this; ⋮---- -export type SignEncodeMethod = 'hex' | 'base64'; -export type SignAlgorithm = 'SHA-256' | 'SHA-512'; +emit>( + event: U, + ...args: Parameters[U]> + ): boolean; ⋮---- /** - * Similar to node crypto's `createHash()` function + * Users can conveniently pass topics as strings or objects (object has topic name + optional params). + * + * This method normalises topics into objects (object has topic name + optional params). */ -export async function hashMessage( - message: string, - method: SignEncodeMethod, - algorithm: SignAlgorithm, -): Promise +function getNormalisedTopicRequests( + wsTopicRequests: WsTopicRequestOrStringTopic[], +): WsTopicRequest[] +⋮---- +// passed as string, convert to object +⋮---- +// already a normalised object, thanks to user ⋮---- /** - * Sign a message, with a secret, using the Web Crypto API + * Base WebSocket abstraction layer. Handles connections, tracking each connection as a unique "WS Key" */ -export async function signMessage( - message: string, - secret: string, - method: SignEncodeMethod, - algorithm: SignAlgorithm, -): Promise +// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging +export abstract class BaseWebsocketClient< ⋮---- -export function checkWebCryptoAPISupported() - -================ -File: src/types/request/account.ts -================ -/**========================================================================================================================== - * ACCOUNT - * ========================================================================================================================== - */ +/** + * The WS connections supported by the client, each identified by a unique primary key + */ ⋮---- -export interface CreateStpGroupReq { - name: string; - id?: number; - creator_id?: number; - create_time?: number; -} - -================ -File: src/types/request/collateralLoan.ts -================ -/**========================================================================================================================== - * COLLATERAL LOAN - * ========================================================================================================================== - */ +/** + * State store to track a list of topics (topic requests) we are expected to be subscribed to if reconnected + */ ⋮---- -export interface SubmitLoanOrderReq { - collateral_amount: string; - collateral_currency: string; - borrow_amount: string; - borrow_currency: string; -} +constructor( + options?: WSClientConfigurableOptions, + logger?: typeof DefaultLogger, +) ⋮---- -export interface GetLoanOrdersReq { - page?: number; - limit?: number; - collateral_currency?: string; - borrow_currency?: string; -} +// Some defaults: ⋮---- -export interface GetLoanRepaymentHistoryReq { - source: 'repay' | 'liquidate'; - borrow_currency?: string; - collateral_currency?: string; - page?: number; - limit?: number; - from?: number; - to?: number; -} +// Gate.io only has one connection (for both public & private). Auth works with every sub, not on connect, so this is turned off. ⋮---- -export interface UpdateLoanCollateralReq { - order_id: number; - collateral_currency: string; - collateral_amount: string; - type: 'append' | 'redeem'; -} +// Gate.io requires auth to be added to every request, when subscribing to private topics. This is handled automatically. ⋮---- -export interface GetLoanCollateralRecordsReq { - page?: number; - limit?: number; - from?: number; - to?: number; - borrow_currency?: string; - collateral_currency?: string; -} - -================ -File: src/types/request/delivery.ts -================ -/**========================================================================================================================== - * DELIVERY - * ========================================================================================================================== - */ +// Automatically re-auth WS API, if we were auth'd before and get reconnected ⋮---- -export interface GetDeliveryOrderBookReq { - settle: 'usdt'; - contract: string; - interval?: '0' | '0.1' | '0.01'; - limit?: number; - with_id?: boolean; -} +// Check Web Crypto API support when credentials are provided and no custom sign function is used ⋮---- -export interface GetDeliveryTradesReq { - settle: 'usdt'; - contract: string; - limit?: number; - last_id?: string; - from?: number; - to?: number; -} +protected abstract isAuthOnConnectWsKey(wsKey: TWSKey): boolean; ⋮---- -export interface GetDeliveryCandlesReq { - settle: 'usdt'; - contract: string; - from?: number; - to?: number; - limit?: number; - interval?: - | '10s' - | '30s' - | '1m' - | '5m' - | '15m' - | '30m' - | '1h' - | '2h' - | '4h' - | '6h' - | '8h' - | '12h' - | '1d' - | '7d' - | '1w' - | '30d'; -} +protected abstract sendPingEvent(wsKey: TWSKey, ws: WebSocket): void; ⋮---- -export interface GetDeliveryBookReq { - settle: 'usdt'; - limit?: number; - from?: number; - to?: number; - type?: - | 'dnw' - | 'pnl' - | 'fee' - | 'refr' - | 'fund' - | 'point_dnw' - | 'point_fee' - | 'point_refr' - | 'bonus_offset'; -} +protected abstract sendPongEvent(wsKey: TWSKey, ws: WebSocket): void; ⋮---- -export interface SubmitDeliveryFuturesOrderReq { - settle: 'usdt'; - contract: string; - size: number; - iceberg?: number; - price?: string; - close?: boolean; - reduce_only?: boolean; - tif?: string; - text?: string; - auto_size?: string; - stp_act?: string; -} +protected abstract isWsPing(data: any): boolean; ⋮---- -export interface GetDeliveryOrdersReq { - settle: 'usdt'; - contract?: string; - status: 'open' | 'finished'; - limit?: number; - offset?: number; - last_id?: string; - count_total?: 0 | 1; -} +protected abstract isWsPong(data: any): boolean; ⋮---- -export interface GetDeliveryTradingHistoryReq { - settle: 'usdt'; - contract?: string; - order?: number; - limit?: number; - offset?: number; - last_id?: string; - count_total?: 0 | 1; -} +protected abstract getWsAuthRequestEvent(wsKey: TWSKey): Promise; ⋮---- -export interface GetDeliveryClosedPositionsReq { - settle: 'usdt'; - contract?: string; - limit?: number; -} +protected abstract isPrivateTopicRequest( + request: WsTopicRequest, + wsKey: TWSKey, + ): boolean; ⋮---- -export interface GetDeliveryLiquidationHistoryReq { - settle: 'usdt'; - contract?: string; - limit?: number; - at?: number; -} +protected abstract getPrivateWSKeys(): TWSKey[]; ⋮---- -export interface GetDeliverySettlementHistoryReq { - settle: 'usdt'; - contract?: string; - limit?: number; - at?: number; -} -export interface GetDeliveryAutoOrdersReq { - settle: 'usdt'; - status: 'open' | 'finished'; - contract?: string; - limit?: number; - offset?: number; -} - -================ -File: src/types/request/earnuni.ts -================ -/**========================================================================================================================== - * EARN UNI - * ========================================================================================================================== - */ +protected abstract getWsUrl(wsKey: TWSKey): string; ⋮---- -export interface SubmitLendOrRedeemReq { - currency: string; - amount: string; - type: 'lend' | 'redeem'; - min_rate?: string; -} +protected abstract getMaxTopicsPerSubscribeEvent( + wsKey: TWSKey, + ): number | null; ⋮---- -export interface GetLendingOrdersReq { - currency?: string; - page?: number; - limit?: number; -} +/** + * Returns a list of string events that can be individually sent upstream to complete subscribing/unsubscribing/etc to these topics + */ +protected abstract getWsOperationEventsForTopics( + topics: WsTopicRequest[], + wsKey: TWSKey, + operation: WsOperation, + ): Promise; ⋮---- -export interface GetLendingRecordsReq { - currency?: string; - page?: number; - limit?: number; - from?: number; - to?: number; - type?: 'lend' | 'redeem'; -} +/** + * Abstraction called to sort ws events into emittable event types (response to a request, data update, etc) + */ +protected abstract resolveEmittableEvents( + wsKey: TWSKey, + event: MessageEventLike, + ): EmittableEvent[]; ⋮---- -export interface GetLendingInterestRecordsReq { - currency?: string; - page?: number; - limit?: number; - from?: number; - to?: number; -} - -================ -File: src/types/request/flashswap.ts -================ -/**========================================================================================================================== - * FLASH SWAP - * ========================================================================================================================== - */ +/** + * Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library + */ +protected abstract connectAll(): Promise[]; ⋮---- -export interface SubmitFlashSwapOrderReq { - preview_id: string; - sell_currency: string; - sell_amount: string; - buy_currency: string; - buy_amount: string; -} +protected isPrivateWsKey(wsKey: TWSKey): boolean ⋮---- -export interface GetFlashSwapOrdersReq { - status?: number; - sell_currency?: string; - buy_currency?: string; - reverse?: boolean; - limit?: number; - page?: number; -} +/** Returns auto-incrementing request ID, used to track promise references for async requests */ +protected getNewRequestId(): string ⋮---- -export interface GetFlashSwapOrderReq { - order_id: number; -} +protected abstract sendWSAPIRequest( + wsKey: TWSKey, + channel: string, + params?: any, + ): Promise; ⋮---- -export interface SubmitFlashSwapOrderPreviewReq { - sell_currency: string; - sell_amount?: string; - buy_currency: string; - buy_amount?: string; -} - -================ -File: src/types/request/margin.ts -================ -/**========================================================================================================================== - * MARGIN - * ========================================================================================================================== - */ +protected abstract sendWSAPIRequest( + wsKey: TWSKey, + channel: string, + params: any, + ): Promise; ⋮---- -export interface GetMarginBalanceHistoryReq { - currency?: string; - currency_pair?: string; - type?: string; - from?: number; - to?: number; - page?: number; - limit?: number; -} +public getTimeOffsetMs() ⋮---- -export interface GetCrossMarginAccountHistoryReq { - currency?: string; - from?: number; - to?: number; - page?: number; - limit?: number; - type?: string; -} +// TODO: not implemented +public setTimeOffsetMs(newOffset: number) ⋮---- -export interface SubmitCrossMarginBorrowLoanReq { - currency: string; - amount: string; - text?: string; -} +/** + * Don't call directly! Use subscribe() instead! + * + * Subscribe to one or more topics on a WS connection (identified by WS Key). + * + * - Topics are automatically cached + * - Connections are automatically opened, if not yet connected + * - Authentication is automatically handled + * - Topics are automatically resubscribed to, if something happens to the connection, unless you call unsubsribeTopicsForWsKey(topics, key). + * + * @param wsRequests array of topics to subscribe to + * @param wsKey ws key referring to the ws connection these topics should be subscribed on + */ +protected subscribeTopicsForWsKey( + wsTopicRequests: WsTopicRequestOrStringTopic[], + wsKey: TWSKey, +) ⋮---- -export interface GetCrossMarginBorrowHistoryReq { - status: number; - currency?: string; - limit?: number; - offset?: number; - reverse?: boolean; -} +// Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically ⋮---- -export interface GetCrossMarginRepaymentsReq { - currency?: string; - loan_id?: string; - limit?: number; - offset?: number; - reverse?: boolean; -} +// start connection process if it hasn't yet begun. Topics are automatically subscribed to on-connect ⋮---- -export interface GetCrossMarginInterestRecordsReq { - currency?: string; - page?: number; - limit?: number; - from?: number; - to?: number; -} - -================ -File: src/types/request/marginuni.ts -================ -/**========================================================================================================================== - * MARGIN UNI - * ========================================================================================================================== - */ +// Subscribe should happen automatically once connected, nothing to do here after topics are added to wsStore. ⋮---- -export interface GetMarginUNILoansReq { - currency_pair?: string; - currency?: string; - page?: number; - limit?: number; -} +/** + * Are we in the process of connection? Nothing to send yet. + */ ⋮---- -export interface GetMarginUNILoanRecordsReq { - type?: 'borrow' | 'repay'; - currency?: string; - currency_pair?: string; - page?: number; - limit?: number; -} +// We're connected. Check if auth is needed and if already authenticated ⋮---- -export interface GetMarginUNIInterestRecordsReq { - currency_pair?: string; - currency?: string; - page?: number; - limit?: number; - from?: number; - to?: number; -} +/** + * If not authenticated yet and auth is required, don't request topics yet. + * + * Auth should already automatically be in progress, so no action needed from here. Topics will automatically subscribe post-auth success. + */ ⋮---- -export interface GetMarginUNIMaxBorrowReq { - currency: string; - currency_pair: string; -} - -================ -File: src/types/request/multicollateralLoan.ts -================ -/**========================================================================================================================== - * MULTI COLLATERAL LOAN - * ========================================================================================================================== - */ +// Finally, request subscription to topics if the connection is healthy and ready ⋮---- -export interface SubmitMultiLoanOrderReq { - order_id?: string; - order_type?: string; - fixed_type?: string; - fixed_rate?: string; - auto_renew?: boolean; - auto_repay?: boolean; - borrow_currency: string; - borrow_amount: string; - collateral_currencies?: { - currency?: string; - amount?: string; - }[]; -} -export interface GetMultiLoanOrdersReq { - page?: number; - limit?: number; - sort?: string; - order_type?: string; -} +protected unsubscribeTopicsForWsKey( + wsTopicRequests: WsTopicRequestOrStringTopic[], + wsKey: TWSKey, +) ⋮---- -export interface RepayMultiLoanReq { - order_id: number; - repay_items: { - currency?: string; - amount?: string; - repaid_all?: boolean; - }[]; -} +// Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically ⋮---- -export interface GetMultiLoanRepayRecordsReq { - type: 'repay' | 'liquidate'; - borrow_currency?: string; - page?: number; - limit?: number; - from?: number; - to?: number; -} +// If not connected, don't need to do anything. +// Removing the topic from the store is enough to stop it from being resubscribed to on reconnect. ⋮---- -export interface UpdateMultiLoanReq { - order_id: number; - type: 'append' | 'redeem'; - collaterals?: { - currency?: string; - amount?: string; - }[]; -} +// We're connected. Check if auth is needed and if already authenticated ⋮---- -export interface GetMultiLoanAdjustmentRecordsReq { - page?: number; - limit?: number; - from?: number; - to?: number; - collateral_currency?: string; -} - -================ -File: src/types/request/subaccount.ts -================ -export interface CreateSubAccountReq { - login_name: string; - remark?: string; - password?: string; - email?: string; -} +/** + * If not authenticated yet and auth is required, don't need to do anything. + * We don't subscribe to topics until auth is complete anyway. + */ ⋮---- -export interface CreateSubAccountApiKeyReq { - user_id: number; - mode?: number; // Mode: 1 - classic, 2 - portfolio account - name?: string; // API key name - perms?: { - name?: - | 'wallet' - | 'spot' - | 'futures' - | 'delivery' - | 'earn' - | 'options' - | 'account' - | 'unified' - | 'loan'; // Permission name - read_only?: boolean; // Read only - }[]; - ip_whitelist?: string[]; // IP white list -} +// Finally, request subscription to topics if the connection is healthy and ready ⋮---- -mode?: number; // Mode: 1 - classic, 2 - portfolio account -name?: string; // API key name +/** + * Splits topic requests into two groups, public & private topic requests + */ +private sortTopicRequestsIntoPublicPrivate( + wsTopicRequests: WsTopicRequest[], + wsKey: TWSKey, +): ⋮---- -| 'loan'; // Permission name -read_only?: boolean; // Read only +/** Get the WsStore that tracks websockets & topics */ +public getWsStore(): WsStore> ⋮---- -ip_whitelist?: string[]; // IP white list +public close(wsKey: TWSKey, force?: boolean) ⋮---- -export type UpdateSubAccountApiKeyReq = { - key: string; -} & CreateSubAccountApiKeyReq; - -================ -File: src/types/request/withdrawal.ts -================ -/**================================================================================================================================ - * WITHDRAW - * ========================================================================================================================== - */ +public closeAll(force?: boolean) ⋮---- -export interface SubmitWithdrawalReq { - amount: string; - currency: string; - chain: string; - withdraw_order_id?: string; - address?: string; - memo?: string; -} - -================ -File: src/types/response/account.ts -================ -/**========================================================================================================================== - * ACCOUNT - * ========================================================================================================================== - */ +public isConnected(wsKey: TWSKey): boolean ⋮---- -export interface AccountDetail { - user_id: number; - ip_whitelist: string[]; - currency_pairs: string[]; - key: { - mode: number; - }; - tier: number; - copy_trading_role: number; -} +/** + * Request connection to a specific websocket, instead of waiting for automatic connection. + */ +protected async connect( + wsKey: TWSKey, +): Promise ⋮---- -export interface AccountRateLimit { - type: string; - tier: string; - ratio: string; - main_ratio: string; - updated_at: string; -} +private connectToWsUrl(url: string, wsKey: TWSKey): WebSocket ⋮---- -export interface StpGroup { - id: number; - name: string; - creator_id: number; - create_time: number; -} +private parseWsError(context: string, error: any, wsKey: TWSKey) ⋮---- -export interface StpGroupUser { - user_id: number; - stp_id: number; - create_time: number; -} +/** Get a signature, build the auth request and send it */ +private async sendAuthRequest(wsKey: TWSKey): Promise ⋮---- -export interface AccountMainKey { - state: number; // 1 - Normal, 2 - Locked, 3 - Frozen - mode: number; // 1 - Classic, 2 - Legacy Unified - name: string; - currency_pairs: string[]; - user_id: number; - ip_whitelist: string[]; - perms: { - name: string; - read_only: boolean; - }[]; - key: string; - created_at: string; - updated_at: string; - last_access: string; -} +// console.log('ws auth req', request); ⋮---- -state: number; // 1 - Normal, 2 - Locked, 3 - Frozen -mode: number; // 1 - Classic, 2 - Legacy Unified - -================ -File: src/types/response/collateralloan.ts -================ -/**========================================================================================================================== - * COLLATERAL LOAN - * ========================================================================================================================== - */ +private reconnectWithDelay(wsKey: TWSKey, connectionDelayMs: number) ⋮---- -export interface LoanOrder { - order_id: number; - collateral_currency: string; +private ping(wsKey: TWSKey) +⋮---- +private clearTimers(wsKey: TWSKey) +⋮---- +// Send a ping at intervals +private clearPingTimer(wsKey: TWSKey) +⋮---- +// Expect a pong within a time limit +private clearPongTimer(wsKey: TWSKey) +⋮---- +// this.logger.trace(`Cleared pong timeout for "${wsKey}"`); +⋮---- +// this.logger.trace(`No active pong timer for "${wsKey}"`); +⋮---- +/** + * Simply builds and sends subscribe events for a list of topics for a ws key + * + * @private Use the `subscribe(topics)` or `subscribeTopicsForWsKey(topics, wsKey)` method to subscribe to topics. Send WS message to subscribe to topics. + */ +private async requestSubscribeTopics( + wsKey: TWSKey, + topics: WsTopicRequest[], +) +⋮---- +// Automatically splits requests into smaller batches, if needed +⋮---- +`Subscribing to ${topics.length} "${wsKey}" topics in ${subscribeWsMessages.length} batches.`, // Events: "${JSON.stringify(topics)}" +⋮---- +// console.log(`batches: `, JSON.stringify(subscribeWsMessages, null, 2)); +⋮---- +// this.logger.trace(`Sending batch via message: "${wsMessage}"`); +⋮---- +/** + * Simply builds and sends unsubscribe events for a list of topics for a ws key + * + * @private Use the `unsubscribe(topics)` method to unsubscribe from topics. Send WS message to unsubscribe from topics. + */ +private async requestUnsubscribeTopics( + wsKey: TWSKey, + wsTopicRequests: WsTopicRequest[], +) +⋮---- +/** + * Try sending a string event on a WS connection (identified by the WS Key) + */ +public tryWsSend( + wsKey: TWSKey, + wsMessage: string, + throwExceptions?: boolean, +) +⋮---- +private async onWsOpen( + event: any, + wsKey: TWSKey, + url: string, + ws: WebSocket, +) +⋮---- +// Resolve & cleanup deferred "connection attempt in progress" promise +⋮---- +// eslint-disable-next-line @typescript-eslint/no-unused-vars +⋮---- +// Remove before resolving, in case there's more requests queued +⋮---- +// Some websockets require an auth packet to be sent after opening the connection +⋮---- +// Reconnect to topics known before it connected +⋮---- +// Request sub to public topics, if any +⋮---- +// Request sub to private topics, if auth on connect isn't needed +⋮---- +// If enabled, automatically reauth WS API if reconnected +⋮---- +// eslint-disable-next-line @typescript-eslint/no-unused-vars +⋮---- +/** + * Handle subscription to private topics _after_ authentication successfully completes asynchronously. + * + * Only used for exchanges that require auth before sending private topic subscription requests + */ +private onWsAuthenticated( + wsKey: TWSKey, + event: { isWSAPI?: boolean; WSAPIAuthChannel?: string }, +) +⋮---- +// Resolve & cleanup deferred "auth attempt in progress" promise +⋮---- +// Remove before continuing, in case there's more requests queued +⋮---- +private onWsMessage(event: unknown, wsKey: TWSKey, ws: WebSocket) +⋮---- +// any message can clear the pong timer - wouldn't get a message if the ws wasn't working +⋮---- +// console.log(`raw event: `, { data, dataType, emittableEvents }); +⋮---- +private onWsClose(event: unknown, wsKey: TWSKey) +⋮---- +// unintentional close, attempt recovery +⋮---- +// clean up any pending promises for this connection +⋮---- +// intentional close - clean up +// clean up any pending promises for this connection +⋮---- +// clean up any pending promises for this connection +⋮---- +// This was an intentional close, delete all state for this connection, as if it never existed: +⋮---- +private getWs(wsKey: TWSKey) +⋮---- +private setWsState(wsKey: TWSKey, state: WsConnectionStateEnum) +⋮---- +/** + * Promise-driven method to assert that a ws has successfully connected (will await until connection is open) + */ +protected async assertIsConnected(wsKey: TWSKey): Promise +⋮---- +// Already in progress? Await shared promise and retry +⋮---- +// Start connection, it should automatically store/return a promise. +⋮---- +/** + * Promise-driven method to assert that a ws has been successfully authenticated (will await until auth is confirmed) + */ +public async assertIsAuthenticated(wsKey: TWSKey): Promise +⋮---- +// Already in progress? Await shared promise and retry +⋮---- +// this.logger.trace('assertIsAuthenticated(): ok'); +⋮---- +// Start authentication, it should automatically store/return a promise. + +================ +File: src/lib/logger.ts +================ +export type LogParams = null | any; +⋮---- +// eslint-disable-next-line @typescript-eslint/no-unused-vars +⋮---- +// console.log(_params); +⋮---- +export type DefaultLogger = typeof DefaultLogger; + +================ +File: src/lib/misc-util.ts +================ +export function neverGuard(x: never, msg: string): Error + +================ +File: src/lib/webCryptoAPI.ts +================ +import { neverGuard } from './misc-util.js'; +⋮---- +function bufferToB64(buffer: ArrayBuffer): string +⋮---- +export type SignEncodeMethod = 'hex' | 'base64'; +export type SignAlgorithm = 'SHA-256' | 'SHA-512'; +⋮---- +/** + * Similar to node crypto's `createHash()` function + */ +export async function hashMessage( + message: string, + method: SignEncodeMethod, + algorithm: SignAlgorithm, +): Promise +⋮---- +/** + * Sign a message, with a secret, using the Web Crypto API + */ +export async function signMessage( + message: string, + secret: string, + method: SignEncodeMethod, + algorithm: SignAlgorithm, +): Promise +⋮---- +export function checkWebCryptoAPISupported() + +================ +File: src/types/request/account.ts +================ +/**========================================================================================================================== + * ACCOUNT + * ========================================================================================================================== + */ +⋮---- +export interface CreateStpGroupReq { + name: string; + id?: number; + creator_id?: number; + create_time?: number; +} + +================ +File: src/types/request/collateralLoan.ts +================ +/**========================================================================================================================== + * COLLATERAL LOAN + * ========================================================================================================================== + */ +⋮---- +export interface SubmitLoanOrderReq { + collateral_amount: string; + collateral_currency: string; + borrow_amount: string; + borrow_currency: string; +} +⋮---- +export interface GetLoanOrdersReq { + page?: number; + limit?: number; + collateral_currency?: string; + borrow_currency?: string; +} +⋮---- +export interface GetLoanRepaymentHistoryReq { + source: 'repay' | 'liquidate'; + borrow_currency?: string; + collateral_currency?: string; + page?: number; + limit?: number; + from?: number; + to?: number; +} +⋮---- +export interface UpdateLoanCollateralReq { + order_id: number; + collateral_currency: string; + collateral_amount: string; + type: 'append' | 'redeem'; +} +⋮---- +export interface GetLoanCollateralRecordsReq { + page?: number; + limit?: number; + from?: number; + to?: number; + borrow_currency?: string; + collateral_currency?: string; +} + +================ +File: src/types/request/delivery.ts +================ +/**========================================================================================================================== + * DELIVERY + * ========================================================================================================================== + */ +⋮---- +export interface GetDeliveryOrderBookReq { + settle: 'usdt'; + contract: string; + interval?: '0' | '0.1' | '0.01'; + limit?: number; + with_id?: boolean; +} +⋮---- +export interface GetDeliveryTradesReq { + settle: 'usdt'; + contract: string; + limit?: number; + last_id?: string; + from?: number; + to?: number; +} +⋮---- +export interface GetDeliveryCandlesReq { + settle: 'usdt'; + contract: string; + from?: number; + to?: number; + limit?: number; + interval?: + | '10s' + | '30s' + | '1m' + | '5m' + | '15m' + | '30m' + | '1h' + | '2h' + | '4h' + | '6h' + | '8h' + | '12h' + | '1d' + | '7d' + | '1w' + | '30d'; +} +⋮---- +export interface GetDeliveryBookReq { + settle: 'usdt'; + limit?: number; + from?: number; + to?: number; + type?: + | 'dnw' + | 'pnl' + | 'fee' + | 'refr' + | 'fund' + | 'point_dnw' + | 'point_fee' + | 'point_refr' + | 'bonus_offset'; +} +⋮---- +export interface SubmitDeliveryFuturesOrderReq { + settle: 'usdt'; + contract: string; + size: number; + iceberg?: number; + price?: string; + close?: boolean; + reduce_only?: boolean; + tif?: string; + text?: string; + auto_size?: string; + stp_act?: string; +} +⋮---- +export interface GetDeliveryOrdersReq { + settle: 'usdt'; + contract?: string; + status: 'open' | 'finished'; + limit?: number; + offset?: number; + last_id?: string; + count_total?: 0 | 1; +} +⋮---- +export interface GetDeliveryTradingHistoryReq { + settle: 'usdt'; + contract?: string; + order?: number; + limit?: number; + offset?: number; + last_id?: string; + count_total?: 0 | 1; +} +⋮---- +export interface GetDeliveryClosedPositionsReq { + settle: 'usdt'; + contract?: string; + limit?: number; +} +⋮---- +export interface GetDeliveryLiquidationHistoryReq { + settle: 'usdt'; + contract?: string; + limit?: number; + at?: number; +} +⋮---- +export interface GetDeliverySettlementHistoryReq { + settle: 'usdt'; + contract?: string; + limit?: number; + at?: number; +} +export interface GetDeliveryAutoOrdersReq { + settle: 'usdt'; + status: 'open' | 'finished'; + contract?: string; + limit?: number; + offset?: number; +} + +================ +File: src/types/request/earnuni.ts +================ +/**========================================================================================================================== + * EARN UNI + * ========================================================================================================================== + */ +⋮---- +export interface SubmitLendOrRedeemReq { + currency: string; + amount: string; + type: 'lend' | 'redeem'; + min_rate?: string; +} +⋮---- +export interface GetLendingOrdersReq { + currency?: string; + page?: number; + limit?: number; +} +⋮---- +export interface GetLendingRecordsReq { + currency?: string; + page?: number; + limit?: number; + from?: number; + to?: number; + type?: 'lend' | 'redeem'; +} +⋮---- +export interface GetLendingInterestRecordsReq { + currency?: string; + page?: number; + limit?: number; + from?: number; + to?: number; +} + +================ +File: src/types/request/flashswap.ts +================ +/**========================================================================================================================== + * FLASH SWAP + * ========================================================================================================================== + */ +⋮---- +export interface SubmitFlashSwapOrderReq { + preview_id: string; + sell_currency: string; + sell_amount: string; + buy_currency: string; + buy_amount: string; +} +⋮---- +export interface GetFlashSwapOrdersReq { + status?: number; + sell_currency?: string; + buy_currency?: string; + reverse?: boolean; + limit?: number; + page?: number; +} +⋮---- +export interface GetFlashSwapOrderReq { + order_id: number; +} +⋮---- +export interface SubmitFlashSwapOrderPreviewReq { + sell_currency: string; + sell_amount?: string; + buy_currency: string; + buy_amount?: string; +} + +================ +File: src/types/request/margin.ts +================ +/**========================================================================================================================== + * MARGIN + * ========================================================================================================================== + */ +⋮---- +export interface GetMarginBalanceHistoryReq { + currency?: string; + currency_pair?: string; + type?: string; + from?: number; + to?: number; + page?: number; + limit?: number; +} +⋮---- +export interface GetCrossMarginAccountHistoryReq { + currency?: string; + from?: number; + to?: number; + page?: number; + limit?: number; + type?: string; +} +⋮---- +export interface SubmitCrossMarginBorrowLoanReq { + currency: string; + amount: string; + text?: string; +} +⋮---- +export interface GetCrossMarginBorrowHistoryReq { + status: number; + currency?: string; + limit?: number; + offset?: number; + reverse?: boolean; +} +⋮---- +export interface GetCrossMarginRepaymentsReq { + currency?: string; + loan_id?: string; + limit?: number; + offset?: number; + reverse?: boolean; +} +⋮---- +export interface GetCrossMarginInterestRecordsReq { + currency?: string; + page?: number; + limit?: number; + from?: number; + to?: number; +} + +================ +File: src/types/request/marginuni.ts +================ +/**========================================================================================================================== + * MARGIN UNI + * ========================================================================================================================== + */ +⋮---- +export interface GetMarginUNILoansReq { + currency_pair?: string; + currency?: string; + page?: number; + limit?: number; +} +⋮---- +export interface GetMarginUNILoanRecordsReq { + type?: 'borrow' | 'repay'; + currency?: string; + currency_pair?: string; + page?: number; + limit?: number; +} +⋮---- +export interface GetMarginUNIInterestRecordsReq { + currency_pair?: string; + currency?: string; + page?: number; + limit?: number; + from?: number; + to?: number; +} +⋮---- +export interface GetMarginUNIMaxBorrowReq { + currency: string; + currency_pair: string; +} + +================ +File: src/types/request/multicollateralLoan.ts +================ +/**========================================================================================================================== + * MULTI COLLATERAL LOAN + * ========================================================================================================================== + */ +⋮---- +export interface SubmitMultiLoanOrderReq { + order_id?: string; + order_type?: string; + fixed_type?: string; + fixed_rate?: string; + auto_renew?: boolean; + auto_repay?: boolean; + borrow_currency: string; + borrow_amount: string; + collateral_currencies?: { + currency?: string; + amount?: string; + }[]; +} +export interface GetMultiLoanOrdersReq { + page?: number; + limit?: number; + sort?: string; + order_type?: string; +} +⋮---- +export interface RepayMultiLoanReq { + order_id: number; + repay_items: { + currency?: string; + amount?: string; + repaid_all?: boolean; + }[]; +} +⋮---- +export interface GetMultiLoanRepayRecordsReq { + type: 'repay' | 'liquidate'; + borrow_currency?: string; + page?: number; + limit?: number; + from?: number; + to?: number; +} +⋮---- +export interface UpdateMultiLoanReq { + order_id: number; + type: 'append' | 'redeem'; + collaterals?: { + currency?: string; + amount?: string; + }[]; +} +⋮---- +export interface GetMultiLoanAdjustmentRecordsReq { + page?: number; + limit?: number; + from?: number; + to?: number; + collateral_currency?: string; +} + +================ +File: src/types/request/subaccount.ts +================ +export interface CreateSubAccountReq { + login_name: string; + remark?: string; + password?: string; + email?: string; +} +⋮---- +export interface CreateSubAccountApiKeyReq { + user_id: number; + mode?: number; // Mode: 1 - classic, 2 - portfolio account + name?: string; // API key name + perms?: { + name?: + | 'wallet' + | 'spot' + | 'futures' + | 'delivery' + | 'earn' + | 'options' + | 'account' + | 'unified' + | 'loan'; // Permission name + read_only?: boolean; // Read only + }[]; + ip_whitelist?: string[]; // IP white list +} +⋮---- +mode?: number; // Mode: 1 - classic, 2 - portfolio account +name?: string; // API key name +⋮---- +| 'loan'; // Permission name +read_only?: boolean; // Read only +⋮---- +ip_whitelist?: string[]; // IP white list +⋮---- +export type UpdateSubAccountApiKeyReq = { + key: string; +} & CreateSubAccountApiKeyReq; + +================ +File: src/types/request/withdrawal.ts +================ +/**================================================================================================================================ + * WITHDRAW + * ========================================================================================================================== + */ +⋮---- +export interface SubmitWithdrawalReq { + amount: string; + currency: string; + chain: string; + withdraw_order_id?: string; + address?: string; + memo?: string; +} + +================ +File: src/types/response/account.ts +================ +/**========================================================================================================================== + * ACCOUNT + * ========================================================================================================================== + */ +⋮---- +export interface AccountDetail { + user_id: number; + ip_whitelist: string[]; + currency_pairs: string[]; + key: { + mode: number; + }; + tier: number; + copy_trading_role: number; +} +⋮---- +export interface AccountRateLimit { + type: string; + tier: string; + ratio: string; + main_ratio: string; + updated_at: string; +} +⋮---- +export interface StpGroup { + id: number; + name: string; + creator_id: number; + create_time: number; +} +⋮---- +export interface StpGroupUser { + user_id: number; + stp_id: number; + create_time: number; +} +⋮---- +export interface AccountMainKey { + state: number; // 1 - Normal, 2 - Locked, 3 - Frozen + mode: number; // 1 - Classic, 2 - Legacy Unified + name: string; + currency_pairs: string[]; + user_id: number; + ip_whitelist: string[]; + perms: { + name: string; + read_only: boolean; + }[]; + key: string; + created_at: string; + updated_at: string; + last_access: string; +} +⋮---- +state: number; // 1 - Normal, 2 - Locked, 3 - Frozen +mode: number; // 1 - Classic, 2 - Legacy Unified + +================ +File: src/types/response/collateralloan.ts +================ +/**========================================================================================================================== + * COLLATERAL LOAN + * ========================================================================================================================== + */ +⋮---- +export interface LoanOrder { + order_id: number; + collateral_currency: string; collateral_amount: string; borrow_currency: string; borrow_amount: string; @@ -3795,2603 +4230,2541 @@ import { LogParams, WebsocketClient, WsTopicRequest } from '../../src/index.js'; // Uncomment the line below to enable trace logging // console.log(new Date(), 'trace', ...params); ⋮---- -// Info level logging: used for general informational messages -⋮---- -// Error level logging: used for error messages -⋮---- -async function start() -⋮---- -// console.log('auth with: ', account); -⋮---- -// Data received -⋮---- -// Something happened, attempting to reconnect -⋮---- -// Reconnect successful -⋮---- -// Connection closed. If unexpected, expect reconnect -> reconnected. -⋮---- -// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate" -⋮---- -// TODO: many private topics use your user ID -⋮---- -/** - * Either send one topic (with params) at a time - */ -// client.subscribe({ -// topic: 'futures.usertrades', -// payload: [myUserID, '!all'], -// }, 'perpFuturesUSDTV4'); -⋮---- -/** - * Or send multiple topics in a batch (grouped by ws connection (WsKey)) - * You can also use strings for topics that don't have any parameters, even if you mix multiple requests into one function call: - */ - -================ -File: examples/Websocket/ws-private-spot.ts -================ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { LogParams, WebsocketClient, WsTopicRequest } from '../../src/index.js'; -// import { LogParams, WebsocketClient, WsTopicRequest } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` -⋮---- -// eslint-disable-next-line @typescript-eslint/no-unused-vars -⋮---- -// Define a custom logger object to handle logging at different levels -⋮---- -// Trace level logging: used for detailed debugging information -⋮---- -// Uncomment the line below to enable trace logging -// console.log(new Date(), 'trace', ...params); -⋮---- -// Info level logging: used for general informational messages -⋮---- -// Error level logging: used for error messages -⋮---- -async function start() -⋮---- -// console.log('auth with: ', account); -⋮---- -// Data received -⋮---- -// Something happened, attempting to reconnect -⋮---- -// Reconnect successful -⋮---- -// Connection closed. If unexpected, expect reconnect -> reconnected. -⋮---- -// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate" -⋮---- -// client.subscribe(topics, 'spotV4'); -⋮---- -// This has the same effect as above, it's just a different way of messaging which topic this is for -// const topicWithoutParamsAsObject: WsTopicRequest = { -// topic: 'spot.balances', -// }; -⋮---- -/** - * Either send one topic (with optional params) at a time - */ -// client.subscribe(topicWithoutParamsAsObject, 'spotV4'); -⋮---- -/** - * Or send multiple topics in a batch (grouped by ws connection (WsKey)) - * You can also use strings for topics that don't have any parameters, even if you mix multiple requests into one function call: - */ -⋮---- -/** - * You can also subscribe in separate function calls as you wish. - * - * Any duplicate requests should get filtered out (e.g. here we subscribed to "spot.balances" twice, but the WS client will filter this out) - */ - -================ -File: examples/Websocket/ws-public.ts -================ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { WebsocketClient, WsTopicRequest } from '../../src/index.js'; -// import { LogParams, WebsocketClient, WsTopicRequest } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` -⋮---- -// const customLogger = { -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// trace: (...params: LogParams): void => { -// console.log('trace', ...params); -// }, -// info: (...params: LogParams): void => { -// console.log('info', ...params); -// }, -// error: (...params: LogParams): void => { -// console.error('error', ...params); -// }, -// }; -⋮---- -async function start() -⋮---- -// Optional, inject a custom logger -// const client = new WebsocketClient({}, customLogger); -⋮---- -// Data received -⋮---- -// Something happened, attempting to reconnect -⋮---- -// Reconnect successful -⋮---- -// Connection closed. If unexpected, expect reconnect -> reconnected. -⋮---- -// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate" -⋮---- -// const topicWithoutParamsAsString = 'spot.balances'; -⋮---- -// This has the same effect as above, it's just a different way of messaging which topic this is for -// const topicWithoutParamsAsObject: WsTopicRequest = { -// topic: 'spot.balances', -// }; -⋮---- -/** - * Either send one topic (with optional params) at a time - */ -// client.subscribe(tickersRequestWithParams, 'spotV4'); -⋮---- -/** - * Or send multiple topics in a batch (grouped by ws connection (WsKey)) - */ -⋮---- -// /** -// * You can also use strings for topics that don't have any parameters, even if you mix multiple requests into one function call: -// */ -// client.subscribe( -// [tickersRequestWithParams, rawTradesRequestWithParams, topicWithoutParamsAsString], -// 'spotV4', -// ); - -================ -File: src/lib/websocket/websocket-util.ts -================ -import WebSocket from 'isomorphic-ws'; -⋮---- -import { WSAPIRequest } from '../../types/websockets/requests.js'; -import { - FuturesWSAPITopic, - SpotWSAPITopic, -} from '../../types/websockets/wsAPI.js'; -⋮---- -/** - * Should be one WS key per unique URL. Some URLs may need a suffix. - */ -⋮---- -/** - * Spot & Margin - * https://www.gate.io/docs/developers/apiv4/ws/en/ - */ -⋮---- -/** - * Perpetual futures (USDT) - * https://www.gate.io/docs/developers/futures/ws/en/#gate-io-futures-websocket-v4 - */ -⋮---- -/** - * Perpetual futures (BTC) - * https://www.gate.io/docs/developers/futures/ws/en/#gate-io-futures-websocket-v4 - */ -⋮---- -/** - * Delivery Futures (USDT) - * https://www.gate.io/docs/developers/delivery/ws/en/ - */ -⋮---- -/** - * Delivery Futures (BTC) - * https://www.gate.io/docs/developers/delivery/ws/en/ - */ -⋮---- -/** - * Options - * https://www.gate.io/docs/developers/options/ws/en/ - */ -⋮---- -/** - * Announcements V4 - * https://www.gate.io/docs/developers/options/ws/en/ - */ -⋮---- -/** This is used to differentiate between each of the available websocket streams */ -export type WsKey = (typeof WS_KEY_MAP)[keyof typeof WS_KEY_MAP]; -⋮---- -export type FuturesWsKey = - | typeof WS_KEY_MAP.perpFuturesUSDTV4 - | typeof WS_KEY_MAP.perpFuturesBTCV4 - | typeof WS_KEY_MAP.deliveryFuturesUSDTV4 - | typeof WS_KEY_MAP.deliveryFuturesBTCV4; -⋮---- -export type WsMarket = 'all'; -⋮---- -/** - * Normalised internal format for a request (subscribe/unsubscribe/etc) on a topic, with optional parameters. - * - * - Topic: the topic this event is for - * - Payload: the parameters to include, optional. E.g. auth requires key + sign. Some topics allow configurable parameters. - */ -export interface WsTopicRequest< - TWSTopic extends string = string, - TWSPayload = any, -> { - topic: TWSTopic; - payload?: TWSPayload; -} -⋮---- -/** - * Conveniently allow users to request a topic either as string topics or objects (containing string topic + params) - */ -export type WsTopicRequestOrStringTopic< - TWSTopic extends string, - TWSPayload = any, -> = WsTopicRequest | string; -⋮---- -/** - * Some exchanges have two livenet environments, some have test environments, some dont. This allows easy flexibility for different exchanges. - * Examples: - * - One livenet and one testnet: NetworkMap<'livenet' | 'testnet'> - * - One livenet, sometimes two, one testnet: NetworkMap<'livenet' | 'testnet', 'livenet2'> - * - Only one livenet, no other networks: NetworkMap<'livenet'> - */ -type NetworkMap< - TRequiredKeys extends string, - TOptionalKeys extends string | undefined = undefined, -> = Record & - (TOptionalKeys extends string - ? Record - : Record); +// Info level logging: used for general informational messages ⋮---- -// https://www.gate.com/docs/developers/apiv4/ws/en/ +// Error level logging: used for error messages ⋮---- -// https://www.gate.com/docs/developers/options/ws/en/ +async function start() ⋮---- -export function neverGuard(x: never, msg: string): Error +// console.log('auth with: ', account); ⋮---- -/** - * WS API promises are stored using a primary key. This key is constructed using - * properties found in every request & reply. - */ -export function getPromiseRefForWSAPIRequest( - requestEvent: WSAPIRequest, -): string +// Data received ⋮---- -export function getPrivateSpotTopics(): string[] +// Something happened, attempting to reconnect ⋮---- -// Consumeable channels for spot +// Reconnect successful ⋮---- -// WebSocket API for spot +// Connection closed. If unexpected, expect reconnect -> reconnected. ⋮---- -export function getPrivateFuturesTopics(): string[] +// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate" ⋮---- -// These are the same for perps vs delivery futures +// TODO: many private topics use your user ID ⋮---- -export function getPrivateOptionsTopics(): string[] +/** + * Either send one topic (with params) at a time + */ +// client.subscribe({ +// topic: 'futures.usertrades', +// payload: [myUserID, '!all'], +// }, 'perpFuturesUSDTV4'); ⋮---- /** - * ws.terminate() is undefined in browsers. - * This only works in node.js, not in browsers. - * Does nothing if `ws` is undefined. Does nothing in browsers. - */ -export function safeTerminateWs( - ws?: WebSocket | any, - fallbackToClose?: boolean, -): boolean + * Or send multiple topics in a batch (grouped by ws connection (WsKey)) + * You can also use strings for topics that don't have any parameters, even if you mix multiple requests into one function call: + */ ================ -File: src/lib/websocket/WsStore.ts +File: examples/Websocket/ws-private-spot.ts ================ -import WebSocket from 'isomorphic-ws'; -⋮---- -import { DefaultLogger } from '../logger.js'; -import { - DeferredPromise, - WSConnectedResult, - WsConnectionStateEnum, - WsStoredState, -} from './WsStore.types.js'; +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { LogParams, WebsocketClient, WsTopicRequest } from '../../src/index.js'; +// import { LogParams, WebsocketClient, WsTopicRequest } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` ⋮---- -/** - * Simple comparison of two objects, recursive for nested objects - */ -export function isDeepObjectMatch(object1: unknown, object2: unknown): boolean +// eslint-disable-next-line @typescript-eslint/no-unused-vars ⋮---- -type DeferredPromiseRef = - (typeof DEFERRED_PROMISE_REF)[keyof typeof DEFERRED_PROMISE_REF]; +// Define a custom logger object to handle logging at different levels ⋮---- -export class WsStore< -WsKey extends string, +// Trace level logging: used for detailed debugging information ⋮---- -constructor(logger: DefaultLogger) +// Uncomment the line below to enable trace logging +// console.log(new Date(), 'trace', ...params); ⋮---- -/** Get WS stored state for key, optionally create if missing */ -get( - key: WsKey, - createIfMissing?: true, - ): WsStoredState; +// Info level logging: used for general informational messages ⋮---- -get( - key: WsKey, - createIfMissing?: false, - ): WsStoredState | undefined; +// Error level logging: used for error messages ⋮---- -get( - key: WsKey, - createIfMissing?: boolean, -): WsStoredState | undefined +async function start() ⋮---- -getKeys(): WsKey[] +// console.log('auth with: ', account); ⋮---- -create(key: WsKey): WsStoredState | undefined +// Data received ⋮---- -delete(key: WsKey): void +// Something happened, attempting to reconnect ⋮---- -// TODO: should we allow this at all? Perhaps block this from happening... +// Reconnect successful ⋮---- -/* connection websocket */ +// Connection closed. If unexpected, expect reconnect -> reconnected. ⋮---- -hasExistingActiveConnection(key: WsKey): boolean +// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate" ⋮---- -getWs(key: WsKey): WebSocket | undefined +// client.subscribe(topics, 'spotV4'); ⋮---- -setWs(key: WsKey, wsConnection: WebSocket): WebSocket +// This has the same effect as above, it's just a different way of messaging which topic this is for +// const topicWithoutParamsAsObject: WsTopicRequest = { +// topic: 'spot.balances', +// }; ⋮---- /** - * deferred promises - */ -⋮---- -getDeferredPromise( - wsKey: WsKey, - promiseRef: string | DeferredPromiseRef, -): DeferredPromise | undefined + * Either send one topic (with optional params) at a time + */ +// client.subscribe(topicWithoutParamsAsObject, 'spotV4'); ⋮---- -createDeferredPromise( - wsKey: WsKey, - promiseRef: string | DeferredPromiseRef, - throwIfExists: boolean, -): DeferredPromise +/** + * Or send multiple topics in a batch (grouped by ws connection (WsKey)) + * You can also use strings for topics that don't have any parameters, even if you mix multiple requests into one function call: + */ ⋮---- -// console.log('existing promise'); +/** + * You can also subscribe in separate function calls as you wish. + * + * Any duplicate requests should get filtered out (e.g. here we subscribed to "spot.balances" twice, but the WS client will filter this out) + */ + +================ +File: examples/Websocket/ws-public.ts +================ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { WebsocketClient, WsTopicRequest } from '../../src/index.js'; +// import { LogParams, WebsocketClient, WsTopicRequest } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` ⋮---- -// console.log('create promise'); +// const customLogger = { +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// trace: (...params: LogParams): void => { +// console.log('trace', ...params); +// }, +// info: (...params: LogParams): void => { +// console.log('info', ...params); +// }, +// error: (...params: LogParams): void => { +// console.error('error', ...params); +// }, +// }; ⋮---- -// TODO: Once stable, use Promise.withResolvers in future +async function start() ⋮---- -resolveDeferredPromise( - wsKey: WsKey, - promiseRef: string | DeferredPromiseRef, - value: unknown, - removeAfter: boolean, -): void +// Optional, inject a custom logger +// const client = new WebsocketClient({}, customLogger); ⋮---- -rejectDeferredPromise( - wsKey: WsKey, - promiseRef: string | DeferredPromiseRef, - value: unknown, - removeAfter: boolean, -): void +// Data received ⋮---- -removeDeferredPromise( - wsKey: WsKey, - promiseRef: string | DeferredPromiseRef, -): void +// Something happened, attempting to reconnect ⋮---- -// Just in case it's pending +// Reconnect successful ⋮---- -rejectAllDeferredPromises(wsKey: WsKey, reason: string): void +// Connection closed. If unexpected, expect reconnect -> reconnected. ⋮---- -// Skip reserved keys, such as the connection promise +// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate" ⋮---- -/** Get promise designed to track a connection attempt in progress. Resolves once connected. */ -getConnectionInProgressPromise( - wsKey: WsKey, -): DeferredPromise | undefined +// const topicWithoutParamsAsString = 'spot.balances'; ⋮---- -getAuthenticationInProgressPromise( - wsKey: WsKey, -): DeferredPromise -⋮---- -createAuthenticationInProgressPromise( - wsKey: WsKey, - throwIfExists: boolean, -): DeferredPromise +/** + * Perpetual futures (BTC) + * https://www.gate.io/docs/developers/futures/ws/en/#gate-io-futures-websocket-v4 + */ ⋮---- -getTopicsByKey(): Record> +/** + * Delivery Futures (USDT) + * https://www.gate.io/docs/developers/delivery/ws/en/ + */ ⋮---- /** - * Find matching "topic" request from the store - * @param key - * @param topic - * @returns + * Delivery Futures (BTC) + * https://www.gate.io/docs/developers/delivery/ws/en/ */ -getMatchingTopic(key: WsKey, topic: TWSTopicSubscribeEventArgs) ⋮---- -addTopic(key: WsKey, topic: TWSTopicSubscribeEventArgs) +/** + * Options + * https://www.gate.io/docs/developers/options/ws/en/ + */ ⋮---- -// Check for duplicate topic. If already tracked, don't store this one +/** + * Announcements V4 + * https://www.gate.io/docs/developers/options/ws/en/ + */ ⋮---- -deleteTopic(key: WsKey, topic: TWSTopicSubscribeEventArgs) +/** This is used to differentiate between each of the available websocket streams */ +export type WsKey = (typeof WS_KEY_MAP)[keyof typeof WS_KEY_MAP]; ⋮---- -// Check if we're subscribed to a topic like this - -================ -File: src/lib/BaseWSClient.ts -================ -import EventEmitter from 'events'; -import WebSocket from 'isomorphic-ws'; +export type FuturesWsKey = + | typeof WS_KEY_MAP.perpFuturesUSDTV4 + | typeof WS_KEY_MAP.perpFuturesBTCV4 + | typeof WS_KEY_MAP.deliveryFuturesUSDTV4 + | typeof WS_KEY_MAP.deliveryFuturesBTCV4; ⋮---- -import { - WebsocketClientOptions, - WSClientConfigurableOptions, -} from '../types/websockets/client.js'; -import { WsOperation } from '../types/websockets/requests.js'; -import { WS_LOGGER_CATEGORY } from '../WebsocketClient.js'; -import { DefaultLogger } from './logger.js'; -import { isMessageEvent, MessageEventLike } from './requestUtils.js'; -import { checkWebCryptoAPISupported } from './webCryptoAPI.js'; -import { - safeTerminateWs, - WsTopicRequest, - WsTopicRequestOrStringTopic, -} from './websocket/websocket-util.js'; -import { WsStore } from './websocket/WsStore.js'; -import { - WSConnectedResult, - WsConnectionStateEnum, -} from './websocket/WsStore.types.js'; +export type WsMarket = 'all'; ⋮---- -interface WSClientEventMap { - /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */ - open: (evt: { - wsKey: WsKey; - event: any; - wsUrl: string; - ws: WebSocket; - }) => void /** Reconnecting a dropped connection */; - reconnect: (evt: { wsKey: WsKey; event: any }) => void; - /** Successfully reconnected a connection that dropped */ - reconnected: (evt: { - wsKey: WsKey; - event: any; - wsUrl: string; - ws: WebSocket; - }) => void; - /** Connection closed */ - close: (evt: { wsKey: WsKey; event: any }) => void; - /** Received reply to websocket command (e.g. after subscribing to topics) */ - response: (response: any & { wsKey: WsKey }) => void; - /** Received data for topic */ - update: (response: any & { wsKey: WsKey }) => void; - /** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */ - exception: (response: any & { wsKey: WsKey }) => void; - error: (response: any & { wsKey: WsKey }) => void; - /** Confirmation that a connection successfully authenticated */ - authenticated: (event: { wsKey: WsKey; event: any }) => void; +/** + * Normalised internal format for a request (subscribe/unsubscribe/etc) on a topic, with optional parameters. + * + * - Topic: the topic this event is for + * - Payload: the parameters to include, optional. E.g. auth requires key + sign. Some topics allow configurable parameters. + */ +export interface WsTopicRequest< + TWSTopic extends string = string, + TWSPayload = any, +> { + topic: TWSTopic; + payload?: TWSPayload; } ⋮---- -/** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */ +/** + * Conveniently allow users to request a topic either as string topics or objects (containing string topic + params) + */ +export type WsTopicRequestOrStringTopic< + TWSTopic extends string, + TWSPayload = any, +> = WsTopicRequest | string; ⋮---- -}) => void /** Reconnecting a dropped connection */; +/** + * Some exchanges have two livenet environments, some have test environments, some dont. This allows easy flexibility for different exchanges. + * Examples: + * - One livenet and one testnet: NetworkMap<'livenet' | 'testnet'> + * - One livenet, sometimes two, one testnet: NetworkMap<'livenet' | 'testnet', 'livenet2'> + * - Only one livenet, no other networks: NetworkMap<'livenet'> + */ +type NetworkMap< + TRequiredKeys extends string, + TOptionalKeys extends string | undefined = undefined, +> = Record & + (TOptionalKeys extends string + ? Record + : Record); ⋮---- -/** Successfully reconnected a connection that dropped */ +// https://www.gate.com/docs/developers/apiv4/ws/en/ ⋮---- -/** Connection closed */ +// https://www.gate.com/docs/developers/options/ws/en/ ⋮---- -/** Received reply to websocket command (e.g. after subscribing to topics) */ +export function neverGuard(x: never, msg: string): Error ⋮---- -/** Received data for topic */ +/** + * WS API promises are stored using a primary key. This key is constructed using + * properties found in every request & reply. + */ +export function getPromiseRefForWSAPIRequest( + requestEvent: WSAPIRequest, +): string ⋮---- -/** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */ +export function getPrivateSpotTopics(): string[] ⋮---- -/** Confirmation that a connection successfully authenticated */ +// Consumeable channels for spot ⋮---- -export interface EmittableEvent { - eventType: 'response' | 'update' | 'exception' | 'authenticated'; - event: TEvent; -} +// WebSocket API for spot ⋮---- -// Type safety for on and emit handlers: https://stackoverflow.com/a/61609010/880837 -export interface BaseWebsocketClient { - on>( - event: U, - listener: WSClientEventMap[U], - ): this; - - emit>( - event: U, - ...args: Parameters[U]> - ): boolean; -} +export function getPrivateFuturesTopics(): string[] ⋮---- -on>( - event: U, - listener: WSClientEventMap[U], - ): this; +// These are the same for perps vs delivery futures ⋮---- -emit>( - event: U, - ...args: Parameters[U]> - ): boolean; +export function getPrivateOptionsTopics(): string[] ⋮---- /** - * Users can conveniently pass topics as strings or objects (object has topic name + optional params). - * - * This method normalises topics into objects (object has topic name + optional params). + * ws.terminate() is undefined in browsers. + * This only works in node.js, not in browsers. + * Does nothing if `ws` is undefined. Does nothing in browsers. */ -function getNormalisedTopicRequests( - wsTopicRequests: WsTopicRequestOrStringTopic[], -): WsTopicRequest[] -⋮---- -// passed as string, convert to object +export function safeTerminateWs( + ws?: WebSocket | any, + fallbackToClose?: boolean, +): boolean + +================ +File: src/lib/websocket/WsStore.ts +================ +import WebSocket from 'isomorphic-ws'; ⋮---- -// already a normalised object, thanks to user +import { DefaultLogger } from '../logger.js'; +import { + DeferredPromise, + WSConnectedResult, + WsConnectionStateEnum, + WsStoredState, +} from './WsStore.types.js'; ⋮---- /** - * Base WebSocket abstraction layer. Handles connections, tracking each connection as a unique "WS Key" + * Simple comparison of two objects, recursive for nested objects */ -// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -export abstract class BaseWebsocketClient< +export function isDeepObjectMatch(object1: unknown, object2: unknown): boolean ⋮---- -/** - * The WS connections supported by the client, each identified by a unique primary key - */ +type DeferredPromiseRef = + (typeof DEFERRED_PROMISE_REF)[keyof typeof DEFERRED_PROMISE_REF]; ⋮---- -/** - * State store to track a list of topics (topic requests) we are expected to be subscribed to if reconnected - */ +export class WsStore< +WsKey extends string, ⋮---- -constructor( - options?: WSClientConfigurableOptions, - logger?: typeof DefaultLogger, -) +constructor(logger: DefaultLogger) ⋮---- -// Some defaults: +/** Get WS stored state for key, optionally create if missing */ +get( + key: WsKey, + createIfMissing?: true, + ): WsStoredState; ⋮---- -// Gate.io only has one connection (for both public & private). Auth works with every sub, not on connect, so this is turned off. +get( + key: WsKey, + createIfMissing?: false, + ): WsStoredState | undefined; ⋮---- -// Gate.io requires auth to be added to every request, when subscribing to private topics. This is handled automatically. +get( + key: WsKey, + createIfMissing?: boolean, +): WsStoredState | undefined ⋮---- -// Automatically re-auth WS API, if we were auth'd before and get reconnected +getKeys(): WsKey[] ⋮---- -// Check Web Crypto API support when credentials are provided and no custom sign function is used +create(key: WsKey): WsStoredState | undefined ⋮---- -protected abstract isAuthOnConnectWsKey(wsKey: TWSKey): boolean; +delete(key: WsKey): void ⋮---- -protected abstract sendPingEvent(wsKey: TWSKey, ws: WebSocket): void; +// TODO: should we allow this at all? Perhaps block this from happening... ⋮---- -protected abstract sendPongEvent(wsKey: TWSKey, ws: WebSocket): void; +/* connection websocket */ ⋮---- -protected abstract isWsPing(data: any): boolean; +hasExistingActiveConnection(key: WsKey): boolean ⋮---- -protected abstract isWsPong(data: any): boolean; +getWs(key: WsKey): WebSocket | undefined ⋮---- -protected abstract getWsAuthRequestEvent(wsKey: TWSKey): Promise; +setWs(key: WsKey, wsConnection: WebSocket): WebSocket ⋮---- -protected abstract isPrivateTopicRequest( - request: WsTopicRequest, - wsKey: TWSKey, - ): boolean; +/** + * deferred promises + */ ⋮---- -protected abstract getPrivateWSKeys(): TWSKey[]; +getDeferredPromise( + wsKey: WsKey, + promiseRef: string | DeferredPromiseRef, +): DeferredPromise | undefined ⋮---- -protected abstract getWsUrl(wsKey: TWSKey): string; +createDeferredPromise( + wsKey: WsKey, + promiseRef: string | DeferredPromiseRef, + throwIfExists: boolean, +): DeferredPromise ⋮---- -protected abstract getMaxTopicsPerSubscribeEvent( - wsKey: TWSKey, - ): number | null; +// console.log('existing promise'); ⋮---- -/** - * Returns a list of string events that can be individually sent upstream to complete subscribing/unsubscribing/etc to these topics - */ -protected abstract getWsOperationEventsForTopics( - topics: WsTopicRequest[], - wsKey: TWSKey, - operation: WsOperation, - ): Promise; +// console.log('create promise'); ⋮---- -/** - * Abstraction called to sort ws events into emittable event types (response to a request, data update, etc) - */ -protected abstract resolveEmittableEvents( - wsKey: TWSKey, - event: MessageEventLike, - ): EmittableEvent[]; +// TODO: Once stable, use Promise.withResolvers in future ⋮---- -/** - * Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library - */ -protected abstract connectAll(): Promise[]; +resolveDeferredPromise( + wsKey: WsKey, + promiseRef: string | DeferredPromiseRef, + value: unknown, + removeAfter: boolean, +): void ⋮---- -protected isPrivateWsKey(wsKey: TWSKey): boolean +rejectDeferredPromise( + wsKey: WsKey, + promiseRef: string | DeferredPromiseRef, + value: unknown, + removeAfter: boolean, +): void ⋮---- -/** Returns auto-incrementing request ID, used to track promise references for async requests */ -protected getNewRequestId(): string +removeDeferredPromise( + wsKey: WsKey, + promiseRef: string | DeferredPromiseRef, +): void ⋮---- -protected abstract sendWSAPIRequest( - wsKey: TWSKey, - channel: string, - params?: any, - ): Promise; +// Just in case it's pending ⋮---- -protected abstract sendWSAPIRequest( - wsKey: TWSKey, - channel: string, - params: any, - ): Promise; +rejectAllDeferredPromises(wsKey: WsKey, reason: string): void ⋮---- -public getTimeOffsetMs() +// Skip reserved keys, such as the connection promise ⋮---- -// TODO: not implemented -public setTimeOffsetMs(newOffset: number) +/** Get promise designed to track a connection attempt in progress. Resolves once connected. */ +getConnectionInProgressPromise( + wsKey: WsKey, +): DeferredPromise | undefined +⋮---- +getAuthenticationInProgressPromise( + wsKey: WsKey, +): DeferredPromise[], - wsKey: TWSKey, -) +createConnectionInProgressPromise( + wsKey: WsKey, + throwIfExists: boolean, +): DeferredPromise ⋮---- -// Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically +createAuthenticationInProgressPromise( + wsKey: WsKey, + throwIfExists: boolean, +): DeferredPromise[], - wsKey: TWSKey, -) +isConnectionState(key: WsKey, state: WsConnectionStateEnum): boolean ⋮---- -// Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically +/** + * Check if we're currently in the process of opening a connection for any reason. Safer than only checking "CONNECTING" as the state + * @param key + * @returns + */ +isConnectionAttemptInProgress(key: WsKey): boolean ⋮---- -// If not connected, don't need to do anything. -// Removing the topic from the store is enough to stop it from being resubscribed to on reconnect. +const stateChangeTimeout = 15000; // allow a max 15 second timeout since the last state change before assuming stuck; ⋮---- -// We're connected. Check if auth is needed and if already authenticated +/* subscribed topics */ ⋮---- -/** - * If not authenticated yet and auth is required, don't need to do anything. - * We don't subscribe to topics until auth is complete anyway. - */ +getTopics(key: WsKey): Set ⋮---- -// Finally, request subscription to topics if the connection is healthy and ready +getTopicsByKey(): Record> ⋮---- /** - * Splits topic requests into two groups, public & private topic requests + * Find matching "topic" request from the store + * @param key + * @param topic + * @returns */ -private sortTopicRequestsIntoPublicPrivate( - wsTopicRequests: WsTopicRequest[], - wsKey: TWSKey, -): +getMatchingTopic(key: WsKey, topic: TWSTopicSubscribeEventArgs) ⋮---- -/** Get the WsStore that tracks websockets & topics */ -public getWsStore(): WsStore> +addTopic(key: WsKey, topic: TWSTopicSubscribeEventArgs) ⋮---- -public close(wsKey: TWSKey, force?: boolean) +// Check for duplicate topic. If already tracked, don't store this one ⋮---- -public closeAll(force?: boolean) +deleteTopic(key: WsKey, topic: TWSTopicSubscribeEventArgs) ⋮---- -public isConnected(wsKey: TWSKey): boolean +// Check if we're subscribed to a topic like this + +================ +File: src/lib/multipartUtil.ts +================ +/** File payload for Gate multipart/form-data OTC endpoints */ +export type GateMultipartFile = + | Blob + | Buffer + | { filename?: string; content: Blob | Buffer }; ⋮---- -/** - * Request connection to a specific websocket, instead of waiting for automatic connection. - */ -protected async connect( - wsKey: TWSKey, -): Promise +export function appendGateMultipartFile( + form: FormData, + fieldName: string, + file: GateMultipartFile, +): void ⋮---- -private connectToWsUrl(url: string, wsKey: TWSKey): WebSocket +export function appendGateMultipartFields( + form: FormData, + fields: Record, +): void + +================ +File: src/types/request/announcement.ts +================ +/** POST /ann/list_article */ ⋮---- -private parseWsError(context: string, error: any, wsKey: TWSKey) +export interface ListAnnouncementArticlesReq { + title_query?: string; + page?: string; + size?: string; + tags?: string; + timer?: string; + cate_name?: string; + cate_level?: string; + sub_website_id?: string; + pinned?: number; + update_after?: number; + lang?: string; + filter_empty_content?: number; +} + +================ +File: src/types/request/options.ts +================ +/**========================================================================================================================== + * OPTIONS + * ========================================================================================================================== + */ +export interface GetOptionsSettlementHistoryReq { + underlying: string; + limit?: number; + offset?: number; + from?: number; + to?: number; +} +export interface GetOptionsMySettlementsReq { + underlying: string; + contract?: string; + limit?: number; + offset?: number; + from?: number; + to?: number; +} ⋮---- -/** Get a signature, build the auth request and send it */ -private async sendAuthRequest(wsKey: TWSKey): Promise +export interface GetOptionsOrderBookReq { + contract: string; + interval?: '0' | '0.1' | '0.01'; + limit?: number; + with_id?: boolean; +} +⋮---- +export interface GetOptionsCandlesReq { + contract: string; + limit?: number; + from?: number; + to?: number; + interval?: '1m' | '5m' | '15m' | '30m' | '1h'; +} +⋮---- +export interface GetOptionsUnderlyingCandlesReq { + underlying: string; + limit?: number; + from?: number; + to?: number; + interval?: '1m' | '5m' | '15m' | '30m' | '1h'; +} ⋮---- -// console.log('ws auth req', request); +export interface GetOptionsTradesReq { + contract?: string; + type?: 'C' | 'P'; + limit?: number; + offset?: number; + from?: number; + to?: number; +} ⋮---- -private reconnectWithDelay(wsKey: TWSKey, connectionDelayMs: number) +export interface GetOptionsAccountChangeReq { + limit?: number; + offset?: number; + from?: number; + to?: number; + type?: 'dnw' | 'prem' | 'fee' | 'refr' | 'set'; +} ⋮---- -private ping(wsKey: TWSKey) +export interface SubmitOptionsOrderReq { + contract: string; + size: number; + iceberg?: number; + price?: string; + close?: boolean; + reduce_only?: boolean; + tif?: 'gtc' | 'ioc' | 'poc'; + text?: string; +} ⋮---- -private clearTimers(wsKey: TWSKey) +export interface AmendOptionsOrderReq { + contract: string; // Options contract name + price: string; // Order price + size: number; // Order size +} ⋮---- -// Send a ping at intervals -private clearPingTimer(wsKey: TWSKey) +contract: string; // Options contract name +price: string; // Order price +size: number; // Order size ⋮---- -// Expect a pong within a time limit -private clearPongTimer(wsKey: TWSKey) +export interface GetOptionsOrdersReq { + contract?: string; + underlying?: string; + status: 'open' | 'finished'; + limit?: number; + offset?: number; + from?: number; + to?: number; +} ⋮---- -// this.logger.trace(`Cleared pong timeout for "${wsKey}"`); +export interface GetOptionsPersonalHistoryReq { + underlying: string; + contract?: string; + limit?: number; + offset?: number; + from?: number; + to?: number; +} ⋮---- -// this.logger.trace(`No active pong timer for "${wsKey}"`); +export interface OptionsMMPSettingsReq { + underlying: string; + window: number; // Time window in milliseconds, between 1-5000, 0 to disable MMP + frozen_period: number; // Frozen period in milliseconds, 0 to freeze indefinitely until reset API is called + qty_limit: string; // Maximum transaction volume (positive number, up to 2 decimal places) + delta_limit: string; // Maximum net delta value (positive number, up to 2 decimal places) +} ⋮---- -/** - * Simply builds and sends subscribe events for a list of topics for a ws key - * - * @private Use the `subscribe(topics)` or `subscribeTopicsForWsKey(topics, wsKey)` method to subscribe to topics. Send WS message to subscribe to topics. - */ -private async requestSubscribeTopics( - wsKey: TWSKey, - topics: WsTopicRequest[], -) +window: number; // Time window in milliseconds, between 1-5000, 0 to disable MMP +frozen_period: number; // Frozen period in milliseconds, 0 to freeze indefinitely until reset API is called +qty_limit: string; // Maximum transaction volume (positive number, up to 2 decimal places) +delta_limit: string; // Maximum net delta value (positive number, up to 2 decimal places) + +================ +File: src/types/request/rebate.ts +================ +export interface GetAgencyTransactionHistoryReq { + currency_pair?: string; + user_id?: number; + from?: number; + to?: number; + limit?: number; + offset?: number; +} ⋮---- -// Automatically splits requests into smaller batches, if needed +export interface GetAgencyCommissionHistoryReq { + currency?: string; + user_id?: number; + from?: number; + to?: number; + limit?: number; + offset?: number; +} ⋮---- -`Subscribing to ${topics.length} "${wsKey}" topics in ${subscribeWsMessages.length} batches.`, // Events: "${JSON.stringify(topics)}" +export interface GetPartnerSubordinateListReq { + user_id?: number; + limit?: number; + offset?: number; +} ⋮---- -// console.log(`batches: `, JSON.stringify(subscribeWsMessages, null, 2)); +export interface GetBrokerCommissionHistoryReq { + limit?: number; + offset?: number; + user_id?: number; + from?: number; + to?: number; +} ⋮---- -// this.logger.trace(`Sending batch via message: "${wsMessage}"`); +export interface GetBrokerTransactionHistoryReq { + limit?: number; + offset?: number; + user_id?: number; + from?: number; + to?: number; +} ⋮---- -/** - * Simply builds and sends unsubscribe events for a list of topics for a ws key - * - * @private Use the `unsubscribe(topics)` method to unsubscribe from topics. Send WS message to unsubscribe from topics. - */ -private async requestUnsubscribeTopics( - wsKey: TWSKey, - wsTopicRequests: WsTopicRequest[], -) +// Interfaces for request and response +export interface PartnerTransactionReq { + currency_pair?: string; + user_id?: number; + from?: number; + to?: number; + limit?: number; + offset?: number; +} ⋮---- -/** - * Try sending a string event on a WS connection (identified by the WS Key) +/** GET /rebate/partner/data/aggregated */ +export interface GetPartnerAgentDataAggregatedReq { + /** `yyyy-mm-dd hh:ii:ss` (UTC+8); default start of last 7 days */ + start_date?: string; + /** `yyyy-mm-dd hh:ii:ss` (UTC+8); default end of last 7 days */ + end_date?: string; + /** + * 0 All (default), 1 Spot, 2 Futures, 3 Alpha, 4 Web3, 5 Perps (DEX), + * 6 Exchange All, 7 Web3 All, 8 TradFi. `trading_user_count` only when 0. */ -public tryWsSend( - wsKey: TWSKey, - wsMessage: string, - throwExceptions?: boolean, -) -⋮---- -private async onWsOpen( - event: any, - wsKey: TWSKey, - url: string, - ws: WebSocket, -) -⋮---- -// Resolve & cleanup deferred "connection attempt in progress" promise -⋮---- -// eslint-disable-next-line @typescript-eslint/no-unused-vars + business_type?: number; +} ⋮---- -// Remove before resolving, in case there's more requests queued +/** `yyyy-mm-dd hh:ii:ss` (UTC+8); default start of last 7 days */ ⋮---- -// Some websockets require an auth packet to be sent after opening the connection +/** `yyyy-mm-dd hh:ii:ss` (UTC+8); default end of last 7 days */ ⋮---- -// Reconnect to topics known before it connected +/** + * 0 All (default), 1 Spot, 2 Futures, 3 Alpha, 4 Web3, 5 Perps (DEX), + * 6 Exchange All, 7 Web3 All, 8 TradFi. `trading_user_count` only when 0. + */ + +================ +File: src/types/response/alpha.ts +================ +/**========================================================================================================================== + * ALPHA + * ========================================================================================================================== + */ ⋮---- -// Request sub to public topics, if any +export interface AlphaAccount { + currency: string; // Currency name + available: string; // Available Balance + locked: string; // Locked balance + token_address: string; // Token address + chain: string; // Blockchain name +} ⋮---- -// Request sub to private topics, if auth on connect isn't needed +currency: string; // Currency name +available: string; // Available Balance +locked: string; // Locked balance +token_address: string; // Token address +chain: string; // Blockchain name ⋮---- -// If enabled, automatically reauth WS API if reconnected +export interface AlphaAccountBook { + id: number; // Order ID + time: number; // Operation timestamp + currency: string; // Currency name + change: string; // Change amount + balance: string; // Balance after change +} ⋮---- -// eslint-disable-next-line @typescript-eslint/no-unused-vars +id: number; // Order ID +time: number; // Operation timestamp +currency: string; // Currency name +change: string; // Change amount +balance: string; // Balance after change ⋮---- -/** - * Handle subscription to private topics _after_ authentication successfully completes asynchronously. - * - * Only used for exchanges that require auth before sending private topic subscription requests - */ -private onWsAuthenticated( - wsKey: TWSKey, - event: { isWSAPI?: boolean; WSAPIAuthChannel?: string }, -) +export interface CreateAlphaQuoteResp { + quote_id: string; // Quote ID for order placement, valid for 1 minute + min_amount: string; // Minimum order size + max_amount: string; // Maximum order size + price: string; // Token Price (USDT-based) + slippage: string; // Slippage + estimate_gas_fee_amount_usdt: string; // Estimated Gas Fee (USDT-based) + order_fee: string; // Slippage tolerance (10 means 10% tolerance) + target_token_min_amount: string; // Minimum received amount + target_token_max_amount: string; // Maximum received amount + error_type: number; // Failure Type (0: Success, 1: Exceeds maximum value, 2: Below minimum value) +} ⋮---- -// Resolve & cleanup deferred "auth attempt in progress" promise +quote_id: string; // Quote ID for order placement, valid for 1 minute +min_amount: string; // Minimum order size +max_amount: string; // Maximum order size +price: string; // Token Price (USDT-based) +slippage: string; // Slippage +estimate_gas_fee_amount_usdt: string; // Estimated Gas Fee (USDT-based) +order_fee: string; // Slippage tolerance (10 means 10% tolerance) +target_token_min_amount: string; // Minimum received amount +target_token_max_amount: string; // Maximum received amount +error_type: number; // Failure Type (0: Success, 1: Exceeds maximum value, 2: Below minimum value) ⋮---- -// Remove before continuing, in case there's more requests queued +export interface CreateAlphaOrderResp { + order_id: string; // Order ID + status: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) + side: string; // Buy or sell orders (buy/sell) + gas_mode: string; // Trading mode (speed: Smart mode, custom: Custom mode) + create_time: number; // Creation timestamp + amount: string; // Trade Quantity + token_address: string; // Token contract address + chain: string; // Blockchain name +} ⋮---- -private onWsMessage(event: unknown, wsKey: TWSKey, ws: WebSocket) +order_id: string; // Order ID +status: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) +side: string; // Buy or sell orders (buy/sell) +gas_mode: string; // Trading mode (speed: Smart mode, custom: Custom mode) +create_time: number; // Creation timestamp +amount: string; // Trade Quantity +token_address: string; // Token contract address +chain: string; // Blockchain name ⋮---- -// any message can clear the pong timer - wouldn't get a message if the ws wasn't working +export interface AlphaOrder { + order_id: string; // Order ID + tx_hash: string; // Transaction Hash + side: string; // Buy or sell orders (buy/sell) + usdt_amount: string; // Amount (USDT) + currency: string; // Token + currency_amount: string; // Token amount + status: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) + gas_mode: string; // Trading mode (speed: Smart mode, custom: Custom mode) + chain: string; // Blockchain + gas_fee: string; // Gas Fee (USDT-based) + transaction_fee: string; // Trading Fee (USDT-based) + failed_reason: string; // Failure reason (if applicable) + create_time: number; // Creation timestamp +} ⋮---- -// console.log(`raw event: `, { data, dataType, emittableEvents }); +order_id: string; // Order ID +tx_hash: string; // Transaction Hash +side: string; // Buy or sell orders (buy/sell) +usdt_amount: string; // Amount (USDT) +currency: string; // Token +currency_amount: string; // Token amount +status: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) +gas_mode: string; // Trading mode (speed: Smart mode, custom: Custom mode) +chain: string; // Blockchain +gas_fee: string; // Gas Fee (USDT-based) +transaction_fee: string; // Trading Fee (USDT-based) +failed_reason: string; // Failure reason (if applicable) +create_time: number; // Creation timestamp ⋮---- -private onWsClose(event: unknown, wsKey: TWSKey) +export interface AlphaCurrency { + currency: string; // Currency symbol + name: string; // Currency name + chain: string; // The main chain corresponding to the coin + address: string; // Contract Address + amount_precision: number; // Amount scale + precision: number; // Price scale + status: number; // Currency Trading Status (1: Normal trading, 2: Suspended trading, 3: Delisted) +} ⋮---- -// unintentional close, attempt recovery +currency: string; // Currency symbol +name: string; // Currency name +chain: string; // The main chain corresponding to the coin +address: string; // Contract Address +amount_precision: number; // Amount scale +precision: number; // Price scale +status: number; // Currency Trading Status (1: Normal trading, 2: Suspended trading, 3: Delisted) ⋮---- -// clean up any pending promises for this connection +export interface AlphaTicker { + currency: string; // Currency symbol + last: string; // Last trading price + change: string; // 24h price change percentage (negative for decrease, e.g., -7.45) + volume: string; // 24h Trading Volume (USDT) + market_cap: string; // Current Token Market Cap +} ⋮---- -// intentional close - clean up -// clean up any pending promises for this connection +currency: string; // Currency symbol +last: string; // Last trading price +change: string; // 24h price change percentage (negative for decrease, e.g., -7.45) +volume: string; // 24h Trading Volume (USDT) +market_cap: string; // Current Token Market Cap + +================ +File: src/types/response/announcement.ts +================ +export interface AnnouncementArticleLanguage { + code?: string; + name?: string; +} ⋮---- -// clean up any pending promises for this connection +export interface AnnouncementArticle { + id?: number; + title?: string; + brief?: string; + created?: string; + updated?: string; + release_time?: string; + views?: number; + author?: string; + author_id?: number; + tags?: string; + cate?: string; + is_top?: number; + cate_id?: number; + source?: string; + content_lang_list?: AnnouncementArticleLanguage[]; +} ⋮---- -// This was an intentional close, delete all state for this connection, as if it never existed: +export interface AnnouncementArticleListData { + list?: AnnouncementArticle[]; + total?: number; +} ⋮---- -private getWs(wsKey: TWSKey) +export interface AnnouncementArticleListResponse { + code?: number; + data?: AnnouncementArticleListData; + message?: string; + version?: string; +} + +================ +File: src/types/response/autoinvest.ts +================ +/**========================================================================================================================== + * EARN AUTO INVEST + * ========================================================================================================================== + */ ⋮---- -private setWsState(wsKey: TWSKey, state: WsConnectionStateEnum) +/** POST /earn/autoinvest/plans/create — example response shape */ +export interface CreateAutoInvestPlanResp { + id: number; + amount: string; + money: string; + next_time: number; + period_type: string; + period_day: number; + period_hour: number; + fund_flow: string; + fund_source: string; +} ⋮---- -/** - * Promise-driven method to assert that a ws has successfully connected (will await until connection is open) - */ -protected async assertIsConnected(wsKey: TWSKey): Promise +export interface AutoInvestCoinItem { + key: string; + value: string; + asset_icon_url: string; + sort: number; +} ⋮---- -// Already in progress? Await shared promise and retry +export interface AutoInvestMinAmountResp { + min_amount: string; +} ⋮---- -// Start connection, it should automatically store/return a promise. +export interface AutoInvestPlanExecutionRecord { + id: number; + type: string; + money: string; + user_id: number; + plan_id: number; + plan_version: number; + amount: string; + create_time: number; + update_time: number; + status: string; + status_type: number; + /** 2 = buy, other = sell */ + side: number; + status_message: string; + detail: string; + asset: string; +} ⋮---- -/** - * Promise-driven method to assert that a ws has been successfully authenticated (will await until auth is confirmed) - */ -public async assertIsAuthenticated(wsKey: TWSKey): Promise +/** 2 = buy, other = sell */ ⋮---- -// Already in progress? Await shared promise and retry +export interface AutoInvestPlanExecutionRecordsPaginated { + page: number; + page_size: number; + total_page: number; + total: number; + list: AutoInvestPlanExecutionRecord[]; +} ⋮---- -// this.logger.trace('assertIsAuthenticated(): ok'); +export interface AutoInvestOrderItem { + id: number; + type: string; + amount: string; + plan_id: number; + side: number; + asset: string; + record_id: number; + total_money: string; + market: string; + price: string; + create_time: number; + total: string; + fund_flow: string; + error_code: number; + error_msg: string; + status: number; +} ⋮---- -// Start authentication, it should automatically store/return a promise. - -================ -File: src/lib/multipartUtil.ts -================ -/** File payload for Gate multipart/form-data OTC endpoints */ -export type GateMultipartFile = - | Blob - | Buffer - | { filename?: string; content: Blob | Buffer }; +export interface AutoInvestConfigItem { + coin: string; + max_limit: string; +} ⋮---- -export function appendGateMultipartFile( - form: FormData, - fieldName: string, - file: GateMultipartFile, -): void +export interface AutoInvestPlanPortfolioItem { + asset: string; + ratio: string; + cum_invest?: string; + cum_hold?: string; + cum_redeem?: string; + avg_price?: string; + redeem_status?: number; + lend_amount?: string; +} ⋮---- -export function appendGateMultipartFields( - form: FormData, - fields: Record, -): void - -================ -File: src/types/request/announcement.ts -================ -/** POST /ann/list_article */ +export interface AutoInvestPlanDetail { + id: number; + version: number; + name: string; + create_time: number; + update_time: number; + user_id: number; + money: string; + amount: string; + period_type: string; + period_day: number; + period_hour: number; + portfolio: AutoInvestPlanPortfolioItem[]; + next_time?: number; + period?: number; + fund_source?: string; + fund_flow?: string; +} ⋮---- -export interface ListAnnouncementArticlesReq { - title_query?: string; - page?: string; - size?: string; - tags?: string; - timer?: string; - cate_name?: string; - cate_level?: string; - sub_website_id?: string; - pinned?: number; - update_after?: number; - lang?: string; - filter_empty_content?: number; +export interface AutoInvestPlansListResp { + page: number; + page_size: number; + page_count: number; + total_count: number; + list: AutoInvestPlanDetail[]; } ================ -File: src/types/request/options.ts +File: src/types/response/marginuni.ts ================ /**========================================================================================================================== - * OPTIONS + * MARGIN UNI * ========================================================================================================================== */ -export interface GetOptionsSettlementHistoryReq { - underlying: string; - limit?: number; - offset?: number; - from?: number; - to?: number; -} -export interface GetOptionsMySettlementsReq { - underlying: string; - contract?: string; - limit?: number; - offset?: number; - from?: number; - to?: number; -} ⋮---- -export interface GetOptionsOrderBookReq { - contract: string; - interval?: '0' | '0.1' | '0.01'; - limit?: number; - with_id?: boolean; +export interface LendingMarket { + currency_pair: string; + base_min_borrow_amount: string; + quote_min_borrow_amount: string; + leverage: string; + status?: string | number; + delisted_time?: number; } ⋮---- -export interface GetOptionsCandlesReq { - contract: string; - limit?: number; - from?: number; - to?: number; - interval?: '1m' | '5m' | '15m' | '30m' | '1h'; +export interface MarginUNILoan { + currency: string; + currency_pair: string; + amount: string; + type: string; // Lending type, margin indicates margin borrowing + create_time: number; + update_time: number; } ⋮---- -export interface GetOptionsUnderlyingCandlesReq { - underlying: string; - limit?: number; - from?: number; - to?: number; - interval?: '1m' | '5m' | '15m' | '30m' | '1h'; -} +type: string; // Lending type, margin indicates margin borrowing ⋮---- -export interface GetOptionsTradesReq { - contract?: string; - type?: 'C' | 'P'; - limit?: number; - offset?: number; - from?: number; - to?: number; +export interface MarginUNILoanRecord { + type: string; + currency_pair: string; + currency: string; + amount: string; + create_time: number; } ⋮---- -export interface GetOptionsAccountChangeReq { - limit?: number; - offset?: number; - from?: number; - to?: number; - type?: 'dnw' | 'prem' | 'fee' | 'refr' | 'set'; +export interface MarginUNIInterestRecord { + currency: string; + currency_pair: string; + actual_rate: string; + interest: string; + status: number; + type: string; // Lending type, margin indicates margin borrowing + create_time: number; } ⋮---- -export interface SubmitOptionsOrderReq { - contract: string; - size: number; - iceberg?: number; - price?: string; - close?: boolean; - reduce_only?: boolean; - tif?: 'gtc' | 'ioc' | 'poc'; - text?: string; -} +type: string; // Lending type, margin indicates margin borrowing ⋮---- -export interface AmendOptionsOrderReq { - contract: string; // Options contract name - price: string; // Order price - size: number; // Order size +export interface MarginUNIMaxBorrowable { + currency: string; + currency_pair: string; + borrowable: string; } + +================ +File: src/types/response/multicollateralLoan.ts +================ +/**========================================================================================================================== + * MULTI COLLATERAL LOAN + * ========================================================================================================================== + */ ⋮---- -contract: string; // Options contract name -price: string; // Order price -size: number; // Order size -⋮---- -export interface GetOptionsOrdersReq { - contract?: string; - underlying?: string; - status: 'open' | 'finished'; - limit?: number; - offset?: number; - from?: number; - to?: number; +export interface MultiLoanOrder { + order_id: string; + order_type: string; + fixed_type: string; + fixed_rate: string; + expire_time: number; + auto_renew: boolean; + auto_repay: boolean; + current_ltv: string; + status: string; + borrow_time: number; + total_left_repay_usdt: string; + total_left_collateral_usdt: string; + borrow_currencies: { + currency: string; + index_price: string; + left_repay_principal: string; + left_repay_interest: string; + left_repay_usdt: string; + }[]; + collateral_currencies: { + currency: string; + index_price: string; + left_collateral: string; + left_collateral_usdt: string; + }[]; } ⋮---- -export interface GetOptionsPersonalHistoryReq { - underlying: string; - contract?: string; - limit?: number; - offset?: number; - from?: number; - to?: number; +export interface RepayMultiLoanResp { + order_id: number; + repaid_currencies: { + succeeded: boolean; + label?: string; + message?: string; + currency: string; + repaid_principal: string; + repaid_interest: string; + }[]; } ⋮---- -export interface OptionsMMPSettingsReq { - underlying: string; - window: number; // Time window in milliseconds, between 1-5000, 0 to disable MMP - frozen_period: number; // Frozen period in milliseconds, 0 to freeze indefinitely until reset API is called - qty_limit: string; // Maximum transaction volume (positive number, up to 2 decimal places) - delta_limit: string; // Maximum net delta value (positive number, up to 2 decimal places) +export interface MultiLoanRepayRecord { + order_id: number; + record_id: number; + init_ltv: string; + before_ltv: string; + after_ltv: string; + borrow_time: number; + repay_time: number; + borrow_currencies: { + currency: string; + index_price: string; + before_amount: string; + before_amount_usdt: string; + after_amount: string; + after_amount_usdt: string; + }[]; + collateral_currencies: { + currency: string; + index_price: string; + before_amount: string; + before_amount_usdt: string; + after_amount: string; + after_amount_usdt: string; + }[]; + repaid_currencies: { + currency: string; + index_price: string; + repaid_amount: string; + repaid_principal: string; + repaid_interest: string; + repaid_amount_usdt: string; + }[]; + total_interest_list: { + currency: string; + index_price: string; + amount: string; + amount_usdt: string; + }[]; + left_repay_interest_list: { + currency: string; + index_price: string; + before_amount: string; + before_amount_usdt: string; + after_amount: string; + after_amount_usdt: string; + }[]; } ⋮---- -window: number; // Time window in milliseconds, between 1-5000, 0 to disable MMP -frozen_period: number; // Frozen period in milliseconds, 0 to freeze indefinitely until reset API is called -qty_limit: string; // Maximum transaction volume (positive number, up to 2 decimal places) -delta_limit: string; // Maximum net delta value (positive number, up to 2 decimal places) - -================ -File: src/types/request/rebate.ts -================ -export interface GetAgencyTransactionHistoryReq { - currency_pair?: string; - user_id?: number; - from?: number; - to?: number; - limit?: number; - offset?: number; +export interface UpdateMultiLoanResp { + order_id: number; + collateral_currencies: { + succeeded: boolean; + label?: string; + message?: string; + currency: string; + amount: string; + }[]; } ⋮---- -export interface GetAgencyCommissionHistoryReq { - currency?: string; - user_id?: number; - from?: number; - to?: number; - limit?: number; - offset?: number; +export interface MultiLoanAdjustmentRecord { + order_id: number; + record_id: number; + before_ltv: string; + after_ltv: string; + operate_time: number; + borrow_currencies: { + currency: string; + index_price: string; + before_amount: string; + before_amount_usdt: string; + after_amount: string; + after_amount_usdt: string; + }[]; + collateral_currencies: { + currency: string; + index_price: string; + before_amount: string; + before_amount_usdt: string; + after_amount: string; + after_amount_usdt: string; + }[]; } ⋮---- -export interface GetPartnerSubordinateListReq { - user_id?: number; - limit?: number; - offset?: number; +export interface MultiLoanCurrencyQuota { + currency: string; + index_price: string; + min_quota: string; + left_quota: string; + left_quote_usdt: string; + /** Remaining borrow/collateral limit for fixed-term currency */ + left_quota_fixed?: string; + /** Remaining currency limit for fixed-term converted to USDT */ + left_quote_usdt_fixed?: string; } ⋮---- -export interface GetBrokerCommissionHistoryReq { - limit?: number; - offset?: number; - user_id?: number; - from?: number; - to?: number; -} +/** Remaining borrow/collateral limit for fixed-term currency */ ⋮---- -export interface GetBrokerTransactionHistoryReq { - limit?: number; - offset?: number; - user_id?: number; - from?: number; - to?: number; -} +/** Remaining currency limit for fixed-term converted to USDT */ ⋮---- -// Interfaces for request and response -export interface PartnerTransactionReq { - currency_pair?: string; - user_id?: number; - from?: number; - to?: number; - limit?: number; - offset?: number; +export interface MultiLoanSupportedCurrencies { + loan_currencies: { + currency: string; + price: string; + }[]; + collateral_currencies: { + currency: string; + index_price: string; + discount: string; + }[]; } ⋮---- -/** GET /rebate/partner/data/aggregated */ -export interface GetPartnerAgentDataAggregatedReq { - /** `yyyy-mm-dd hh:ii:ss` (UTC+8); default start of last 7 days */ - start_date?: string; - /** `yyyy-mm-dd hh:ii:ss` (UTC+8); default end of last 7 days */ - end_date?: string; - /** - * 0 All (default), 1 Spot, 2 Futures, 3 Alpha, 4 Web3, 5 Perps (DEX), - * 6 Exchange All, 7 Web3 All, 8 TradFi. `trading_user_count` only when 0. - */ - business_type?: number; +export interface MultiLoanRatio { + init_ltv: string; + alert_ltv: string; + liquidate_ltv: string; } ⋮---- -/** `yyyy-mm-dd hh:ii:ss` (UTC+8); default start of last 7 days */ -⋮---- -/** `yyyy-mm-dd hh:ii:ss` (UTC+8); default end of last 7 days */ -⋮---- -/** - * 0 All (default), 1 Spot, 2 Futures, 3 Alpha, 4 Web3, 5 Perps (DEX), - * 6 Exchange All, 7 Web3 All, 8 TradFi. `trading_user_count` only when 0. - */ +export interface MultiLoanFixedRate { + currency: string; + rate_7d: string; + rate_30d: string; + update_time: number; +} ================ -File: src/types/response/alpha.ts +File: src/types/response/rebate.ts ================ -/**========================================================================================================================== - * ALPHA - * ========================================================================================================================== - */ -⋮---- -export interface AlphaAccount { - currency: string; // Currency name - available: string; // Available Balance - locked: string; // Locked balance - token_address: string; // Token address - chain: string; // Blockchain name -} -⋮---- -currency: string; // Currency name -available: string; // Available Balance -locked: string; // Locked balance -token_address: string; // Token address -chain: string; // Blockchain name -⋮---- -export interface AlphaAccountBook { - id: number; // Order ID - time: number; // Operation timestamp - currency: string; // Currency name - change: string; // Change amount - balance: string; // Balance after change +export interface AgencyTransactionHistoryRecord { + transaction_time: number; + user_id: number; + group_name: string; + fee: string; + fee_asset: string; + currency_pair: string; + amount: string; + amount_asset: string; + source: string; } ⋮---- -id: number; // Order ID -time: number; // Operation timestamp -currency: string; // Currency name -change: string; // Change amount -balance: string; // Balance after change -⋮---- -export interface CreateAlphaQuoteResp { - quote_id: string; // Quote ID for order placement, valid for 1 minute - min_amount: string; // Minimum order size - max_amount: string; // Maximum order size - price: string; // Token Price (USDT-based) - slippage: string; // Slippage - estimate_gas_fee_amount_usdt: string; // Estimated Gas Fee (USDT-based) - order_fee: string; // Slippage tolerance (10 means 10% tolerance) - target_token_min_amount: string; // Minimum received amount - target_token_max_amount: string; // Maximum received amount - error_type: number; // Failure Type (0: Success, 1: Exceeds maximum value, 2: Below minimum value) +export interface AgencyCommissionHistoryRecord { + commission_time: number; + user_id: number; + group_name: string; + /** Rebate commission amount (not a generic trade notional). */ + commission_amount: string; + /** Asset of the rebate commission. */ + commission_asset: string; + source: string; } ⋮---- -quote_id: string; // Quote ID for order placement, valid for 1 minute -min_amount: string; // Minimum order size -max_amount: string; // Maximum order size -price: string; // Token Price (USDT-based) -slippage: string; // Slippage -estimate_gas_fee_amount_usdt: string; // Estimated Gas Fee (USDT-based) -order_fee: string; // Slippage tolerance (10 means 10% tolerance) -target_token_min_amount: string; // Minimum received amount -target_token_max_amount: string; // Maximum received amount -error_type: number; // Failure Type (0: Success, 1: Exceeds maximum value, 2: Below minimum value) -⋮---- -export interface CreateAlphaOrderResp { - order_id: string; // Order ID - status: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) - side: string; // Buy or sell orders (buy/sell) - gas_mode: string; // Trading mode (speed: Smart mode, custom: Custom mode) - create_time: number; // Creation timestamp - amount: string; // Trade Quantity - token_address: string; // Token contract address - chain: string; // Blockchain name -} +/** Rebate commission amount (not a generic trade notional). */ ⋮---- -order_id: string; // Order ID -status: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) -side: string; // Buy or sell orders (buy/sell) -gas_mode: string; // Trading mode (speed: Smart mode, custom: Custom mode) -create_time: number; // Creation timestamp -amount: string; // Trade Quantity -token_address: string; // Token contract address -chain: string; // Blockchain name +/** Asset of the rebate commission. */ ⋮---- -export interface AlphaOrder { - order_id: string; // Order ID - tx_hash: string; // Transaction Hash - side: string; // Buy or sell orders (buy/sell) - usdt_amount: string; // Amount (USDT) - currency: string; // Token - currency_amount: string; // Token amount - status: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) - gas_mode: string; // Trading mode (speed: Smart mode, custom: Custom mode) - chain: string; // Blockchain - gas_fee: string; // Gas Fee (USDT-based) - transaction_fee: string; // Trading Fee (USDT-based) - failed_reason: string; // Failure reason (if applicable) - create_time: number; // Creation timestamp +export interface PartnerSubordinate { + user_id: number; + user_join_time: number; + type: number; + desc: string; } ⋮---- -order_id: string; // Order ID -tx_hash: string; // Transaction Hash -side: string; // Buy or sell orders (buy/sell) -usdt_amount: string; // Amount (USDT) -currency: string; // Token -currency_amount: string; // Token amount -status: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) -gas_mode: string; // Trading mode (speed: Smart mode, custom: Custom mode) -chain: string; // Blockchain -gas_fee: string; // Gas Fee (USDT-based) -transaction_fee: string; // Trading Fee (USDT-based) -failed_reason: string; // Failure reason (if applicable) -create_time: number; // Creation timestamp -⋮---- -export interface AlphaCurrency { - currency: string; // Currency symbol - name: string; // Currency name - chain: string; // The main chain corresponding to the coin - address: string; // Contract Address - amount_precision: number; // Amount scale - precision: number; // Price scale - status: number; // Currency Trading Status (1: Normal trading, 2: Suspended trading, 3: Delisted) +export interface BrokerCommissionHistoryRecord { + commission_time: number; + user_id: number; + group_name: string; + amount: string; + fee: string; + fee_asset: string; + rebate_fee: string; + source: string; // Rebate source, e.g. Spot, Futures, Options, Alpha, TradFi + currency_pair: string; + sub_broker_info: { + user_id: number; + original_commission_rate: string; + relative_commission_rate: string; + commission_rate: string; + }; } ⋮---- -currency: string; // Currency symbol -name: string; // Currency name -chain: string; // The main chain corresponding to the coin -address: string; // Contract Address -amount_precision: number; // Amount scale -precision: number; // Price scale -status: number; // Currency Trading Status (1: Normal trading, 2: Suspended trading, 3: Delisted) +source: string; // Rebate source, e.g. Spot, Futures, Options, Alpha, TradFi ⋮---- -export interface AlphaTicker { - currency: string; // Currency symbol - last: string; // Last trading price - change: string; // 24h price change percentage (negative for decrease, e.g., -7.45) - volume: string; // 24h Trading Volume (USDT) - market_cap: string; // Current Token Market Cap +export interface BrokerTransactionHistoryRecord { + transaction_time: number; + user_id: number; + group_name: string; + fee: string; + currency_pair: string; + amount: string; + fee_asset: string; + source: string; // Rebate source, e.g. Spot, Futures, Options, Alpha, TradFi + sub_broker_info: { + user_id: number; + original_commission_rate: string; + relative_commission_rate: string; + commission_rate: string; + }; } ⋮---- -currency: string; // Currency symbol -last: string; // Last trading price -change: string; // 24h price change percentage (negative for decrease, e.g., -7.45) -volume: string; // 24h Trading Volume (USDT) -market_cap: string; // Current Token Market Cap - -================ -File: src/types/response/announcement.ts -================ -export interface AnnouncementArticleLanguage { - code?: string; - name?: string; +source: string; // Rebate source, e.g. Spot, Futures, Options, Alpha, TradFi +⋮---- +export interface PartnerCommission { + commission_time: number; + user_id: number; + group_name: string; + /** Rebate commission amount (not a generic trade notional). */ + commission_amount: string; + /** Asset of the rebate commission. */ + commission_asset: string; + source: string; } ⋮---- -export interface AnnouncementArticle { - id?: number; - title?: string; - brief?: string; - created?: string; - updated?: string; - release_time?: string; - views?: number; - author?: string; - author_id?: number; - tags?: string; - cate?: string; - is_top?: number; - cate_id?: number; - source?: string; - content_lang_list?: AnnouncementArticleLanguage[]; +/** Rebate commission amount (not a generic trade notional). */ +⋮---- +/** Asset of the rebate commission. */ +⋮---- +export interface PartnerTransaction { + transaction_time: number; + user_id: number; + group_name: string; + fee: string; + fee_asset: string; + currency_pair: string; + amount: string; + amount_asset: string; + source: string; } ⋮---- -export interface AnnouncementArticleListData { - list?: AnnouncementArticle[]; - total?: number; +/** `data` object for GET /rebate/partner/data/aggregated */ +export interface PartnerDataAggregated { + rebate_amount: string; + trade_volume: string; + net_fee: string; + customer_count: number; + /** Only when querying all business types (`business_type=0`); may be null */ + trading_user_count?: string | null; + time_range_desc: string; + business_type: number; + business_type_desc: string; } ⋮---- -export interface AnnouncementArticleListResponse { - code?: number; - data?: AnnouncementArticleListData; - message?: string; - version?: string; +/** Only when querying all business types (`business_type=0`); may be null */ +⋮---- +export interface PartnerDataAggregatedResponse { + code: number; + message: string; + data: PartnerDataAggregated; + timestamp: number; } ================ -File: src/types/response/autoinvest.ts +File: src/types/response/withdrawal.ts ================ -/**========================================================================================================================== - * EARN AUTO INVEST - * ========================================================================================================================== - */ -⋮---- -/** POST /earn/autoinvest/plans/create — example response shape */ -export interface CreateAutoInvestPlanResp { - id: number; +export interface WithdrawalRecord { + id: string; + txid: string; + block_number: string; + withdraw_order_id: string; + /** When `status` is DONE, withdrawal success time (not conditioned on `block_number`). */ + timestamp: string; amount: string; - money: string; - next_time: number; - period_type: string; - period_day: number; - period_hour: number; - fund_flow: string; - fund_source: string; -} -⋮---- -export interface AutoInvestCoinItem { - key: string; - value: string; - asset_icon_url: string; - sort: number; + currency: string; + address: string; + memo?: string; + status: + | 'BCODE' // Deposit Code Operation + | 'CANCEL' // Cancelled + | 'CANCELPEND' // Withdrawal Cancellation Pending + | 'DMOVE' // Pending Manual Review + | 'DONE' // Completed + | 'EXTPEND' // Sent and Waiting for Confirmation + | 'FAIL' // On-Chain Failure Pending Confirmation + | 'FVERIFY' // Facial Verification in Progress + | 'INVALID' // Invalid Transaction + | 'LOCKED' // Wallet-Side Order Locked + | 'MANUAL' // Pending Manual Review + | 'PEND' // Processing + | 'PROCES' // Processing + | 'REJECT' // Rejected + | 'REQUEST' // Request in Progress + | 'REVIEW' // Under Review + | 'SPLITPEND' // Split Pending + | 'VERIFY'; // Verification in Progress + chain: string; } ⋮---- -export interface AutoInvestMinAmountResp { - min_amount: string; -} +/** When `status` is DONE, withdrawal success time (not conditioned on `block_number`). */ ⋮---- -export interface AutoInvestPlanExecutionRecord { - id: number; - type: string; - money: string; - user_id: number; - plan_id: number; - plan_version: number; - amount: string; - create_time: number; - update_time: number; - status: string; - status_type: number; - /** 2 = buy, other = sell */ - side: number; - status_message: string; - detail: string; - asset: string; -} +| 'BCODE' // Deposit Code Operation +| 'CANCEL' // Cancelled +| 'CANCELPEND' // Withdrawal Cancellation Pending +| 'DMOVE' // Pending Manual Review +| 'DONE' // Completed +| 'EXTPEND' // Sent and Waiting for Confirmation +| 'FAIL' // On-Chain Failure Pending Confirmation +| 'FVERIFY' // Facial Verification in Progress +| 'INVALID' // Invalid Transaction +| 'LOCKED' // Wallet-Side Order Locked +| 'MANUAL' // Pending Manual Review +| 'PEND' // Processing +| 'PROCES' // Processing +| 'REJECT' // Rejected +| 'REQUEST' // Request in Progress +| 'REVIEW' // Under Review +| 'SPLITPEND' // Split Pending +| 'VERIFY'; // Verification in Progress + +================ +File: .gitignore +================ +!.gitkeep +.DS_STORE +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json +pids +*.pid +*.seed +*.pid.lock +node_modules/ +.npm +.eslintcache +.node_repl_history +*.tgz +.yarn-integrity +.env +.env.test +.cache +bundleReport.html +.history/ +dist +coverage +localtest.sh +repomix.sh +doc +examples/ignored/ + +ws-private-spot-wsapi-performance.ts +ws-private-perp-futures-wsapi-readonly.ts +privatetest.ts + +privaterepotracker +restClientRegex.ts + +testfile.ts + +================ +File: .npmrc +================ +min-release-age=30 +save-exact=true + +================ +File: .nvmrc +================ +v24.18.0 + +================ +File: examples/Rest/otc/submitOTCBankPersonalSupplement.ts +================ +import { readFileSync } from 'fs'; ⋮---- -/** 2 = buy, other = sell */ +import { RestClient } from '../../../src/index.js'; +// import { RestClient } from 'gateio-api'; ⋮---- -export interface AutoInvestPlanExecutionRecordsPaginated { - page: number; - page_size: number; - total_page: number; - total: number; - list: AutoInvestPlanExecutionRecord[]; -} +async function submitOTCBankPersonalSupplementExample() + +================ +File: src/types/request/alpha.ts +================ +/**========================================================================================================================== + * ALPHA + * ========================================================================================================================== + */ ⋮---- -export interface AutoInvestOrderItem { - id: number; - type: string; - amount: string; - plan_id: number; - side: number; - asset: string; - record_id: number; - total_money: string; - market: string; - price: string; - create_time: number; - total: string; - fund_flow: string; - error_code: number; - error_msg: string; - status: number; +export interface GetAlphaAccountBookReq { + from: number; // Start timestamp for the query + to?: number; // End timestamp for the query, defaults to current time if not specified + page?: number; // Page number + limit?: number; // Maximum 100 items per page } ⋮---- -export interface AutoInvestConfigItem { - coin: string; - max_limit: string; -} +from: number; // Start timestamp for the query +to?: number; // End timestamp for the query, defaults to current time if not specified +page?: number; // Page number +limit?: number; // Maximum 100 items per page ⋮---- -export interface AutoInvestPlanPortfolioItem { - asset: string; - ratio: string; - cum_invest?: string; - cum_hold?: string; - cum_redeem?: string; - avg_price?: string; - redeem_status?: number; - lend_amount?: string; +export interface CreateAlphaQuoteReq { + currency: string; // Trading symbol + side: 'buy' | 'sell'; // Buy or sell orders + amount: string; // Trade Quantity (side: buy refers to quote currency USDT, side: sell refers to base currency) + gas_mode: 'speed' | 'custom'; // Trading mode (speed: Smart mode, custom: Custom mode uses slippage parameter) + slippage?: string; // Slippage tolerance (10 means 10% tolerance) - required when gas_mode is custom } ⋮---- -export interface AutoInvestPlanDetail { - id: number; - version: number; - name: string; - create_time: number; - update_time: number; - user_id: number; - money: string; - amount: string; - period_type: string; - period_day: number; - period_hour: number; - portfolio: AutoInvestPlanPortfolioItem[]; - next_time?: number; - period?: number; - fund_source?: string; - fund_flow?: string; -} +currency: string; // Trading symbol +side: 'buy' | 'sell'; // Buy or sell orders +amount: string; // Trade Quantity (side: buy refers to quote currency USDT, side: sell refers to base currency) +gas_mode: 'speed' | 'custom'; // Trading mode (speed: Smart mode, custom: Custom mode uses slippage parameter) +slippage?: string; // Slippage tolerance (10 means 10% tolerance) - required when gas_mode is custom ⋮---- -export interface AutoInvestPlansListResp { - page: number; - page_size: number; - page_count: number; - total_count: number; - list: AutoInvestPlanDetail[]; +export interface CreateAlphaOrderReq { + currency: string; // Trading symbol + side: 'buy' | 'sell'; // Buy or sell orders + amount: string; // Trade Quantity (side: buy refers to quote currency USDT, side: sell refers to base currency) + gas_mode: 'speed' | 'custom'; // Trading mode (speed: Smart mode, custom: Custom mode uses slippage parameter) + slippage?: string; // Slippage tolerance (10 means 10% tolerance) - required when gas_mode is custom + quote_id: string; // Quote ID returned from quotation API } - -================ -File: src/types/response/marginuni.ts -================ -/**========================================================================================================================== - * MARGIN UNI - * ========================================================================================================================== - */ ⋮---- -export interface LendingMarket { - currency_pair: string; - base_min_borrow_amount: string; - quote_min_borrow_amount: string; - leverage: string; - status?: string | number; - delisted_time?: number; -} +currency: string; // Trading symbol +side: 'buy' | 'sell'; // Buy or sell orders +amount: string; // Trade Quantity (side: buy refers to quote currency USDT, side: sell refers to base currency) +gas_mode: 'speed' | 'custom'; // Trading mode (speed: Smart mode, custom: Custom mode uses slippage parameter) +slippage?: string; // Slippage tolerance (10 means 10% tolerance) - required when gas_mode is custom +quote_id: string; // Quote ID returned from quotation API ⋮---- -export interface MarginUNILoan { - currency: string; - currency_pair: string; - amount: string; - type: string; // Lending type, margin indicates margin borrowing - create_time: number; - update_time: number; +export interface GetAlphaOrdersReq { + currency?: string; // Trading symbol + side?: 'buy' | 'sell'; // Buy or sell orders + status?: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) + from?: number; // Start time for order query + to?: number; // End time for order query, defaults to current time if not specified + limit?: number; // Maximum number of items returned. Default: 100, minimum: 1, maximum: 100 + page?: number; // Page number } ⋮---- -type: string; // Lending type, margin indicates margin borrowing +currency?: string; // Trading symbol +side?: 'buy' | 'sell'; // Buy or sell orders +status?: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) +from?: number; // Start time for order query +to?: number; // End time for order query, defaults to current time if not specified +limit?: number; // Maximum number of items returned. Default: 100, minimum: 1, maximum: 100 +page?: number; // Page number ⋮---- -export interface MarginUNILoanRecord { - type: string; - currency_pair: string; - currency: string; - amount: string; - create_time: number; +export interface GetAlphaOrderReq { + order_id: string; // Order ID } ⋮---- -export interface MarginUNIInterestRecord { - currency: string; - currency_pair: string; - actual_rate: string; - interest: string; - status: number; - type: string; // Lending type, margin indicates margin borrowing - create_time: number; +order_id: string; // Order ID +⋮---- +export interface GetAlphaCurrenciesReq { + currency?: string; // Query currency information by currency symbol + limit?: number; // Maximum number of records returned in a single list + page?: number; // Page number } ⋮---- -type: string; // Lending type, margin indicates margin borrowing +currency?: string; // Query currency information by currency symbol +limit?: number; // Maximum number of records returned in a single list +page?: number; // Page number ⋮---- -export interface MarginUNIMaxBorrowable { - currency: string; - currency_pair: string; - borrowable: string; +export interface GetAlphaTickersReq { + currency?: string; // Query by specified currency name + limit?: number; // Maximum number of records returned in a single list + page?: number; // Page number } +⋮---- +currency?: string; // Query by specified currency name +limit?: number; // Maximum number of records returned in a single list +page?: number; // Page number ================ -File: src/types/response/multicollateralLoan.ts +File: src/types/request/autoinvest.ts ================ /**========================================================================================================================== - * MULTI COLLATERAL LOAN + * EARN AUTO INVEST * ========================================================================================================================== */ ⋮---- -export interface MultiLoanOrder { - order_id: string; - order_type: string; - fixed_type: string; - fixed_rate: string; - expire_time: number; - auto_renew: boolean; - auto_repay: boolean; - current_ltv: string; - status: string; - borrow_time: number; - total_left_repay_usdt: string; - total_left_collateral_usdt: string; - borrow_currencies: { - currency: string; - index_price: string; - left_repay_principal: string; - left_repay_interest: string; - left_repay_usdt: string; - }[]; - collateral_currencies: { - currency: string; - index_price: string; - left_collateral: string; - left_collateral_usdt: string; - }[]; +export interface AutoInvestPlanPortfolioItemInput { + asset: string; + ratio: string; } ⋮---- -export interface RepayMultiLoanResp { - order_id: number; - repaid_currencies: { - succeeded: boolean; - label?: string; - message?: string; - currency: string; - repaid_principal: string; - repaid_interest: string; - }[]; +/** POST /earn/autoinvest/plans/create */ +export interface CreateAutoInvestPlanReq { + plan_name?: string; + plan_des?: string; + plan_money: string; + plan_amount: string; + plan_period_type: + | 'daily' + | 'weekly' + | 'biweekly' + | 'monthly' + | 'hourly' + | '4-hourly'; + plan_period_day: number; + plan_period_hour: number; + items: AutoInvestPlanPortfolioItemInput[]; + /** Fund source: `spot` or `earn`; default spot */ + fund_source?: string; + /** Fund flow: `auto_invest` or `earn`; default auto_invest */ + fund_flow?: string; + /** 0 normal creation, 1 quick investment */ + type?: number; +} +⋮---- +/** Fund source: `spot` or `earn`; default spot */ +⋮---- +/** Fund flow: `auto_invest` or `earn`; default auto_invest */ +⋮---- +/** 0 normal creation, 1 quick investment */ +⋮---- +/** POST /earn/autoinvest/plans/update */ +export interface UpdateAutoInvestPlanReq { + plan_id: number; + fund_source?: string; + fund_flow?: string; } ⋮---- -export interface MultiLoanRepayRecord { - order_id: number; - record_id: number; - init_ltv: string; - before_ltv: string; - after_ltv: string; - borrow_time: number; - repay_time: number; - borrow_currencies: { - currency: string; - index_price: string; - before_amount: string; - before_amount_usdt: string; - after_amount: string; - after_amount_usdt: string; - }[]; - collateral_currencies: { - currency: string; - index_price: string; - before_amount: string; - before_amount_usdt: string; - after_amount: string; - after_amount_usdt: string; - }[]; - repaid_currencies: { - currency: string; - index_price: string; - repaid_amount: string; - repaid_principal: string; - repaid_interest: string; - repaid_amount_usdt: string; - }[]; - total_interest_list: { - currency: string; - index_price: string; - amount: string; - amount_usdt: string; - }[]; - left_repay_interest_list: { - currency: string; - index_price: string; - before_amount: string; - before_amount_usdt: string; - after_amount: string; - after_amount_usdt: string; - }[]; +/** POST /earn/autoinvest/plans/stop */ +export interface StopAutoInvestPlanReq { + plan_id: number; } ⋮---- -export interface UpdateMultiLoanResp { - order_id: number; - collateral_currencies: { - succeeded: boolean; - label?: string; - message?: string; - currency: string; - amount: string; - }[]; +/** POST /earn/autoinvest/plans/add_position */ +export interface AddAutoInvestPlanPositionReq { + plan_id: number; + amount: string; } ⋮---- -export interface MultiLoanAdjustmentRecord { - order_id: number; - record_id: number; - before_ltv: string; - after_ltv: string; - operate_time: number; - borrow_currencies: { - currency: string; - index_price: string; - before_amount: string; - before_amount_usdt: string; - after_amount: string; - after_amount_usdt: string; - }[]; - collateral_currencies: { - currency: string; - index_price: string; - before_amount: string; - before_amount_usdt: string; - after_amount: string; - after_amount_usdt: string; - }[]; +/** POST /earn/autoinvest/min_invest_amount */ +export interface GetAutoInvestMinAmountReq { + money: string; + items: AutoInvestPlanPortfolioItemInput[]; } ⋮---- -export interface MultiLoanCurrencyQuota { - currency: string; - index_price: string; - min_quota: string; - left_quota: string; - left_quote_usdt: string; - /** Remaining borrow/collateral limit for fixed-term currency */ - left_quota_fixed?: string; - /** Remaining currency limit for fixed-term converted to USDT */ - left_quote_usdt_fixed?: string; +/** GET /earn/autoinvest/coins */ +export interface GetAutoInvestCoinsReq { + /** Pricing currency: USDT or BTC; default USDT */ + plan_money?: string; } ⋮---- -/** Remaining borrow/collateral limit for fixed-term currency */ +/** Pricing currency: USDT or BTC; default USDT */ ⋮---- -/** Remaining currency limit for fixed-term converted to USDT */ +/** GET /earn/autoinvest/plans/records */ +export interface GetAutoInvestPlanRecordsReq { + plan_id: number; + page?: number; + page_size?: number; +} ⋮---- -export interface MultiLoanSupportedCurrencies { - loan_currencies: { - currency: string; - price: string; - }[]; - collateral_currencies: { - currency: string; - index_price: string; - discount: string; - }[]; +/** GET /earn/autoinvest/orders */ +export interface GetAutoInvestOrdersReq { + plan_id: number; + record_id: number; } ⋮---- -export interface MultiLoanRatio { - init_ltv: string; - alert_ltv: string; - liquidate_ltv: string; +/** GET /earn/autoinvest/plans/detail */ +export interface GetAutoInvestPlanDetailReq { + plan_id: number; } ⋮---- -export interface MultiLoanFixedRate { - currency: string; - rate_7d: string; - rate_30d: string; - update_time: number; +/** GET /earn/autoinvest/plans/list_info */ +export interface GetAutoInvestPlansReq { + /** Plan status: e.g. History (history) or Active (active) */ + status: string; + page?: number; + page_size?: number; } +⋮---- +/** Plan status: e.g. History (history) or Active (active) */ ================ -File: src/types/response/rebate.ts +File: src/types/request/p2pMerchant.ts ================ -export interface AgencyTransactionHistoryRecord { - transaction_time: number; - user_id: number; - group_name: string; - fee: string; - fee_asset: string; - currency_pair: string; - amount: string; - amount_asset: string; - source: string; +/** P2P Merchant API request types */ +⋮---- +export interface P2PMerchantGetCounterpartyUserInfoReq { + biz_uid: string; } ⋮---- -export interface AgencyCommissionHistoryRecord { - commission_time: number; - user_id: number; - group_name: string; - /** Rebate commission amount (not a generic trade notional). */ - commission_amount: string; - /** Asset of the rebate commission. */ - commission_asset: string; - source: string; +export interface P2PMerchantGetMyselfPaymentReq { + fiat?: string; +} +⋮---- +export interface P2PMerchantGetPendingTransactionListReq { + crypto_currency: string; + fiat_currency: string; + order_tab?: string; + select_type?: string; + status?: string; + txid?: number; + start_time?: number; + end_time?: number; +} +⋮---- +export interface P2PMerchantGetCompletedTransactionListReq { + crypto_currency: string; + fiat_currency: string; + select_type?: string; + status?: string; + txid?: number; + start_time?: number; + end_time?: number; + query_dispute?: number; + page?: number; + per_page?: number; +} +⋮---- +export interface P2PMerchantGetTransactionDetailsReq { + txid: number; + channel?: string; +} +⋮---- +export interface P2PMerchantConfirmPaymentReq { + trade_id: string; + payment_method: string; +} +⋮---- +export interface P2PMerchantConfirmReceiptReq { + trade_id: string; +} +⋮---- +export interface P2PMerchantCancelTransactionReq { + trade_id: string; + reason_id?: string; + reason_memo?: string; +} +⋮---- +export interface P2PMerchantPlaceBizPushOrderReq { + currencyType: string; + exchangeType: string; + type: string; + unitPrice: string; + number: string; + payType: string; + minAmount?: string; // v4.106.102: No longer required; trade quantity priced by currencyType + maxAmount?: string; // v4.106.102: No longer required; trade quantity priced by currencyType + pay_type_json?: string; + rateFixed?: string; + oid?: string; + tierLimit?: string; + verifiedLimit?: string; + regTimeLimit?: string; + advertisersLimit?: string; + hide_payment?: string; + expire_min?: string; + trade_tips?: string; + auto_reply?: string; + min_completed_limit?: string; + max_completed_limit?: string; + completed_rate_limit?: string; + user_country_limit?: string; + user_order_limit?: string; + rateReferenceId?: string; + rateOffset?: string; + float_trend?: string; + limitBasis?: string; // v4.106.102: 0 by crypto quantity, 1 by fiat amount; defaults to 0 + fiatMinAmount?: string; // v4.106.102: Required when limitBasis is 1 + fiatMaxAmount?: string; // v4.106.102: Required when limitBasis is 1 + polymarket_limit?: string; // v4.106.102: Restrict trading with Polymarket users } ⋮---- -/** Rebate commission amount (not a generic trade notional). */ +minAmount?: string; // v4.106.102: No longer required; trade quantity priced by currencyType +maxAmount?: string; // v4.106.102: No longer required; trade quantity priced by currencyType ⋮---- -/** Asset of the rebate commission. */ +limitBasis?: string; // v4.106.102: 0 by crypto quantity, 1 by fiat amount; defaults to 0 +fiatMinAmount?: string; // v4.106.102: Required when limitBasis is 1 +fiatMaxAmount?: string; // v4.106.102: Required when limitBasis is 1 +polymarket_limit?: string; // v4.106.102: Restrict trading with Polymarket users ⋮---- -export interface PartnerSubordinate { - user_id: number; - user_join_time: number; - type: number; - desc: string; +/** POST /p2p/merchant/account/set_merchant_work_hours — v4.106.96 */ +export interface P2PMerchantSetMerchantWorkHoursReq { + work_status: 0 | 1 | 2; // 0 resting, 1 working, 2 custom working hours + cycle_type?: string; + day_of_week?: string; + time_zone?: string; // UTC offset -12 to +14 + start_time?: string; + end_time?: string; } ⋮---- -export interface BrokerCommissionHistoryRecord { - commission_time: number; - user_id: number; - group_name: string; - amount: string; - fee: string; - fee_asset: string; - rebate_fee: string; - source: string; // Rebate source, e.g. Spot, Futures, Options, Alpha, TradFi - currency_pair: string; - sub_broker_info: { - user_id: number; - original_commission_rate: string; - relative_commission_rate: string; - commission_rate: string; - }; -} +work_status: 0 | 1 | 2; // 0 resting, 1 working, 2 custom working hours ⋮---- -source: string; // Rebate source, e.g. Spot, Futures, Options, Alpha, TradFi +time_zone?: string; // UTC offset -12 to +14 ⋮---- -export interface BrokerTransactionHistoryRecord { - transaction_time: number; - user_id: number; - group_name: string; - fee: string; - currency_pair: string; - amount: string; - fee_asset: string; - source: string; // Rebate source, e.g. Spot, Futures, Options, Alpha, TradFi - sub_broker_info: { - user_id: number; - original_commission_rate: string; - relative_commission_rate: string; - commission_rate: string; - }; +export interface P2PMerchantAdsUpdateStatusReq { + adv_no: number; + adv_status: 1 | 3 | 4; + /** Optional query param */ + trade_type?: string; } ⋮---- -source: string; // Rebate source, e.g. Spot, Futures, Options, Alpha, TradFi +/** Optional query param */ ⋮---- -export interface PartnerCommission { - commission_time: number; - user_id: number; - group_name: string; - /** Rebate commission amount (not a generic trade notional). */ - commission_amount: string; - /** Asset of the rebate commission. */ - commission_asset: string; - source: string; +export interface P2PMerchantAdsDetailReq { + adv_no: string; } ⋮---- -/** Rebate commission amount (not a generic trade notional). */ +export interface P2PMerchantMyAdsListReq { + asset?: string; + fiat_unit?: string; + trade_type?: string; +} ⋮---- -/** Asset of the rebate commission. */ +export interface P2PMerchantGetAdsListReq { + asset: string; + fiat_unit: string; + trade_type: string; +} ⋮---- -export interface PartnerTransaction { - transaction_time: number; - user_id: number; - group_name: string; - fee: string; - fee_asset: string; - currency_pair: string; - amount: string; - amount_asset: string; - source: string; +export interface P2PMerchantGetChatsListReq { + txid: number; + lastreceived?: number; + firstreceived?: number; } ⋮---- -/** `data` object for GET /rebate/partner/data/aggregated */ -export interface PartnerDataAggregated { - rebate_amount: string; - trade_volume: string; - net_fee: string; - customer_count: number; - /** Only when querying all business types (`business_type=0`); may be null */ - trading_user_count?: string | null; - time_range_desc: string; - business_type: number; - business_type_desc: string; +export interface P2PMerchantSendChatMessageReq { + txid: number; + message: string; + /** 0=Text, 1=File (video or image). Default 0 */ + type?: 0 | 1; } ⋮---- -/** Only when querying all business types (`business_type=0`); may be null */ +/** 0=Text, 1=File (video or image). Default 0 */ ⋮---- -export interface PartnerDataAggregatedResponse { - code: number; - message: string; - data: PartnerDataAggregated; - timestamp: number; +export interface P2PMerchantUploadChatFileReq { + image_content_type: string; + base64_img: string; } ================ -File: src/types/response/withdrawal.ts +File: src/types/request/stock.ts ================ -export interface WithdrawalRecord { - id: string; - txid: string; - block_number: string; - withdraw_order_id: string; - /** When `status` is DONE, withdrawal success time (not conditioned on `block_number`). */ - timestamp: string; - amount: string; - currency: string; - address: string; - memo?: string; - status: - | 'BCODE' // Deposit Code Operation - | 'CANCEL' // Cancelled - | 'CANCELPEND' // Withdrawal Cancellation Pending - | 'DMOVE' // Pending Manual Review - | 'DONE' // Completed - | 'EXTPEND' // Sent and Waiting for Confirmation - | 'FAIL' // On-Chain Failure Pending Confirmation - | 'FVERIFY' // Facial Verification in Progress - | 'INVALID' // Invalid Transaction - | 'LOCKED' // Wallet-Side Order Locked - | 'MANUAL' // Pending Manual Review - | 'PEND' // Processing - | 'PROCES' // Processing - | 'REJECT' // Rejected - | 'REQUEST' // Request in Progress - | 'REVIEW' // Under Review - | 'SPLITPEND' // Split Pending - | 'VERIFY'; // Verification in Progress - chain: string; +/** Stock / TradFi Spot API request types */ +⋮---- +export interface GetStockUserAssetsReq { + pnl_calc_type?: number; + pnl_calc_price?: number; } ⋮---- -/** When `status` is DONE, withdrawal success time (not conditioned on `block_number`). */ +export interface GetStockSymbolsReq { + symbols?: string; + exchange?: string; // us | hk | jp + with_desc_i18n?: boolean; + page?: number; + page_size?: number; +} ⋮---- -| 'BCODE' // Deposit Code Operation -| 'CANCEL' // Cancelled -| 'CANCELPEND' // Withdrawal Cancellation Pending -| 'DMOVE' // Pending Manual Review -| 'DONE' // Completed -| 'EXTPEND' // Sent and Waiting for Confirmation -| 'FAIL' // On-Chain Failure Pending Confirmation -| 'FVERIFY' // Facial Verification in Progress -| 'INVALID' // Invalid Transaction -| 'LOCKED' // Wallet-Side Order Locked -| 'MANUAL' // Pending Manual Review -| 'PEND' // Processing -| 'PROCES' // Processing -| 'REJECT' // Rejected -| 'REQUEST' // Request in Progress -| 'REVIEW' // Under Review -| 'SPLITPEND' // Split Pending -| 'VERIFY'; // Verification in Progress - -================ -File: .npmrc -================ -min-release-age=30 -save-exact=true - -================ -File: .nvmrc -================ -v24.18.0 - -================ -File: examples/Rest/otc/submitOTCBankPersonalSupplement.ts -================ -import { readFileSync } from 'fs'; +exchange?: string; // us | hk | jp ⋮---- -import { RestClient } from '../../../src/index.js'; -// import { RestClient } from 'gateio-api'; +export interface GetStockSymbolDetailReq { + symbols?: string; + exchange?: string; // us | hk | jp + page?: number; + page_size?: number; +} ⋮---- -async function submitOTCBankPersonalSupplementExample() - -================ -File: src/types/request/alpha.ts -================ -/**========================================================================================================================== - * ALPHA - * ========================================================================================================================== - */ +exchange?: string; // us | hk | jp ⋮---- -export interface GetAlphaAccountBookReq { - from: number; // Start timestamp for the query - to?: number; // End timestamp for the query, defaults to current time if not specified - page?: number; // Page number - limit?: number; // Maximum 100 items per page +export interface GetStockOrdersReq { + symbol?: string; +} +⋮---- +export interface CreateStockOrderReq { + volume: string; + symbol: string; + side: 1 | 2; + price_type: 'market' | 'limit'; + /** Limit: all only; market: regular only */ + trading_session: 'all' | 'regular'; + time_in_force: 'day'; + price?: string; + client_order_id?: string; +} +⋮---- +/** Limit: all only; market: regular only */ +⋮---- +export interface GetStockOrderHistoryReq { + symbol?: string; + order_ids?: string; + begin_time?: number; + end_time?: number; + side?: 1 | 2; + page?: number; + page_size?: number; } ⋮---- -from: number; // Start timestamp for the query -to?: number; // End timestamp for the query, defaults to current time if not specified -page?: number; // Page number -limit?: number; // Maximum 100 items per page +export interface UpdateStockOrderReq { + volume: string; + price: string; +} ⋮---- -export interface CreateAlphaQuoteReq { - currency: string; // Trading symbol - side: 'buy' | 'sell'; // Buy or sell orders - amount: string; // Trade Quantity (side: buy refers to quote currency USDT, side: sell refers to base currency) - gas_mode: 'speed' | 'custom'; // Trading mode (speed: Smart mode, custom: Custom mode uses slippage parameter) - slippage?: string; // Slippage tolerance (10 means 10% tolerance) - required when gas_mode is custom +export interface GetStockPositionsReq { + pnl_calc_type?: number; + pnl_calc_price?: number; + symbol?: string; + exchange?: string; // us | hk | jp } ⋮---- -currency: string; // Trading symbol -side: 'buy' | 'sell'; // Buy or sell orders -amount: string; // Trade Quantity (side: buy refers to quote currency USDT, side: sell refers to base currency) -gas_mode: 'speed' | 'custom'; // Trading mode (speed: Smart mode, custom: Custom mode uses slippage parameter) -slippage?: string; // Slippage tolerance (10 means 10% tolerance) - required when gas_mode is custom +exchange?: string; // us | hk | jp ⋮---- -export interface CreateAlphaOrderReq { - currency: string; // Trading symbol - side: 'buy' | 'sell'; // Buy or sell orders - amount: string; // Trade Quantity (side: buy refers to quote currency USDT, side: sell refers to base currency) - gas_mode: 'speed' | 'custom'; // Trading mode (speed: Smart mode, custom: Custom mode uses slippage parameter) - slippage?: string; // Slippage tolerance (10 means 10% tolerance) - required when gas_mode is custom - quote_id: string; // Quote ID returned from quotation API +export interface CloseStockPositionReq { + symbol: string; + close_type: 1 | 2; + close_volume?: string; } ⋮---- -currency: string; // Trading symbol -side: 'buy' | 'sell'; // Buy or sell orders -amount: string; // Trade Quantity (side: buy refers to quote currency USDT, side: sell refers to base currency) -gas_mode: 'speed' | 'custom'; // Trading mode (speed: Smart mode, custom: Custom mode uses slippage parameter) -slippage?: string; // Slippage tolerance (10 means 10% tolerance) - required when gas_mode is custom -quote_id: string; // Quote ID returned from quotation API -⋮---- -export interface GetAlphaOrdersReq { - currency?: string; // Trading symbol - side?: 'buy' | 'sell'; // Buy or sell orders - status?: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) - from?: number; // Start time for order query - to?: number; // End time for order query, defaults to current time if not specified - limit?: number; // Maximum number of items returned. Default: 100, minimum: 1, maximum: 100 - page?: number; // Page number +export interface GetStockTransactionsReq { + begin_time?: number; + end_time?: number; + ref_id?: string; + type?: string; + page?: number; + page_size?: number; } ⋮---- -currency?: string; // Trading symbol -side?: 'buy' | 'sell'; // Buy or sell orders -status?: number; // Order Status (0: All, 1: Processing, 2: Successful, 3: Failed, 4: Cancelled, 5: Buy order placed but transfer not completed, 6: Order cancelled but transfer not completed) -from?: number; // Start time for order query -to?: number; // End time for order query, defaults to current time if not specified -limit?: number; // Maximum number of items returned. Default: 100, minimum: 1, maximum: 100 -page?: number; // Page number +export interface CreateStockTransactionReq { + asset: string; + change: string; + type: 'deposit' | 'withdraw'; + ref_id: string; +} + +================ +File: src/types/response/p2pMerchant.ts +================ +/** P2P Merchant API response types */ ⋮---- -export interface GetAlphaOrderReq { - order_id: string; // Order ID +export interface P2PMerchantApiResp { + timestamp: number; + method: string; + code: number; + message: string; + data: T; + version: string; } ⋮---- -order_id: string; // Order ID +export interface P2PMerchantUserInfo { + is_self?: boolean; + user_timest?: string; + counterparties_num?: number; + email_verified?: string; + verified?: string; + has_phone?: string; + user_name?: string; + user_note?: string; + complete_transactions?: string; + paid_transactions?: string; + accepted_transactions?: string; + transactions_used_time?: string; + cancelled_used_time_month?: string; + complete_transactions_month?: string; + complete_rate_month?: number; + orders_buy_rate_month?: number; + is_black?: number; + is_follow?: number; + have_traded?: number; + biz_uid?: string; + blue_vip?: number; + work_status?: number; + registration_days?: number; + first_trade_days?: number; + need_replenish?: number; + merchant_info?: { type?: string; market?: string }; + online_status?: number; + work_hours?: Record | null; + transactions_month?: number; + transactions_all?: number; + trade_versatile?: boolean; + [key: string]: unknown; +} ⋮---- -export interface GetAlphaCurrenciesReq { - currency?: string; // Query currency information by currency symbol - limit?: number; // Maximum number of records returned in a single list - page?: number; // Page number +export interface P2PMerchantCounterpartyUserInfo { + user_timest?: string; + email_verified?: string; + verified?: string; + has_phone?: string; + user_name?: string; + user_note?: string; + complete_transactions?: string; + paid_transactions?: string; + accepted_transactions?: string; + transactions_used_time?: string; + cancelled_used_time_month?: string; + complete_transactions_month?: string; + complete_rate_month?: number; + is_follow?: number; + have_traded?: number; + biz_uid?: string; + registration_days?: number; + first_trade_days?: number; + trade_versatile?: boolean; + [key: string]: unknown; } ⋮---- -currency?: string; // Query currency information by currency symbol -limit?: number; // Maximum number of records returned in a single list -page?: number; // Page number +export interface P2PMerchantPaymentMethod { + pay_type: string; + pay_name: string; + ids: number[]; + list: Record[]; +} ⋮---- -export interface GetAlphaTickersReq { - currency?: string; // Query by specified currency name - limit?: number; // Maximum number of records returned in a single list - page?: number; // Page number +export interface P2PMerchantTransactionListItem { + type_buy?: number; + timest?: string; + timest_expire?: string; + type?: string; + trade_type?: string; + timestamp?: number; + rate?: string; + amount?: string; + total?: string; + txid?: number; + status?: string; + order_status?: string; + [key: string]: unknown; } ⋮---- -currency?: string; // Query by specified currency name -limit?: number; // Maximum number of records returned in a single list -page?: number; // Page number - -================ -File: src/types/request/autoinvest.ts -================ -/**========================================================================================================================== - * EARN AUTO INVEST - * ========================================================================================================================== - */ +export interface P2PMerchantTransactionListData { + list: P2PMerchantTransactionListItem[]; + trans_time?: { od_time?: number }[]; + count: number; + exported_num: number; +} ⋮---- -export interface AutoInvestPlanPortfolioItemInput { - asset: string; - ratio: string; +export interface P2PMerchantTransactionDetails { + is_sell?: number; + txid?: number; + orderid?: number; + timest?: number; + last_pay_time?: number; + remain_pay_time?: number; + currencyType?: string; + want_type?: string; + rate?: string; + amount?: string; + total?: string; + status?: string; + state?: string; + its_uid?: string; + its_nickname?: string; + its_realname?: string; + [key: string]: unknown; } ⋮---- -/** POST /earn/autoinvest/plans/create */ -export interface CreateAutoInvestPlanReq { - plan_name?: string; - plan_des?: string; - plan_money: string; - plan_amount: string; - plan_period_type: - | 'daily' - | 'weekly' - | 'biweekly' - | 'monthly' - | 'hourly' - | '4-hourly'; - plan_period_day: number; - plan_period_hour: number; - items: AutoInvestPlanPortfolioItemInput[]; - /** Fund source: `spot` or `earn`; default spot */ - fund_source?: string; - /** Fund flow: `auto_invest` or `earn`; default auto_invest */ - fund_flow?: string; - /** 0 normal creation, 1 quick investment */ - type?: number; +export interface P2PMerchantAdsDetail { + rate?: string; + type?: string; + amount?: string; + min_amount?: string; + max_amount?: string; + fiat_min_amount?: string; // v4.106.102: Min fiat amount per order + fiat_max_amount?: string; // v4.106.102: Max fiat amount per order + minFiatAmount?: string; // v4.106.102 + maxFiatAmount?: string; // v4.106.102 + limitBasis?: string; // v4.106.102: 0 by crypto quantity, 1 by fiat amount + limitBasisText?: string; // v4.106.102 + polymarket_limit?: string; // v4.106.102 + total?: string; + orderid?: number; + timestamp?: number; + currencyType?: string; + want_type?: string; + status?: string; + [key: string]: unknown; } ⋮---- -/** Fund source: `spot` or `earn`; default spot */ -⋮---- -/** Fund flow: `auto_invest` or `earn`; default auto_invest */ -⋮---- -/** 0 normal creation, 1 quick investment */ -⋮---- -/** POST /earn/autoinvest/plans/update */ -export interface UpdateAutoInvestPlanReq { - plan_id: number; - fund_source?: string; - fund_flow?: string; -} +fiat_min_amount?: string; // v4.106.102: Min fiat amount per order +fiat_max_amount?: string; // v4.106.102: Max fiat amount per order +minFiatAmount?: string; // v4.106.102 +maxFiatAmount?: string; // v4.106.102 +limitBasis?: string; // v4.106.102: 0 by crypto quantity, 1 by fiat amount +limitBasisText?: string; // v4.106.102 +polymarket_limit?: string; // v4.106.102 ⋮---- -/** POST /earn/autoinvest/plans/stop */ -export interface StopAutoInvestPlanReq { - plan_id: number; +export interface P2PMerchantMyAdsListItem { + type?: string; + rate?: string; + amount?: string; + total?: string; + id?: string; + status?: string; + currencyType?: string; + want_type?: string; + fiat_min_amount?: string; // v4.106.102 + fiat_max_amount?: string; // v4.106.102 + limit_basis?: string; // v4.106.103 + limit_basis_text?: string; // v4.106.103 + [key: string]: unknown; } ⋮---- -/** POST /earn/autoinvest/plans/add_position */ -export interface AddAutoInvestPlanPositionReq { - plan_id: number; - amount: string; -} +fiat_min_amount?: string; // v4.106.102 +fiat_max_amount?: string; // v4.106.102 +limit_basis?: string; // v4.106.103 +limit_basis_text?: string; // v4.106.103 ⋮---- -/** POST /earn/autoinvest/min_invest_amount */ -export interface GetAutoInvestMinAmountReq { - money: string; - items: AutoInvestPlanPortfolioItemInput[]; +export interface P2PMerchantMyAdsListData { + lists: P2PMerchantMyAdsListItem[]; } ⋮---- -/** GET /earn/autoinvest/coins */ -export interface GetAutoInvestCoinsReq { - /** Pricing currency: USDT or BTC; default USDT */ - plan_money?: string; +export interface P2PMerchantAdsListItem { + index?: number; + asset?: string; + fiat_unit?: string; + adv_no?: number; + price?: string; + max_single_trans_amount?: string; + min_single_trans_amount?: string; + nick_name?: string; + surplus_amount?: string; // v4.106.103: Remaining tradable crypto quantity + trade_methods?: string[]; // v4.106.103: Supported payment methods list + fiat_min_amount?: string; // v4.106.103 + fiat_max_amount?: string; // v4.106.103 + limit_basis?: string; // v4.106.103 + limit_basis_text?: string; // v4.106.103 } ⋮---- -/** Pricing currency: USDT or BTC; default USDT */ +surplus_amount?: string; // v4.106.103: Remaining tradable crypto quantity +trade_methods?: string[]; // v4.106.103: Supported payment methods list +fiat_min_amount?: string; // v4.106.103 +fiat_max_amount?: string; // v4.106.103 +limit_basis?: string; // v4.106.103 +limit_basis_text?: string; // v4.106.103 ⋮---- -/** GET /earn/autoinvest/plans/records */ -export interface GetAutoInvestPlanRecordsReq { - plan_id: number; - page?: number; - page_size?: number; +export interface P2PMerchantChatMessage { + is_sell?: number; + msg_type?: number; + msg?: string; + username?: string; + uid?: string; + timest?: number; + type?: number; + pic?: string; + file_key?: string; + file_type?: string; + width?: string; + height?: string; + msg_obj?: Record; + risk_type?: number; // v4.106.96: 1 off-platform traffic diversion risk + toast_msg?: string; // v4.106.96 + [key: string]: unknown; } ⋮---- -/** GET /earn/autoinvest/orders */ -export interface GetAutoInvestOrdersReq { - plan_id: number; - record_id: number; -} +risk_type?: number; // v4.106.96: 1 off-platform traffic diversion risk +toast_msg?: string; // v4.106.96 ⋮---- -/** GET /earn/autoinvest/plans/detail */ -export interface GetAutoInvestPlanDetailReq { - plan_id: number; +/** v4.106.96: Risk control response when place_biz_push_order hits off-platform diversion check */ +export interface P2PMerchantPlaceOrderRiskData { + risk_code?: string; + risk_event?: { + type?: string; + title?: string; + msg?: string; + action?: string; + content_risk_type?: string; + trade_tips?: string; + auto_reply?: string; + }; } ⋮---- -/** GET /earn/autoinvest/plans/list_info */ -export interface GetAutoInvestPlansReq { - /** Plan status: e.g. History (history) or Active (active) */ - status: string; - page?: number; - page_size?: number; +/** v4.106.96: send_chat_message risk fields in data */ +export interface P2PMerchantSendChatMessageData { + risk_type?: number; + toast_msg?: string; + [key: string]: unknown; } ⋮---- -/** Plan status: e.g. History (history) or Active (active) */ +export interface P2PMerchantChatsListData { + messages: P2PMerchantChatMessage[]; + has_history?: boolean; + txid?: number; + SRVTM?: number; + order_status?: string; + memo?: string; +} ================ -File: src/types/request/p2pMerchant.ts +File: src/types/websockets/client.ts ================ -/** P2P Merchant API request types */ +import type { ClientRequestArgs } from 'http'; +import WebSocket from 'isomorphic-ws'; ⋮---- -export interface P2PMerchantGetCounterpartyUserInfoReq { - biz_uid: string; -} +/** + * Event args for subscribing/unsubscribing + */ ⋮---- -export interface P2PMerchantGetMyselfPaymentReq { - fiat?: string; -} +// export type WsTopicSubscribePrivateArgsV2 = +// | WsTopicSubscribePrivateInstIdArgsV2 +// | WsTopicSubscribePrivateCoinArgsV2; ⋮---- -export interface P2PMerchantGetPendingTransactionListReq { - crypto_currency: string; - fiat_currency: string; - order_tab?: string; - select_type?: string; - status?: string; - txid?: number; - start_time?: number; - end_time?: number; +// export type WsTopicSubscribeEventArgsV2 = +// | WsTopicSubscribePublicArgsV2 +// | WsTopicSubscribePrivateArgsV2; +⋮---- +/** General configuration for the WebsocketClient */ +export interface WSClientConfigurableOptions { + /** Your API key */ + apiKey?: string; + + /** Your API secret */ + apiSecret?: string; + + /** Use the Gate TestNet WebSocket hosts. */ + useTestnet?: boolean; + + /** Define a recv window when preparing a private websocket signature. This is in milliseconds, so 5000 == 5 seconds */ + recvWindow?: number; + + /** How often to check if the connection is alive */ + pingInterval?: number; + + /** How long to wait for a pong (heartbeat reply) before assuming the connection is dead */ + pongTimeout?: number; + + /** Delay in milliseconds before respawning the connection */ + reconnectTimeout?: number; + + requestOptions?: {}; + + wsUrl?: string; + + wsOptions?: { + protocols?: string[]; + agent?: any; + } & ( + | Omit, 'agent'> + | Omit, 'agent'> + ); + + /** + * Allows you to provide a custom "signMessage" function, e.g. to use node's much faster createHmac method + * + * Look in the examples folder for a demonstration on using node's createHmac instead. + */ + customSignMessageFn?: (message: string, secret: string) => Promise; + + /** + * If you authenticated the WS API before, automatically try to re-authenticate the WS API if you're disconnected/reconnected for any reason. + */ + reauthWSAPIOnReconnect?: boolean; } ⋮---- -export interface P2PMerchantGetCompletedTransactionListReq { - crypto_currency: string; - fiat_currency: string; - select_type?: string; - status?: string; - txid?: number; - start_time?: number; - end_time?: number; - query_dispute?: number; - page?: number; - per_page?: number; +/** Your API key */ +⋮---- +/** Your API secret */ +⋮---- +/** Use the Gate TestNet WebSocket hosts. */ +⋮---- +/** Define a recv window when preparing a private websocket signature. This is in milliseconds, so 5000 == 5 seconds */ +⋮---- +/** How often to check if the connection is alive */ +⋮---- +/** How long to wait for a pong (heartbeat reply) before assuming the connection is dead */ +⋮---- +/** Delay in milliseconds before respawning the connection */ +⋮---- +/** + * Allows you to provide a custom "signMessage" function, e.g. to use node's much faster createHmac method + * + * Look in the examples folder for a demonstration on using node's createHmac instead. + */ +⋮---- +/** + * If you authenticated the WS API before, automatically try to re-authenticate the WS API if you're disconnected/reconnected for any reason. + */ +⋮---- +/** + * WS configuration that's always defined, regardless of user configuration + * (usually comes from defaults if there's no user-provided values) + */ +export interface WebsocketClientOptions extends WSClientConfigurableOptions { + pingInterval: number; + pongTimeout: number; + reconnectTimeout: number; + recvWindow: number; + authPrivateConnectionsOnConnect: boolean; + authPrivateRequests: boolean; + reauthWSAPIOnReconnect: boolean; } + +================ +File: webpack/webpack.config.cjs +================ +function generateConfig(name) ⋮---- -export interface P2PMerchantGetTransactionDetailsReq { - txid: number; - channel?: string; -} +// Add '.ts' and '.tsx' as resolvable extensions. ⋮---- -export interface P2PMerchantConfirmPaymentReq { - trade_id: string; - payment_method: string; -} +// Node.js core modules not available in browsers +// The REST client's https.Agent (for keepAlive) is Node.js-only and won't work in browsers ⋮---- -export interface P2PMerchantConfirmReceiptReq { - trade_id: string; -} +// Code is already transpiled from TypeScript, no additional loaders needed + +================ +File: src/lib/BaseRestClient.ts +================ +import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'; +// NOTE: https.Agent is Node.js-only and not available in browser environments +// Browser builds (via webpack) exclude this module - see webpack.config.js fallback settings +import https from 'https'; ⋮---- -export interface P2PMerchantCancelTransactionReq { - trade_id: string; - reason_id?: string; - reason_memo?: string; -} +import { neverGuard } from './misc-util.js'; +import { + CHANNEL_ID, + getRestBaseUrl, + RestClientOptions, + serializeParams, +} from './requestUtils.js'; +import { + checkWebCryptoAPISupported, + hashMessage, + SignAlgorithm, + SignEncodeMethod, + signMessage, +} from './webCryptoAPI.js'; ⋮---- -export interface P2PMerchantPlaceBizPushOrderReq { - currencyType: string; - exchangeType: string; - type: string; - unitPrice: string; - number: string; - payType: string; - minAmount?: string; // v4.106.102: No longer required; trade quantity priced by currencyType - maxAmount?: string; // v4.106.102: No longer required; trade quantity priced by currencyType - pay_type_json?: string; - rateFixed?: string; - oid?: string; - tierLimit?: string; - verifiedLimit?: string; - regTimeLimit?: string; - advertisersLimit?: string; - hide_payment?: string; - expire_min?: string; - trade_tips?: string; - auto_reply?: string; - min_completed_limit?: string; - max_completed_limit?: string; - completed_rate_limit?: string; - user_country_limit?: string; - user_order_limit?: string; - rateReferenceId?: string; - rateOffset?: string; - float_trend?: string; - limitBasis?: string; // v4.106.102: 0 by crypto quantity, 1 by fiat amount; defaults to 0 - fiatMinAmount?: string; // v4.106.102: Required when limitBasis is 1 - fiatMaxAmount?: string; // v4.106.102: Required when limitBasis is 1 - polymarket_limit?: string; // v4.106.102: Restrict trading with Polymarket users -} +/** + * Used to switch how authentication/requests work under the hood + */ ⋮---- -minAmount?: string; // v4.106.102: No longer required; trade quantity priced by currencyType -maxAmount?: string; // v4.106.102: No longer required; trade quantity priced by currencyType +export type RestClientType = + (typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM]; ⋮---- -limitBasis?: string; // v4.106.102: 0 by crypto quantity, 1 by fiat amount; defaults to 0 -fiatMinAmount?: string; // v4.106.102: Required when limitBasis is 1 -fiatMaxAmount?: string; // v4.106.102: Required when limitBasis is 1 -polymarket_limit?: string; // v4.106.102: Restrict trading with Polymarket users +interface SignedRequest { + originalParams: T; + paramsWithSign?: T & { sign: string }; + serializedParams: string; + sign: string; + queryParamsWithSign: string; + timestamp: number; + recvWindow: number; +} ⋮---- -/** POST /p2p/merchant/account/set_merchant_work_hours — v4.106.96 */ -export interface P2PMerchantSetMerchantWorkHoursReq { - work_status: 0 | 1 | 2; // 0 resting, 1 working, 2 custom working hours - cycle_type?: string; - day_of_week?: string; - time_zone?: string; // UTC offset -12 to +14 - start_time?: string; - end_time?: string; +interface UnsignedRequest { + originalParams: T; + paramsWithSign: T; } ⋮---- -work_status: 0 | 1 | 2; // 0 resting, 1 working, 2 custom working hours +type SignMethod = 'gateV4'; ⋮---- -time_zone?: string; // UTC offset -12 to +14 +/** + * Some requests require some params to be in the query string and some in the body. Some even support passing params via headers. + * This type anticipates these are possible in any combination. + * + * The request builder will automatically handle where parameters should go. + */ +type ParamsInQueryBodyOrHeader = { + query?: object; + body?: object; + headers?: object; + /** multipart/form-data body; mutually exclusive with `body` */ + multipart?: FormData; +}; ⋮---- -export interface P2PMerchantAdsUpdateStatusReq { - adv_no: number; - adv_status: 1 | 3 | 4; - /** Optional query param */ - trade_type?: string; -} +/** multipart/form-data body; mutually exclusive with `body` */ ⋮---- -/** Optional query param */ +/** + * Enables: + * - Detailed request/response logging + * - Full request dump in any exceptions thrown from API responses + */ ⋮---- -export interface P2PMerchantAdsDetailReq { - adv_no: string; -} +// request: { +// url: response.config.url, +// method: response.config.method, +// data: response.config.data, +// headers: response.config.headers, +// }, ⋮---- -export interface P2PMerchantMyAdsListReq { - asset?: string; - fiat_unit?: string; - trade_type?: string; -} +/** + * Impure, mutates params to remove any values that have a key but are undefined. + */ +function deleteUndefinedValues(params?: any): void ⋮---- -export interface P2PMerchantGetAdsListReq { - asset: string; - fiat_unit: string; - trade_type: string; -} +export abstract class BaseRestClient ⋮---- -export interface P2PMerchantGetChatsListReq { - txid: number; - lastreceived?: number; - firstreceived?: number; -} +/** Defines the client type (affecting how requests & signatures behave) */ +abstract getClientType(): RestClientType; ⋮---- -export interface P2PMerchantSendChatMessageReq { - txid: number; - message: string; - /** 0=Text, 1=File (video or image). Default 0 */ - type?: 0 | 1; -} +/** + * Create an instance of the REST client. Pass API credentials in the object in the first parameter. + * @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity + * @param {AxiosRequestConfig} [networkOptions={}] HTTP networking options for axios + */ +constructor( + restClientOptions: RestClientOptions = {}, + networkOptions: AxiosRequestConfig = {}, +) ⋮---- -/** 0=Text, 1=File (video or image). Default 0 */ +/** Throw errors if any request params are empty */ ⋮---- -export interface P2PMerchantUploadChatFileReq { - image_content_type: string; - base64_img: string; -} - -================ -File: src/types/request/stock.ts -================ -/** Stock / TradFi Spot API request types */ +/** in ms == 5 minutes by default */ ⋮---- -export interface GetStockUserAssetsReq { - pnl_calc_type?: number; - pnl_calc_price?: number; -} +/** inject custom rquest options based on axios specs - see axios docs for more guidance on AxiosRequestConfig: https://github.com/axios/axios#request-config */ ⋮---- -export interface GetStockSymbolsReq { - symbols?: string; - exchange?: string; // us | hk | jp - with_desc_i18n?: boolean; - page?: number; - page_size?: number; -} +// If enabled, configure a https agent with keepAlive enabled +// NOTE: This is Node.js-only functionality. In browser environments, this code is skipped +// as the 'https' module is excluded via webpack fallback configuration. +// Browser connection pooling is handled automatically by the browser itself. ⋮---- -exchange?: string; // us | hk | jp +// Extract existing https agent parameters, if provided, to prevent the keepAlive flag from overwriting an existing https agent completely ⋮---- -export interface GetStockSymbolDetailReq { - symbols?: string; - exchange?: string; // us | hk | jp - page?: number; - page_size?: number; -} +// For more advanced configuration, raise an issue on GitHub or use the "networkOptions" +// parameter to define a custom httpsAgent with the desired properties ⋮---- -exchange?: string; // us | hk | jp +// Check Web Crypto API support when credentials are provided and no custom sign function is used ⋮---- -export interface GetStockOrdersReq { - symbol?: string; -} +// Throw if one of the 3 values is missing, but at least one of them is set ⋮---- -export interface CreateStockOrderReq { - volume: string; - symbol: string; - side: 1 | 2; - price_type: 'market' | 'limit'; - /** Limit: all only; market: regular only */ - trading_session: 'all' | 'regular'; - time_in_force: 'day'; - price?: string; - client_order_id?: string; -} +/** + * Timestamp used to sign the request. Override this method to implement your own timestamp/sync mechanism + */ +getSignTimestampMs(): number +⋮---- +protected get(endpoint: string, params?: object) +⋮---- +// GET only supports params in the query string ⋮---- -/** Limit: all only; market: regular only */ +protected post(endpoint: string, params?: ParamsInQueryBodyOrHeader) ⋮---- -export interface GetStockOrderHistoryReq { - symbol?: string; - order_ids?: string; - begin_time?: number; - end_time?: number; - side?: 1 | 2; - page?: number; - page_size?: number; -} +protected getPrivate(endpoint: string, params?: object) ⋮---- -export interface UpdateStockOrderReq { - volume: string; - price: string; -} +// GET only supports params in the query string ⋮---- -export interface GetStockPositionsReq { - pnl_calc_type?: number; - pnl_calc_price?: number; - symbol?: string; - exchange?: string; // us | hk | jp -} +protected postPrivate(endpoint: string, params?: ParamsInQueryBodyOrHeader) ⋮---- -exchange?: string; // us | hk | jp +/** POST private endpoint with multipart/form-data (empty body hash for signing) */ +protected postPrivateMultipart( + endpoint: string, + formData: FormData, + query?: object, +) ⋮---- -export interface CloseStockPositionReq { - symbol: string; - close_type: 1 | 2; - close_volume?: string; -} +protected deletePrivate( + endpoint: string, + params?: ParamsInQueryBodyOrHeader, +) ⋮---- -export interface GetStockTransactionsReq { - begin_time?: number; - end_time?: number; - ref_id?: string; - type?: string; - page?: number; - page_size?: number; -} +protected putPrivate(endpoint: string, params?: ParamsInQueryBodyOrHeader) ⋮---- -export interface CreateStockTransactionReq { - asset: string; - change: string; - type: 'deposit' | 'withdraw'; - ref_id: string; -} - -================ -File: src/types/response/p2pMerchant.ts -================ -/** P2P Merchant API response types */ +// protected patchPrivate(endpoint: string, params?: any) { +protected patchPrivate(endpoint: string, params?: ParamsInQueryBodyOrHeader) ⋮---- -export interface P2PMerchantApiResp { - timestamp: number; - method: string; - code: number; - message: string; - data: T; - version: string; -} +/** + * @private Make a HTTP request to a specific endpoint. Private endpoint API calls are automatically signed. + */ +private async _call( + method: Method, + endpoint: string, + params?: ParamsInQueryBodyOrHeader, + isPublicApi?: boolean, +): Promise ⋮---- -export interface P2PMerchantUserInfo { - is_self?: boolean; - user_timest?: string; - counterparties_num?: number; - email_verified?: string; - verified?: string; - has_phone?: string; - user_name?: string; - user_note?: string; - complete_transactions?: string; - paid_transactions?: string; - accepted_transactions?: string; - transactions_used_time?: string; - cancelled_used_time_month?: string; - complete_transactions_month?: string; - complete_rate_month?: number; - orders_buy_rate_month?: number; - is_black?: number; - is_follow?: number; - have_traded?: number; - biz_uid?: string; - blue_vip?: number; - work_status?: number; - registration_days?: number; - first_trade_days?: number; - need_replenish?: number; - merchant_info?: { type?: string; market?: string }; - online_status?: number; - work_hours?: Record | null; - transactions_month?: number; - transactions_all?: number; - trade_versatile?: boolean; - [key: string]: unknown; -} +// Sanity check to make sure it's only ever prefixed by one forward slash ⋮---- -export interface P2PMerchantCounterpartyUserInfo { - user_timest?: string; - email_verified?: string; - verified?: string; - has_phone?: string; - user_name?: string; - user_note?: string; - complete_transactions?: string; - paid_transactions?: string; - accepted_transactions?: string; - transactions_used_time?: string; - cancelled_used_time_month?: string; - complete_transactions_month?: string; - complete_rate_month?: number; - is_follow?: number; - have_traded?: number; - biz_uid?: string; - registration_days?: number; - first_trade_days?: number; - trade_versatile?: boolean; - [key: string]: unknown; -} +// Build a request and handle signature process ⋮---- -export interface P2PMerchantPaymentMethod { - pay_type: string; - pay_name: string; - ids: number[]; - list: Record[]; -} +// Dispatch request ⋮---- -export interface P2PMerchantTransactionListItem { - type_buy?: number; - timest?: string; - timest_expire?: string; - type?: string; - trade_type?: string; - timestamp?: number; - rate?: string; - amount?: string; - total?: string; - txid?: number; - status?: string; - order_status?: string; - [key: string]: unknown; -} +// See: https://www.gate.io/docs/developers/apiv4/en/#return-format ⋮---- -export interface P2PMerchantTransactionListData { - list: P2PMerchantTransactionListItem[]; - trans_time?: { od_time?: number }[]; - count: number; - exported_num: number; -} +// Throw API rejections by parsing the response code from the body ⋮---- -export interface P2PMerchantTransactionDetails { - is_sell?: number; - txid?: number; - orderid?: number; - timest?: number; - last_pay_time?: number; - remain_pay_time?: number; - currencyType?: string; - want_type?: string; - rate?: string; - amount?: string; - total?: string; - status?: string; - state?: string; - its_uid?: string; - its_nickname?: string; - its_realname?: string; - [key: string]: unknown; -} +/** + * @private generic handler to parse request exceptions + */ +parseException(e: any, request: AxiosRequestConfig): unknown ⋮---- -export interface P2PMerchantAdsDetail { - rate?: string; - type?: string; - amount?: string; - min_amount?: string; - max_amount?: string; - fiat_min_amount?: string; // v4.106.102: Min fiat amount per order - fiat_max_amount?: string; // v4.106.102: Max fiat amount per order - minFiatAmount?: string; // v4.106.102 - maxFiatAmount?: string; // v4.106.102 - limitBasis?: string; // v4.106.102: 0 by crypto quantity, 1 by fiat amount - limitBasisText?: string; // v4.106.102 - polymarket_limit?: string; // v4.106.102 - total?: string; - orderid?: number; - timestamp?: number; - currencyType?: string; - want_type?: string; - status?: string; - [key: string]: unknown; -} +// Something happened in setting up the request that triggered an error ⋮---- -fiat_min_amount?: string; // v4.106.102: Min fiat amount per order -fiat_max_amount?: string; // v4.106.102: Max fiat amount per order -minFiatAmount?: string; // v4.106.102 -maxFiatAmount?: string; // v4.106.102 -limitBasis?: string; // v4.106.102: 0 by crypto quantity, 1 by fiat amount -limitBasisText?: string; // v4.106.102 -polymarket_limit?: string; // v4.106.102 +// request made but no response received ⋮---- -export interface P2PMerchantMyAdsListItem { - type?: string; - rate?: string; - amount?: string; - total?: string; - id?: string; - status?: string; - currencyType?: string; - want_type?: string; - fiat_min_amount?: string; // v4.106.102 - fiat_max_amount?: string; // v4.106.102 - limit_basis?: string; // v4.106.103 - limit_basis_text?: string; // v4.106.103 - [key: string]: unknown; -} +// The request was made and the server responded with a status code +// that falls out of the range of 2xx ⋮---- -fiat_min_amount?: string; // v4.106.102 -fiat_max_amount?: string; // v4.106.102 -limit_basis?: string; // v4.106.103 -limit_basis_text?: string; // v4.106.103 +// console.error('err: ', response?.data); +⋮---- +// Prevent credentials from leaking into error messages +⋮---- +/** + * @private sign request and set recv window + */ +private async signRequest< + T extends ParamsInQueryBodyOrHeader | undefined = {}, + >( + data: T, + endpoint: string, + method: Method, + signMethod: SignMethod, +): Promise> ⋮---- -export interface P2PMerchantMyAdsListData { - lists: P2PMerchantMyAdsListItem[]; -} +const timestamp = +(this.getSignTimestampMs() / 1000).toFixed(0); // in seconds ⋮---- -export interface P2PMerchantAdsListItem { - index?: number; - asset?: string; - fiat_unit?: string; - adv_no?: number; - price?: string; - max_single_trans_amount?: string; - min_single_trans_amount?: string; - nick_name?: string; - surplus_amount?: string; // v4.106.103: Remaining tradable crypto quantity - trade_methods?: string[]; // v4.106.103: Supported payment methods list - fiat_min_amount?: string; // v4.106.103 - fiat_max_amount?: string; // v4.106.103 - limit_basis?: string; // v4.106.103 - limit_basis_text?: string; // v4.106.103 -} +// recvWindow: this.options.recvWindow, ⋮---- -surplus_amount?: string; // v4.106.103: Remaining tradable crypto quantity -trade_methods?: string[]; // v4.106.103: Supported payment methods list -fiat_min_amount?: string; // v4.106.103 -fiat_max_amount?: string; // v4.106.103 -limit_basis?: string; // v4.106.103 -limit_basis_text?: string; // v4.106.103 +// It's possible to override the recv window on a per rquest level ⋮---- -export interface P2PMerchantChatMessage { - is_sell?: number; - msg_type?: number; - msg?: string; - username?: string; - uid?: string; - timest?: number; - type?: number; - pic?: string; - file_key?: string; - file_type?: string; - width?: string; - height?: string; - msg_obj?: Record; - risk_type?: number; // v4.106.96: 1 off-platform traffic diversion risk - toast_msg?: string; // v4.106.96 - [key: string]: unknown; -} +// console.log('sign params: ', { +// requestBodyToHash, +// paramsStr: toSign, +// url: this.baseUrl, +// urlPath: this.baseUrlPath, +// }); ⋮---- -risk_type?: number; // v4.106.96: 1 off-platform traffic diversion risk -toast_msg?: string; // v4.106.96 +private async signMessage( + paramsStr: string, + secret: string, + method: 'hex' | 'base64', + algorithm: SignAlgorithm, +): Promise ⋮---- -/** v4.106.96: Risk control response when place_biz_push_order hits off-platform diversion check */ -export interface P2PMerchantPlaceOrderRiskData { - risk_code?: string; - risk_event?: { - type?: string; - title?: string; - msg?: string; - action?: string; - content_risk_type?: string; - trade_tips?: string; - auto_reply?: string; - }; -} +private async prepareSignParams< + TParams extends ParamsInQueryBodyOrHeader | undefined, + >( + method: Method, + endpoint: string, + signMethod: SignMethod, + params?: TParams, + isPublicApi?: true, + ): Promise>; ⋮---- -/** v4.106.96: send_chat_message risk fields in data */ -export interface P2PMerchantSendChatMessageData { - risk_type?: number; - toast_msg?: string; - [key: string]: unknown; -} +private async prepareSignParams< + TParams extends ParamsInQueryBodyOrHeader | undefined, + >( + method: Method, + endpoint: string, + signMethod: SignMethod, + params?: TParams, + isPublicApi?: false | undefined, + ): Promise>; ⋮---- -export interface P2PMerchantChatsListData { - messages: P2PMerchantChatMessage[]; - has_history?: boolean; - txid?: number; - SRVTM?: number; - order_status?: string; - memo?: string; -} - -================ -File: .gitignore -================ -!.gitkeep -.DS_STORE -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json -pids -*.pid -*.seed -*.pid.lock -node_modules/ -.npm -.eslintcache -.node_repl_history -*.tgz -.yarn-integrity -.env -.env.test -.cache -bundleReport.html -.history/ -dist -coverage -localtest.sh -repomix.sh -doc -examples/ignored/ - -ws-private-spot-wsapi-performance.ts -ws-private-perp-futures-wsapi-readonly.ts -privatetest.ts - -privaterepotracker -restClientRegex.ts - -testfile.ts +private async prepareSignParams< + TParams extends ParamsInQueryBodyOrHeader | undefined, + >( + method: Method, + endpoint: string, + signMethod: SignMethod, + params?: TParams, + isPublicApi?: boolean, +) +⋮---- +/** Returns an axios request object. Handles signing process automatically if this is a private API call */ +private async buildRequest( + method: Method, + endpoint: string, + url: string, + params?: ParamsInQueryBodyOrHeader, + isPublicApi?: boolean, +): Promise ================ File: src/lib/requestUtils.ts @@ -6619,96 +6992,9 @@ export interface SetUnifiedDeltaNeutralReq { enabled: boolean; } ⋮---- -/** POST /unified/leverage/user_setting — set leverage for all borrowed currencies */ -export interface SetUserLeverageReq { - leverage?: string; -} - -================ -File: src/types/request/wallet.ts -================ -/** GET /wallet/sub_account_balances */ -export interface GetSubAccountBalancesReq { - sub_uid?: string; - page?: number; - limit?: number; -} -⋮---- -export interface GetWithdrawalDepositRecordsReq { - currency?: string; - from?: number; - to?: number; - limit?: number; - offset?: number; -} -⋮---- -export interface SubmitTransferReq { - currency: string; - from: 'spot' | 'margin' | 'futures' | 'delivery' | 'cross_margin' | 'options'; - to: 'spot' | 'margin' | 'futures' | 'delivery' | 'cross_margin' | 'options'; - amount: string; - currency_pair?: string; - settle?: string; - client_order_id?: string; -} -⋮---- -export interface GetMainSubTransfersReq { - sub_uid?: string; - from?: number; - to?: number; - limit?: number; - offset?: number; -} -⋮---- -export interface GetSavedAddressReq { - currency?: string; // v4.106.94: Optional filter by currency - chain?: string; - limit?: string; - page?: number; - verified?: string; // v4.106.94: 1 verification-free, 0 normal, empty for no filter -} -⋮---- -currency?: string; // v4.106.94: Optional filter by currency -⋮---- -verified?: string; // v4.106.94: 1 verification-free, 0 normal, empty for no filter -⋮---- -export interface GetSmallBalanceHistoryReq { - currency?: string; - page?: number; - limit?: number; -} -⋮---- -export interface ListPushOrdersReq { - id?: number; - from?: number; - to?: number; - limit?: number; - offset?: number; - transaction_type?: string; -} -⋮---- -export interface SubmitSubToSubTransferReq { - currency: string; - sub_account_from: string; - sub_account_from_type: 'spot' | 'futures' | 'delivery' | 'cross_margin'; - sub_account_to: string; - sub_account_to_type: 'spot' | 'futures' | 'delivery' | 'cross_margin'; - amount: string; - sub_account_type?: string; -} -⋮---- -export interface SubmitMainSubTransferReq { - currency: string; - sub_account: string; - direction: 'to' | 'from'; - amount: string; - client_order_id?: string; - sub_account_type?: 'spot' | 'futures' | 'cross_margin' | 'delivery'; -} -⋮---- -/** GET /wallet/transfers */ -export interface GetTransferReq { - tx_id: string; +/** POST /unified/leverage/user_setting — set leverage for all borrowed currencies */ +export interface SetUserLeverageReq { + leverage?: string; } ================ @@ -7308,18 +7594,6 @@ export interface CurrencyPair { up_rate?: string; // v4.106.4: Maximum price increase percentage down_rate?: string; // v4.106.4: Maximum price decrease percentage -================ -File: webpack/webpack.config.cjs -================ -function generateConfig(name) -⋮---- -// Add '.ts' and '.tsx' as resolvable extensions. -⋮---- -// Node.js core modules not available in browsers -// The REST client's https.Agent (for keepAlive) is Node.js-only and won't work in browsers -⋮---- -// Code is already transpiled from TypeScript, no additional loaders needed - ================ File: examples/Rest/futures/testnet.ts ================ @@ -7335,276 +7609,19 @@ secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' ⋮---- async function submitFuturesOrder() ⋮---- -// Submit a market order for futures trading -⋮---- -settle: 'usdt', // Specify the settlement currency -contract: 'BTC_USDT', // Specify the contract -size: 20, // Order size: positive for long, negative for short -price: '0', // Market order, so price is set to '0' -tif: 'ioc', // Time in force: 'ioc' (Immediate Or Cancel) -⋮---- -console.log('Response: ', result); // Log the response to the console -⋮---- -console.error('Error in execution: ', e); // Log any errors that occur -⋮---- -// Execute the function to submit a futures order - -================ -File: src/lib/BaseRestClient.ts -================ -import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'; -// NOTE: https.Agent is Node.js-only and not available in browser environments -// Browser builds (via webpack) exclude this module - see webpack.config.js fallback settings -import https from 'https'; -⋮---- -import { neverGuard } from './misc-util.js'; -import { - CHANNEL_ID, - getRestBaseUrl, - RestClientOptions, - serializeParams, -} from './requestUtils.js'; -import { - checkWebCryptoAPISupported, - hashMessage, - SignAlgorithm, - SignEncodeMethod, - signMessage, -} from './webCryptoAPI.js'; -⋮---- -/** - * Used to switch how authentication/requests work under the hood - */ -⋮---- -export type RestClientType = - (typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM]; -⋮---- -interface SignedRequest { - originalParams: T; - paramsWithSign?: T & { sign: string }; - serializedParams: string; - sign: string; - queryParamsWithSign: string; - timestamp: number; - recvWindow: number; -} -⋮---- -interface UnsignedRequest { - originalParams: T; - paramsWithSign: T; -} -⋮---- -type SignMethod = 'gateV4'; -⋮---- -/** - * Some requests require some params to be in the query string and some in the body. Some even support passing params via headers. - * This type anticipates these are possible in any combination. - * - * The request builder will automatically handle where parameters should go. - */ -type ParamsInQueryBodyOrHeader = { - query?: object; - body?: object; - headers?: object; - /** multipart/form-data body; mutually exclusive with `body` */ - multipart?: FormData; -}; -⋮---- -/** multipart/form-data body; mutually exclusive with `body` */ -⋮---- -/** - * Enables: - * - Detailed request/response logging - * - Full request dump in any exceptions thrown from API responses - */ -⋮---- -// request: { -// url: response.config.url, -// method: response.config.method, -// data: response.config.data, -// headers: response.config.headers, -// }, -⋮---- -/** - * Impure, mutates params to remove any values that have a key but are undefined. - */ -function deleteUndefinedValues(params?: any): void -⋮---- -export abstract class BaseRestClient -⋮---- -/** Defines the client type (affecting how requests & signatures behave) */ -abstract getClientType(): RestClientType; -⋮---- -/** - * Create an instance of the REST client. Pass API credentials in the object in the first parameter. - * @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity - * @param {AxiosRequestConfig} [networkOptions={}] HTTP networking options for axios - */ -constructor( - restClientOptions: RestClientOptions = {}, - networkOptions: AxiosRequestConfig = {}, -) -⋮---- -/** Throw errors if any request params are empty */ -⋮---- -/** in ms == 5 minutes by default */ -⋮---- -/** inject custom rquest options based on axios specs - see axios docs for more guidance on AxiosRequestConfig: https://github.com/axios/axios#request-config */ -⋮---- -// If enabled, configure a https agent with keepAlive enabled -// NOTE: This is Node.js-only functionality. In browser environments, this code is skipped -// as the 'https' module is excluded via webpack fallback configuration. -// Browser connection pooling is handled automatically by the browser itself. -⋮---- -// Extract existing https agent parameters, if provided, to prevent the keepAlive flag from overwriting an existing https agent completely -⋮---- -// For more advanced configuration, raise an issue on GitHub or use the "networkOptions" -// parameter to define a custom httpsAgent with the desired properties -⋮---- -// Check Web Crypto API support when credentials are provided and no custom sign function is used -⋮---- -// Throw if one of the 3 values is missing, but at least one of them is set -⋮---- -/** - * Timestamp used to sign the request. Override this method to implement your own timestamp/sync mechanism - */ -getSignTimestampMs(): number -⋮---- -protected get(endpoint: string, params?: object) -⋮---- -// GET only supports params in the query string -⋮---- -protected post(endpoint: string, params?: ParamsInQueryBodyOrHeader) -⋮---- -protected getPrivate(endpoint: string, params?: object) -⋮---- -// GET only supports params in the query string -⋮---- -protected postPrivate(endpoint: string, params?: ParamsInQueryBodyOrHeader) -⋮---- -/** POST private endpoint with multipart/form-data (empty body hash for signing) */ -protected postPrivateMultipart( - endpoint: string, - formData: FormData, - query?: object, -) -⋮---- -protected deletePrivate( - endpoint: string, - params?: ParamsInQueryBodyOrHeader, -) -⋮---- -protected putPrivate(endpoint: string, params?: ParamsInQueryBodyOrHeader) -⋮---- -// protected patchPrivate(endpoint: string, params?: any) { -protected patchPrivate(endpoint: string, params?: ParamsInQueryBodyOrHeader) -⋮---- -/** - * @private Make a HTTP request to a specific endpoint. Private endpoint API calls are automatically signed. - */ -private async _call( - method: Method, - endpoint: string, - params?: ParamsInQueryBodyOrHeader, - isPublicApi?: boolean, -): Promise -⋮---- -// Sanity check to make sure it's only ever prefixed by one forward slash -⋮---- -// Build a request and handle signature process -⋮---- -// Dispatch request -⋮---- -// See: https://www.gate.io/docs/developers/apiv4/en/#return-format -⋮---- -// Throw API rejections by parsing the response code from the body -⋮---- -/** - * @private generic handler to parse request exceptions - */ -parseException(e: any, request: AxiosRequestConfig): unknown -⋮---- -// Something happened in setting up the request that triggered an error -⋮---- -// request made but no response received -⋮---- -// The request was made and the server responded with a status code -// that falls out of the range of 2xx -⋮---- -// console.error('err: ', response?.data); -⋮---- -// Prevent credentials from leaking into error messages -⋮---- -/** - * @private sign request and set recv window - */ -private async signRequest< - T extends ParamsInQueryBodyOrHeader | undefined = {}, - >( - data: T, - endpoint: string, - method: Method, - signMethod: SignMethod, -): Promise> -⋮---- -const timestamp = +(this.getSignTimestampMs() / 1000).toFixed(0); // in seconds -⋮---- -// recvWindow: this.options.recvWindow, -⋮---- -// It's possible to override the recv window on a per rquest level -⋮---- -// console.log('sign params: ', { -// requestBodyToHash, -// paramsStr: toSign, -// url: this.baseUrl, -// urlPath: this.baseUrlPath, -// }); -⋮---- -private async signMessage( - paramsStr: string, - secret: string, - method: 'hex' | 'base64', - algorithm: SignAlgorithm, -): Promise -⋮---- -private async prepareSignParams< - TParams extends ParamsInQueryBodyOrHeader | undefined, - >( - method: Method, - endpoint: string, - signMethod: SignMethod, - params?: TParams, - isPublicApi?: true, - ): Promise>; +// Submit a market order for futures trading ⋮---- -private async prepareSignParams< - TParams extends ParamsInQueryBodyOrHeader | undefined, - >( - method: Method, - endpoint: string, - signMethod: SignMethod, - params?: TParams, - isPublicApi?: false | undefined, - ): Promise>; +settle: 'usdt', // Specify the settlement currency +contract: 'BTC_USDT', // Specify the contract +size: 20, // Order size: positive for long, negative for short +price: '0', // Market order, so price is set to '0' +tif: 'ioc', // Time in force: 'ioc' (Immediate Or Cancel) ⋮---- -private async prepareSignParams< - TParams extends ParamsInQueryBodyOrHeader | undefined, - >( - method: Method, - endpoint: string, - signMethod: SignMethod, - params?: TParams, - isPublicApi?: boolean, -) +console.log('Response: ', result); // Log the response to the console ⋮---- -/** Returns an axios request object. Handles signing process automatically if this is a private API call */ -private async buildRequest( - method: Method, - endpoint: string, - url: string, - params?: ParamsInQueryBodyOrHeader, - isPublicApi?: boolean, -): Promise +console.error('Error in execution: ', e); // Log any errors that occur +⋮---- +// Execute the function to submit a futures order ================ File: src/types/request/earn.ts @@ -8237,6 +8254,119 @@ export interface CancelSpotPovOrdersReq { currency_pair?: string; } +================ +File: src/types/request/wallet.ts +================ +/** GET /wallet/sub_account_balances */ +export interface GetSubAccountBalancesReq { + sub_uid?: string; + page?: number; + limit?: number; +} +⋮---- +export interface GetWithdrawalDepositRecordsReq { + currency?: string; + from?: number; + to?: number; + limit?: number; + offset?: number; +} +⋮---- +/** GET /wallet/withdrawals. Deposit records do not take these filters. */ +export interface GetWithdrawalRecordsReq + extends GetWithdrawalDepositRecordsReq { + /** + * Withdrawal record id. Starts with `w`, for example `w1879219868`. + * When set, only that record is returned and the time filter is disabled. + */ + withdraw_id?: string; + + /** + * User-defined withdrawal order number. + * When set, that order's record is returned. + */ + withdraw_order_id?: string; +} +⋮---- +/** + * Withdrawal record id. Starts with `w`, for example `w1879219868`. + * When set, only that record is returned and the time filter is disabled. + */ +⋮---- +/** + * User-defined withdrawal order number. + * When set, that order's record is returned. + */ +⋮---- +export interface SubmitTransferReq { + currency: string; + from: 'spot' | 'margin' | 'futures' | 'delivery' | 'cross_margin' | 'options'; + to: 'spot' | 'margin' | 'futures' | 'delivery' | 'cross_margin' | 'options'; + amount: string; + currency_pair?: string; + settle?: string; + client_order_id?: string; +} +⋮---- +export interface GetMainSubTransfersReq { + sub_uid?: string; + from?: number; + to?: number; + limit?: number; + offset?: number; +} +⋮---- +export interface GetSavedAddressReq { + currency?: string; // v4.106.94: Optional filter by currency + chain?: string; + limit?: string; + page?: number; + verified?: string; // v4.106.94: 1 verification-free, 0 normal, empty for no filter +} +⋮---- +currency?: string; // v4.106.94: Optional filter by currency +⋮---- +verified?: string; // v4.106.94: 1 verification-free, 0 normal, empty for no filter +⋮---- +export interface GetSmallBalanceHistoryReq { + currency?: string; + page?: number; + limit?: number; +} +⋮---- +export interface ListPushOrdersReq { + id?: number; + from?: number; + to?: number; + limit?: number; + offset?: number; + transaction_type?: string; +} +⋮---- +export interface SubmitSubToSubTransferReq { + currency: string; + sub_account_from: string; + sub_account_from_type: 'spot' | 'futures' | 'delivery' | 'cross_margin'; + sub_account_to: string; + sub_account_to_type: 'spot' | 'futures' | 'delivery' | 'cross_margin'; + amount: string; + sub_account_type?: string; +} +⋮---- +export interface SubmitMainSubTransferReq { + currency: string; + sub_account: string; + direction: 'to' | 'from'; + amount: string; + client_order_id?: string; + sub_account_type?: 'spot' | 'futures' | 'cross_margin' | 'delivery'; +} +⋮---- +/** GET /wallet/transfers */ +export interface GetTransferReq { + tx_id: string; +} + ================ File: src/types/response/unified.ts ================ @@ -8520,110 +8650,6 @@ export interface LeverageFailedCurrency { reason: string; } -================ -File: src/types/websockets/client.ts -================ -import type { ClientRequestArgs } from 'http'; -import WebSocket from 'isomorphic-ws'; -⋮---- -/** - * Event args for subscribing/unsubscribing - */ -⋮---- -// export type WsTopicSubscribePrivateArgsV2 = -// | WsTopicSubscribePrivateInstIdArgsV2 -// | WsTopicSubscribePrivateCoinArgsV2; -⋮---- -// export type WsTopicSubscribeEventArgsV2 = -// | WsTopicSubscribePublicArgsV2 -// | WsTopicSubscribePrivateArgsV2; -⋮---- -/** General configuration for the WebsocketClient */ -export interface WSClientConfigurableOptions { - /** Your API key */ - apiKey?: string; - - /** Your API secret */ - apiSecret?: string; - - /** Use the Gate TestNet WebSocket hosts. */ - useTestnet?: boolean; - - /** Define a recv window when preparing a private websocket signature. This is in milliseconds, so 5000 == 5 seconds */ - recvWindow?: number; - - /** How often to check if the connection is alive */ - pingInterval?: number; - - /** How long to wait for a pong (heartbeat reply) before assuming the connection is dead */ - pongTimeout?: number; - - /** Delay in milliseconds before respawning the connection */ - reconnectTimeout?: number; - - requestOptions?: {}; - - wsUrl?: string; - - wsOptions?: { - protocols?: string[]; - agent?: any; - } & ( - | Omit, 'agent'> - | Omit, 'agent'> - ); - - /** - * Allows you to provide a custom "signMessage" function, e.g. to use node's much faster createHmac method - * - * Look in the examples folder for a demonstration on using node's createHmac instead. - */ - customSignMessageFn?: (message: string, secret: string) => Promise; - - /** - * If you authenticated the WS API before, automatically try to re-authenticate the WS API if you're disconnected/reconnected for any reason. - */ - reauthWSAPIOnReconnect?: boolean; -} -⋮---- -/** Your API key */ -⋮---- -/** Your API secret */ -⋮---- -/** Use the Gate TestNet WebSocket hosts. */ -⋮---- -/** Define a recv window when preparing a private websocket signature. This is in milliseconds, so 5000 == 5 seconds */ -⋮---- -/** How often to check if the connection is alive */ -⋮---- -/** How long to wait for a pong (heartbeat reply) before assuming the connection is dead */ -⋮---- -/** Delay in milliseconds before respawning the connection */ -⋮---- -/** - * Allows you to provide a custom "signMessage" function, e.g. to use node's much faster createHmac method - * - * Look in the examples folder for a demonstration on using node's createHmac instead. - */ -⋮---- -/** - * If you authenticated the WS API before, automatically try to re-authenticate the WS API if you're disconnected/reconnected for any reason. - */ -⋮---- -/** - * WS configuration that's always defined, regardless of user configuration - * (usually comes from defaults if there's no user-provided values) - */ -export interface WebsocketClientOptions extends WSClientConfigurableOptions { - pingInterval: number; - pongTimeout: number; - reconnectTimeout: number; - recvWindow: number; - authPrivateConnectionsOnConnect: boolean; - authPrivateRequests: boolean; - reauthWSAPIOnReconnect: boolean; -} - ================ File: src/types/request/tradfi.ts ================ @@ -14891,6 +14917,7 @@ import { GetSubAccountBalancesReq, GetTransferReq, GetWithdrawalDepositRecordsReq, + GetWithdrawalRecordsReq, ListPushOrdersReq, SubmitMainSubTransferReq, SubmitSubToSubTransferReq, @@ -15268,6 +15295,9 @@ listAnnouncementArticles( * * Withdrawals to Gate addresses do not incur transaction fees. * + * On HTTP 5xx or `SERVER_ERROR`, the withdrawal may still have been accepted. + * Set `withdraw_order_id`, then check `getWithdrawalRecords({ withdraw_order_id })` before sending it again. + * * @param params Withdrawal parameters * @returns Promise */ @@ -15325,13 +15355,15 @@ createDepositAddress(params: { /** * Retrieve withdrawal records * - * Record time range cannot exceed 30 days + * Record time range cannot exceed 30 days. + * `withdraw_id` returns that one record and disables the time filter. + * `withdraw_order_id` returns the user-defined order. * * @param params Parameters for filtering withdrawal records * @returns Promise */ getWithdrawalRecords( - params?: GetWithdrawalDepositRecordsReq, + params?: GetWithdrawalRecordsReq, ): Promise ⋮---- /** @@ -15376,6 +15408,9 @@ getTransfer(params: GetTransferReq): Promise * * Support transferring with sub user's spot or futures account. Note that only main user's spot account is used no matter which sub user's account is operated. * + * On HTTP 5xx or `SERVER_ERROR`, the transfer may still have been accepted. + * Set `client_order_id`, then check `getTransferStatus({ client_order_id })` before sending it again. + * * @param params Transfer parameters * @returns Promise */ @@ -20008,10 +20043,24 @@ File: README.md [![Build & Test](https://github.com/sieblyio/gateio-api/actions/workflows/e2etest.yml/badge.svg?branch=master)](https://github.com/sieblyio/gateio-api/actions/workflows/e2etest.yml) [![last commit](https://img.shields.io/github/last-commit/sieblyio/gateio-api)][1] [![Telegram](https://img.shields.io/badge/chat-on%20telegram-blue.svg)](https://t.me/nodetraders) -[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/sieblyio/gateio-api) +[![Gate Tutorial](https://img.shields.io/badge/Gate%20Tutorial-siebly.io-blue)](https://siebly.io/sdk/gate/javascript/tutorial) [1]: https://www.npmjs.com/package/gateio-api +Public spot tickers: + +```javascript +const { WebsocketClient } = require('gateio-api'); +const ws = new WebsocketClient(); +ws.subscribe({ topic: 'spot.tickers', payload: ['BTC_USDT'] }, 'spotV4'); +``` + +`WebsocketClient` handles what a raw WebSocket does not: + +- reconnect +- heartbeat +- resubscribe + Updated & performant JavaScript & Node.js SDK for the Gate.com (gate.io) REST APIs and WebSockets: - Professional, robust & performant Gate.com SDK with extensive production use in live trading environments. @@ -20570,7 +20619,7 @@ File: package.json ================ { "name": "gateio-api", - "version": "1.6.6", + "version": "1.6.7", "description": "Complete & Robust Node.js SDK for Gate.com's REST APIs, WebSockets & WebSocket APIs, with TypeScript declarations.", "scripts": { "clean": "rm -rf dist/*", @@ -20600,15 +20649,15 @@ File: package.json ], "dependencies": { "@types/ws": "8.18.1", - "axios": "1.18.1", + "axios": "1.20.0", "isomorphic-ws": "4.0.1", "ws": "8.21.1" }, "devDependencies": { "@types/jest": "^29.5.12", "@types/node": "^22.10.2", - "@typescript-eslint/eslint-plugin": "^8.18.0", - "@typescript-eslint/parser": "^8.18.0", + "@typescript-eslint/eslint-plugin": "8.70.0", + "@typescript-eslint/parser": "8.70.0", "eslint": "^8.29.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", @@ -20622,12 +20671,12 @@ File: package.json "webpack-cli": "^4.0.0" }, "overrides": { - "brace-expansion@<2": "1.1.18", - "brace-expansion@>=2 <3": "2.1.4", - "brace-expansion@>=5 <6": "5.0.9", - "fast-uri@>=3 <4": "3.1.5", - "js-yaml@>=3 <4": "3.15.1", - "js-yaml@>=4 <5": "4.3.1" + "brace-expansion@<2": "1.1.21", + "brace-expansion@>=2 <3": "2.1.7", + "brace-expansion@>=5 <6": "5.0.12", + "fast-uri@>=3 <4": "3.1.8", + "js-yaml@>=3 <4": "3.15.2", + "js-yaml@>=4 <5": "4.3.2" }, "keywords": [ "Gate", diff --git a/package-lock.json b/package-lock.json index e6b4b65..38af265 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gateio-api", - "version": "1.6.6", + "version": "1.6.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gateio-api", - "version": "1.6.6", + "version": "1.6.7", "license": "MIT", "dependencies": { "@types/ws": "8.18.1", diff --git a/package.json b/package.json index 68956df..2bab0ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gateio-api", - "version": "1.6.6", + "version": "1.6.7", "description": "Complete & Robust Node.js SDK for Gate.com's REST APIs, WebSockets & WebSocket APIs, with TypeScript declarations.", "scripts": { "clean": "rm -rf dist/*", diff --git a/src/RestClient.ts b/src/RestClient.ts index 8a9ed08..2b0a81c 100644 --- a/src/RestClient.ts +++ b/src/RestClient.ts @@ -306,6 +306,7 @@ import { GetSubAccountBalancesReq, GetTransferReq, GetWithdrawalDepositRecordsReq, + GetWithdrawalRecordsReq, ListPushOrdersReq, SubmitMainSubTransferReq, SubmitSubToSubTransferReq, @@ -735,6 +736,9 @@ export class RestClient extends BaseRestClient { * * Withdrawals to Gate addresses do not incur transaction fees. * + * On HTTP 5xx or `SERVER_ERROR`, the withdrawal may still have been accepted. + * Set `withdraw_order_id`, then check `getWithdrawalRecords({ withdraw_order_id })` before sending it again. + * * @param params Withdrawal parameters * @returns Promise */ @@ -804,13 +808,15 @@ export class RestClient extends BaseRestClient { /** * Retrieve withdrawal records * - * Record time range cannot exceed 30 days + * Record time range cannot exceed 30 days. + * `withdraw_id` returns that one record and disables the time filter. + * `withdraw_order_id` returns the user-defined order. * * @param params Parameters for filtering withdrawal records * @returns Promise */ getWithdrawalRecords( - params?: GetWithdrawalDepositRecordsReq, + params?: GetWithdrawalRecordsReq, ): Promise { return this.getPrivate('/wallet/withdrawals', params); } @@ -863,6 +869,9 @@ export class RestClient extends BaseRestClient { * * Support transferring with sub user's spot or futures account. Note that only main user's spot account is used no matter which sub user's account is operated. * + * On HTTP 5xx or `SERVER_ERROR`, the transfer may still have been accepted. + * Set `client_order_id`, then check `getTransferStatus({ client_order_id })` before sending it again. + * * @param params Transfer parameters * @returns Promise */ diff --git a/src/types/request/wallet.ts b/src/types/request/wallet.ts index 8531473..1e25868 100644 --- a/src/types/request/wallet.ts +++ b/src/types/request/wallet.ts @@ -13,6 +13,22 @@ export interface GetWithdrawalDepositRecordsReq { offset?: number; } +/** GET /wallet/withdrawals. Deposit records do not take these filters. */ +export interface GetWithdrawalRecordsReq + extends GetWithdrawalDepositRecordsReq { + /** + * Withdrawal record id. Starts with `w`, for example `w1879219868`. + * When set, only that record is returned and the time filter is disabled. + */ + withdraw_id?: string; + + /** + * User-defined withdrawal order number. + * When set, that order's record is returned. + */ + withdraw_order_id?: string; +} + export interface SubmitTransferReq { currency: string; from: 'spot' | 'margin' | 'futures' | 'delivery' | 'cross_margin' | 'options';