import { APICredentials } from './utils'; import { ASSET_BILL_TYPE } from './constants'; import type { AccountAssetValuation, AccountBalance, AccountBill, AccountChangeMarginResult, AccountConfiguration, AccountFeeRate, AccountHistoryBill, AccountInstrument, AccountIsolatedMode, AccountLevel, AccountLeverage, AccountLeverageResult, AccountMaxLoan, AccountMaxOrderAmount, AccountMaxTradableAmount, AccountModeResult, AccountPosition, AccountPositionModeResult, AccountPositionRisk, AccountRiskState, AdjustLeverageInfo, AdjustMarginBalanceRequest, AlgoLongHistoryRequest, AlgoOrderDetailsRequest, AlgoOrderDetailsResult, AlgoOrderListItem, AlgoOrderRequest, AlgoOrderResult, AlgoRecentHistoryRequest, AmendAlgoOrderRequest, AmendAlgoOrderResult, AmendedOrder, AmendOrderRequest, AmendRecurringBuyOrderRequest, AmendTPSLRequest, Announcement, APIResponse, AssetBillDetails, AutoLoanResult, BlockCounterParty, BlockMakerInstrumentSettings, BlockMMPConfig, BlockRFQResult, BorrowRepayHistoryItem, CancelAlgoOrderRequest, CancelAllAfterResponse, CancelBlockQuoteRequest, CancelBlockQuoteResult, CancelBlockRFQRequest, CancelBlockRFQResult, CancelledOrderResult, CancelMultipleBlockQuoteRequest, CancelMultipleBlockRFQRequest, CancelSignalBotsResult, CancelSpreadOrderResponse, CancelSubOrderRequest, Candle, CandleNoVolume, CandleRequest, ChangePositionMarginRequest, CloseContractGridPositionRequest, ClosedPositions, ClosePositionRequest, CloseSubpositionRequest, ContractGridDirection, ConvertQuoteEstimateRequest, ConvertTradeRequest, CopySettingsRequest, CreateBlockQuoteRequest, CreateBlockQuoteResult, CreateBlockRFQRequest, CreateRFQResult, CreateSignalBotRequest, CreateSignalBotResult, CreateSignalRequest, CreateSignalResult, CurrentSubposition, EconomicCalendarData, EconomicCalendarRequest, ExecuteBlockQuoteRequest, ExecuteBlockQuoteResult, FillsHistoryRequest, FixedLoanBorrowingLimit, FixedLoanBorrowQuote, FundingBalance, FundingCurrency, FundingRateRequest, FundsTransferRequest, FundTransferResult, FundTransferState, GetAccountConfigurationResult, GetActiveSpreadOrdersRequest, GetBlockQuoteParams, GetBlockQuoteResult, GetBlockRFQSParams, GetBorrowRepayHistoryRequest, GetContractOpenInterestHistoryRequest, GetContractTakerVolumeRequest, GetCopySettingsResult, GetCopyTradersRequest, GetCopyTradersResult, GetCopyTradingConfigResult, GetCTBatchLeverageInfoRequest, GetCTBatchLeverageInfoResult, GetCTHistoryLeadTradersRequest, GetCTHistoryLeadTradersResult, GetCTMyLeadTradersResult, GetCTProfitDetailsRequest, GetCTProfitDetailsResult, GetCTTotalProfitResult, GetCTUnrealizedProfitResult, GetCurrentSubpositionsRequest, GetDepositWithdrawStatusRequest, GetFixedLoanBorrowingOrdersListRequest, GetFixedLoanBorrowQuoteRequest, GetGridAlgoOrdersRequest, GetHistoricPositionParams, GetInstrumentsRequest, GetLeadTraderPositionsRequest, GetLeadTraderRanksRequest, GetLeadTraderRanksResult, GetLeadTraderStatsRequest, GetLendingOrderListRequest, GetLendingSubOrderListRequest, GetManagedSubAccountTransferHistoryRequest, GetOptionTradesRequest, GetPositionsParams, GetPremiumHistoryRequest, GetPrivateLeadTraderRanksRequest, GetPrivateLeadTraderRanksResult, GetQuickMarginBorrowRepayHistoryRequest, GetRecurringBuyOrderListRequest, GetRSIBackTestingRequest, GetSignalBotEventHistoryRequest, GetSignalBotPositionHistoryRequest, GetSignalBotRequest, GetSignalBotSubOrdersRequest, GetSignalsRequest, GetSignalsResult, GetSpreadCandlesRequest, GetSpreadOrderHistoryArchiveRequest, GetSpreadOrderHistoryRequest, GetSpreadsRequest, GetSpreadTradesRequest, GetSubAccountMaxWithdrawalsRequest, GetSubpositionsHistoryRequest, GetTopTradersContractLongShortRatioRequest, GetVIPInterestRequest, GetVIPLoanOrderDetailRequest, GetVIPLoanOrderListRequest, Greeks, GridAlgoOrderRequest, GridAlgoOrderType, GridAlgoSubOrderType, HistoricAccountPosition, HistoricAlgoOrder, HistoricOrder, IndexTicker, Instrument, InstrumentType, InterestAccrued, InterestRate, LeadTraderCurrentPosition, LeadTraderPnl, LeadTraderPositionHistory, LeadTraderPreference, LeadTraderStats, LendingOrder, ManagedSubAccountTransfer, MarginMode, MaxGridQuantityRequest, MaxWithdrawal, MMPConfig, NonTradableAsset, numberInString, OptionTrade, OptionTrades, OrderBook, OrderDetails, OrderFill, OrderHistoryRequest, OrderIdRequest, OrderListItem, OrderPrecheckRequest, OrderRequest, OrderResult, PaginatedSymbolRequest, Pagination, PlaceCTAlgoOrderRequest, PlaceCTAlgoOrderResult, PlaceRecurringBuyOrderRequest, PlaceSpreadOrderRequest, PlaceSpreadOrderResponse, PlaceSubOrderRequest, PositionBuilderRequest, PositionSide, PosMode, PublicBlockTrade, PublicSpreadTrade, QuickMarginBorrowRepayRecord, QuickMarginBorrowRepayRequest, QuickMarginBorrowRepayResult, RecurringBuyOrder, RecurringBuyOrderResult, RecurringBuySubOrder, SetCTBatchLeverageRequest, SetCTBatchLeverageResult, SetLeverageRequest, SetMMPConfigRequest, SetMmpConfigRequest, SetMMPConfigResult, SetMmpConfigResult, SetQuoteProductsRequest, SetSignalInstrumentsRequest, SetSubAccountLoanAllocationRequest, SpreadCandle, SpreadDetails, SpreadOrder, SpreadOrderBook, SpreadTicker, SpreadTrade, StopGridAlgoOrderRequest, SubAccount, SubAccountAPIReset, SubAccountBalances, SubAccountMaxWithdrawal, SubAccountTransferRequest, SubAccountTransferResult, SubmitFixedLoanBorrowingOrderRequest, SubpositionsHistory, SystemTime, Ticker, TimestampObject, Trade, UnitConvertData, UnitConvertRequest, UpdateFixedLoanBorrowingOrderRequest, UpdateSpreadOrderRequest, UpdateSpreadOrderResponse, VIPInterest, VIPLoanOrder, VIPLoanOrderDetail, WithdrawalHistoryRequest, WithdrawRequest, WithdrawResponse, AccruedInterestItem, AccruedInterestRequest, AdjustCollateralRequest, CollateralAssetsResponse, LoanHistoryItem, LoanHistoryRequest, LoanInfo, MaxLoanRequest, MaxLoanResponse, } from './types'; export class HttpApi { public static async create(apiKey: string, apiSecret: string, passphrase: string, baseURL = 'https://www.okx.com') { return new HttpApi(await APICredentials.create(apiKey, apiSecret, passphrase), baseURL); } constructor(private credentials?: APICredentials, private baseURL = 'https://www.okx.com') { } private getUrl(path: string, params: Record = {}) { 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; } private getResponseData(response: any) { if (response.code !== '0' && response.code !== 0) throw new Error(JSON.stringify(response)); return response.data; } private async getPrivate(path: string, params: any = {}) { 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()) as T; } private async postPrivate(path: string, body: any = {}) { 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()) as T; } private async get(path: string, params: any = {}) { const response = await fetch(this.getUrl(path, params)); return this.getResponseData(await response.json()) as T; } private async post(path: string, body: any = {}) { const response = await fetch(this.baseURL + path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); return this.getResponseData(await response.json()) as T; } async getServerTime(): Promise<{ts?: string}[]> { return await this.get('/api/v5/public/time'); } getAccountInstruments( params: GetInstrumentsRequest, ): Promise { return this.getPrivate('/api/v5/account/instruments', params); } getBalance(params?: { ccy?: string }): Promise { return this.getPrivate('/api/v5/account/balance', { ...params }); } getPositions(params?: GetPositionsParams): Promise { return this.getPrivate('/api/v5/account/positions', params); } getPositionsHistory( params?: GetHistoricPositionParams, ): Promise { return this.getPrivate('/api/v5/account/positions-history', params); } getAccountPositionRisk( params?: { instType?: Omit<'SPOT', InstrumentType> } ): Promise { return this.getPrivate('/api/v5/account/account-position-risk', { ...params }); } /** Up to last 7 days */ getBills(params?: any): Promise { return this.getPrivate('/api/v5/account/bills', params); } /** Last 3 months */ getBillsArchive(params?: any): Promise { 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: { year: string; quarter: 'Q1' | 'Q2' | 'Q3' | 'Q4'; }): Promise { 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: { year: string; quarter: 'Q1' | 'Q2' | 'Q3' | 'Q4'; }): Promise { return this.getPrivate('/api/v5/account/bills-history-archive', params); } getAccountConfiguration(): Promise { return this.getPrivate('/api/v5/account/config'); } setPositionMode(params: { posMode: PosMode }): Promise { return this.postPrivate('/api/v5/account/set-position-mode', params); } setLeverage(params: SetLeverageRequest): Promise { return this.postPrivate('/api/v5/account/set-leverage', params); } /** Max buy/sell amount or open amount */ getMaxBuySellAmount(params: { instId: string; tdMode: 'cross' | 'isolated' | 'cash'; ccy?: string; px?: string; leverage?: string; unSpotOffset?: boolean; }): Promise { return this.getPrivate('/api/v5/account/max-size', params); } getMaxAvailableTradableAmount(params: { instId: string; ccy?: string; tdMode: 'cross' | 'isolated' | 'cash'; reduceOnly?: boolean; unSpotOffset?: boolean; }): Promise { return this.getPrivate('/api/v5/account/max-avail-size', params); } changePositionMargin( params: ChangePositionMarginRequest, ): Promise { return this.postPrivate('/api/v5/account/position/margin-balance', params); } getLeverage(params: { instId: string, mgnMode: MarginMode }): Promise { return this.getPrivate('/api/v5/account/leverage-info', params); } getLeverageV2(params: { instId?: string; ccy?: string; mgnMode: MarginMode; }): Promise { return this.getPrivate('/api/v5/account/leverage-info', params); } getLeverageEstimatedInfo(params: { instType: string; mgnMode: MarginMode; lever: string; instId?: string; ccy?: string; posSide: PositionSide; }): Promise { return this.getPrivate('/api/v5/account/adjust-leverage-info', params); } getMaxLoan(params: { instId: string, mgnMode: MarginMode, mgnCcy?: string | undefined, ccy?: string, }): Promise { return this.getPrivate('/api/v5/account/max-loan', params); } getMaxLoanV2(params: { instId: string; mgnMode: MarginMode; mgnCcy?: string; ccy?: string; }): Promise { return this.getPrivate('/api/v5/account/max-loan', params); } getFeeRates(params: { instType: InstrumentType, instId?: string, uly?: string, instFamily?: string, ruleType?: string, }): Promise { return this.getPrivate('/api/v5/account/trade-fee', params); } getFeeRatesV2(params: { instType: InstrumentType; instId?: string; uly?: string; instFamily?: string; ruleType?: string; }): Promise { return this.getPrivate('/api/v5/account/trade-fee', params); } getInterestAccrued(params?: { type?: '1' | '2'; ccy?: string; instId?: string; mgnMode?: MarginMode; after?: string; before?: string; limit?: string; }): Promise { return this.getPrivate('/api/v5/account/interest-accrued', params); } getInterestRate(params?: { ccy?: string }): Promise { return this.getPrivate('/api/v5/account/interest-rate', { ...params }); } setGreeksDisplayType(params: { greeksType: 'PA' | 'BS' }): Promise { return this.postPrivate('/api/v5/account/set-greeks', params); } setIsolatedMode(params: { isoMode: 'automatic' | 'autonomy', type: 'MARGIN' | 'CONTRACTS', }): Promise { return this.postPrivate('/api/v5/account/set-isolated-mode', params); } getMaxWithdrawals(params?: { ccy?: string }): Promise { return this.getPrivate('/api/v5/account/max-withdrawal', { ...params }); } getAccountRiskState(): Promise { return this.getPrivate('/api/v5/account/risk-state'); } submitQuickMarginBorrowRepay( params: QuickMarginBorrowRepayRequest, ): Promise { return this.postPrivate( '/api/v5/account/quick-margin-borrow-repay', params, ); } getQuickMarginBorrowRepayHistory( params: GetQuickMarginBorrowRepayHistoryRequest, ): Promise { return this.getPrivate( '/api/v5/account/quick-margin-borrow-repay-history', params, ); } borrowRepayVIPLoan(params: { ccy: string, side: 'borrow' | 'repay', amt: numberInString, ordId?: string, }): Promise { return this.postPrivate('/api/v5/account/borrow-repay', params); } getVIPLoanBorrowRepayHistory(params?: any): Promise { return this.getPrivate('/api/v5/account/borrow-repay-history', params); } getVIPInterestAccrued(params: GetVIPInterestRequest): Promise { return this.getPrivate('/api/v5/account/vip-interest-accrued', params); } getVIPInterestDeducted( params: GetVIPInterestRequest, ): Promise { return this.getPrivate('/api/v5/account/vip-interest-deducted', params); } getVIPLoanOrders( params: GetVIPLoanOrderListRequest, ): Promise { return this.getPrivate('/api/v5/account/vip-loan-order-list', params); } getVIPLoanOrder( params: GetVIPLoanOrderDetailRequest, ): Promise { return this.getPrivate('/api/v5/account/vip-loan-order-detail', params); } getBorrowInterestLimits(params?: { type?: '1' | '2'; ccy?: string; }): Promise { return this.getPrivate('/api/v5/account/interest-limits', params); } getFixedLoanBorrowLimit(): Promise { return this.getPrivate('/api/v5/account/fixed-loan/borrowing-limit'); } getFixedLoanBorrowQuote( params: GetFixedLoanBorrowQuoteRequest, ): Promise { return this.getPrivate( '/api/v5/account/fixed-loan/borrowing-quote', params, ); } submitFixedLoanBorrowOrder( params: SubmitFixedLoanBorrowingOrderRequest, ): Promise< { ordId: string; }[] > { return this.postPrivate( '/api/v5/account/fixed-loan/borrowing-order', params, ); } updateFixedLoanBorrowOrder( params: UpdateFixedLoanBorrowingOrderRequest, ): Promise< { ordId: string; }[] > { return this.postPrivate( '/api/v5/account/fixed-loan/amend-borrowing-order', params, ); } manualRenewFixedLoanBorrowOrder(params: { ordId: string; maxRate: string; }): Promise< { ordId: string; }[] > { return this.postPrivate( '/api/v5/account/fixed-loan/manual-reborrow', params, ); } repayFixedLoanBorrowOrder(params: { ordId: string }): Promise< { ordId: string; }[] > { return this.postPrivate( '/api/v5/account/fixed-loan/repay-borrowing-order', params, ); } convertFixedLoanToMarketLoan(params: { ordId: string }): Promise< { ordId: string; }[] > { return this.postPrivate( '/api/v5/account/fixed-loan/convert-to-market-loan', params, ); } reduceFixedLoanLiabilities(params: { ordId: string; pendingRepay: boolean; }): Promise< { ordId: string; pendingRepay: boolean; }[] > { return this.postPrivate( '/api/v5/account/fixed-loan/reduce-liabilities', params, ); } getFixedLoanBorrowOrders( params: GetFixedLoanBorrowingOrdersListRequest, ): Promise { return this.getPrivate( '/api/v5/account/fixed-loan/borrowing-orders-list', params, ); } manualBorrowRepay(params: { ccy: string; side: 'borrow' | 'repay'; amt: string; }): Promise< { ccy: string; side: 'borrow' | 'repay'; amt: string; }[] > { return this.postPrivate('/api/v5/account/spot-manual-borrow-repay', params); } setAutoRepay(params: { autoRepay: boolean }): Promise< { autoRepay: boolean; }[] > { return this.postPrivate('/api/v5/account/set-auto-repay', params); } getBorrowRepayHistory( params?: GetBorrowRepayHistoryRequest, ): Promise { return this.getPrivate('/api/v5/account/spot-borrow-repay-history', params); } positionBuilder(params: PositionBuilderRequest): Promise { return this.postPrivate('/api/v5/account/position-builder', params); } updateRiskOffsetAmount(params: { ccy: string; clSpotInUseAmt: string; }): Promise< { ccy: string; clSpotInUseAmt: string; }[] > { return this.postPrivate('/api/v5/account/set-riskOffset-amt', params); } getGreeks(params?: { ccy?: string }): Promise { return this.getPrivate('/api/v5/account/greeks', { ...params }); } getPMLimitation(params: { instType: 'SWAP' | 'FUTURES' | 'OPTION'; uly?: string; instFamily?: string; }): Promise { return this.getPrivate('/api/v5/account/position-tiers', params); } updateRiskOffsetType(params: { type: '1' | '2' | '3' | '4' }): Promise< { type: '1' | '2' | '3' | '4'; }[] > { return this.postPrivate('/api/v5/account/set-riskOffset-type', params); } activateOption(): Promise< { ts: string; }[] > { return this.postPrivate('/api/v5/account/activate-option'); } setAutoLoan(params: { autoLoan: boolean }): Promise { return this.postPrivate('/api/v5/account/set-auto-loan', params); } presetAccountLevelSwitch(params: { acctLv: '2' | '3' | '4'; lever?: string; riskOffsetType?: '1' | '2' | '3' | '4'; }): Promise { return this.postPrivate( '/api/v5/account/account-level-switch-preset', params, ); } getAccountSwitchPrecheck(params: { acctLv: '1' | '2' | '3' | '4'; }): Promise { return this.getPrivate( '/api/v5/account/set-account-switch-precheck', params, ); } setAccountMode(params: { acctLv: AccountLevel; }): Promise { return this.postPrivate('/api/v5/account/set-account-level', params); } resetMMPStatus(params: { instType?: 'OPTION'; instFamily: string }): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/account/mmp-reset', params); } setMMPConfig(params: SetMMPConfigRequest): Promise { return this.postPrivate('/api/v5/account/mmp-config', params); } getMMPConfig(params?: { instFamily?: string }): Promise { return this.getPrivate('/api/v5/account/mmp-config', params); } /** * * Orderbook trading - trade endpoints * */ submitOrder(params: OrderRequest): Promise { return this.postPrivate('/api/v5/trade/order', params); } submitMultipleOrders(params: OrderRequest[]): Promise { return this.postPrivate('/api/v5/trade/batch-orders', params); } cancelOrder(params: OrderIdRequest): Promise { return this.postPrivate('/api/v5/trade/cancel-order', params); } cancelMultipleOrders( params: OrderIdRequest[], ): Promise { return this.postPrivate('/api/v5/trade/cancel-batch-orders', params); } amendOrder(params: AmendOrderRequest): Promise { return this.postPrivate('/api/v5/trade/amend-order', params); } amendMultipleOrders(params: AmendOrderRequest[]): Promise { return this.postPrivate('/api/v5/trade/amend-batch-orders', params); } closePositions(params: ClosePositionRequest): Promise { return this.postPrivate('/api/v5/trade/close-position', params); } getOrderDetails(params: OrderIdRequest): Promise { return this.getPrivate('/api/v5/trade/order', params); } getOrderList(params?: OrderHistoryRequest): Promise { return this.getPrivate('/api/v5/trade/orders-pending', params); } /** * Get history for last 7 days */ getOrderHistory(params: OrderHistoryRequest): Promise { return this.getPrivate('/api/v5/trade/orders-history', params); } /** * Get history for last 3 months */ getOrderHistoryArchive( params: OrderHistoryRequest, ): Promise { return this.getPrivate('/api/v5/trade/orders-history-archive', params); } /** * Get history for last 7 days */ getFills(params?: FillsHistoryRequest): Promise { return this.getPrivate('/api/v5/trade/fills', params); } /** * Get history for last 3 months */ getFillsHistory(params: FillsHistoryRequest): Promise { return this.getPrivate('/api/v5/trade/fills-history', params); } /** Get easy convert currency list */ getEasyConvertCurrencies(params?: { source?: string }): Promise { 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: { fromCcy: string[], toCcy: string, source?: string, }): Promise> { return this.postPrivate('/api/v5/trade/easy-convert', params); } /** Get easy convert history : Get the history and status of easy convert trades. */ getEasyConvertHistory(params?: Pagination): Promise> { 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?: { debtType?: 'cross' | 'isolated', }): Promise> { 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: { debtCcys: string[], repayCcy: string, }): Promise> { 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?: Pagination): Promise> { return this.getPrivate('/api/v5/trade/one-click-repay-history', params); } cancelMassOrder(params: { instType: string; instFamily: string; lockInterval?: string; }): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/trade/mass-cancel', params); } cancelAllAfter(params: { timeOut: string; tag?: string; }): Promise { return this.postPrivate('/api/v5/trade/cancel-all-after', params); } getAccountRateLimit(): Promise { return this.getPrivate('/api/v5/trade/account-rate-limit'); } submitOrderPrecheck(params: OrderPrecheckRequest): Promise { return this.postPrivate('/api/v5/trade/order-precheck', params); } /** * * Orderbook trading - Algo trading endpoints * */ placeAlgoOrder(params: AlgoOrderRequest): Promise { return this.postPrivate('/api/v5/trade/order-algo', params); } cancelAlgoOrder( params: CancelAlgoOrderRequest[], ): Promise { return this.postPrivate('/api/v5/trade/cancel-algos', params); } amendAlgoOrder( params: AmendAlgoOrderRequest, ): Promise { return this.postPrivate('/api/v5/trade/amend-algos', params); } cancelAdvanceAlgoOrder( params: CancelAlgoOrderRequest[], ): Promise { return this.postPrivate('/api/v5/trade/cancel-advance-algos', params); } getAlgoOrderDetails( params: AlgoOrderDetailsRequest, ): Promise { return this.getPrivate('/api/v5/trade/order-algo', params); } getAlgoOrderList( params: AlgoRecentHistoryRequest, ): Promise { return this.getPrivate('/api/v5/trade/orders-algo-pending', params); } getAlgoOrderHistory( params: AlgoLongHistoryRequest, ): Promise { return this.getPrivate('/api/v5/trade/orders-algo-history', params); } /** * * Orderbook trading - Grid trading endpoints * */ placeGridAlgoOrder(params: GridAlgoOrderRequest): Promise { return this.postPrivate('/api/v5/tradingBot/grid/order-algo', params); } amendGridAlgoOrder(params: { algoId: string, instId: string, slTriggerPx?: numberInString, tpTriggerPx?: numberInString, }): Promise { return this.postPrivate('/api/v5/tradingBot/grid/amend-order-algo', params); } stopGridAlgoOrder(orders: StopGridAlgoOrderRequest[]): Promise { return this.postPrivate('/api/v5/tradingBot/grid/stop-order-algo', orders); } closeGridContractPosition( params: CloseContractGridPositionRequest, ): Promise { return this.postPrivate('/api/v5/tradingBot/grid/close-position', params); } cancelGridContractCloseOrder(params: { algoId: string; ordId: string; }): Promise { return this.postPrivate( '/api/v5/tradingBot/grid/cancel-close-order', params, ); } instantTriggerGridAlgoOrder(params: { algoId: string }): Promise< { algoId: string; algoClOrdId: string; }[] > { return this.postPrivate( '/api/v5/tradingBot/grid/order-instant-trigger', params, ); } getGridAlgoOrderList(params: GetGridAlgoOrdersRequest): Promise { return this.getPrivate( '/api/v5/tradingBot/grid/orders-algo-pending', params, ); } getGridAlgoOrderHistory(params: GetGridAlgoOrdersRequest): Promise { return this.getPrivate( '/api/v5/tradingBot/grid/orders-algo-history', params, ); } getGridAlgoOrderDetails(params: { algoOrdType: GridAlgoOrderType, algoId: string, }): Promise { return this.getPrivate('/api/v5/tradingBot/grid/orders-algo-details', params); } getGridAlgoSubOrders(params: { algoOrdType: GridAlgoOrderType, algoId: string, type: GridAlgoSubOrderType, groupId?: string, after?: numberInString, before?: numberInString, limit?: number, }): Promise { return this.getPrivate('/api/v5/tradingBot/grid/sub-orders', params); } getGridAlgoOrderPositions(params: { algoOrdType: 'contract_grid', algoId: string, }): Promise { return this.getPrivate('/api/v5/tradingBot/grid/positions', params); } spotGridWithdrawIncome(params: { algoId: string }): Promise { return this.postPrivate('/api/v5/tradingBot/grid/withdraw-income', params); } computeGridMarginBalance(params: { algoId: string, type: 'add' | 'reduce', amt?: numberInString, }): Promise { return this.postPrivate('/api/v5/tradingBot/grid/compute-margin-balance', params); } adjustGridMarginBalance(params: { algoId: string, type: 'add' | 'reduce', amt?: numberInString, percent?: numberInString }): Promise { return this.postPrivate('/api/v5/tradingBot/grid/margin-balance', params); } adjustGridInvestment(params: { algoId: string; amt: string }): Promise< { algoId: string; }[] > { return this.postPrivate( '/api/v5/tradingBot/grid/adjust-investment', params, ); } getGridAIParameter(params: { algoOrdType: GridAlgoOrderType, instId: string, direction: ContractGridDirection, duration?: '7D' | '30D' | '180D', }): Promise { return this.get('/api/v5/tradingBot/grid/ai-param', params); } computeGridMinInvestment(params: { amt: string; ccy: string; }): Promise { return this.post('/api/v5/tradingBot/grid/min-investment', params); } getRSIBackTesting(params: GetRSIBackTestingRequest): Promise< { triggerNum: string; }[] > { return this.get('/api/v5/tradingBot/public/rsi-back-testing', params); } getMaxGridQuantity(params: MaxGridQuantityRequest): Promise< { maxGridQty: string; }[] > { return this.get('/api/v5/tradingBot/grid/grid-quantity', params); } /** * * Orderbook trading - Signal bot trading endpoints * */ createSignal(params: CreateSignalRequest): Promise { return this.postPrivate('/api/v5/tradingBot/signal/create-signal', params); } getSignals(params: GetSignalsRequest): Promise { return this.getPrivate('/api/v5/tradingBot/signal/signals', params); } createSignalBot( params: CreateSignalBotRequest, ): Promise { return this.postPrivate('/api/v5/tradingBot/signal/order-algo', params); } cancelSignalBots(params: { algoId: string; }): Promise { return this.postPrivate( '/api/v5/tradingBot/signal/stop-order-algo', params, ); } updateSignalMargin(params: AdjustMarginBalanceRequest): Promise< { algoId: string; }[] > { return this.postPrivate('/api/v5/tradingBot/signal/margin-balance', params); } updateSignalTPSL(params: AmendTPSLRequest): Promise< { algoId: string; }[] > { return this.postPrivate('/api/v5/tradingBot/signal/amendTPSL', params); } setSignalInstruments(params: SetSignalInstrumentsRequest): Promise< { algoId: string; }[] > { return this.postPrivate( '/api/v5/tradingBot/signal/set-instruments', params, ); } getSignalBotOrder(params: { algoOrdType: string; algoId: string; }): Promise { return this.getPrivate( '/api/v5/tradingBot/signal/orders-algo-details', params, ); } getActiveSignalBot(params: GetSignalBotRequest): Promise { return this.getPrivate( '/api/v5/tradingBot/signal/orders-algo-details', params, ); } getSignalBotHistory(params: GetSignalBotRequest): Promise { return this.getPrivate( '/api/v5/tradingBot/signal/orders-algo-history', params, ); } getSignalBotPositions(params: { algoOrdType: string; algoId: string; }): Promise { return this.getPrivate('/api/v5/tradingBot/signal/positions', params); } getSignalBotPositionHistory( params: GetSignalBotPositionHistoryRequest, ): Promise { return this.getPrivate( '/api/v5/tradingBot/signal/positions-history', params, ); } closeSignalBotPosition(params: { algoId: string; instId: string }): Promise< { algoId: string; }[] > { return this.postPrivate('/api/v5/tradingBot/signal/close-position', params); } placeSignalBotSubOrder(params: PlaceSubOrderRequest): Promise { return this.postPrivate('/api/v5/tradingBot/signal/sub-order', params); } cancelSubOrder(params: CancelSubOrderRequest): Promise { return this.postPrivate( '/api/v5/tradingBot/signal/cancel-sub-order', params, ); } getSignalBotSubOrders(params: GetSignalBotSubOrdersRequest): Promise { return this.getPrivate('/api/v5/tradingBot/signal/sub-orders', params); } getSignalBotEventHistory( params: GetSignalBotEventHistoryRequest, ): Promise { return this.getPrivate('/api/v5/tradingBot/signal/event-history', params); } /** * * Orderbook trading - Recurring buy endpoints * */ submitRecurringBuyOrder( params: PlaceRecurringBuyOrderRequest, ): Promise { return this.postPrivate('/api/v5/tradingBot/recurring/order-algo', params); } amendRecurringBuyOrder( params: AmendRecurringBuyOrderRequest, ): Promise { return this.postPrivate( '/api/v5/tradingBot/recurring/amend-order-algo', params, ); } stopRecurringBuyOrder(params: { algoId: string; }): Promise { return this.postPrivate( '/api/v5/tradingBot/recurring/stop-order-algo', params, ); } getRecurringBuyOrders( params: GetRecurringBuyOrderListRequest, ): Promise { return this.getPrivate( '/api/v5/tradingBot/recurring/orders-algo-pending', params, ); } getRecurringBuyOrderHistory( params: GetRecurringBuyOrderListRequest, ): Promise { return this.getPrivate( '/api/v5/tradingBot/recurring/orders-algo-history', params, ); } getRecurringBuyOrderDetails(params: { algoId: string; }): Promise { return this.getPrivate( '/api/v5/tradingBot/recurring/orders-algo-details', params, ); } getRecurringBuySubOrders( params: GetRecurringBuyOrderListRequest, ): Promise { return this.getPrivate('/api/v5/tradingBot/recurring/sub-orders', params); } /** * * Orderbook trading - Copy trading endpoints * */ getCopytradingSubpositions( params?: GetCurrentSubpositionsRequest, ): Promise { return this.getPrivate('/api/v5/copytrading/current-subpositions', params); } getCopytradingSubpositionsHistory( params?: GetSubpositionsHistoryRequest, ): Promise { return this.getPrivate('/api/v5/copytrading/subpositions-history', params); } submitCopytradingAlgoOrder( params: PlaceCTAlgoOrderRequest, ): Promise { return this.postPrivate('/api/v5/copytrading/algo-order', params); } closeCopytradingSubposition(params: CloseSubpositionRequest): Promise< { subPosId: string; tag: string; }[] > { return this.postPrivate('/api/v5/copytrading/close-subposition', params); } getCopytradingInstruments(params?: { instType?: 'SPOT' | 'SWAP' }): Promise< { instId: string; enabled: boolean; }[] > { return this.getPrivate('/api/v5/copytrading/instruments', params); } setCopytradingInstruments(params: { instType?: 'SPOT' | 'SWAP'; instId: string; }): Promise< { instId: string; enabled: boolean; }[] > { return this.postPrivate('/api/v5/copytrading/set-instruments', params); } getCopytradingProfitDetails( params?: GetCTProfitDetailsRequest, ): Promise { return this.getPrivate( '/api/v5/copytrading/profit-sharing-details', params, ); } getCopytradingTotalProfit(params?: { instType?: 'SPOT' | 'SWAP'; }): Promise { return this.getPrivate('/api/v5/copytrading/total-profit-sharing', params); } getCopytradingUnrealizedProfit(params?: { instType?: 'SPOT' | 'SWAP'; }): Promise { return this.getPrivate( '/api/v5/copytrading/unrealized-profit-sharing-details', params, ); } getCopytradingTotalUnrealizedProfit(params?: { instType?: 'SWAP' }): Promise< { instType?: 'SWAP'; instId: string; }[] > { return this.getPrivate( '/api/v5/copytrading/total-unrealized-profit-sharing', params, ); } applyCopytradingLeadTrading(params: { profitSharingTs: string; totalUnrealizedProfitSharingAmt: string; }): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/copytrading/apply-lead-trading', params); } stopCopytradingLeadTrading(params: { instType?: 'SWAP' }): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/copytrading/stop-lead-trading', params); } updateCopytradingProfitSharing(params: { instType?: 'SWAP'; profitSharingRatio: string; }): Promise< { result: boolean; }[] > { return this.postPrivate( '/api/v5/copytrading/amend-profit-sharing-ratio', params, ); } getCopytradingAccount(): Promise { return this.getPrivate('/api/v5/copytrading/config'); } setCopytradingFirstCopy(params: CopySettingsRequest): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/copytrading/first-copy-settings', params); } updateCopytradingCopySettings(params: CopySettingsRequest): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/copytrading/amend-copy-settings', params); } stopCopytradingCopy(params: { instType?: 'SWAP'; uniqueCode: string; subPosCloseType: 'market_close' | 'copy_close' | 'manual_close'; }): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/copytrading/stop-copy-trading', params); } getCopytradingCopySettings(params: { instType?: 'SWAP'; uniqueCode: string; }): Promise { return this.getPrivate('/api/v5/copytrading/copy-settings', params); } getCopytradingBatchLeverageInfo( params: GetCTBatchLeverageInfoRequest, ): Promise { return this.getPrivate('/api/v5/copytrading/batch-leverage-info', params); } setCopytradingBatchLeverage( params: SetCTBatchLeverageRequest, ): Promise { return this.postPrivate('/api/v5/copytrading/batch-set-leverage', params); } getCopytradingMyLeadTraders(params?: { instType?: 'SWAP'; }): Promise { return this.getPrivate('/api/v5/copytrading/current-lead-traders', params); } getCopytradingLeadTradersHistory( params?: GetCTHistoryLeadTradersRequest, ): Promise { return this.getPrivate('/api/v5/copytrading/lead-traders-history', params); } getCopytradingConfig(params?: { instType?: 'SWAP'; }): Promise { return this.get('/api/v5/copytrading/public-config', params); } getCopytradingLeadRanks( params?: GetLeadTraderRanksRequest, ): Promise { return this.get('/api/v5/copytrading/public-lead-traders', params); } getCopytradingLeadWeeklyPnl(params: { instType?: 'SWAP'; uniqueCode: string; }): Promise { return this.get('/api/v5/copytrading/public-weekly-pnl', params); } getCopytradingLeadDailyPnl( params: GetLeadTraderStatsRequest, ): Promise { return this.get('/api/v5/copytrading/public-pnl', params); } getCopytradingLeadStats( params: GetLeadTraderStatsRequest, ): Promise { return this.get('/api/v5/copytrading/public-stats', params); } getCopytradingLeadPreferences(params: { instType?: 'SWAP'; uniqueCode: string; }): Promise { return this.get('/api/v5/copytrading/public-preference-currency', params); } getCopytradingLeadOpenPositions( params: GetLeadTraderPositionsRequest, ): Promise { return this.get('/api/v5/copytrading/public-current-subpositions', params); } getCopytradingLeadPositionHistory( params: GetLeadTraderPositionsRequest, ): Promise { return this.get('/api/v5/copytrading/public-subpositions-history', params); } getCopyTraders( params: GetCopyTradersRequest, ): Promise { return this.get('/api/v5/copytrading/public-copy-traders', params); } getCopytradingLeadPrivateRanks( params?: GetPrivateLeadTraderRanksRequest, ): Promise { return this.getPrivate('/api/v5/copytrading/lead-traders', params); } getCopytradingLeadPrivateWeeklyPnl(params: { instType?: 'SWAP'; uniqueCode: string; }): Promise { return this.getPrivate('/api/v5/copytrading/weekly-pnl', params); } getCopytradingPLeadPrivateDailyPnl( params: GetLeadTraderStatsRequest, ): Promise { return this.getPrivate('/api/v5/copytrading/pnl', params); } geCopytradingLeadPrivateStats( params: GetLeadTraderStatsRequest, ): Promise { return this.getPrivate('/api/v5/copytrading/stats', params); } getCopytradingLeadPrivatePreferences(params: { instType?: 'SWAP'; uniqueCode: string; }): Promise { return this.getPrivate('/api/v5/copytrading/preference-currency', params); } getCopytradingLeadPrivateOpenPositions( params: GetLeadTraderPositionsRequest, ): Promise { return this.getPrivate( '/api/v5/copytrading/performance-current-subpositions', params, ); } getCopytradingLeadPrivatePositionHistory( params: GetLeadTraderPositionsRequest, ): Promise { return this.getPrivate( '/api/v5/copytrading/performance-subpositions-history', params, ); } getCopyTradersPrivate( params: GetCopyTradersRequest, ): Promise { return this.getPrivate('/api/v5/copytrading/copy-traders', params); } /** * * Orderbook trading - Market data endpoints * */ getTickers(params: { instType: InstrumentType, uly?: string }): Promise { return this.get('/api/v5/market/tickers', params); } getTicker(params: { instId: string }): Promise { return this.get('/api/v5/market/ticker', params); } getOrderBook(params: { instId: string, sz?: numberInString }): Promise { return this.get('/api/v5/market/books', params); } getFullOrderBook(params: { instId: string; sz?: string; }): Promise { return this.get('/api/v5/market/books-full', params); } getCandles({ instId, bar = '1m', pagination }: { instId: string, bar?: string, pagination?: Pagination, }): Promise { return this.get('/api/v5/market/candles', { instId, bar, ...pagination, }); } getCandlesV2(params: CandleRequest): Promise { return this.get('/api/v5/market/candles', params); } getHistoricCandles({ instId, bar = '1m', pagination }: { instId: string, bar: string, pagination?: Pagination, }): Promise { return this.get('/api/v5/market/history-candles', { instId, bar, ...pagination, }); } getHistoricCandlesV2(params: CandleRequest): Promise { return this.get('/api/v5/market/history-candles', params); } getTrades(params: { instId: string, limit?: number }): Promise { return this.get('/api/v5/market/trades', params); } getHistoricTrades(params: { instId: string; after?: numberInString; before?: numberInString; limit?: numberInString; type?: '1' | '2'; }): Promise { return this.get('/api/v5/market/history-trades', params); } getOptionTradesByInstrument(params: { instFamily: string; }): Promise { return this.get('/api/v5/market/option/instrument-family-trades', params); } getOptionTrades(params: GetOptionTradesRequest): Promise { return this.get('/api/v5/public/option-trades', params); } get24hrTotalVolume(): Promise { return this.get('/api/v5/market/platform-24-volume'); } /** * * Block trading - REST endpoints * */ getBlockCounterParties(): Promise { return this.getPrivate('/api/v5/rfq/counterparties'); } createBlockRFQ(params: CreateBlockRFQRequest): Promise { return this.postPrivate('/api/v5/rfq/create-rfq', params); } cancelBlockRFQ( params: CancelBlockRFQRequest, ): Promise { return this.postPrivate('/api/v5/rfq/cancel-rfq', params); } cancelMultipleBlockRFQs( params: CancelMultipleBlockRFQRequest, ): Promise { return this.postPrivate('/api/v5/rfq/cancel-batch-rfqs', params); } cancelAllRFQs(): Promise { return this.postPrivate('/api/v5/rfq/cancel-all-rfqs'); } executeBlockQuote( params: ExecuteBlockQuoteRequest, ): Promise { return this.postPrivate('/api/v5/rfq/execute-quote', params); } getQuoteProducts(): Promise { return this.getPrivate('/api/v5/rfq/maker-instrument-settings'); } updateBlockQuoteProducts(params: SetQuoteProductsRequest): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/rfq/maker-instrument-settings', params); } resetBlockMmp(): Promise< { ts: string; }[] > { return this.postPrivate('/api/v5/rfq/mmp-reset'); } updateBlockMmpConfig( params: SetMmpConfigRequest, ): Promise { return this.postPrivate('/api/v5/rfq/mmp-config', params); } getBlockMmpConfig(): Promise { return this.getPrivate('/api/v5/rfq/mmp-config'); } createBlockQuote( params: CreateBlockQuoteRequest, ): Promise { return this.postPrivate('/api/v5/rfq/create-quote', params); } cancelBlockQuote( params: CancelBlockQuoteRequest, ): Promise { return this.postPrivate('/api/v5/rfq/cancel-quote', params); } cancelMultipleBlockQuotes( params: CancelMultipleBlockQuoteRequest, ): Promise { return this.postPrivate('/api/v5/rfq/cancel-batch-quotes', params); } cancelAllBlockQuotes(): Promise { return this.postPrivate('/api/v5/rfq/cancel-all-quotes'); } cancelAllBlockAfter(params: { timeOut: string }): Promise< { triggerTime: string; ts: string; }[] > { return this.postPrivate('/api/v5/rfq/cancel-all-after', params); } getBlockRFQs(params?: GetBlockRFQSParams): Promise { return this.getPrivate('/api/v5/rfq/rfqs', params); } getBlockQuotes(params?: GetBlockQuoteParams): Promise { return this.getPrivate('/api/v5/rfq/quotes', params); } getBlockTrades(params?: any): Promise { return this.getPrivate('/api/v5/rfq/trades', params); } getPublicRFQBlockTrades(params?: any): Promise { return this.get('/api/v5/rfq/public-trades', params); } getBlockTickers(params: { instType: InstrumentType, uly?: string }): Promise { return this.get('/api/v5/market/block-tickers', params); } getBlockTicker(params: { instId: string }): Promise { return this.get('/api/v5/market/block-ticker', params); } getBlockPublicTrades(params: { instId: string; }): Promise { return this.get('/api/v5/public/block-trades', params); } /** * * Spread trading - REST endpoints * */ submitSpreadOrder( params: PlaceSpreadOrderRequest, ): Promise { return this.postPrivate('/api/v5/sprd/order', params); } cancelSpreadOrder(params?: { ordId?: string; clOrdId?: string; }): Promise { return this.postPrivate('/api/v5/sprd/cancel-order', params); } cancelAllSpreadOrders(params: { sprdId?: string }): Promise< { result: boolean; }[] > { return this.postPrivate('/api/v5/sprd/mass-cancel', params); } updateSpreadOrder( params: UpdateSpreadOrderRequest, ): Promise { return this.postPrivate('/api/v5/sprd/amend-order', params); } getSpreadOrder(params: { ordId?: string; clOrdId?: string; }): Promise { return this.getPrivate('/api/v5/sprd/order', params); } getSpreadActiveOrders( params?: GetActiveSpreadOrdersRequest, ): Promise { return this.getPrivate('/api/v5/sprd/orders-pending', params); } getSpreadOrdersRecent( params?: GetSpreadOrderHistoryRequest, ): Promise { return this.getPrivate('/api/v5/sprd/orders-history', params); } getSpreadOrdersArchive( params?: GetSpreadOrderHistoryArchiveRequest, ): Promise { return this.getPrivate('/api/v5/sprd/orders-history-archive', params); } getSpreadTrades(params?: GetSpreadTradesRequest): Promise { return this.getPrivate('/api/v5/sprd/trades', params); } getSpreads(params?: GetSpreadsRequest): Promise { return this.get('/api/v5/sprd/spreads', params); } getSpreadOrderBook(params: { sprdId: string; sz?: string; }): Promise { return this.get('/api/v5/sprd/books', params); } getSpreadTicker(params: { sprdId: string }): Promise { return this.get('/api/v5/market/sprd-ticker', params); } getSpreadPublicTrades(params?: { sprdId?: string; }): Promise { return this.get('/api/v5/sprd/public-trades', params); } getSpreadCandles(params: GetSpreadCandlesRequest): Promise { return this.get('/api/v5/market/sprd-candles', params); } getSpreadHistoryCandles( params: GetSpreadCandlesRequest, ): Promise { return this.get('/api/v5/market/sprd-history-candles', params); } cancelSpreadAllAfter(params: { timeOut: string }): Promise< { triggerTime: string; ts: string; }[] > { return this.postPrivate('/api/v5/sprd/cancel-all-after', params); } /** * * Public data - rest endpoints * */ getInstruments(params: { instType: InstrumentType, uly?: string, instFamily?: string, instId?: string, }): Promise { return this.get('/api/v5/public/instruments', params); } getDeliveryExerciseHistory(params: any): Promise { return this.get('/api/v5/public/delivery-exercise-history', params); } getOpenInterest(params: any): Promise { return this.get('/api/v5/public/open-interest', params); } getFundingRate(params: any): Promise { return this.get('/api/v5/public/funding-rate', params); } getFundingRateHistory(params: FundingRateRequest): Promise { return this.get('/api/v5/public/funding-rate-history', params); } getMinMaxLimitPrice(params: any): Promise { return this.get('/api/v5/public/price-limit', params); } getOptionMarketData(params: any): Promise { return this.get('/api/v5/public/opt-summary', params); } getEstimatedDeliveryExercisePrice(params: any): Promise { return this.get('/api/v5/public/estimated-price', params); } getDiscountRateAndInterestFreeQuota(params: any): Promise { return this.get('/api/v5/public/discount-rate-interest-free-quota', params); } getSystemTime(params: any): Promise { return this.get('/api/v5/public/time', params); } getMarkPrice(params: any): Promise { return this.get('/api/v5/public/mark-price', params); } getPositionTiers(params: any): Promise { return this.get('/api/v5/public/position-tiers', params); } getInterestRateAndLoanQuota(params: any): Promise { return this.get('/api/v5/public/interest-rate-loan-quota', params); } getVIPInterestRateAndLoanQuota(params: any): Promise { return this.get('/api/v5/public/vip-interest-rate-loan-quota', params); } getUnderlying(params: any): Promise { return this.get('/api/v5/public/underlying', params); } getInsuranceFund(params: any): Promise { return this.get('/api/v5/public/insurance-fund', params); } getUnitConvert(params: UnitConvertRequest): Promise { return this.get('/api/v5/public/convert-contract-coin', params); } getOptionTickBands(params: { instType: string; instFamily?: string; }): Promise { return this.get('/api/v5/public/instrument-tick-bands', params); } getPremiumHistory(params: GetPremiumHistoryRequest): Promise { return this.get('/api/v5/public/premium-history', params); } getIndexTickers(params?: { quoteCcy?: string; instId?: string; }): Promise { return this.get('/api/v5/market/index-tickers', { ...params }); } getIndexCandles({ instId, bar = '1m', pagination }: { instId: string, bar: string, pagination?: Pagination, }): Promise { return this.get('/api/v5/market/index-candles', { instId, bar, ...pagination, }); } getIndexCandlesV2(params: CandleRequest): Promise { return this.get('/api/v5/market/index-candles', params); } getHistoricIndexCandles({ instId, bar = '1m', pagination }: { instId: string, bar: string, pagination?: Pagination, }): Promise { return this.get('/api/v5/market/history-index-candles', { instId, bar, ...pagination, }); } getHistoricIndexCandlesV2(params: CandleRequest): Promise { return this.get('/api/v5/market/history-index-candles', params); } getMarkPriceCandles({ instId, bar = '1m', pagination }: { instId: string, bar: string, pagination?: Pagination, }): Promise { return this.get('/api/v5/market/mark-price-candles', { instId, bar, ...pagination, }); } getMarkPriceCandlesV2(params: CandleRequest): Promise { return this.get('/api/v5/market/mark-price-candles', params); } getHistoricMarkPriceCandles({ instId, bar = '1m', pagination }: { instId: string, bar?: string, pagination?: Pagination, }): Promise { return this.get('/api/v5/market/historic-mark-price-candles', { instId, bar, ...pagination, }); } getHistoricMarkPriceCandlesV2( params: CandleRequest, ): Promise { return this.get('/api/v5/market/history-mark-price-candles', params); } getOracle(): Promise { return this.get('/api/v5/market/open-oracle'); } getExchangeRate(): Promise { return this.get('/api/v5/market/exchange-rate'); } getIndexComponents(params: { index: string }): Promise { return this.get('/api/v5/market/index-components', params); } getEconomicCalendar( params: EconomicCalendarRequest, ): Promise { return this.getPrivate('/api/v5/public/economic-calendar', params); } getPublicBlockTrades(params: { instId: string }): Promise { return this.get('/api/v5/market/block-trades', params); } /** * * Trading statistics - REST endpoints * */ getSupportCoin(): Promise { return this.get('/api/v5/rubik/stat/trading-data/support-coin'); } getOpenInterestHistory( params: GetContractOpenInterestHistoryRequest, ): Promise { return this.get( '/api/v5/rubik/stat/contracts/open-interest-history', params, ); } getTakerVolume(params: { instType: string; ccy: string; period?: string; end?: string; begin?: string; }): Promise { return this.get('/api/v5/rubik/stat/taker-volume', params); } getContractTakerVolume( params: GetContractTakerVolumeRequest, ): Promise { return this.get('/api/v5/rubik/stat/taker-volume-contract', params); } getMarginLendingRatio(params: { ccy: string; begin?: numberInString; end?: numberInString; period: '5m' | '1H' | '1D'; }): Promise { return this.get('/api/v5/rubik/stat/margin/loan-ratio', params); } getTopTradersAccountRatio( params: GetTopTradersContractLongShortRatioRequest, ): Promise { return this.get( '/api/v5/rubik/stat/contracts/long-short-account-ratio-contract-top-trader', params, ); } getTopTradersContractPositionRatio( params: GetTopTradersContractLongShortRatioRequest, ): Promise { return this.get( '/api/v5/rubik/stat/contracts/long-short-position-ratio-contract-top-trader', params, ); } getLongShortContractRatio( params: GetTopTradersContractLongShortRatioRequest, ): Promise { return this.get( '/api/v5/rubik/stat/contracts/long-short-account-ratio-contract', params, ); } getLongShortRatio(params: { ccy: string; begin?: numberInString; end?: numberInString; period: '5m' | '1H' | '1D'; }): Promise { return this.get( '/api/v5/rubik/stat/contracts/long-short-account-ratio', params, ); } getContractsOpenInterestAndVolume(params: { ccy: string; begin?: numberInString; end?: numberInString; period: '5m' | '1H' | '1D'; }): Promise { return this.get( '/api/v5/rubik/stat/contracts/open-interest-volume', params, ); } getOptionsOpenInterestAndVolume(params: { ccy: string; period: '8H' | '1D'; }): Promise { return this.get('/api/v5/rubik/stat/option/open-interest-volume', params); } getPutCallRatio(params: { ccy: string; period: '8H' | '1D'; }): Promise { return this.get( '/api/v5/rubik/stat/option/open-interest-volume-ratio', params, ); } getOpenInterestAndVolumeExpiry(params: { ccy: string; period: '8H' | '1D'; }): Promise { return this.get( '/api/v5/rubik/stat/option/open-interest-volume-expiry', params, ); } getOpenInterestAndVolumeStrike(params: { ccy: string; expTime: string; period: '8H' | '1D'; }): Promise { return this.get( '/api/v5/rubik/stat/option/open-interest-volume-strike', params, ); } getTakerFlow(params: { ccy: string; period: '8H' | '1D' }): Promise { return this.get('/api/v5/rubik/stat/option/taker-block-volume', params); } /** * * Funding account - REST endpoints * */ getCurrencies(params?: { ccy?: string }): Promise { return this.getPrivate('/api/v5/asset/currencies', { ...params }); } getBalances(params?: { ccy?: string }): Promise { return this.getPrivate('/api/v5/asset/balances', { ...params }); } getNonTradableAssets(params?: { ccy?: string }): Promise { return this.getPrivate('/api/v5/asset/non-tradable-assets', params); } getAccountAssetValuation(params: { ccy?: string }): Promise { return this.getPrivate('/api/v5/asset/asset-valuation', { ...params }); } fundsTransfer(params: FundsTransferRequest): Promise { return this.postPrivate('/api/v5/asset/transfer', params); } /** Either parameter transId or clientId is required. */ getFundsTransferState(params: { transId?: string; clientId?: string; type?: '0' | '1' | '2'; }): Promise { return this.getPrivate('/api/v5/asset/transfer-state', params); } getAssetBillsDetails(params?: { ccy?: string; type?: `${ASSET_BILL_TYPE}`; clientId?: string; after?: numberInString; before?: numberInString; limit?: numberInString; }): Promise { return this.getPrivate('/api/v5/asset/bills', params); } getLightningDeposits(params: { ccy: string, amt: numberInString, to?: '6' | '18', }): Promise { return this.getPrivate('/api/v5/asset/deposit-lightning', params); } getDepositAddress(params: { ccy: string }): Promise { return this.getPrivate('/api/v5/asset/deposit-address', params); } getDepositHistory(params?: any): Promise { return this.getPrivate('/api/v5/asset/deposit-history', params); } submitWithdraw(params: WithdrawRequest): Promise { return this.postPrivate('/api/v5/asset/withdrawal', params); } submitWithdrawLightning(params: { ccy: string, invoice: string, memo?: string, }): Promise { return this.postPrivate('/api/v5/asset/withdrawal-lightning', params); } cancelWithdrawal(params: { wdId: string }): Promise { return this.postPrivate('/api/v5/asset/cancel-withdrawal', params); } getWithdrawalHistory(params?: WithdrawalHistoryRequest): Promise { return this.getPrivate('/api/v5/asset/withdrawal-history', params); } getDepositWithdrawStatus( params: GetDepositWithdrawStatusRequest, ): Promise { return this.getPrivate('/api/v5/asset/deposit-withdraw-status', params); } getExchanges(): Promise { return this.get('/api/v5/asset/exchange-list'); } applyForMonthlyStatement(params?: { month?: string }): Promise { return this.postPrivate('/api/v5/asset/monthly-statement', params); } getMonthlyStatement(params: { month: string }): Promise { return this.getPrivate('/api/v5/asset/monthly-statement', params); } getConvertCurrencies(): Promise { return this.getPrivate('/api/v5/asset/convert/currencies'); } getConvertCurrencyPair(params: { fromCcy: string, toCcy: string }): Promise { return this.getPrivate('/api/v5/asset/convert/currency-pair', params); } estimateConvertQuote(params: ConvertQuoteEstimateRequest): Promise { return this.postPrivate('/api/v5/asset/convert/estimate-quote', params); } convertTrade(params: ConvertTradeRequest): Promise { return this.postPrivate('/api/v5/asset/convert/trade', params); } getConvertHistory(params?: any): Promise { return this.getPrivate('/api/v5/asset/convert/history', params); } /** * * Subaccount - REST endpoints * */ /** View sub-account list */ getSubAccountList(params?: any): Promise { return this.getPrivate('/api/v5/users/subaccount/list', params); } resetSubAccountAPIKey(params: { subAcct: string; apiKey: string; label?: string; perm?: string; ip?: string; }): Promise { return this.postPrivate('/api/v5/users/subaccount/modify-apikey', params); } getSubAccountBalances(params: { subAcct: string }): Promise { return this.getPrivate('/api/v5/account/subaccount/balances', params); } getSubAccountFundingBalances(params: { subAcct: string, ccy?: string, }): Promise { return this.getPrivate('/api/v5/asset/subaccount/balances', params); } getSubAccountMaxWithdrawal( params: GetSubAccountMaxWithdrawalsRequest, ): Promise { return this.getPrivate('/api/v5/account/subaccount/max-withdrawal', params); } /** History of sub-account transfer */ getSubAccountTransferHistory(params?: { ccy?: string; type?: '0' | '1'; subAcct?: string; after?: string; before?: string; limit?: string; }): Promise { return this.getPrivate('/api/v5/asset/subaccount/bills', params); } getManagedSubAccountTransferHistory( params: GetManagedSubAccountTransferHistoryRequest, ): Promise { return this.getPrivate( '/api/v5/asset/subaccount/managed-subaccount-bills', params, ); } /** Master accounts manage the transfers between sub-accounts */ transferSubAccountBalance( params: SubAccountTransferRequest, ): Promise { return this.postPrivate('/api/v5/asset/subaccount/transfer', params); } setSubAccountTransferOutPermission(params: { subAcct: string, canTransOut: boolean, }): Promise { return this.postPrivate('/api/v5/users/subaccount/set-transfer-out', params); } getSubAccountCustodyTradingList(params?: { subAcct?: string }): Promise { return this.getPrivate('/api/v5/users/entrust-subaccount-list', { ...params }); } setSubAccountLoanAllocation( params: SetSubAccountLoanAllocationRequest, ): Promise< { result: boolean; }[] > { return this.postPrivate( '/api/v5/account/subaccount/set-loan-allocation', params, ); } getSubAccountBorrowInterestAndLimit(params: { subAcct: string; ccy?: string; }): Promise { return this.getPrivate( '/api/v5/account/subaccount/interest-limits', params, ); } /** * * Financial product - on chain earn endpoints * */ /** Get earn offers */ getStakingOffers(params?: { productId?: string; protocolType?: 'staking' | 'defi'; ccy?: string; }): Promise { return this.getPrivate('/api/v5/finance/staking-defi/offers', params); } submitStake(params: { productId: string, investData: { ccy: string; amt: string; }[], term?: string, }): Promise { return this.postPrivate('/api/v5/finance/staking-defi/purchase', params); } redeemStake(params: { ordId: string, protocolType: 'staking' | 'defi', allowEarlyRedeem?: boolean, }): Promise { return this.postPrivate('/api/v5/finance/staking-defi/redeem', params); } cancelStakingRequest(params: { ordId: string, protocolType: 'staking' | 'defi', }): Promise { return this.postPrivate('/api/v5/finance/staking-defi/cancel', params); } /** Earn/staking get active orders */ getActiveStakingOrders(params?: { productId?: string; protocolType?: 'staking' | 'defi'; ccy?: string; state?: '8' | '13' | '9' | '1' | '2'; }): Promise { return this.getPrivate( '/api/v5/finance/staking-defi/orders-active', params, ); } /** Earn/staking get order history */ getStakingOrderHistory(params?: { productId?: string; protocolType?: string; ccy?: string; after?: string; before?: string; limit?: string; }): Promise { return this.getPrivate( '/api/v5/finance/staking-defi/orders-history', params, ); } /** * * Financial product - ETH staking endpoints * */ getETHStakingProductInfo(): Promise { return this.get('/api/v5/finance/staking-defi/eth/product-info'); } purchaseETHStaking(params: { amt: string }): Promise { return this.postPrivate( '/api/v5/finance/staking-defi/eth/purchase', params, ); } redeemETHStaking(params: { amt: string }): Promise { return this.postPrivate('/api/v5/finance/staking-defi/eth/redeem', params); } getETHStakingBalance(): Promise { return this.getPrivate('/api/v5/finance/staking-defi/eth/balance'); } getETHStakingHistory(params: { type: 'purchase' | 'redeem'; status?: 'pending' | 'success' | 'failed'; after?: string; before?: string; limit?: string; }): Promise { return this.getPrivate( '/api/v5/finance/staking-defi/eth/purchase-redeem-history', params, ); } getAPYHistory(params: { days: string }): Promise { return this.get('/api/v5/finance/staking-defi/eth/apy-history', params); } /** * * Financial product - simple earn flexible endpoints * */ getSavingBalance(params?: { ccy?: string }): Promise { return this.getPrivate('/api/v5/finance/savings/balance', { ...params }); } savingsPurchaseRedemption(params: { ccy: string, amt: numberInString, side: 'purchase' | 'redempt', rate: numberInString, }): Promise { return this.postPrivate('/api/v5/finance/savings/purchase-redempt', params); } setLendingRate(params: { ccy: string, rate: numberInString }): Promise { return this.postPrivate('/api/v5/finance/savings/set-lending-rate', params); } getLendingHistory(params?: PaginatedSymbolRequest): Promise { return this.getPrivate('/api/v5/finance/savings/lending-history', params); } getPublicBorrowInfo(params?: { ccy?: string }): Promise { return this.get('/api/v5/finance/savings/lending-rate-summary', { ...params }); } getPublicBorrowHistory(params?: PaginatedSymbolRequest): Promise { return this.get('/api/v5/finance/savings/lending-rate-history', params); } /** * * Financial product - simple earn fixed endpoints * */ getLendingOffers(params?: { ccy?: string; term?: string }): Promise { return this.get('/api/v5/finance/fixed-loan/lending-offers', params); } getLendingAPYHistory(params: { ccy: string; term: string }): Promise { return this.get('/api/v5/finance/fixed-loan/lending-apy-history', params); } getLendingVolume(params: { ccy: string; term: string }): Promise { return this.get( '/api/v5/finance/fixed-loan/pending-lending-volume', params, ); } placeLendingOrder(params: LendingOrder): Promise { return this.postPrivate('/api/v5/finance/fixed-loan/lending-order', params); } amendLendingOrder(params: LendingOrder): Promise { return this.postPrivate( '/api/v5/finance/fixed-loan/amend-lending-order', params, ); } getLendingOrders(params: GetLendingOrderListRequest): Promise { return this.getPrivate( '/api/v5/finance/fixed-loan/lending-orders-list', params, ); } getLendingSubOrders(params: GetLendingSubOrderListRequest): Promise { return this.getPrivate( '/api/v5/finance/fixed-loan/lending-sub-orders', params, ); } /** * * Financial product - Flexible loan endpoints * */ getBorrowableCurrencies(): Promise< { borrowCcy: string; }[] > { return this.get('/api/v5/finance/flexible-loan/borrow-currencies'); } getCollateralAssets(params?: { ccy?: string; }): Promise { return this.get('/api/v5/finance/flexible-loan/collateral-assets', params); } getMaxLoanAmount(params: MaxLoanRequest): Promise { return this.postPrivate('/api/v5/finance/flexible-loan/max-loan', params); } adjustCollateral(params: AdjustCollateralRequest): Promise<[]> { return this.postPrivate( '/api/v5/finance/flexible-loan/adjust-collateral', params, ); } getLoanInfo(): Promise { return this.getPrivate('/api/v5/finance/flexible-loan/loan-info'); } getLoanHistory(params?: LoanHistoryRequest): Promise { return this.getPrivate( '/api/v5/finance/flexible-loan/loan-history', params, ); } getAccruedInterest( params?: AccruedInterestRequest, ): Promise { return this.getPrivate( '/api/v5/finance/flexible-loan/interest-accrued', params, ); } /** * * Affiliate endpoints * */ getInviteeDetail(params: { uid: string }): Promise { return this.getPrivate('/api/v5/affiliate/invitee/detail', params); } getAffiliateRebateInfo(params: { apiKey: string }): Promise { return this.getPrivate('/api/v5/users/partner/if-rebate', params); } /** * * Status endpoints (public) * */ getSystemStatus(params?: { state?: 'scheduled' | 'ongoing' | 'pre_open' | 'completed' | 'canceled', }): Promise { return this.get('/api/v5/system/status', { ...params }); } /** * * Announcement endpoints * */ getAnnouncements(params?: { annType?: string; page?: string }): Promise< { totalPage: string; details: Announcement[]; }[] > { return this.get('/api/v5/support/announcements', params); } getAnnouncementTypes(): Promise< { annType: string; annTypeDesc: string; }[] > { return this.get('/api/v5/support/announcement-types'); } /** * * Broker endpoints (private) * */ /** * * @deprecated */ getBrokerAccountInformation(): Promise { return this.getPrivate('/api/v5/broker/nd/info'); } createSubAccount(params: { subAcct: string; label?: string; clientIP?: string; mainAcct: string; }): Promise { return this.postPrivate('/api/v5/broker/nd/create-subaccount', params); } deleteSubAccount(params: { subAcct: string }): Promise { return this.postPrivate('/api/v5/broker/nd/delete-subaccount', params); } createSubAccountAPIKey(params: { subAcct: string; label: string; passphrase: string; ip?: string; perm?: string; }): Promise { return this.postPrivate('/api/v5/broker/nd/subaccount/apikey', params); } }