UNPKG

okex-api

Version:

A modern, asynchronous, and easy-to-use [Okx API](https://www.okx.com/docs-v5) wrapper for Node.js/bun/Web Browser/Cloudflare workers.

1,302 lines (1,301 loc) 48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpApi = void 0; const utils_1 = require("./utils"); class HttpApi { credentials; baseURL; static async create(apiKey, apiSecret, passphrase, baseURL = 'https://www.okx.com') { return new HttpApi(await utils_1.APICredentials.create(apiKey, apiSecret, passphrase), baseURL); } constructor(credentials, baseURL = 'https://www.okx.com') { this.credentials = credentials; this.baseURL = baseURL; } getUrl(path, params = {}) { const url = new URL(this.baseURL + path); for (const key in params) { if (params[key] !== null && params[key] !== undefined) url.searchParams.append(key, params[key]); } return url; } getResponseData(response) { if (response.code !== '0' && response.code !== 0) throw new Error(JSON.stringify(response)); return response.data; } async getPrivate(path, params = {}) { if (!this.credentials) throw new Error('Missing credentials'); const url = this.getUrl(path, params); const headers = await this.credentials.getHttpHeaders('GET', path, url.search); const response = await fetch(url, { headers }); return this.getResponseData(await response.json()); } async postPrivate(path, body = {}) { if (!this.credentials) throw new Error('Missing credentials'); const message = JSON.stringify(body); const headers = await this.credentials.getHttpHeaders('POST', path, message); const response = await fetch(this.baseURL + path, { method: 'POST', headers, body: message }); return this.getResponseData(await response.json()); } async get(path, params = {}) { const response = await fetch(this.getUrl(path, params)); return this.getResponseData(await response.json()); } async post(path, body = {}) { const response = await fetch(this.baseURL + path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); return this.getResponseData(await response.json()); } async getServerTime() { return await this.get('/api/v5/public/time'); } getAccountInstruments(params) { return this.getPrivate('/api/v5/account/instruments', params); } getBalance(params) { return this.getPrivate('/api/v5/account/balance', { ...params }); } getPositions(params) { return this.getPrivate('/api/v5/account/positions', params); } getPositionsHistory(params) { return this.getPrivate('/api/v5/account/positions-history', params); } getAccountPositionRisk(params) { return this.getPrivate('/api/v5/account/account-position-risk', { ...params }); } /** Up to last 7 days */ getBills(params) { return this.getPrivate('/api/v5/account/bills', params); } /** Last 3 months */ getBillsArchive(params) { return this.getPrivate('/api/v5/account/bills-archive', params); } /** * Apply for bill data since 1 February, 2021 except for the current quarter. * Check the file link from the "Get bills details (since 2021)" endpoint in 30 hours to allow for data generation. * During peak demand, data generation may take longer. If the file link is still unavailable after 48 hours, reach out to customer support for assistance. * It is only applicable to the data from the unified account. * * This endpoint submits a request for bill data. You can then use getRequestedBillsHistoryLink to get the link to the bill data. * It may take some time to generate the data. */ requestBillsHistoryDownloadLink(params) { return this.postPrivate('/api/v5/account/bills-history-archive', params); } /** * This endpoint returns the link to the bill data which you can request using requestBillsHistoryDownloadLink. */ getRequestedBillsHistoryLink(params) { return this.getPrivate('/api/v5/account/bills-history-archive', params); } getAccountConfiguration() { return this.getPrivate('/api/v5/account/config'); } setPositionMode(params) { return this.postPrivate('/api/v5/account/set-position-mode', params); } setLeverage(params) { return this.postPrivate('/api/v5/account/set-leverage', params); } /** Max buy/sell amount or open amount */ getMaxBuySellAmount(params) { return this.getPrivate('/api/v5/account/max-size', params); } getMaxAvailableTradableAmount(params) { return this.getPrivate('/api/v5/account/max-avail-size', params); } changePositionMargin(params) { return this.postPrivate('/api/v5/account/position/margin-balance', params); } getLeverage(params) { return this.getPrivate('/api/v5/account/leverage-info', params); } getLeverageV2(params) { return this.getPrivate('/api/v5/account/leverage-info', params); } getLeverageEstimatedInfo(params) { return this.getPrivate('/api/v5/account/adjust-leverage-info', params); } getMaxLoan(params) { return this.getPrivate('/api/v5/account/max-loan', params); } getMaxLoanV2(params) { return this.getPrivate('/api/v5/account/max-loan', params); } getFeeRates(params) { return this.getPrivate('/api/v5/account/trade-fee', params); } getFeeRatesV2(params) { return this.getPrivate('/api/v5/account/trade-fee', params); } getInterestAccrued(params) { return this.getPrivate('/api/v5/account/interest-accrued', params); } getInterestRate(params) { return this.getPrivate('/api/v5/account/interest-rate', { ...params }); } setGreeksDisplayType(params) { return this.postPrivate('/api/v5/account/set-greeks', params); } setIsolatedMode(params) { return this.postPrivate('/api/v5/account/set-isolated-mode', params); } getMaxWithdrawals(params) { return this.getPrivate('/api/v5/account/max-withdrawal', { ...params }); } getAccountRiskState() { return this.getPrivate('/api/v5/account/risk-state'); } submitQuickMarginBorrowRepay(params) { return this.postPrivate('/api/v5/account/quick-margin-borrow-repay', params); } getQuickMarginBorrowRepayHistory(params) { return this.getPrivate('/api/v5/account/quick-margin-borrow-repay-history', params); } borrowRepayVIPLoan(params) { return this.postPrivate('/api/v5/account/borrow-repay', params); } getVIPLoanBorrowRepayHistory(params) { return this.getPrivate('/api/v5/account/borrow-repay-history', params); } getVIPInterestAccrued(params) { return this.getPrivate('/api/v5/account/vip-interest-accrued', params); } getVIPInterestDeducted(params) { return this.getPrivate('/api/v5/account/vip-interest-deducted', params); } getVIPLoanOrders(params) { return this.getPrivate('/api/v5/account/vip-loan-order-list', params); } getVIPLoanOrder(params) { return this.getPrivate('/api/v5/account/vip-loan-order-detail', params); } getBorrowInterestLimits(params) { return this.getPrivate('/api/v5/account/interest-limits', params); } getFixedLoanBorrowLimit() { return this.getPrivate('/api/v5/account/fixed-loan/borrowing-limit'); } getFixedLoanBorrowQuote(params) { return this.getPrivate('/api/v5/account/fixed-loan/borrowing-quote', params); } submitFixedLoanBorrowOrder(params) { return this.postPrivate('/api/v5/account/fixed-loan/borrowing-order', params); } updateFixedLoanBorrowOrder(params) { return this.postPrivate('/api/v5/account/fixed-loan/amend-borrowing-order', params); } manualRenewFixedLoanBorrowOrder(params) { return this.postPrivate('/api/v5/account/fixed-loan/manual-reborrow', params); } repayFixedLoanBorrowOrder(params) { return this.postPrivate('/api/v5/account/fixed-loan/repay-borrowing-order', params); } convertFixedLoanToMarketLoan(params) { return this.postPrivate('/api/v5/account/fixed-loan/convert-to-market-loan', params); } reduceFixedLoanLiabilities(params) { return this.postPrivate('/api/v5/account/fixed-loan/reduce-liabilities', params); } getFixedLoanBorrowOrders(params) { return this.getPrivate('/api/v5/account/fixed-loan/borrowing-orders-list', params); } manualBorrowRepay(params) { return this.postPrivate('/api/v5/account/spot-manual-borrow-repay', params); } setAutoRepay(params) { return this.postPrivate('/api/v5/account/set-auto-repay', params); } getBorrowRepayHistory(params) { return this.getPrivate('/api/v5/account/spot-borrow-repay-history', params); } positionBuilder(params) { return this.postPrivate('/api/v5/account/position-builder', params); } updateRiskOffsetAmount(params) { return this.postPrivate('/api/v5/account/set-riskOffset-amt', params); } getGreeks(params) { return this.getPrivate('/api/v5/account/greeks', { ...params }); } getPMLimitation(params) { return this.getPrivate('/api/v5/account/position-tiers', params); } updateRiskOffsetType(params) { return this.postPrivate('/api/v5/account/set-riskOffset-type', params); } activateOption() { return this.postPrivate('/api/v5/account/activate-option'); } setAutoLoan(params) { return this.postPrivate('/api/v5/account/set-auto-loan', params); } presetAccountLevelSwitch(params) { return this.postPrivate('/api/v5/account/account-level-switch-preset', params); } getAccountSwitchPrecheck(params) { return this.getPrivate('/api/v5/account/set-account-switch-precheck', params); } setAccountMode(params) { return this.postPrivate('/api/v5/account/set-account-level', params); } resetMMPStatus(params) { return this.postPrivate('/api/v5/account/mmp-reset', params); } setMMPConfig(params) { return this.postPrivate('/api/v5/account/mmp-config', params); } getMMPConfig(params) { return this.getPrivate('/api/v5/account/mmp-config', params); } /** * * Orderbook trading - trade endpoints * */ submitOrder(params) { return this.postPrivate('/api/v5/trade/order', params); } submitMultipleOrders(params) { return this.postPrivate('/api/v5/trade/batch-orders', params); } cancelOrder(params) { return this.postPrivate('/api/v5/trade/cancel-order', params); } cancelMultipleOrders(params) { return this.postPrivate('/api/v5/trade/cancel-batch-orders', params); } amendOrder(params) { return this.postPrivate('/api/v5/trade/amend-order', params); } amendMultipleOrders(params) { return this.postPrivate('/api/v5/trade/amend-batch-orders', params); } closePositions(params) { return this.postPrivate('/api/v5/trade/close-position', params); } getOrderDetails(params) { return this.getPrivate('/api/v5/trade/order', params); } getOrderList(params) { return this.getPrivate('/api/v5/trade/orders-pending', params); } /** * Get history for last 7 days */ getOrderHistory(params) { return this.getPrivate('/api/v5/trade/orders-history', params); } /** * Get history for last 3 months */ getOrderHistoryArchive(params) { return this.getPrivate('/api/v5/trade/orders-history-archive', params); } /** * Get history for last 7 days */ getFills(params) { return this.getPrivate('/api/v5/trade/fills', params); } /** * Get history for last 3 months */ getFillsHistory(params) { return this.getPrivate('/api/v5/trade/fills-history', params); } /** Get easy convert currency list */ getEasyConvertCurrencies(params) { return this.getPrivate('/api/v5/trade/easy-convert-currency-list', params); } /** * Place easy convert : Convert small currencies to mainstream currencies. * Only applicable to the crypto balance less than $10. * * Maximum 5 currencies can be selected in one order. * If there are multiple currencies, separate them with commas in the "from" field. * */ submitEasyConvert(params) { return this.postPrivate('/api/v5/trade/easy-convert', params); } /** Get easy convert history : Get the history and status of easy convert trades. */ getEasyConvertHistory(params) { return this.getPrivate('/api/v5/trade/easy-convert-history', params); } /** * Get one-click repay currency list : Get list of debt currency data and repay currencies. * Debt currencies include both cross and isolated debts. */ getOneClickRepayCurrencyList(params) { return this.getPrivate('/api/v5/trade/one-click-repay-currency-list', { ...params }); } /** * Trade one-click repay to repay cross debts. * Isolated debts are not applicable. * The maximum repayment amount is based on the remaining available balance of funding and trading accounts. */ submitOneClickRepay(params) { return this.postPrivate('/api/v5/trade/one-click-repay', { debtCcy: params.debtCcys.join(','), repayCcy: params.repayCcy, }); } /** Get the history and status of one-click repay trades. */ getOneClickRepayHistory(params) { return this.getPrivate('/api/v5/trade/one-click-repay-history', params); } cancelMassOrder(params) { return this.postPrivate('/api/v5/trade/mass-cancel', params); } cancelAllAfter(params) { return this.postPrivate('/api/v5/trade/cancel-all-after', params); } getAccountRateLimit() { return this.getPrivate('/api/v5/trade/account-rate-limit'); } submitOrderPrecheck(params) { return this.postPrivate('/api/v5/trade/order-precheck', params); } /** * * Orderbook trading - Algo trading endpoints * */ placeAlgoOrder(params) { return this.postPrivate('/api/v5/trade/order-algo', params); } cancelAlgoOrder(params) { return this.postPrivate('/api/v5/trade/cancel-algos', params); } amendAlgoOrder(params) { return this.postPrivate('/api/v5/trade/amend-algos', params); } cancelAdvanceAlgoOrder(params) { return this.postPrivate('/api/v5/trade/cancel-advance-algos', params); } getAlgoOrderDetails(params) { return this.getPrivate('/api/v5/trade/order-algo', params); } getAlgoOrderList(params) { return this.getPrivate('/api/v5/trade/orders-algo-pending', params); } getAlgoOrderHistory(params) { return this.getPrivate('/api/v5/trade/orders-algo-history', params); } /** * * Orderbook trading - Grid trading endpoints * */ placeGridAlgoOrder(params) { return this.postPrivate('/api/v5/tradingBot/grid/order-algo', params); } amendGridAlgoOrder(params) { return this.postPrivate('/api/v5/tradingBot/grid/amend-order-algo', params); } stopGridAlgoOrder(orders) { return this.postPrivate('/api/v5/tradingBot/grid/stop-order-algo', orders); } closeGridContractPosition(params) { return this.postPrivate('/api/v5/tradingBot/grid/close-position', params); } cancelGridContractCloseOrder(params) { return this.postPrivate('/api/v5/tradingBot/grid/cancel-close-order', params); } instantTriggerGridAlgoOrder(params) { return this.postPrivate('/api/v5/tradingBot/grid/order-instant-trigger', params); } getGridAlgoOrderList(params) { return this.getPrivate('/api/v5/tradingBot/grid/orders-algo-pending', params); } getGridAlgoOrderHistory(params) { return this.getPrivate('/api/v5/tradingBot/grid/orders-algo-history', params); } getGridAlgoOrderDetails(params) { return this.getPrivate('/api/v5/tradingBot/grid/orders-algo-details', params); } getGridAlgoSubOrders(params) { return this.getPrivate('/api/v5/tradingBot/grid/sub-orders', params); } getGridAlgoOrderPositions(params) { return this.getPrivate('/api/v5/tradingBot/grid/positions', params); } spotGridWithdrawIncome(params) { return this.postPrivate('/api/v5/tradingBot/grid/withdraw-income', params); } computeGridMarginBalance(params) { return this.postPrivate('/api/v5/tradingBot/grid/compute-margin-balance', params); } adjustGridMarginBalance(params) { return this.postPrivate('/api/v5/tradingBot/grid/margin-balance', params); } adjustGridInvestment(params) { return this.postPrivate('/api/v5/tradingBot/grid/adjust-investment', params); } getGridAIParameter(params) { return this.get('/api/v5/tradingBot/grid/ai-param', params); } computeGridMinInvestment(params) { return this.post('/api/v5/tradingBot/grid/min-investment', params); } getRSIBackTesting(params) { return this.get('/api/v5/tradingBot/public/rsi-back-testing', params); } getMaxGridQuantity(params) { return this.get('/api/v5/tradingBot/grid/grid-quantity', params); } /** * * Orderbook trading - Signal bot trading endpoints * */ createSignal(params) { return this.postPrivate('/api/v5/tradingBot/signal/create-signal', params); } getSignals(params) { return this.getPrivate('/api/v5/tradingBot/signal/signals', params); } createSignalBot(params) { return this.postPrivate('/api/v5/tradingBot/signal/order-algo', params); } cancelSignalBots(params) { return this.postPrivate('/api/v5/tradingBot/signal/stop-order-algo', params); } updateSignalMargin(params) { return this.postPrivate('/api/v5/tradingBot/signal/margin-balance', params); } updateSignalTPSL(params) { return this.postPrivate('/api/v5/tradingBot/signal/amendTPSL', params); } setSignalInstruments(params) { return this.postPrivate('/api/v5/tradingBot/signal/set-instruments', params); } getSignalBotOrder(params) { return this.getPrivate('/api/v5/tradingBot/signal/orders-algo-details', params); } getActiveSignalBot(params) { return this.getPrivate('/api/v5/tradingBot/signal/orders-algo-details', params); } getSignalBotHistory(params) { return this.getPrivate('/api/v5/tradingBot/signal/orders-algo-history', params); } getSignalBotPositions(params) { return this.getPrivate('/api/v5/tradingBot/signal/positions', params); } getSignalBotPositionHistory(params) { return this.getPrivate('/api/v5/tradingBot/signal/positions-history', params); } closeSignalBotPosition(params) { return this.postPrivate('/api/v5/tradingBot/signal/close-position', params); } placeSignalBotSubOrder(params) { return this.postPrivate('/api/v5/tradingBot/signal/sub-order', params); } cancelSubOrder(params) { return this.postPrivate('/api/v5/tradingBot/signal/cancel-sub-order', params); } getSignalBotSubOrders(params) { return this.getPrivate('/api/v5/tradingBot/signal/sub-orders', params); } getSignalBotEventHistory(params) { return this.getPrivate('/api/v5/tradingBot/signal/event-history', params); } /** * * Orderbook trading - Recurring buy endpoints * */ submitRecurringBuyOrder(params) { return this.postPrivate('/api/v5/tradingBot/recurring/order-algo', params); } amendRecurringBuyOrder(params) { return this.postPrivate('/api/v5/tradingBot/recurring/amend-order-algo', params); } stopRecurringBuyOrder(params) { return this.postPrivate('/api/v5/tradingBot/recurring/stop-order-algo', params); } getRecurringBuyOrders(params) { return this.getPrivate('/api/v5/tradingBot/recurring/orders-algo-pending', params); } getRecurringBuyOrderHistory(params) { return this.getPrivate('/api/v5/tradingBot/recurring/orders-algo-history', params); } getRecurringBuyOrderDetails(params) { return this.getPrivate('/api/v5/tradingBot/recurring/orders-algo-details', params); } getRecurringBuySubOrders(params) { return this.getPrivate('/api/v5/tradingBot/recurring/sub-orders', params); } /** * * Orderbook trading - Copy trading endpoints * */ getCopytradingSubpositions(params) { return this.getPrivate('/api/v5/copytrading/current-subpositions', params); } getCopytradingSubpositionsHistory(params) { return this.getPrivate('/api/v5/copytrading/subpositions-history', params); } submitCopytradingAlgoOrder(params) { return this.postPrivate('/api/v5/copytrading/algo-order', params); } closeCopytradingSubposition(params) { return this.postPrivate('/api/v5/copytrading/close-subposition', params); } getCopytradingInstruments(params) { return this.getPrivate('/api/v5/copytrading/instruments', params); } setCopytradingInstruments(params) { return this.postPrivate('/api/v5/copytrading/set-instruments', params); } getCopytradingProfitDetails(params) { return this.getPrivate('/api/v5/copytrading/profit-sharing-details', params); } getCopytradingTotalProfit(params) { return this.getPrivate('/api/v5/copytrading/total-profit-sharing', params); } getCopytradingUnrealizedProfit(params) { return this.getPrivate('/api/v5/copytrading/unrealized-profit-sharing-details', params); } getCopytradingTotalUnrealizedProfit(params) { return this.getPrivate('/api/v5/copytrading/total-unrealized-profit-sharing', params); } applyCopytradingLeadTrading(params) { return this.postPrivate('/api/v5/copytrading/apply-lead-trading', params); } stopCopytradingLeadTrading(params) { return this.postPrivate('/api/v5/copytrading/stop-lead-trading', params); } updateCopytradingProfitSharing(params) { return this.postPrivate('/api/v5/copytrading/amend-profit-sharing-ratio', params); } getCopytradingAccount() { return this.getPrivate('/api/v5/copytrading/config'); } setCopytradingFirstCopy(params) { return this.postPrivate('/api/v5/copytrading/first-copy-settings', params); } updateCopytradingCopySettings(params) { return this.postPrivate('/api/v5/copytrading/amend-copy-settings', params); } stopCopytradingCopy(params) { return this.postPrivate('/api/v5/copytrading/stop-copy-trading', params); } getCopytradingCopySettings(params) { return this.getPrivate('/api/v5/copytrading/copy-settings', params); } getCopytradingBatchLeverageInfo(params) { return this.getPrivate('/api/v5/copytrading/batch-leverage-info', params); } setCopytradingBatchLeverage(params) { return this.postPrivate('/api/v5/copytrading/batch-set-leverage', params); } getCopytradingMyLeadTraders(params) { return this.getPrivate('/api/v5/copytrading/current-lead-traders', params); } getCopytradingLeadTradersHistory(params) { return this.getPrivate('/api/v5/copytrading/lead-traders-history', params); } getCopytradingConfig(params) { return this.get('/api/v5/copytrading/public-config', params); } getCopytradingLeadRanks(params) { return this.get('/api/v5/copytrading/public-lead-traders', params); } getCopytradingLeadWeeklyPnl(params) { return this.get('/api/v5/copytrading/public-weekly-pnl', params); } getCopytradingLeadDailyPnl(params) { return this.get('/api/v5/copytrading/public-pnl', params); } getCopytradingLeadStats(params) { return this.get('/api/v5/copytrading/public-stats', params); } getCopytradingLeadPreferences(params) { return this.get('/api/v5/copytrading/public-preference-currency', params); } getCopytradingLeadOpenPositions(params) { return this.get('/api/v5/copytrading/public-current-subpositions', params); } getCopytradingLeadPositionHistory(params) { return this.get('/api/v5/copytrading/public-subpositions-history', params); } getCopyTraders(params) { return this.get('/api/v5/copytrading/public-copy-traders', params); } getCopytradingLeadPrivateRanks(params) { return this.getPrivate('/api/v5/copytrading/lead-traders', params); } getCopytradingLeadPrivateWeeklyPnl(params) { return this.getPrivate('/api/v5/copytrading/weekly-pnl', params); } getCopytradingPLeadPrivateDailyPnl(params) { return this.getPrivate('/api/v5/copytrading/pnl', params); } geCopytradingLeadPrivateStats(params) { return this.getPrivate('/api/v5/copytrading/stats', params); } getCopytradingLeadPrivatePreferences(params) { return this.getPrivate('/api/v5/copytrading/preference-currency', params); } getCopytradingLeadPrivateOpenPositions(params) { return this.getPrivate('/api/v5/copytrading/performance-current-subpositions', params); } getCopytradingLeadPrivatePositionHistory(params) { return this.getPrivate('/api/v5/copytrading/performance-subpositions-history', params); } getCopyTradersPrivate(params) { return this.getPrivate('/api/v5/copytrading/copy-traders', params); } /** * * Orderbook trading - Market data endpoints * */ getTickers(params) { return this.get('/api/v5/market/tickers', params); } getTicker(params) { return this.get('/api/v5/market/ticker', params); } getOrderBook(params) { return this.get('/api/v5/market/books', params); } getFullOrderBook(params) { return this.get('/api/v5/market/books-full', params); } getCandles({ instId, bar = '1m', pagination }) { return this.get('/api/v5/market/candles', { instId, bar, ...pagination, }); } getCandlesV2(params) { return this.get('/api/v5/market/candles', params); } getHistoricCandles({ instId, bar = '1m', pagination }) { return this.get('/api/v5/market/history-candles', { instId, bar, ...pagination, }); } getHistoricCandlesV2(params) { return this.get('/api/v5/market/history-candles', params); } getTrades(params) { return this.get('/api/v5/market/trades', params); } getHistoricTrades(params) { return this.get('/api/v5/market/history-trades', params); } getOptionTradesByInstrument(params) { return this.get('/api/v5/market/option/instrument-family-trades', params); } getOptionTrades(params) { return this.get('/api/v5/public/option-trades', params); } get24hrTotalVolume() { return this.get('/api/v5/market/platform-24-volume'); } /** * * Block trading - REST endpoints * */ getBlockCounterParties() { return this.getPrivate('/api/v5/rfq/counterparties'); } createBlockRFQ(params) { return this.postPrivate('/api/v5/rfq/create-rfq', params); } cancelBlockRFQ(params) { return this.postPrivate('/api/v5/rfq/cancel-rfq', params); } cancelMultipleBlockRFQs(params) { return this.postPrivate('/api/v5/rfq/cancel-batch-rfqs', params); } cancelAllRFQs() { return this.postPrivate('/api/v5/rfq/cancel-all-rfqs'); } executeBlockQuote(params) { return this.postPrivate('/api/v5/rfq/execute-quote', params); } getQuoteProducts() { return this.getPrivate('/api/v5/rfq/maker-instrument-settings'); } updateBlockQuoteProducts(params) { return this.postPrivate('/api/v5/rfq/maker-instrument-settings', params); } resetBlockMmp() { return this.postPrivate('/api/v5/rfq/mmp-reset'); } updateBlockMmpConfig(params) { return this.postPrivate('/api/v5/rfq/mmp-config', params); } getBlockMmpConfig() { return this.getPrivate('/api/v5/rfq/mmp-config'); } createBlockQuote(params) { return this.postPrivate('/api/v5/rfq/create-quote', params); } cancelBlockQuote(params) { return this.postPrivate('/api/v5/rfq/cancel-quote', params); } cancelMultipleBlockQuotes(params) { return this.postPrivate('/api/v5/rfq/cancel-batch-quotes', params); } cancelAllBlockQuotes() { return this.postPrivate('/api/v5/rfq/cancel-all-quotes'); } cancelAllBlockAfter(params) { return this.postPrivate('/api/v5/rfq/cancel-all-after', params); } getBlockRFQs(params) { return this.getPrivate('/api/v5/rfq/rfqs', params); } getBlockQuotes(params) { return this.getPrivate('/api/v5/rfq/quotes', params); } getBlockTrades(params) { return this.getPrivate('/api/v5/rfq/trades', params); } getPublicRFQBlockTrades(params) { return this.get('/api/v5/rfq/public-trades', params); } getBlockTickers(params) { return this.get('/api/v5/market/block-tickers', params); } getBlockTicker(params) { return this.get('/api/v5/market/block-ticker', params); } getBlockPublicTrades(params) { return this.get('/api/v5/public/block-trades', params); } /** * * Spread trading - REST endpoints * */ submitSpreadOrder(params) { return this.postPrivate('/api/v5/sprd/order', params); } cancelSpreadOrder(params) { return this.postPrivate('/api/v5/sprd/cancel-order', params); } cancelAllSpreadOrders(params) { return this.postPrivate('/api/v5/sprd/mass-cancel', params); } updateSpreadOrder(params) { return this.postPrivate('/api/v5/sprd/amend-order', params); } getSpreadOrder(params) { return this.getPrivate('/api/v5/sprd/order', params); } getSpreadActiveOrders(params) { return this.getPrivate('/api/v5/sprd/orders-pending', params); } getSpreadOrdersRecent(params) { return this.getPrivate('/api/v5/sprd/orders-history', params); } getSpreadOrdersArchive(params) { return this.getPrivate('/api/v5/sprd/orders-history-archive', params); } getSpreadTrades(params) { return this.getPrivate('/api/v5/sprd/trades', params); } getSpreads(params) { return this.get('/api/v5/sprd/spreads', params); } getSpreadOrderBook(params) { return this.get('/api/v5/sprd/books', params); } getSpreadTicker(params) { return this.get('/api/v5/market/sprd-ticker', params); } getSpreadPublicTrades(params) { return this.get('/api/v5/sprd/public-trades', params); } getSpreadCandles(params) { return this.get('/api/v5/market/sprd-candles', params); } getSpreadHistoryCandles(params) { return this.get('/api/v5/market/sprd-history-candles', params); } cancelSpreadAllAfter(params) { return this.postPrivate('/api/v5/sprd/cancel-all-after', params); } /** * * Public data - rest endpoints * */ getInstruments(params) { return this.get('/api/v5/public/instruments', params); } getDeliveryExerciseHistory(params) { return this.get('/api/v5/public/delivery-exercise-history', params); } getOpenInterest(params) { return this.get('/api/v5/public/open-interest', params); } getFundingRate(params) { return this.get('/api/v5/public/funding-rate', params); } getFundingRateHistory(params) { return this.get('/api/v5/public/funding-rate-history', params); } getMinMaxLimitPrice(params) { return this.get('/api/v5/public/price-limit', params); } getOptionMarketData(params) { return this.get('/api/v5/public/opt-summary', params); } getEstimatedDeliveryExercisePrice(params) { return this.get('/api/v5/public/estimated-price', params); } getDiscountRateAndInterestFreeQuota(params) { return this.get('/api/v5/public/discount-rate-interest-free-quota', params); } getSystemTime(params) { return this.get('/api/v5/public/time', params); } getMarkPrice(params) { return this.get('/api/v5/public/mark-price', params); } getPositionTiers(params) { return this.get('/api/v5/public/position-tiers', params); } getInterestRateAndLoanQuota(params) { return this.get('/api/v5/public/interest-rate-loan-quota', params); } getVIPInterestRateAndLoanQuota(params) { return this.get('/api/v5/public/vip-interest-rate-loan-quota', params); } getUnderlying(params) { return this.get('/api/v5/public/underlying', params); } getInsuranceFund(params) { return this.get('/api/v5/public/insurance-fund', params); } getUnitConvert(params) { return this.get('/api/v5/public/convert-contract-coin', params); } getOptionTickBands(params) { return this.get('/api/v5/public/instrument-tick-bands', params); } getPremiumHistory(params) { return this.get('/api/v5/public/premium-history', params); } getIndexTickers(params) { return this.get('/api/v5/market/index-tickers', { ...params }); } getIndexCandles({ instId, bar = '1m', pagination }) { return this.get('/api/v5/market/index-candles', { instId, bar, ...pagination, }); } getIndexCandlesV2(params) { return this.get('/api/v5/market/index-candles', params); } getHistoricIndexCandles({ instId, bar = '1m', pagination }) { return this.get('/api/v5/market/history-index-candles', { instId, bar, ...pagination, }); } getHistoricIndexCandlesV2(params) { return this.get('/api/v5/market/history-index-candles', params); } getMarkPriceCandles({ instId, bar = '1m', pagination }) { return this.get('/api/v5/market/mark-price-candles', { instId, bar, ...pagination, }); } getMarkPriceCandlesV2(params) { return this.get('/api/v5/market/mark-price-candles', params); } getHistoricMarkPriceCandles({ instId, bar = '1m', pagination }) { return this.get('/api/v5/market/historic-mark-price-candles', { instId, bar, ...pagination, }); } getHistoricMarkPriceCandlesV2(params) { return this.get('/api/v5/market/history-mark-price-candles', params); } getOracle() { return this.get('/api/v5/market/open-oracle'); } getExchangeRate() { return this.get('/api/v5/market/exchange-rate'); } getIndexComponents(params) { return this.get('/api/v5/market/index-components', params); } getEconomicCalendar(params) { return this.getPrivate('/api/v5/public/economic-calendar', params); } getPublicBlockTrades(params) { return this.get('/api/v5/market/block-trades', params); } /** * * Trading statistics - REST endpoints * */ getSupportCoin() { return this.get('/api/v5/rubik/stat/trading-data/support-coin'); } getOpenInterestHistory(params) { return this.get('/api/v5/rubik/stat/contracts/open-interest-history', params); } getTakerVolume(params) { return this.get('/api/v5/rubik/stat/taker-volume', params); } getContractTakerVolume(params) { return this.get('/api/v5/rubik/stat/taker-volume-contract', params); } getMarginLendingRatio(params) { return this.get('/api/v5/rubik/stat/margin/loan-ratio', params); } getTopTradersAccountRatio(params) { return this.get('/api/v5/rubik/stat/contracts/long-short-account-ratio-contract-top-trader', params); } getTopTradersContractPositionRatio(params) { return this.get('/api/v5/rubik/stat/contracts/long-short-position-ratio-contract-top-trader', params); } getLongShortContractRatio(params) { return this.get('/api/v5/rubik/stat/contracts/long-short-account-ratio-contract', params); } getLongShortRatio(params) { return this.get('/api/v5/rubik/stat/contracts/long-short-account-ratio', params); } getContractsOpenInterestAndVolume(params) { return this.get('/api/v5/rubik/stat/contracts/open-interest-volume', params); } getOptionsOpenInterestAndVolume(params) { return this.get('/api/v5/rubik/stat/option/open-interest-volume', params); } getPutCallRatio(params) { return this.get('/api/v5/rubik/stat/option/open-interest-volume-ratio', params); } getOpenInterestAndVolumeExpiry(params) { return this.get('/api/v5/rubik/stat/option/open-interest-volume-expiry', params); } getOpenInterestAndVolumeStrike(params) { return this.get('/api/v5/rubik/stat/option/open-interest-volume-strike', params); } getTakerFlow(params) { return this.get('/api/v5/rubik/stat/option/taker-block-volume', params); } /** * * Funding account - REST endpoints * */ getCurrencies(params) { return this.getPrivate('/api/v5/asset/currencies', { ...params }); } getBalances(params) { return this.getPrivate('/api/v5/asset/balances', { ...params }); } getNonTradableAssets(params) { return this.getPrivate('/api/v5/asset/non-tradable-assets', params); } getAccountAssetValuation(params) { return this.getPrivate('/api/v5/asset/asset-valuation', { ...params }); } fundsTransfer(params) { return this.postPrivate('/api/v5/asset/transfer', params); } /** Either parameter transId or clientId is required. */ getFundsTransferState(params) { return this.getPrivate('/api/v5/asset/transfer-state', params); } getAssetBillsDetails(params) { return this.getPrivate('/api/v5/asset/bills', params); } getLightningDeposits(params) { return this.getPrivate('/api/v5/asset/deposit-lightning', params); } getDepositAddress(params) { return this.getPrivate('/api/v5/asset/deposit-address', params); } getDepositHistory(params) { return this.getPrivate('/api/v5/asset/deposit-history', params); } submitWithdraw(params) { return this.postPrivate('/api/v5/asset/withdrawal', params); } submitWithdrawLightning(params) { return this.postPrivate('/api/v5/asset/withdrawal-lightning', params); } cancelWithdrawal(params) { return this.postPrivate('/api/v5/asset/cancel-withdrawal', params); } getWithdrawalHistory(params) { return this.getPrivate('/api/v5/asset/withdrawal-history', params); } getDepositWithdrawStatus(params) { return this.getPrivate('/api/v5/asset/deposit-withdraw-status', params); } getExchanges() { return this.get('/api/v5/asset/exchange-list'); } applyForMonthlyStatement(params) { return this.postPrivate('/api/v5/asset/monthly-statement', params); } getMonthlyStatement(params) { return this.getPrivate('/api/v5/asset/monthly-statement', params); } getConvertCurrencies() { return this.getPrivate('/api/v5/asset/convert/currencies'); } getConvertCurrencyPair(params) { return this.getPrivate('/api/v5/asset/convert/currency-pair', params); } estimateConvertQuote(params) { return this.postPrivate('/api/v5/asset/convert/estimate-quote', params); } convertTrade(params) { return this.postPrivate('/api/v5/asset/convert/trade', params); } getConvertHistory(params) { return this.getPrivate('/api/v5/asset/convert/history', params); } /** * * Subaccount - REST endpoints * */ /** View sub-account list */ getSubAccountList(params) { return this.getPrivate('/api/v5/users/subaccount/list', params); } resetSubAccountAPIKey(params) { return this.postPrivate('/api/v5/users/subaccount/modify-apikey', params); } getSubAccountBalances(params) { return this.getPrivate('/api/v5/account/subaccount/balances', params); } getSubAccountFundingBalances(params) { return this.getPrivate('/api/v5/asset/subaccount/balances', params); } getSubAccountMaxWithdrawal(params) { return this.getPrivate('/api/v5/account/subaccount/max-withdrawal', params); } /** History of sub-account transfer */ getSubAccountTransferHistory(params) { return this.getPrivate('/api/v5/asset/subaccount/bills', params); } getManagedSubAccountTransferHistory(params) { return this.getPrivate('/api/v5/asset/subaccount/managed-subaccount-bills', params); } /** Master accounts manage the transfers between sub-accounts */ transferSubAccountBalance(params) { return this.postPrivate('/api/v5/asset/subaccount/transfer', params); } setSubAccountTransferOutPermission(params) { return this.postPrivate('/api/v5/users/subaccount/set-transfer-out', params); } getSubAccountCustodyTradingList(params) { return this.getPrivate('/api/v5/users/entrust-subaccount-list', { ...params }); } setSubAccountLoanAllocation(params) { return this.postPrivate('/api/v5/account/subaccount/set-loan-allocation', params); } getSubAccountBorrowInterestAndLimit(params) { return this.getPrivate('/api/v5/account/subaccount/interest-limits', params); } /** * * Financial product - on chain earn endpoints * */ /** Get earn offers */ getStakingOffers(params) { return this.getPrivate('/api/v5/finance/staking-defi/offers', params); } submitStake(params) { return this.postPrivate('/api/v5/finance/staking-defi/purchase', params); } redeemStake(params) { return this.postPrivate('/api/v5/finance/staking-defi/redeem', params); } cancelStakingRequest(params) { return this.postPrivate('/api/v5/finance/staking-defi/cancel', params); } /** Earn/staking get active orders */ getActiveStakingOrders(params) { return this.getPrivate('/api/v5/finance/staking-defi/orders-active', params); } /** Earn/staking get order history */ getStakingOrderHistory(params) { return this.getPrivate('/api/v5/finance/staking-defi/orders-history', params); } /** * * Financial product - ETH staking endpoints * */ getETHStakingProductInfo() { return this.get('/api/v5/finance/staking-defi/eth/product-info'); } purchaseETHStaking(params) { return this.postPrivate('/api/v5/finance/staking-defi/eth/purchase', params); } redeemETHStaking(params) { return this.postPrivate('/api/v5/finance/staking-defi/eth/redeem', params); } getETHStakingBalance() { return this.getPrivate('/api/v5/finance/staking-defi/eth/balance'); } getETHStakingHistory(params) { return this.getPrivate('/api/v5/finance/staking-defi/eth/purchase-redeem-history', params); } getAPYHistory(params) { return this.get('/api/v5/finance/staking-defi/eth/apy-history', params); } /** * * Financial product - simple earn flexible endpoints * */ getSavingBalance(params) { return this.getPrivate('/api/v5/finance/savings/balance', { ...params }); } savingsPurchaseRedemption(params) { return this.postPrivate('/api/v5/finance/savings/purchase-redempt', params); } setLendingRate(params) { return this.postPrivate('/api/v5/finance/savings/set-lending-rate', params); } getLendingHistory(params) { return this.getPrivate('/api/v5/finance/savings/lending-history', params); } getPublicBorrowInfo(params) { return this.get('/api/v5/finance/savings/lending-rate-summary', { ...params }); } getPublicBorrowHistory(params) { return this.get('/api/v5/finance/savings/lending-rate-history', params); } /** * * Financial product - simple earn fixed endpoints * */ getLendingOffers(params) { return this.get('/api/v5/finance/fixed-loan/lending-offers', params); } getLendingAPYHistory(params) { return this.get('/api/v5/finance/fixed-loan/lending-apy-history', params); } getLendingVolume(params) { return this.get('/api/v5/finance/fixed-loan/pending-lending-volume', params); } placeLendingOrder(params) { return this.postPrivate('/api/v5/finance/fixed-loan/lending-order', params); } amendLendingOrder(params) { return this.postPrivate('/api/v5/finance/fixed-loan/amend-lending-order', params); } getLendingOrders(params) { return this.getPrivate('/api/v5/finance/fixed-loan/lending-orders-list', params); } getLendingSubOrders(params) { return this.getPrivate('/api/v5/finance/fixed-loan/lending-sub-orders', params); } /** * * Financial product - Flexible loan endpoints * */ getBorrowableCurrencies() { return this.get('/api/v5/finance/flexible-loan/borrow-currencies'); } getCollateralAssets(params) { return this.get('/api/v5/finance/flexible-loan/collateral-assets', params); } getMaxLoanAmount(params) { return this.postPrivate('/api/v5/finance/flexible-loan/max-loan', params); } adjustCollateral(params) { return this.postPrivate('/api/v5/finance/flexible-loan/adjust-collateral', params); } getLoanInfo() { return this.getPrivate('/api/v5/finance/flexible-loan/loan-info'); } getLoanHistory(params) { return this.getPrivate('/api/v5/finance/flexible-loan/loan-history', params); } getAccruedInterest(params) { return this.getPrivate('/api/v5/finance/flexible-loan/interest-accrued', params); } /** * * Affiliate endpoints * */ getInviteeDetail(params) { return this.getPrivate('/api/v5/affiliate/invitee/detail', params); } getAffiliateRebateInfo(params) { return this.getPrivate('/api/v5/users/partner/if-rebate', params); } /** * * Status endpoints (public) * */ getSystemStatus(params) { return this.get('/api/v5/system/status', { ...params }); } /** * * Announcement endpoints * */ getAnnouncements(params) { return this.get('/api/v5/support/announcements', params); } getAnnouncementTypes() { return this.get('/api/v5/support/announcement-types'); } /** * * Broker endpoints (private) * */ /** * * @deprecated */ getBrokerAccountInformation() { return this.getPrivate('/api/v5/broker/nd/info'); } createSubAccount(params) { return this.postPrivate('/api/v5/broker/nd/create-subaccount', params); } deleteSubAccount(params) { return this.postPrivate('/api/v5/broker/nd/delete-subaccount', params); } createSubAccountAPIKey(params) { return this.postPrivate('/api/v5/broker/nd/subaccount/apikey', params); } } exports.HttpApi = HttpApi;