diff --git a/package-lock.json b/package-lock.json index b4963cb4..5344f7c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "binance", - "version": "2.12.3", + "version": "2.13.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "binance", - "version": "2.12.3", + "version": "2.13.0", "license": "MIT", "dependencies": { "axios": "^1.6.2", diff --git a/package.json b/package.json index 78e319f6..80d93862 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "binance", - "version": "2.12.3", + "version": "2.13.0", "description": "Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/coinm-client.ts b/src/coinm-client.ts index 79976812..06edb599 100644 --- a/src/coinm-client.ts +++ b/src/coinm-client.ts @@ -173,10 +173,6 @@ export class CoinMClient extends BaseRestClient { return this.get('dapi/v1/klines', params); } - getPremiumIndexKlines(params: KlinesParams): Promise { - return this.get('dapi/v1/premiumIndexKlines', params); - } - getContinuousContractKlines( params: ContinuousContractKlinesParams, ): Promise { @@ -191,6 +187,10 @@ export class CoinMClient extends BaseRestClient { return this.get('dapi/v1/markPriceKlines', params); } + getPremiumIndexKlines(params: KlinesParams): Promise { + return this.get('dapi/v1/premiumIndexKlines', params); + } + /** * @deprecated use get24hrChangeStatistics() instead (method without the typo) */ @@ -220,12 +220,6 @@ export class CoinMClient extends BaseRestClient { ); } - getIndexPriceConstituents(params: { - symbol: string; - }): Promise { - return this.get('dapi/v1/constituents', params); - } - getOpenInterest(params: { symbol: string }): Promise { return this.get('dapi/v1/openInterest', params); } @@ -262,6 +256,20 @@ export class CoinMClient extends BaseRestClient { return this.get('futures/data/basis', params); } + /** + * possibly @deprecated + * Only in old documentation, not in new one + **/ + getIndexPriceConstituents(params: { + symbol: string; + }): Promise { + return this.get('dapi/v1/constituents', params); + } + + /** + * possibly @deprecated + * Only in old documentation, not in new one + **/ getQuarterlyContractSettlementPrices(params: { pair: string; }): Promise { @@ -270,32 +278,15 @@ export class CoinMClient extends BaseRestClient { /** * - * USD-Futures Account/Trade Endpoints + * Trade Endpoints * **/ - setPositionMode(params: PositionModeParams): Promise { - return this.postPrivate('dapi/v1/positionSide/dual', params); - } - - getCurrentPositionMode(): Promise { - return this.getPrivate('dapi/v1/positionSide/dual'); - } - submitNewOrder(params: NewFuturesOrderParams): Promise { this.validateOrderId(params, 'newClientOrderId'); return this.postPrivate('dapi/v1/order', params); } - /** - * Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue - */ - modifyOrder( - params: ModifyFuturesOrderParams, - ): Promise { - return this.putPrivate('dapi/v1/order', params); - } - /** * Warning: max 5 orders at a time! This method does not throw, instead it returns individual errors in the response array if any orders were rejected. * @@ -315,6 +306,15 @@ export class CoinMClient extends BaseRestClient { return this.postPrivate('dapi/v1/batchOrders', requestBody); } + /** + * Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue + */ + modifyOrder( + params: ModifyFuturesOrderParams, + ): Promise { + return this.putPrivate('dapi/v1/order', params); + } + /** * Warning: max 5 orders at a time! This method does not throw, instead it returns individual errors in the response array if any orders were rejected. */ @@ -337,20 +337,10 @@ export class CoinMClient extends BaseRestClient { return this.getPrivate('dapi/v1/orderAmendment', params); } - getOrder(params: GetOrderParams): Promise { - return this.getPrivate('dapi/v1/order', params); - } - cancelOrder(params: CancelOrderParams): Promise { return this.deletePrivate('dapi/v1/order', params); } - cancelAllOpenOrders( - params: BasicSymbolParam, - ): Promise { - return this.deletePrivate('dapi/v1/allOpenOrders', params); - } - cancelMultipleOrders( params: CancelMultipleOrdersParams, ): Promise<(CancelFuturesOrderResult | GenericCodeMsgError)[]> { @@ -371,6 +361,12 @@ export class CoinMClient extends BaseRestClient { return this.deletePrivate('dapi/v1/batchOrders', requestParams); } + cancelAllOpenOrders( + params: BasicSymbolParam, + ): Promise { + return this.deletePrivate('dapi/v1/allOpenOrders', params); + } + // Auto-cancel all open orders setCancelOrdersOnTimeout( params: CancelOrdersTimeoutParams, @@ -378,34 +374,52 @@ export class CoinMClient extends BaseRestClient { return this.postPrivate('dapi/v1/countdownCancelAll', params); } - getCurrentOpenOrder(params: GetOrderParams): Promise { - return this.getPrivate('dapi/v1/openOrder', params); + getOrder(params: GetOrderParams): Promise { + return this.getPrivate('dapi/v1/order', params); + } + + getAllOrders(params: GetAllOrdersParams): Promise { + return this.getPrivate('dapi/v1/allOrders', params); } getAllOpenOrders(params?: Partial): Promise { return this.getPrivate('dapi/v1/openOrders', params); } - getAllOrders(params: GetAllOrdersParams): Promise { - return this.getPrivate('dapi/v1/allOrders', params); + getCurrentOpenOrder(params: GetOrderParams): Promise { + return this.getPrivate('dapi/v1/openOrder', params); } - getBalance(): Promise { - return this.getPrivate('dapi/v1/balance'); + getForceOrders(params?: GetForceOrdersParams): Promise { + return this.getPrivate('dapi/v1/forceOrders', params); } - getAccountInformation(): Promise { - return this.getPrivate('dapi/v1/account'); + getAccountTrades( + params: CoinMAccountTradeParams & { orderId?: number }, + ): Promise { + return this.getPrivate('dapi/v1/userTrades', params); } - setLeverage(params: SetLeverageParams): Promise { - return this.postPrivate('dapi/v1/leverage', params); + getPositions(): Promise { + return this.getPrivate('dapi/v1/positionRisk'); + } + + setPositionMode(params: PositionModeParams): Promise { + return this.postPrivate('dapi/v1/positionSide/dual', params); } setMarginType(params: SetMarginTypeParams): Promise { return this.postPrivate('dapi/v1/marginType', params); } + setLeverage(params: SetLeverageParams): Promise { + return this.postPrivate('dapi/v1/leverage', params); + } + + getADLQuantileEstimation(params?: Partial): Promise { + return this.getPrivate('dapi/v1/adlQuantile', params); + } + setIsolatedPositionMargin( params: SetIsolatedMarginParams, ): Promise { @@ -417,19 +431,24 @@ export class CoinMClient extends BaseRestClient { ): Promise { return this.getPrivate('dapi/v1/positionMargin/history', params); } + /** + * + * Account Endpoints + * + **/ - getPositions(): Promise { - return this.getPrivate('dapi/v1/positionRisk'); + getBalance(): Promise { + return this.getPrivate('dapi/v1/balance'); } - getAccountTrades( - params: CoinMAccountTradeParams & { orderId?: number }, - ): Promise { - return this.getPrivate('dapi/v1/userTrades', params); + getAccountComissionRate( + params: BasicSymbolParam, + ): Promise { + return this.getPrivate('dapi/v1/commissionRate', params); } - getIncomeHistory(params?: GetIncomeHistoryParams): Promise { - return this.getPrivate('dapi/v1/income', params); + getAccountInformation(): Promise { + return this.getPrivate('dapi/v1/account'); } /** @@ -441,27 +460,52 @@ export class CoinMClient extends BaseRestClient { return this.getPrivate('dapi/v2/leverageBracket', params); } - getForceOrders(params?: GetForceOrdersParams): Promise { - return this.getPrivate('dapi/v1/forceOrders', params); + // TO ADD: dapi/v1/leverageBracket + // can use dapi/v2/leverageBracket + + getCurrentPositionMode(): Promise { + return this.getPrivate('dapi/v1/positionSide/dual'); } - getADLQuantileEstimation(params?: Partial): Promise { - return this.getPrivate('dapi/v1/adlQuantile', params); + getIncomeHistory(params?: GetIncomeHistoryParams): Promise { + return this.getPrivate('dapi/v1/income', params); } - getAccountComissionRate( - params: BasicSymbolParam, - ): Promise { - return this.getPrivate('dapi/v1/commissionRate', params); + /** + * + * Portfolio Margin Endpoints + * + **/ + + getClassicPortfolioMarginAccount(params: { + asset: string; + }): Promise { + return this.getPrivate('dapi/v1/pmAccountInfo', params); + } + + /** + * possibly @deprecated + * Only in old documentation, not in new one + **/ + getClassicPortfolioMarginNotionalLimits( + params?: GetClassicPortfolioMarginNotionalLimitParams, + ): Promise<{ + notionalLimits: ClassicPortfolioMarginNotionalLimit[]; + }> { + return this.getPrivate('dapi/v1/pmExchangeInfo', params); } /** * * Broker Futures Endpoints + * Possibly @deprecated, found only in old docs + * All broker endpoints start with /sapi/v1/broker or sapi/v2/broker or sapi/v3/broker * **/ - // 1 == USDT-Margined, 2 == Coin-margined + /** + * @deprecated + **/ getBrokerIfNewFuturesUser( brokerId: string, type: 1 | 2 = 1, @@ -472,6 +516,9 @@ export class CoinMClient extends BaseRestClient { }); } + /** + * @deprecated + **/ setBrokerCustomIdForClient( customerId: string, email: string, @@ -482,6 +529,9 @@ export class CoinMClient extends BaseRestClient { }); } + /** + * @deprecated + **/ getBrokerClientCustomIds( customerId: string, email: string, @@ -496,18 +546,27 @@ export class CoinMClient extends BaseRestClient { }); } + /** + * @deprecated + **/ getBrokerUserCustomId(brokerId: string): Promise { return this.getPrivate('dapi/v1/apiReferral/userCustomization', { brokerId, }); } + /** + * @deprecated + **/ getBrokerRebateDataOverview(type: 1 | 2 = 1): Promise { return this.getPrivate('dapi/v1/apiReferral/overview', { type, }); } + /** + * @deprecated + **/ getBrokerUserTradeVolume( type: 1 | 2 = 1, startTime?: number, @@ -522,6 +581,9 @@ export class CoinMClient extends BaseRestClient { }); } + /** + * @deprecated + **/ getBrokerRebateVolume( type: 1 | 2 = 1, startTime?: number, @@ -536,6 +598,9 @@ export class CoinMClient extends BaseRestClient { }); } + /** + * @deprecated + **/ getBrokerTradeDetail( type: 1 | 2 = 1, startTime?: number, @@ -568,26 +633,6 @@ export class CoinMClient extends BaseRestClient { return this.delete('dapi/v1/listenKey'); } - /** - * - * Classic Portfolio Margin Endpoints - * - **/ - - getClassicPortfolioMarginNotionalLimits( - params?: GetClassicPortfolioMarginNotionalLimitParams, - ): Promise<{ - notionalLimits: ClassicPortfolioMarginNotionalLimit[]; - }> { - return this.getPrivate('dapi/v1/pmExchangeInfo', params); - } - - getClassicPortfolioMarginAccount(params: { - asset: string; - }): Promise { - return this.getPrivate('dapi/v1/pmAccountInfo', params); - } - /** * Validate syntax meets requirements set by binance. Log warning if not. */ diff --git a/src/main-client.ts b/src/main-client.ts index 9628cceb..b1836024 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -490,6 +490,7 @@ import { GetNftTransactionHistoryParams, CollateralRecord, DualInvestmentProduct, + UpdateIpRestrictionForSubApiKey, } from './types/spot'; import { @@ -524,2388 +525,2494 @@ export class MainClient extends BaseRestClient { /** * - * Wallet Endpoints + * SPOT TRADING Endpoints - General endpoints * **/ - getSystemStatus(): Promise { - return this.get('sapi/v1/system/status'); + testConnectivity(): Promise<{}> { + return this.get('api/v3/ping'); } - getBalances(): Promise { - return this.getPrivate('sapi/v1/capital/config/getall'); - } + getExchangeInfo(params?: ExchangeInfoParams): Promise { + const symbols = params?.symbols && JSON.stringify(params.symbols); + const symbol = params?.symbol; - getDailyAccountSnapshot( - params: DailyAccountSnapshotParams, - ): Promise { - return this.getPrivate('sapi/v1/accountSnapshot', params); - } + let urlSuffix = ''; + if (symbol) { + urlSuffix += '?symbol=' + symbol; + } else if (symbols) { + urlSuffix += '?symbols=' + symbols; + } - disableFastWithdrawSwitch(): Promise<{}> { - return this.postPrivate('sapi/v1/account/disableFastWithdrawSwitch'); + return this.get('api/v3/exchangeInfo' + urlSuffix); } - enableFastWithdrawSwitch(): Promise<{}> { - return this.postPrivate('sapi/v1/account/enableFastWithdrawSwitch'); - } + /** + * + * SPOT TRADING Endpoints - Market endpoints + * + **/ - withdraw(params: WithdrawParams): Promise<{ id: string }> { - return this.postPrivate('sapi/v1/capital/withdraw/apply', params); + getOrderBook(params: OrderBookParams): Promise { + return this.get('api/v3/depth', params); } - getDepositHistory(params?: DepositHistoryParams): Promise { - return this.getPrivate('sapi/v1/capital/deposit/hisrec', params); + getRecentTrades(params: RecentTradesParams): Promise { + return this.get('api/v3/trades', params); } - getWithdrawHistory( - params?: WithdrawHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/capital/withdraw/history', params); + getHistoricalTrades(params: HistoricalTradesParams): Promise { + return this.get('api/v3/historicalTrades', params); } - getDepositAddress( - params: DepositAddressParams, - ): Promise { - return this.getPrivate('sapi/v1/capital/deposit/address', params); + getAggregateTrades( + params: SymbolFromPaginatedRequestFromId, + ): Promise { + return this.get('api/v3/aggTrades', params); } - getAccountStatus(): Promise<{ data: string }> { - return this.getPrivate('sapi/v1/account/status'); + getKlines(params: KlinesParams): Promise { + return this.get('api/v3/klines', params); } - getDustLog(params?: BasicTimeRangeParam): Promise { - return this.getPrivate('sapi/v1/asset/dribblet', params); + getUIKlines(params: KlinesParams): Promise { + return this.get('api/v3/uiKlines', params); } - convertDustToBnb(params: ConvertDustParams): Promise { - return this.postPrivate('sapi/v1/asset/dust', params); + getAvgPrice(params: BasicSymbolParam): Promise { + return this.get('api/v3/avgPrice', params); } - getDust(): Promise { - return this.postPrivate('sapi/v1/asset/dust-btc'); - } + get24hrChangeStatististics( + params: BasicSymbolParam, + ): Promise; - getAssetDividendRecord(params?: BasicAssetPaginatedParams): Promise { - return this.getPrivate('sapi/v1/asset/assetDividend', params); - } + get24hrChangeStatististics( + params?: SymbolArrayParam, + ): Promise; - getAssetDetail( - params?: Partial, - ): Promise> { - return this.getPrivate('sapi/v1/asset/assetDetail', params); - } + get24hrChangeStatististics( + params?: Partial | Partial, + ): Promise { + if (params && typeof params['symbol'] === 'string') { + return this.get('api/v3/ticker/24hr', params); + } - getTradeFee(params?: Partial): Promise { - return this.getPrivate('sapi/v1/asset/tradeFee', params); + if (params && params['symbols'] && Array.isArray(params['symbols'])) { + const symbols = (params as SymbolArrayParam).symbols; + const symbolsQueryParam = JSON.stringify(symbols); + + return this.get('api/v3/ticker/24hr?symbols=' + symbolsQueryParam); + } + + return this.get('api/v3/ticker/24hr'); } - submitUniversalTransfer( - params: UniversalTransferParams, - ): Promise<{ tranId: number }> { - return this.postPrivate('sapi/v1/asset/transfer', params); + getTradingDayTicker( + params: TradingDayTickerParams, + ): Promise { + return this.get('api/v3/ticker/tradingDay', params); } - getUniversalTransferHistory( - params: UniversalTransferHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/asset/transfer', params); + getSymbolPriceTicker( + params?: Partial, + ): Promise { + return this.get('api/v3/ticker/price', params); } - getApiTradingStatus(): Promise { - return this.getPrivate('sapi/v1/account/apiTradingStatus'); + getSymbolOrderBookTicker( + params?: Partial, + ): Promise { + return this.get('api/v3/ticker/bookTicker', params); } - getApiKeyPermissions(): Promise { - return this.getPrivate('sapi/v1/account/apiRestrictions'); + getRollingWindowTicker( + params: RollingWindowTickerParams, + ): Promise { + return this.get('api/v3/ticker', params); } - enableConvertSubAccount(params: EnableConvertSubAccountParams): Promise { - return this.postPrivate('sapi/v1/broker/subAccount/convert', params); + /** + * + * SPOT TRADING Endpoints - Trading endpoints + * + **/ + + submitNewOrder< + T extends OrderType, + RT extends OrderResponseType | undefined = undefined, + >(params: NewSpotOrderParams): Promise> { + this.validateOrderId(params, 'newClientOrderId'); + return this.postPrivate('api/v3/order', params); } - getFundingAsset(params: GetAssetParams): Promise { - return this.postPrivate('sapi/v1/asset/get-funding-asset', params); + testNewOrder< + T extends OrderType, + RT extends OrderResponseType | undefined = undefined, + >(params: NewSpotOrderParams): Promise<{}> { + this.validateOrderId(params, 'newClientOrderId'); + return this.postPrivate('api/v3/order/test', params); } - getUserAsset(params: GetAssetParams): Promise { - return this.postPrivate('sapi/v3/asset/getUserAsset', params); + getOrder(params: GetOrderParams): Promise { + return this.getPrivate('api/v3/order', params); } - convertBUSD(params: ConvertTransfer): Promise { - return this.postPrivate('sapi/v1/asset/convert-transfer', params); + cancelOrder(params: CancelOrderParams): Promise { + return this.deletePrivate('api/v3/order', params); } - getConvertBUSDHistory(params: GetConvertBUSDHistoryParams): Promise<{ - total: number; - rows: BUSDConversionRecord[]; - }> { - return this.getPrivate( - 'sapi/v1/asset/convert-transfer/queryByPage', - params, - ); + cancelAllSymbolOrders( + params: BasicSymbolParam, + ): Promise { + return this.deletePrivate('api/v3/openOrders', params); } - getCloudMiningHistory(params: CloudMiningHistoryParams): Promise<{ - total: number; - rows: CloudMining[]; - }> { - return this.getPrivate( - 'sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage', - params, - ); + replaceOrder< + T extends OrderType, + RT extends OrderResponseType | undefined = undefined, + >( + params: ReplaceSpotOrderParams, + ): Promise> { + return this.postPrivate('api/v3/order/cancelReplace', params); } - getAutoConvertStablecoins(): Promise { - return this.getPrivate('sapi/v1/capital/contract/convertible-coins'); + getOpenOrders(params?: Partial): Promise { + return this.getPrivate('api/v3/openOrders', params); } - setConvertibleCoins(params: ConvertibleCoinsParams): Promise { - return this.postPrivate( - 'sapi/v1/capital/contract/convertible-coins', - params, - ); + getAllOrders(params: GetAllOrdersParams): Promise { + return this.getPrivate('api/v3/allOrders', params); } - submitDepositCredit( - params: SubmitDepositCreditParams, - ): Promise { - return this.postPrivate('sapi/v1/capital/deposit/credit-apply', params); + /** + * @deprecated + */ + submitNewOCO(params: NewOCOParams): Promise { + this.validateOrderId(params, 'listClientOrderId'); + this.validateOrderId(params, 'limitClientOrderId'); + this.validateOrderId(params, 'stopClientOrderId'); + return this.postPrivate('api/v3/order/oco', params); } - getDepositAddresses( - params: DepositAddressListParams, - ): Promise { - return this.getPrivate('sapi/v1/capital/deposit/address/list', params); + submitNewOrderList( + params: NewOrderListParams, + ): Promise> { + this.validateOrderId(params, 'listClientOrderId'); + this.validateOrderId(params, 'aboveClientOrderId'); + this.validateOrderId(params, 'belowClientOrderId'); + return this.postPrivate('api/v3/orderList/oco', params); } - getWalletBalances(): Promise { - return this.getPrivate('sapi/v1/asset/wallet/balance'); + // TO CHECK!! + submitNewOrderListOTO( + params: NewOrderListOTOParams, + ): Promise { + this.validateOrderId(params, 'listClientOrderId'); + this.validateOrderId(params, 'workingClientOrderId'); + this.validateOrderId(params, 'pendingClientOrderId'); + return this.postPrivate('api/v3/orderList/oto', params); } - getDelegationHistory( - params: DelegationHistoryParams, - ): Promise> { - return this.getPrivate('sapi/v1/asset/custody/transfer-history', params); + // TO CHECK!! + submitNewOrderListOTOCO( + params: NewOrderListOTOCOParams, + ): Promise { + this.validateOrderId(params, 'listClientOrderId'); + this.validateOrderId(params, 'workingClientOrderId'); + this.validateOrderId(params, 'pendingAboveClientOrderId'); + this.validateOrderId(params, 'pendingBelowClientOrderId'); + return this.postPrivate('api/v3/orderList/otoco', params); } - getDelistSchedule(): Promise { - return this.getPrivate('sapi/v1/spot/delist-schedule'); + cancelOCO(params: CancelOCOParams): Promise { + this.validateOrderId(params, 'newClientOrderId'); + return this.deletePrivate('api/v3/orderList', params); } - getWithdrawAddresses(): Promise { - return this.getPrivate('sapi/v1/capital/withdraw/address/list'); + getOCO(params?: GetOCOParams): Promise { + return this.getPrivate('api/v3/orderList', params); } - getAccountInfo(): Promise { - return this.getPrivate('sapi/v1/account/info'); + getAllOCO(params?: BasicFromPaginatedParams): Promise { + return this.getPrivate('api/v3/allOrderList', params); } /** - * - * - * Sub-Account Endpoints - * - **/ + * Query open OCO + */ + getAllOpenOCO(): Promise { + return this.getPrivate('api/v3/openOrderList'); + } - createVirtualSubAccount( - params: CreateSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/sub-account/virtualSubAccount', params); + /** + * Places an order using smart order routing (SOR). + */ + submitNewSOROrder( + params: NewSpotSOROrderParams, + ): Promise { + this.validateOrderId(params, 'newClientOrderId'); + return this.postPrivate('api/v3/sor/order', params); } - getSubAccountList( - params?: SubAccountListParams, - ): Promise { - return this.getPrivate('sapi/v1/sub-account/list', params); + /** + * Test new order creation and signature/recvWindow using smart order routing (SOR). + * Creates and validates a new order but does not send it into the matching engine. + */ + testNewSOROrder( + params: NewSpotSOROrderParams & { computeCommissionRates?: boolean }, + ): Promise<{} | SORTestOrderResponse> { + this.validateOrderId(params, 'newClientOrderId'); + return this.postPrivate('api/v3/sor/order/test', params); } - getSubAccountSpotAssetTransferHistory( - params?: SubAccountSpotAssetTransferHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/sub-account/sub/transfer/history', params); + /** + * + * SPOT TRADING Endpoints - Account endpoints + * + **/ + + /** + * Get current account information + */ + getAccountInformation(): Promise { + return this.getPrivate('api/v3/account'); } - getSubAccountFuturesAssetTransferHistory( - params: SubAccountFuturesAssetTransferHistoryParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/sub-account/futures/internalTransfer', - params, - ); + getAccountTradeList( + params: SymbolFromPaginatedRequestFromId & { orderId?: number }, + ): Promise { + return this.getPrivate('api/v3/myTrades', params); } - subAccountFuturesAssetTransfer( - params: SubAccountFuturesAssetTransferParams, - ): Promise { - return this.postPrivate( - 'sapi/v1/sub-account/futures/internalTransfer', - params, - ); + getOrderRateLimit(): Promise { + return this.getPrivate('api/v3/rateLimit/order'); } - getSubAccountAssets( - params: SubAccountAssetsParams, - ): Promise { - return this.getPrivate('sapi/v3/sub-account/assets', params); + getPreventedMatches( + params: PreventedMatchesParams, + ): Promise { + return this.getPrivate('api/v3/myPreventedMatches', params); } - getSubAccountSpotAssetsSummary( - params?: SubAccountSpotAssetsSummaryParams, - ): Promise { - return this.getPrivate('sapi/v1/sub-account/spotSummary', params); + getAllocations(params: AllocationsParams): Promise { + return this.getPrivate('api/v3/myAllocations', params); } - getSubAccountDepositAddress( - params: SubAccountDepositAddressParams, - ): Promise { - return this.getPrivate('sapi/v1/capital/deposit/subAddress', params); + getCommissionRates(params: { symbol: string }): Promise { + return this.getPrivate('api/v3/account/commission', params); } - getSubAccountDepositHistory( - params: SubAccountDepositHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/capital/deposit/subHisrec', params); + /** + * + * MARGIN TRADING Endpoints - Market Data endpoints + * + **/ + + getCrossMarginCollateralRatio(): Promise< + { + collaterals: Collateral[]; + assetNames: string[]; + }[] + > { + return this.getPrivate('sapi/v1/margin/crossMarginCollateralRatio'); } - getSubAccountStatusOnMarginOrFutures(params?: { - email?: string; - }): Promise { - return this.getPrivate('sapi/v1/sub-account/status', params); + getAllCrossMarginPairs(): Promise { + return this.get('sapi/v1/margin/allPairs'); } - subAccountEnableMargin(email: string): Promise { - return this.postPrivate('sapi/v1/sub-account/margin/enable', { email }); + getIsolatedMarginAllSymbols(params?: { + symbol?: string; + }): Promise { + return this.getPrivate('sapi/v1/margin/isolated/allPairs', params); } - getSubAccountDetailOnMarginAccount( - email: string, - ): Promise { - return this.getPrivate('sapi/v1/sub-account/margin/account', { email }); + getAllMarginAssets(): Promise { + return this.get('sapi/v1/margin/allAssets'); } - getSubAccountsSummaryOfMarginAccount(): Promise { - return this.getPrivate('sapi/v1/sub-account/margin/accountSummary'); + getMarginDelistSchedule(): Promise { + return this.getPrivate('sapi/v1/margin/delist-schedule'); } - subAccountEnableFutures(email: string): Promise { - return this.postPrivate('sapi/v1/sub-account/futures/enable', { email }); + getIsolatedMarginTierData( + params: QueryIsolatedMarginTierDataParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/isolatedMarginTier', params); } - getSubAccountFuturesAccountDetail( - email: string, - ): Promise { - return this.getPrivate('sapi/v1/sub-account/futures/account', { email }); + queryMarginPriceIndex( + params: BasicSymbolParam, + ): Promise { + return this.get('sapi/v1/margin/priceIndex', params); } - getSubAccountFuturesAccountSummary(): Promise { - return this.getPrivate('sapi/v1/sub-account/futures/accountSummary'); + getMarginAvailableInventory(params: { + type: string; + }): Promise { + return this.getPrivate('sapi/v1/margin/available-inventory', params); } - getSubAccountFuturesPositionRisk( - email: string, - ): Promise { - return this.getPrivate('sapi/v1/sub-account/futures/positionRisk', { - email, - }); + getLeverageBracket(): Promise { + return this.getPrivate('sapi/v1/margin/leverageBracket'); } - subAccountFuturesTransfer( - params: SubAccountTransferParams, - ): Promise { - return this.postPrivate('sapi/v1/sub-account/futures/transfer', params); + /** + * + * MARGIN TRADING Endpoints - Borrow and Repay endpoints + * + **/ + + getNextHourlyInterestRate( + params: GetNextHourlyInterestRateParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/next-hourly-interest-rate', params); } - subAccountMarginTransfer( - params: SubAccountTransferParams, - ): Promise { - return this.postPrivate('sapi/v1/sub-account/margin/transfer', params); + getMarginInterestHistory(params: GetMarginInterestHistoryParams): Promise<{ + rows: MarginInterestHistory[]; + total: number; + }> { + return this.getPrivate('sapi/v1/margin/interestHistory', params); } - subAccountTransferToSameMaster( - params: SubAccountTransferToSameMasterParams, - ): Promise { - return this.postPrivate('sapi/v1/sub-account/transfer/subToSub', params); + submitMarginAccountBorrowRepay( + params: MarginAccountLoanParams, + ): Promise { + return this.postPrivate('sapi/v1/margin/borrow-repay', params); } - subAccountTransferToMaster( - params: SubAccountTransferToMasterParams, - ): Promise { - return this.postPrivate('sapi/v1/sub-account/transfer/subToMaster', params); + getMarginAccountBorrowRepayRecords( + params: GetMarginAccountBorrowRepayRecordsParams, + ): Promise<{ rows: MarginAccountRecord[]; total: number }> { + return this.getPrivate('sapi/v1/margin/borrow-repay', params); } - subAccountTransferHistory( - params?: SubAccountTransferHistoryParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/sub-account/transfer/subUserHistory', - params, - ); + getMarginInterestRateHistory( + params: QueryMarginInterestRateHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/interestRateHistory', params); } - subAccountUniversalTransfer( - params: SubAccountUniversalTransferParams, - ): Promise { - return this.postPrivate('sapi/v1/sub-account/universalTransfer', params); + queryMaxBorrow( + params: BasicMarginAssetParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/maxBorrowable', params); } - getSubAccountUniversalTransferHistory( - params?: SubAccountUniversalTransferHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/sub-account/universalTransfer', params); + /** + * + * MARGIN TRADING Endpoints - Trade endpoints + * + **/ + + getMarginForceLiquidationRecord( + params: GetForceLiquidationRecordParams, + ): Promise<{ + rows: ForceLiquidationRecord[]; + total: number; + }> { + return this.getPrivate('sapi/v1/margin/forceLiquidationRec', params); } - getSubAccountDetailOnFuturesAccountV2( - params: BasicFuturesSubAccountParams, - ): Promise { - return this.getPrivate('sapi/v2/sub-account/futures/account', params); + getSmallLiabilityExchangeCoins(): Promise { + return this.getPrivate('sapi/v1/margin/exchange-small-liability'); } - getSubAccountSummaryOnFuturesAccountV2( - params: SubAccountSummaryOnFuturesAccountV2Params, - ): Promise { + getSmallLiabilityExchangeHistory( + params: GetSmallLiabilityExchangeHistoryParams, + ): Promise<{ + total: number; + rows: SmallLiabilityExchangeHistory[]; + }> { return this.getPrivate( - 'sapi/v2/sub-account/futures/accountSummary', + 'sapi/v1/margin/exchange-small-liability-history', params, ); } - getSubAccountFuturesPositionRiskV2( - params: BasicFuturesSubAccountParams, - ): Promise { - return this.getPrivate('sapi/v2/sub-account/futures/positionRisk', params); + marginAccountCancelOpenOrders( + params: BasicSymbolParam, + ): Promise { + return this.deletePrivate('sapi/v1/margin/openOrders', params); } - subAccountEnableLeverageToken( - params: SubAccountEnableLeverageToken, - ): Promise { - return this.postPrivate('sapi/v1/sub-account/blvt/enable', params); + marginAccountCancelOCO(params: CancelOCOParams): Promise { + this.validateOrderId(params, 'newClientOrderId'); + return this.deletePrivate('sapi/v1/margin/orderList', params); } - subAccountEnableOrDisableIPRestriction( - params: EnableOrDisableIPRestrictionForSubAccountParams, - ): Promise { - return this.postPrivate( - 'sapi/v1/sub-account/subAccountApi/ipRestriction', - params, - ); + marginAccountCancelOrder( + params: CancelOrderParams, + ): Promise { + return this.deletePrivate('sapi/v1/margin/order', params); } - subAccountAddIPList( - params: SubAccountEnableOrDisableIPRestriction, - ): Promise { - return this.postPrivate( - 'sapi/v1/sub-account/subAccountApi/ipRestriction/ipList', - params, - ); + marginAccountNewOCO(params: NewOCOParams): Promise { + this.validateOrderId(params, 'listClientOrderId'); + this.validateOrderId(params, 'limitClientOrderId'); + this.validateOrderId(params, 'stopClientOrderId'); + return this.postPrivate('sapi/v1/margin/order/oco', params); } - subAccountAddIPRestriction( - params: AddIpRestriction, - ): Promise { - return this.postPrivate( - 'sapi/v2/sub-account/subAccountApi/ipRestriction', - params, - ); + marginAccountNewOrder< + T extends OrderType, + RT extends OrderResponseType | undefined = undefined, + >(params: NewSpotOrderParams): Promise> { + this.validateOrderId(params, 'newClientOrderId'); + return this.postPrivate('sapi/v1/margin/order', params); } - getSubAccountIPRestriction( - params: BasicSubAccount, - ): Promise { - return this.getPrivate( - 'sapi/v1/sub-account/subAccountApi/ipRestriction', - params, - ); + getMarginOrderCountUsage( + params: GetMarginOrderCountUsageParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/rateLimit/order', params); } - subAccountDeleteIPList( - params: SubAccountEnableOrDisableIPRestriction, - ): Promise { - return this.deletePrivate( - 'sapi/v1/sub-account/subAccountApi/ipRestriction/ipList', - params, - ); + queryMarginAccountAllOCO( + params: QueryMarginAccountAllOCOParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/allOrderList', params); } - depositAssetsIntoManagedSubAccount( - params: SubAccountTransferToSameMasterParams, - ): Promise { - return this.postPrivate('sapi/v1/managed-subaccount/deposit', params); + queryMarginAccountAllOrders( + params: GetAllOrdersParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/allOrders', params); } - getManagedSubAccountAssetDetails( - email: string, - ): Promise { - return this.getPrivate('sapi/v1/managed-subaccount/asset', { email }); + queryMarginAccountOCO(params: GetOCOParams): Promise { + return this.getPrivate('sapi/v1/margin/orderList', params); } - withdrawAssetsFromManagedSubAccount( - params: WithdrawAssetsFromManagedSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/managed-subaccount/withdraw', params); + queryMarginAccountOpenOCO(params: { + isIsolated?: 'TRUE' | 'FALSE'; + symbol?: string; + }): Promise { + return this.getPrivate('sapi/v1/margin/openOrderList', params); } - getManagedSubAccountSnapshot( - params: ManagedSubAccountSnapshotParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/managed-subaccount/accountSnapshot', - params, - ); + queryMarginAccountOpenOrders(params: BasicSymbolParam): Promise { + return this.getPrivate('sapi/v1/margin/openOrders', params); } - getManagedSubAccountTransfersInvestor( - params: ManagedSubAccountTransferLogParams, - ): Promise<{ - managerSubTransferHistoryVos: ManagerSubTransferHistoryVos[]; - count: number; - }> { - return this.getPrivate( - 'sapi/v1/managed-subaccount/queryTransLogForInvestor', - params, - ); + queryMarginAccountOrder(params: GetOrderParams): Promise { + return this.getPrivate('sapi/v1/margin/order', params); } - getManagedSubAccountTransfersParent( - params: ManagedSubAccountTransferLogParams, - ): Promise<{ - managerSubTransferHistoryVos: ManagerSubTransferHistoryVos[]; - count: number; - }> { - return this.getPrivate( - 'sapi/v1/managed-subaccount/queryTransLogForTradeParent', - params, - ); + queryMarginAccountTradeList( + params: QueryMarginAccountTradeListParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/myTrades', params); } - getManagedSubAccountFuturesAssets(params: { - email: string; - }): Promise { - return this.getPrivate( - 'sapi/v1/managed-subaccount/fetch-future-asset', - params, - ); + submitSmallLiabilityExchange(params: { assetNames: string[] }): Promise<{ + success: boolean; + message: string; + }> { + return this.postPrivate('sapi/v1/margin/exchange-small-liability', params); } - getManagedSubAccountMarginAssets(params: { - email: string; - }): Promise { - return this.getPrivate('sapi/v1/managed-subaccount/marginAsset', params); + submitManualLiquidation( + params: ManualLiquidationParams, + ): Promise { + return this.postPrivate('sapi/v1/margin/manual-liquidation', params); } - getSubAccountAssetsMaster(params: { email: string }): Promise<{ - balances: SubaccountBalances[]; - }> { - return this.getPrivate('sapi/v4/sub-account/assets', params); - } + /** + * + * MARGIN TRADING Endpoints - Transfer endpoints + * + **/ - getManagedSubAccounts(params: ManagedSubAccountListParams): Promise<{ - total: number; - managerSubUserInfoVoList: ManagerSubUserInfoVo[]; - }> { - return this.getPrivate('sapi/v1/managed-subaccount/info', params); + getCrossMarginTransferHistory( + params: GetCrossMarginTransferHistoryParams, + ): Promise> { + return this.getPrivate('sapi/v1/margin/transfer', params); } - getSubAccountTransactionStatistics(params: { - email: string; - }): Promise { - return this.getPrivate( - 'sapi/v1/sub-account/transaction-statistics', - params, - ); + queryMaxTransferOutAmount( + params: BasicMarginAssetParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/maxTransferable', params); } - getManagedSubAccountDepositAddress( - params: ManagedSubAccountDepositAddressParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/managed-subaccount/deposit/address', - params, - ); - } + /** + * + * MARGIN TRADING Endpoints - Account endpoints + * + **/ - enableOptionsForSubAccount(params: { - email: string; - }): Promise { - return this.postPrivate('sapi/v1/sub-account/eoptions/enable', params); + updateCrossMarginMaxLeverage(params: { maxLeverage: number }): Promise<{ + success: boolean; + }> { + return this.postPrivate('sapi/v1/margin/max-leverage', params); } - getManagedSubAccountTransferLog( - params: ManagedSubAccountTransferTTLogParams, - ): Promise<{ - managerSubTransferHistoryVos: ManagerSubTransferHistoryVos[]; - count: number; + disableIsolatedMarginAccount(params: { symbol: string }): Promise<{ + success: boolean; + symbol: string; }> { - return this.getPrivate( - 'sapi/v1/managed-subaccount/query-trans-log', - params, - ); + return this.deletePrivate('sapi/v1/margin/isolated/account', params); } - /** - * Broker Endpoints - */ - - getBrokerIfNewSpotUser(): Promise<{ - rebateWorking: boolean; - ifNewUser: boolean; + enableIsolatedMarginAccount(params: { symbols: string }): Promise<{ + success: boolean; + symbol: string; }> { - return this.getPrivate('sapi/v1/apiReferral/ifNewUser'); + return this.postPrivate('sapi/v1/margin/isolated/account', params); } - getBrokerSubAccountDepositHistory( - params?: GetBrokerSubAccountDepositHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/broker/subAccount/depositHist', params); + getBNBBurn(): Promise { + return this.getPrivate('sapi/v1/bnbBurn'); } - getBrokerUserCustomisedId(market: 'spot' | 'futures') { - const prefix = market === 'spot' ? 'sapi' : 'fapi'; - return this.getPrivate(prefix + '/v1/apiReferral/userCustomization'); + getMarginSummary(): Promise { + return this.getPrivate('sapi/v1/margin/tradeCoeff'); } - createBrokerSubAccount( - params: CreateBrokerSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/subAccount', params); + queryCrossMarginAccountDetails(): Promise { + return this.getPrivate('sapi/v1/margin/account'); } - getBrokerSubAccountHistory( - params: GetBrokerSubAccountHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/broker/transfer', params); + getCrossMarginFeeData( + params: QueryCrossMarginFeeDataParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/crossMarginData', params); } - getBrokerSubAccount( - params: GetBrokerSubAccountParams, - ): Promise { - return this.getPrivate('sapi/v1/broker/subAccount', params); + getIsolatedMarginAccountLimit(): Promise<{ + enabledAccount: number; + maxAccount: number; + }> { + return this.getPrivate('sapi/v1/margin/isolated/accountLimit'); } - getApiKeyBrokerSubAccount( - params: GetApiKeyBrokerSubAccountParams, - ): Promise { - return this.getPrivate('sapi/v1/broker/subAccountApi', params); + getIsolatedMarginAccountInfo(params?: { + symbols?: string; + }): Promise { + return this.getPrivate('sapi/v1/margin/isolated/account', { params }); } - createApiKeyBrokerSubAccount( - params: CreateApiKeyBrokerSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/subAccountApi', params); + getIsolatedMarginFeeData( + params: QueryCrossMarginFeeDataParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/isolatedMarginData', params); } - deleteApiKeyBrokerSubAccount( - params: DeleteApiKeyBrokerSubAccountParams, - ): Promise<{}> { - return this.deletePrivate('sapi/v1/broker/subAccountApi', params); + toggleBNBBurn(params: ToggleBNBBurnParams): Promise { + return this.postPrivate('sapi/v1/bnbBurn', params); } - changePermissionApiKeyBrokerSubAccount( - params: ChangePermissionApiKeyBrokerSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/subAccountApi/permission', params); + /** + * Possibly @deprecated + * Only existing in old documentation, not in new documentation + */ + getMarginCapitalFlow( + params: GetMarginCapitalFlowParams, + ): Promise { + return this.getPrivate('sapi/v1/margin/capital-flow', params); } - changeComissionBrokerSubAccount( - params: ChangePermissionApiKeyBrokerSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/subAccountApi/permission', params); + /** + * @deprecated on 2024-01-09, use getMarginAccountBorrowRepayRecords() instead + */ + queryLoanRecord( + params: QueryMarginRecordParams, + ): Promise<{ rows: MarginAccountRecord[]; total: number }> { + return this.getPrivate('sapi/v1/margin/loan', params); } - enableUniversalTransferApiKeyBrokerSubAccount( - params: EnableUniversalTransferApiKeyBrokerSubAccountParams, - ): Promise { - return this.postPrivate( - 'sapi/v1/broker/subAccountApi/permission/universalTransfer', - params, - ); + /** + * @deprecated on 2024-01-09, use getMarginAccountBorrowRepayRecords() instead + */ + queryRepayRecord( + params: QueryMarginRecordParams, + ): Promise<{ rows: MarginAccountRecord[]; total: number }> { + return this.getPrivate('sapi/v1/margin/repay', params); } - enableMarginBrokerSubAccount( - params: EnableMarginBrokerSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/subAccount/futures', params); + /** + * @deprecated on 2024-01-09, use submitUniversalTransfer() instead + */ + isolatedMarginAccountTransfer( + params: IsolatedMarginAccountTransferParams, + ): Promise { + return this.postPrivate('sapi/v1/margin/isolated/transfer', params); } - enableFuturesBrokerSubAccount( - params: EnableFuturesBrokerSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/subAccount', params); + /** + * + * WALLET Endpoints - Capital endpoints + * + **/ + + getBalances(): Promise { + return this.getPrivate('sapi/v1/capital/config/getall'); + } + withdraw(params: WithdrawParams): Promise<{ id: string }> { + return this.postPrivate('sapi/v1/capital/withdraw/apply', params); } - enableMarginApiKeyBrokerSubAccount( - params: EnableMarginApiKeyBrokerSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/subAccount/margin', params); + getWithdrawHistory( + params?: WithdrawHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/capital/withdraw/history', params); } - transferBrokerSubAccount( - params: TransferBrokerSubAccountParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/transfer', params); + getWithdrawAddresses(): Promise { + return this.getPrivate('sapi/v1/capital/withdraw/address/list'); } - universalTransferBroker( - params: UniversalTransferBrokerParams, - ): Promise { - return this.postPrivate('sapi/v1/broker/universalTransfer', params); + getDepositHistory(params?: DepositHistoryParams): Promise { + return this.getPrivate('sapi/v1/capital/deposit/hisrec', params); } - getUniversalTransferBroker( - params: GetUniversalTransferBrokerParams, - ): Promise { - return this.getPrivate('sapi/v1/broker/universalTransfer', params); + getDepositAddress( + params: DepositAddressParams, + ): Promise { + return this.getPrivate('sapi/v1/capital/deposit/address', params); } - getBrokerInfo(): Promise { - return this.getPrivate('sapi/v1/broker/info'); + getDepositAddresses( + params: DepositAddressListParams, + ): Promise { + return this.getPrivate('sapi/v1/capital/deposit/address/list', params); } - // USD & Coin-M can be found under API getIncome() (find "API rebate" in results) - getBrokerSpotRebateHistory(days: 7 | 30, customerId?: string) { - if (days === 7) { - return this.getPrivate('sapi/v1/apiReferral/rebate/recentRecord', { - customerId, - }); - } - if (days === 30) { - return this.getPrivate('sapi/v1/apiReferral/rebate/historicalRecord', { - customerId, - }); - } + submitDepositCredit( + params: SubmitDepositCreditParams, + ): Promise { + return this.postPrivate('sapi/v1/capital/deposit/credit-apply', params); + } + + getAutoConvertStablecoins(): Promise { + return this.getPrivate('sapi/v1/capital/contract/convertible-coins'); + } + + setConvertibleCoins(params: ConvertibleCoinsParams): Promise { + return this.postPrivate( + 'sapi/v1/capital/contract/convertible-coins', + params, + ); } /** * - * Market Data Endpoints + * WALLET Endpoints - Asset endpoints * **/ - testConnectivity(): Promise<{}> { - return this.get('api/v3/ping'); - } - - getExchangeInfo(params?: ExchangeInfoParams): Promise { - const symbols = params?.symbols && JSON.stringify(params.symbols); - const symbol = params?.symbol; - - let urlSuffix = ''; - if (symbol) { - urlSuffix += '?symbol=' + symbol; - } else if (symbols) { - urlSuffix += '?symbols=' + symbols; - } - - return this.get('api/v3/exchangeInfo' + urlSuffix); + getAssetDetail( + params?: Partial, + ): Promise> { + return this.getPrivate('sapi/v1/asset/assetDetail', params); } - getOrderBook(params: OrderBookParams): Promise { - return this.get('api/v3/depth', params); + getWalletBalances(): Promise { + return this.getPrivate('sapi/v1/asset/wallet/balance'); } - getRecentTrades(params: RecentTradesParams): Promise { - return this.get('api/v3/trades', params); + getUserAsset(params: GetAssetParams): Promise { + return this.postPrivate('sapi/v3/asset/getUserAsset', params); } - getHistoricalTrades(params: HistoricalTradesParams): Promise { - return this.get('api/v3/historicalTrades', params); + submitUniversalTransfer( + params: UniversalTransferParams, + ): Promise<{ tranId: number }> { + return this.postPrivate('sapi/v1/asset/transfer', params); } - getAggregateTrades( - params: SymbolFromPaginatedRequestFromId, - ): Promise { - return this.get('api/v3/aggTrades', params); + getUniversalTransferHistory( + params: UniversalTransferHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/asset/transfer', params); } - getKlines(params: KlinesParams): Promise { - return this.get('api/v3/klines', params); + getDust(): Promise { + return this.postPrivate('sapi/v1/asset/dust-btc'); } - getUIKlines(params: KlinesParams): Promise { - return this.get('api/v3/uiKlines', params); + convertDustToBnb(params: ConvertDustParams): Promise { + return this.postPrivate('sapi/v1/asset/dust', params); } - getAvgPrice(params: BasicSymbolParam): Promise { - return this.get('api/v3/avgPrice', params); + getDustLog(params?: BasicTimeRangeParam): Promise { + return this.getPrivate('sapi/v1/asset/dribblet', params); } - get24hrChangeStatististics( - params: BasicSymbolParam, - ): Promise; - - get24hrChangeStatististics( - params?: SymbolArrayParam, - ): Promise; - - get24hrChangeStatististics( - params?: Partial | Partial, - ): Promise { - if (params && typeof params['symbol'] === 'string') { - return this.get('api/v3/ticker/24hr', params); - } - - if (params && params['symbols'] && Array.isArray(params['symbols'])) { - const symbols = (params as SymbolArrayParam).symbols; - const symbolsQueryParam = JSON.stringify(symbols); - - return this.get('api/v3/ticker/24hr?symbols=' + symbolsQueryParam); - } - - return this.get('api/v3/ticker/24hr'); + getAssetDividendRecord(params?: BasicAssetPaginatedParams): Promise { + return this.getPrivate('sapi/v1/asset/assetDividend', params); } - getTradingDayTicker( - params: TradingDayTickerParams, - ): Promise { - return this.get('api/v3/ticker/tradingDay', params); + getTradeFee(params?: Partial): Promise { + return this.getPrivate('sapi/v1/asset/tradeFee', params); } - getSymbolPriceTicker( - params?: Partial, - ): Promise { - return this.get('api/v3/ticker/price', params); + getFundingAsset(params: GetAssetParams): Promise { + return this.postPrivate('sapi/v1/asset/get-funding-asset', params); } - getSymbolOrderBookTicker( - params?: Partial, - ): Promise { - return this.get('api/v3/ticker/bookTicker', params); + getCloudMiningHistory(params: CloudMiningHistoryParams): Promise<{ + total: number; + rows: CloudMining[]; + }> { + return this.getPrivate( + 'sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage', + params, + ); } - getRollingWindowTicker( - params: RollingWindowTickerParams, - ): Promise { - return this.get('api/v3/ticker', params); + getDelegationHistory( + params: DelegationHistoryParams, + ): Promise> { + return this.getPrivate('sapi/v1/asset/custody/transfer-history', params); } /** * - * Spot Account/Trade Endpoints + * Futures Management Endpoints: + * https://binance-docs.github.io/apidocs/spot/en/#futures + * + * Note: to trade futures use the usdm-client or coinm-client. + * MainClient only has the futures endpoints listed in the "spot" docs category, primarily used for transfers. * **/ - testNewOrder< - T extends OrderType, - RT extends OrderResponseType | undefined = undefined, - >(params: NewSpotOrderParams): Promise<{}> { - this.validateOrderId(params, 'newClientOrderId'); - return this.postPrivate('api/v3/order/test', params); - } - - replaceOrder< - T extends OrderType, - RT extends OrderResponseType | undefined = undefined, - >( - params: ReplaceSpotOrderParams, - ): Promise> { - return this.postPrivate('api/v3/order/cancelReplace', params); - } + /** + * Execute transfer between spot account and futures account. + * + * Type: + * - 1: transfer from spot account to USDT-Ⓜ futures account. + * - 2: transfer from USDT-Ⓜ futures account to spot account. + * - 3: transfer from spot account to COIN-Ⓜ futures account. + * - 4: transfer from COIN-Ⓜ futures account to spot account. + */ - submitNewOrder< - T extends OrderType, - RT extends OrderResponseType | undefined = undefined, - >(params: NewSpotOrderParams): Promise> { - this.validateOrderId(params, 'newClientOrderId'); - return this.postPrivate('api/v3/order', params); + /** + * Possibly @deprecated, found only in old docs only + * Use sapi/v1/asset/transfer instead + */ + submitNewFutureAccountTransfer( + params: NewFutureAccountTransferParams, + ): Promise<{ tranId: number }> { + return this.postPrivate(`sapi/v1/futures/transfer`, params); } - cancelOrder(params: CancelOrderParams): Promise { - return this.deletePrivate('api/v3/order', params); + /** + * Possibly @deprecated, found only in old docs only + * Use sapi/v1/asset/transfer instead + */ + getFutureAccountTransferHistory( + params: GetFutureAccountTransferHistoryParams, + ): Promise> { + return this.getPrivate(`sapi/v1/futures/transfer`, params); } - cancelAllSymbolOrders( - params: BasicSymbolParam, - ): Promise { - return this.deletePrivate('api/v3/openOrders', params); + /** + * @deprecated as of 2023-09-25 + */ + getCrossCollateralBorrowHistory(params?: CoinStartEndLimit): Promise { + return this.getPrivate(`sapi/v1/futures/loan/borrow/history`, params); } - - getOrder(params: GetOrderParams): Promise { - return this.getPrivate('api/v3/order', params); + /** + * @deprecated as of 2023-09-25 + */ + getCrossCollateralRepaymentHistory(params?: CoinStartEndLimit): Promise { + return this.getPrivate(`sapi/v1/futures/loan/repay/history`, params); } - - getOpenOrders(params?: Partial): Promise { - return this.getPrivate('api/v3/openOrders', params); + /** + * @deprecated as of 2023-09-25 + */ + getCrossCollateralWalletV2(): Promise { + return this.getPrivate(`sapi/v2/futures/loan/wallet`); } - - getAllOrders(params: GetAllOrdersParams): Promise { - return this.getPrivate('api/v3/allOrders', params); + /** + * @deprecated as of 2023-09-25 + */ + getAdjustCrossCollateralLTVHistory( + params?: GetLoanCoinPaginatedHistoryParams, + ): Promise { + return this.getPrivate( + `sapi/v1/futures/loan/adjustCollateral/history`, + params, + ); } - /** - * @deprecated + * @deprecated as of 2023-09-25 */ - submitNewOCO(params: NewOCOParams): Promise { - this.validateOrderId(params, 'listClientOrderId'); - this.validateOrderId(params, 'limitClientOrderId'); - this.validateOrderId(params, 'stopClientOrderId'); - return this.postPrivate('api/v3/order/oco', params); + getCrossCollateralLiquidationHistory( + params?: GetLoanCoinPaginatedHistoryParams, + ): Promise { + return this.getPrivate(`sapi/v1/futures/loan/liquidationHistory`, params); } - - submitNewOrderList( - params: NewOrderListParams, - ): Promise> { - this.validateOrderId(params, 'listClientOrderId'); - this.validateOrderId(params, 'aboveClientOrderId'); - this.validateOrderId(params, 'belowClientOrderId'); - return this.postPrivate('api/v3/orderList/oco', params); + /** + * @deprecated as of 2023-09-25 + */ + getCrossCollateralInterestHistory( + params?: GetLoanCoinPaginatedHistoryParams, + ): Promise { + return this.getPrivate(`sapi/v1/futures/loan/interestHistory`, params); } - // TO CHECK!! - submitNewOrderListOTO( - params: NewOrderListOTOParams, - ): Promise { - this.validateOrderId(params, 'listClientOrderId'); - this.validateOrderId(params, 'workingClientOrderId'); - this.validateOrderId(params, 'pendingClientOrderId'); - return this.postPrivate('api/v3/orderList/oto', params); - } + /** + * + * WALLET Endpoints - Account endpoints + * + **/ - // TO CHECK!! - submitNewOrderListOTOCO( - params: NewOrderListOTOCOParams, - ): Promise { - this.validateOrderId(params, 'listClientOrderId'); - this.validateOrderId(params, 'workingClientOrderId'); - this.validateOrderId(params, 'pendingAboveClientOrderId'); - this.validateOrderId(params, 'pendingBelowClientOrderId'); - return this.postPrivate('api/v3/orderList/otoco', params); + getAccountInfo(): Promise { + return this.getPrivate('sapi/v1/account/info'); } - cancelOCO(params: CancelOCOParams): Promise { - this.validateOrderId(params, 'newClientOrderId'); - return this.deletePrivate('api/v3/orderList', params); + getDailyAccountSnapshot( + params: DailyAccountSnapshotParams, + ): Promise { + return this.getPrivate('sapi/v1/accountSnapshot', params); } - getOCO(params?: GetOCOParams): Promise { - return this.getPrivate('api/v3/orderList', params); + disableFastWithdrawSwitch(): Promise<{}> { + return this.postPrivate('sapi/v1/account/disableFastWithdrawSwitch'); } - getAllOCO(params?: BasicFromPaginatedParams): Promise { - return this.getPrivate('api/v3/allOrderList', params); + enableFastWithdrawSwitch(): Promise<{}> { + return this.postPrivate('sapi/v1/account/enableFastWithdrawSwitch'); } - /** - * Query open OCO - */ - getAllOpenOCO(): Promise { - return this.getPrivate('api/v3/openOrderList'); + getAccountStatus(): Promise<{ data: string }> { + return this.getPrivate('sapi/v1/account/status'); } - /** - * Places an order using smart order routing (SOR). - */ - submitNewSOROrder( - params: NewSpotSOROrderParams, - ): Promise { - this.validateOrderId(params, 'newClientOrderId'); - return this.postPrivate('api/v3/sor/order', params); + getApiTradingStatus(): Promise { + return this.getPrivate('sapi/v1/account/apiTradingStatus'); } - /** - * Test new order creation and signature/recvWindow using smart order routing (SOR). - * Creates and validates a new order but does not send it into the matching engine. - */ - testNewSOROrder( - params: NewSpotSOROrderParams & { computeCommissionRates?: boolean }, - ): Promise<{} | SORTestOrderResponse> { - this.validateOrderId(params, 'newClientOrderId'); - return this.postPrivate('api/v3/sor/order/test', params); + getApiKeyPermissions(): Promise { + return this.getPrivate('sapi/v1/account/apiRestrictions'); } /** * + * WALLET Endpoints - Travel Rule endpoints * - * Spot Account Endpoints - * - * - */ - - /** - * Get current account information - */ - getAccountInformation(): Promise { - return this.getPrivate('api/v3/account'); - } - - getAccountTradeList( - params: SymbolFromPaginatedRequestFromId & { orderId?: number }, - ): Promise { - return this.getPrivate('api/v3/myTrades', params); - } + **/ - getOrderRateLimit(): Promise { - return this.getPrivate('api/v3/rateLimit/order'); - } + // to be added - getPreventedMatches( - params: PreventedMatchesParams, - ): Promise { - return this.getPrivate('api/v3/myPreventedMatches', params); - } + /** + * + * WALLET Endpoints - Other endpoints + * + **/ - getAllocations(params: AllocationsParams): Promise { - return this.getPrivate('api/v3/myAllocations', params); + getSystemStatus(): Promise { + return this.get('sapi/v1/system/status'); } - getCommissionRates(params: { symbol: string }): Promise { - return this.getPrivate('api/v3/account/commission', params); + getDelistSchedule(): Promise { + return this.getPrivate('sapi/v1/spot/delist-schedule'); } /** * - * Margin Account/Trade Endpoints + * SUB ACCOUNT Endpoints - Account management * **/ - submitMarginAccountBorrowRepay( - params: MarginAccountLoanParams, - ): Promise { - return this.postPrivate('sapi/v1/margin/borrow-repay', params); + createVirtualSubAccount( + params: CreateSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/sub-account/virtualSubAccount', params); } - getMarginAccountBorrowRepayRecords( - params: GetMarginAccountBorrowRepayRecordsParams, - ): Promise<{ rows: MarginAccountRecord[]; total: number }> { - return this.getPrivate('sapi/v1/margin/borrow-repay', params); + getSubAccountList( + params?: SubAccountListParams, + ): Promise { + return this.getPrivate('sapi/v1/sub-account/list', params); } - getAllMarginAssets(): Promise { - return this.get('sapi/v1/margin/allAssets'); + subAccountEnableFutures(email: string): Promise { + return this.postPrivate('sapi/v1/sub-account/futures/enable', { email }); } - getAllCrossMarginPairs(): Promise { - return this.get('sapi/v1/margin/allPairs'); + subAccountEnableMargin(email: string): Promise { + return this.postPrivate('sapi/v1/sub-account/margin/enable', { email }); } - queryMarginPriceIndex( - params: BasicSymbolParam, - ): Promise { - return this.get('sapi/v1/margin/priceIndex', params); + enableOptionsForSubAccount(params: { + email: string; + }): Promise { + return this.postPrivate('sapi/v1/sub-account/eoptions/enable', params); } - marginAccountNewOrder< - T extends OrderType, - RT extends OrderResponseType | undefined = undefined, - >(params: NewSpotOrderParams): Promise> { - this.validateOrderId(params, 'newClientOrderId'); - return this.postPrivate('sapi/v1/margin/order', params); + subAccountEnableLeverageToken( + params: SubAccountEnableLeverageToken, + ): Promise { + return this.postPrivate('sapi/v1/sub-account/blvt/enable', params); } - marginAccountCancelOrder( - params: CancelOrderParams, - ): Promise { - return this.deletePrivate('sapi/v1/margin/order', params); + getSubAccountStatusOnMarginOrFutures(params?: { + email?: string; + }): Promise { + return this.getPrivate('sapi/v1/sub-account/status', params); } - marginAccountCancelOpenOrders( - params: BasicSymbolParam, - ): Promise { - return this.deletePrivate('sapi/v1/margin/openOrders', params); - } + getSubAccountFuturesPositionRisk( + email: string, + ): Promise { + return this.getPrivate('sapi/v1/sub-account/futures/positionRisk', { + email, + }); + } - updateCrossMarginMaxLeverage(params: { maxLeverage: number }): Promise<{ - success: boolean; - }> { - return this.postPrivate('sapi/v1/margin/max-leverage', params); + getSubAccountFuturesPositionRiskV2( + params: BasicFuturesSubAccountParams, + ): Promise { + return this.getPrivate('sapi/v2/sub-account/futures/positionRisk', params); } - getCrossMarginTransferHistory( - params: GetCrossMarginTransferHistoryParams, - ): Promise> { - return this.getPrivate('sapi/v1/margin/transfer', params); + getSubAccountTransactionStatistics(params: { + email: string; + }): Promise { + return this.getPrivate( + 'sapi/v1/sub-account/transaction-statistics', + params, + ); } - getMarginInterestHistory(params: GetMarginInterestHistoryParams): Promise<{ - rows: MarginInterestHistory[]; - total: number; - }> { - return this.getPrivate('sapi/v1/margin/interestHistory', params); + /** + * + * SUB ACCOUNT Endpoints - API management + * + **/ + + getSubAccountIPRestriction( + params: BasicSubAccount, + ): Promise { + return this.getPrivate( + 'sapi/v1/sub-account/subAccountApi/ipRestriction', + params, + ); } - getMarginForceLiquidationRecord( - params: GetForceLiquidationRecordParams, - ): Promise<{ - rows: ForceLiquidationRecord[]; - total: number; - }> { - return this.getPrivate('sapi/v1/margin/forceLiquidationRec', params); + subAccountDeleteIPList( + params: SubAccountAddOrDeleteIPList, + ): Promise { + return this.deletePrivate( + 'sapi/v1/sub-account/subAccountApi/ipRestriction/ipList', + params, + ); + } + + subAccountAddIPRestriction( + params: AddIpRestriction, + ): Promise { + return this.postPrivate( + 'sapi/v2/sub-account/subAccountApi/ipRestriction', + params, + ); } /** - * @deprecated on 2024-01-09, use getMarginAccountBorrowRepayRecords() instead - */ - queryLoanRecord( - params: QueryMarginRecordParams, - ): Promise<{ rows: MarginAccountRecord[]; total: number }> { - return this.getPrivate('sapi/v1/margin/loan', params); + * @deprecated + * Use subAccountAddIPRestriction instead + **/ + subAccountAddIPList( + params: SubAccountEnableOrDisableIPRestriction, + ): Promise { + return this.postPrivate( + 'sapi/v1/sub-account/subAccountApi/ipRestriction/ipList', + params, + ); } /** - * @deprecated on 2024-01-09, use getMarginAccountBorrowRepayRecords() instead - */ - queryRepayRecord( - params: QueryMarginRecordParams, - ): Promise<{ rows: MarginAccountRecord[]; total: number }> { - return this.getPrivate('sapi/v1/margin/repay', params); + * @deprecated + * Use subAccountAddIPRestriction instead, or subAccountDeleteIPList + **/ + subAccountEnableOrDisableIPRestriction( + params: EnableOrDisableIPRestrictionForSubAccountParams, + ): Promise { + return this.postPrivate( + 'sapi/v1/sub-account/subAccountApi/ipRestriction', + params, + ); } - queryCrossMarginAccountDetails(): Promise { - return this.getPrivate('sapi/v1/margin/account'); + /** + * + * SUB ACCOUNT Endpoints - Asset management + * + **/ + + subAccountFuturesTransfer( + params: SubAccountTransferParams, + ): Promise { + return this.postPrivate('sapi/v1/sub-account/futures/transfer', params); } - queryMarginAccountOrder(params: GetOrderParams): Promise { - return this.getPrivate('sapi/v1/margin/order', params); + getSubAccountFuturesAccountDetail( + email: string, + ): Promise { + return this.getPrivate('sapi/v1/sub-account/futures/account', { email }); } - queryMarginAccountOpenOrders(params: BasicSymbolParam): Promise { - return this.getPrivate('sapi/v1/margin/openOrders', params); + getSubAccountDetailOnFuturesAccountV2( + params: BasicFuturesSubAccountParams, + ): Promise { + return this.getPrivate('sapi/v2/sub-account/futures/account', params); } - queryMarginAccountAllOrders( - params: GetAllOrdersParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/allOrders', params); + getSubAccountDetailOnMarginAccount( + email: string, + ): Promise { + return this.getPrivate('sapi/v1/sub-account/margin/account', { email }); } - marginAccountNewOCO(params: NewOCOParams): Promise { - this.validateOrderId(params, 'listClientOrderId'); - this.validateOrderId(params, 'limitClientOrderId'); - this.validateOrderId(params, 'stopClientOrderId'); - return this.postPrivate('sapi/v1/margin/order/oco', params); + getSubAccountDepositAddress( + params: SubAccountDepositAddressParams, + ): Promise { + return this.getPrivate('sapi/v1/capital/deposit/subAddress', params); } - marginAccountCancelOCO(params: CancelOCOParams): Promise { - this.validateOrderId(params, 'newClientOrderId'); - return this.deletePrivate('sapi/v1/margin/orderList', params); + getSubAccountDepositHistory( + params: SubAccountDepositHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/capital/deposit/subHisrec', params); } - queryMarginAccountOCO(params: GetOCOParams): Promise { - return this.getPrivate('sapi/v1/margin/orderList', params); + getSubAccountFuturesAccountSummary(): Promise { + return this.getPrivate('sapi/v1/sub-account/futures/accountSummary'); } - queryMarginAccountAllOCO( - params: QueryMarginAccountAllOCOParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/allOrderList', params); + getSubAccountSummaryOnFuturesAccountV2( + params: SubAccountSummaryOnFuturesAccountV2Params, + ): Promise { + return this.getPrivate( + 'sapi/v2/sub-account/futures/accountSummary', + params, + ); } - /** - * Query margin account's open OCO - */ - queryMarginAccountOpenOCO(params: { - isIsolated?: 'TRUE' | 'FALSE'; - symbol?: string; - }): Promise { - return this.getPrivate('sapi/v1/margin/openOrderList', params); + getSubAccountsSummaryOfMarginAccount(): Promise { + return this.getPrivate('sapi/v1/sub-account/margin/accountSummary'); } - /** - * Query margin account's trade list - */ - queryMarginAccountTradeList( - params: QueryMarginAccountTradeListParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/myTrades', params); + subAccountMarginTransfer( + params: SubAccountTransferParams, + ): Promise { + return this.postPrivate('sapi/v1/sub-account/margin/transfer', params); } - queryMaxBorrow( - params: BasicMarginAssetParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/maxBorrowable', params); + getSubAccountAssets( + params: SubAccountAssetsParams, + ): Promise { + return this.getPrivate('sapi/v3/sub-account/assets', params); } - queryMaxTransferOutAmount( - params: BasicMarginAssetParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/maxTransferable', params); + getSubAccountAssetsMaster(params: { email: string }): Promise<{ + balances: SubaccountBalances[]; + }> { + return this.getPrivate('sapi/v4/sub-account/assets', params); + } + + getSubAccountFuturesAssetTransferHistory( + params: SubAccountFuturesAssetTransferHistoryParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/sub-account/futures/internalTransfer', + params, + ); + } + + getSubAccountSpotAssetTransferHistory( + params?: SubAccountSpotAssetTransferHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/sub-account/sub/transfer/history', params); + } + + getSubAccountSpotAssetsSummary( + params?: SubAccountSpotAssetsSummaryParams, + ): Promise { + return this.getPrivate('sapi/v1/sub-account/spotSummary', params); + } + + getSubAccountUniversalTransferHistory( + params?: SubAccountUniversalTransferHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/sub-account/universalTransfer', params); + } + + subAccountFuturesAssetTransfer( + params: SubAccountFuturesAssetTransferParams, + ): Promise { + return this.postPrivate( + 'sapi/v1/sub-account/futures/internalTransfer', + params, + ); + } + + subAccountTransferHistory( + params?: SubAccountTransferHistoryParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/sub-account/transfer/subUserHistory', + params, + ); + } + + subAccountTransferToMaster( + params: SubAccountTransferToMasterParams, + ): Promise { + return this.postPrivate('sapi/v1/sub-account/transfer/subToMaster', params); + } + + subAccountTransferToSameMaster( + params: SubAccountTransferToSameMasterParams, + ): Promise { + return this.postPrivate('sapi/v1/sub-account/transfer/subToSub', params); + } + + subAccountUniversalTransfer( + params: SubAccountUniversalTransferParams, + ): Promise { + return this.postPrivate('sapi/v1/sub-account/universalTransfer', params); } /** - * @deprecated on 2024-01-09, use submitUniversalTransfer() instead - */ - isolatedMarginAccountTransfer( - params: IsolatedMarginAccountTransferParams, + * + * SUB ACCOUNT Endpoints - Managed Sub Account + * + **/ + + depositAssetsIntoManagedSubAccount( + params: SubAccountTransferToSameMasterParams, ): Promise { - return this.postPrivate('sapi/v1/margin/isolated/transfer', params); + return this.postPrivate('sapi/v1/managed-subaccount/deposit', params); + } + + getManagedSubAccountDepositAddress( + params: ManagedSubAccountDepositAddressParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/managed-subaccount/deposit/address', + params, + ); + } + + withdrawAssetsFromManagedSubAccount( + params: WithdrawAssetsFromManagedSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/managed-subaccount/withdraw', params); + } + + getManagedSubAccountTransfersParent( + params: ManagedSubAccountTransferLogParams, + ): Promise<{ + managerSubTransferHistoryVos: ManagerSubTransferHistoryVos[]; + count: number; + }> { + return this.getPrivate( + 'sapi/v1/managed-subaccount/queryTransLogForTradeParent', + params, + ); + } + + getManagedSubAccountTransferLog( + params: ManagedSubAccountTransferTTLogParams, + ): Promise<{ + managerSubTransferHistoryVos: ManagerSubTransferHistoryVos[]; + count: number; + }> { + return this.getPrivate( + 'sapi/v1/managed-subaccount/query-trans-log', + params, + ); + } + + getManagedSubAccountTransfersInvestor( + params: ManagedSubAccountTransferLogParams, + ): Promise<{ + managerSubTransferHistoryVos: ManagerSubTransferHistoryVos[]; + count: number; + }> { + return this.getPrivate( + 'sapi/v1/managed-subaccount/queryTransLogForInvestor', + params, + ); + } + + getManagedSubAccounts(params: ManagedSubAccountListParams): Promise<{ + total: number; + managerSubUserInfoVoList: ManagerSubUserInfoVo[]; + }> { + return this.getPrivate('sapi/v1/managed-subaccount/info', params); + } + + getManagedSubAccountSnapshot( + params: ManagedSubAccountSnapshotParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/managed-subaccount/accountSnapshot', + params, + ); + } + + getManagedSubAccountAssetDetails( + email: string, + ): Promise { + return this.getPrivate('sapi/v1/managed-subaccount/asset', { email }); + } + + getManagedSubAccountMarginAssets(params: { + email: string; + }): Promise { + return this.getPrivate('sapi/v1/managed-subaccount/marginAsset', params); } - getIsolatedMarginAccountInfo(params?: { - symbols?: string; - }): Promise { - return this.getPrivate('sapi/v1/margin/isolated/account', { params }); + getManagedSubAccountFuturesAssets(params: { + email: string; + }): Promise { + return this.getPrivate( + 'sapi/v1/managed-subaccount/fetch-future-asset', + params, + ); } /** - * Disable isolated margin account - */ - disableIsolatedMarginAccount(params: { symbol: string }): Promise<{ - success: boolean; - symbol: string; + * + * AUTO INVEST Endpoints - Market data + * + **/ + + getAutoInvestAssets(): Promise<{ + targetAssets: string[]; + sourceAssets: string[]; }> { - return this.deletePrivate('sapi/v1/margin/isolated/account', params); + return this.getPrivate('sapi/v1/lending/auto-invest/all/asset'); } - /** - * Enable isolated margin account - */ - enableIsolatedMarginAccount(params: { symbols: string }): Promise<{ - success: boolean; - symbol: string; - }> { - return this.postPrivate('sapi/v1/margin/isolated/account', params); + getAutoInvestSourceAssets( + params: GetSourceAssetListParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/lending/auto-invest/source-asset/list', + params, + ); } - /** - * Query enabled isolated margin account limit - */ - getIsolatedMarginAccountLimit(): Promise<{ - enabledAccount: number; - maxAccount: number; - }> { - return this.getPrivate('sapi/v1/margin/isolated/accountLimit'); + getAutoInvestTargetAssets( + params: GetTargetAssetListParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/lending/auto-invest/target-asset/list', + params, + ); } - /** - * Get all isolated margin symbols - */ - getIsolatedMarginAllSymbols(params?: { - symbol?: string; - }): Promise { - return this.getPrivate('sapi/v1/margin/isolated/allPairs', params); + getAutoInvestTargetAssetsROI( + params: GetTargetAssetROIParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/lending/auto-invest/target-asset/roi/list', + params, + ); } - /** - * Toggle BNB burn on spot trade and margin interest - */ - toggleBNBBurn(params: ToggleBNBBurnParams): Promise { - return this.postPrivate('sapi/v1/bnbBurn', params); + getAutoInvestIndex(params: { + indexId: number; + }): Promise { + return this.getPrivate('sapi/v1/lending/auto-invest/index/info', params); } - /** - * Get BNB burn status - */ - getBNBBurn(): Promise { - return this.getPrivate('sapi/v1/bnbBurn'); + getAutoInvestPlans(params: { + planType: 'SINGLE' | 'PORTFOLIO' | 'INDEX'; + }): Promise { + return this.getPrivate('sapi/v1/lending/auto-invest/plan/list', params); } /** - * Query margin interest rate history - */ - getMarginInterestRateHistory( - params: QueryMarginInterestRateHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/interestRateHistory', params); - } + * + * AUTO INVEST Endpoints - Trade + * + **/ /** - * Query cross margin fee data + * https://developers.binance.com/docs/auto_invest/trade/One-Time-Transaction + * + * @param params + * @returns */ - getCrossMarginFeeData( - params: QueryCrossMarginFeeDataParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/crossMarginData', params); + submitAutoInvestOneTimeTransaction( + params: SubmitOneTimeTransactionParams, + ): Promise { + const { details, ...allParams } = params; + const requestParameters = { ...allParams }; + for (let i = 0; i < details.length; i++) { + requestParameters[`details[${i}].targetAsset`] = details[i].targetAsset; + requestParameters[`details[${i}].percentage`] = details[i].percentage; + } + + return this.postPrivate( + 'sapi/v1/lending/auto-invest/one-off', + requestParameters, + ); } - /** - * Query isolated margin fee data - */ - getIsolatedMarginFeeData( - params: QueryCrossMarginFeeDataParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/isolatedMarginData', params); + updateAutoInvestPlanStatus( + params: ChangePlanStatusParams, + ): Promise { + return this.postPrivate( + 'sapi/v1/lending/auto-invest/plan/edit-status', + params, + ); } /** - * Query isolated margin tier data - */ - getIsolatedMarginTierData( - params: QueryIsolatedMarginTierDataParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/isolatedMarginTier', params); + * + * @deprecated , use updateAutoInvestmentPlan instead + * + **/ + updateAutoInvestmentPlanOld( + params: EditInvestmentPlanParams, + ): Promise { + return this.postPrivate('sapi/v1/lending/auto-invest/plan/edit', params); } - getMarginOrderCountUsage( - params: GetMarginOrderCountUsageParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/rateLimit/order', params); - } + updateAutoInvestmentPlan( + params: EditInvestmentPlanParams, + ): Promise { + const { details, ...allParams } = params; - getCrossMarginCollateralRatio(): Promise< - { - collaterals: Collateral[]; - assetNames: string[]; - }[] - > { - return this.getPrivate('sapi/v1/margin/crossMarginCollateralRatio'); - } + const requestParameters = { ...allParams }; + for (let i = 0; i < details.length; i++) { + requestParameters[`details[${i}].targetAsset`] = details[i].targetAsset; + requestParameters[`details[${i}].percentage`] = details[i].percentage; + } - getSmallLiabilityExchangeCoins(): Promise { - return this.getPrivate('sapi/v1/margin/exchange-small-liability'); + return this.postPrivate( + 'sapi/v1/lending/auto-invest/plan/edit', + requestParameters, + ); } - submitSmallLiabilityExchange(params: { assetNames: string[] }): Promise<{ - success: boolean; - message: string; + submitAutoInvestRedemption( + params: SubmitIndexLinkedPlanRedemptionParams, + ): Promise<{ + redemptionId: number; }> { - return this.postPrivate('sapi/v1/margin/exchange-small-liability', params); + return this.postPrivate('sapi/v1/lending/auto-invest/redeem', params); } - getSmallLiabilityExchangeHistory( - params: GetSmallLiabilityExchangeHistoryParams, - ): Promise<{ - total: number; - rows: SmallLiabilityExchangeHistory[]; - }> { + getAutoInvestSubscriptionTransactions( + params: GetSubscriptionTransactionHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/lending/auto-invest/history/list', params); + } + + getOneTimeTransactionStatus( + params: GetOneTimeTransactionStatusParams, + ): Promise { return this.getPrivate( - 'sapi/v1/margin/exchange-small-liability-history', + 'sapi/v1/lending/auto-invest/one-off/status', params, ); } - getNextHourlyInterestRate( - params: GetNextHourlyInterestRateParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/next-hourly-interest-rate', params); + /** + * @deprecated , use submitAutoInvestmentPlan instead + * + **/ + submitAutoInvestmentPlanOld( + params: CreateInvestmentPlanParams, + ): Promise { + return this.postPrivate('sapi/v1/lending/auto-invest/plan/add', params); } - getMarginCapitalFlow( - params: GetMarginCapitalFlowParams, - ): Promise { - return this.getPrivate('sapi/v1/margin/capital-flow', params); + submitAutoInvestmentPlan( + params: CreateInvestmentPlanParams, + ): Promise { + const { details, ...allParams } = params; + const requestParameters = { ...allParams }; + for (let i = 0; i < details.length; i++) { + requestParameters[`details[${i}].targetAsset`] = details[i].targetAsset; + requestParameters[`details[${i}].percentage`] = details[i].percentage; + } + return this.postPrivate( + 'sapi/v1/lending/auto-invest/plan/add', + requestParameters, + ); } - getMarginDelistSchedule(): Promise { - return this.getPrivate('sapi/v1/margin/delist-schedule'); + getAutoInvestRedemptionHistory( + params: GetIndexLinkedPlanRedemptionHistoryParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/lending/auto-invest/redeem/history', + params, + ); } - getMarginAvailableInventory(params: { - type: string; - }): Promise { - return this.getPrivate('sapi/v1/margin/available-inventory', params); + getAutoInvestPlan(params: GetPlanDetailsParams): Promise { + return this.getPrivate('sapi/v1/lending/auto-invest/plan/id', params); } - submitManualLiquidation( - params: ManualLiquidationParams, - ): Promise { - return this.postPrivate('sapi/v1/margin/manual-liquidation', params); + getAutoInvestUserIndex(params: { + indexId: number; + }): Promise { + return this.getPrivate( + 'sapi/v1/lending/auto-invest/index/user-summary', + params, + ); } - getLeverageBracket(): Promise { - return this.getPrivate('sapi/v1/margin/leverageBracket'); + getAutoInvestRebalanceHistory( + params: GetIndexLinkedPlanRebalanceHistoryParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/lending/auto-invest/rebalance/history', + params, + ); } /** * - * User Data Stream Endpoints + * CONVERT Endpoints - Market Data * **/ - // spot - getSpotUserDataListenKey(): Promise<{ listenKey: string }> { - return this.post('api/v3/userDataStream'); + getConvertPairs(params: GetAllConvertPairsParams): Promise { + return this.getPrivate('sapi/v1/convert/exchangeInfo', params); } - keepAliveSpotUserDataListenKey(listenKey: string): Promise<{}> { - return this.put(`api/v3/userDataStream?listenKey=${listenKey}`); + getConvertAssetInfo(): Promise { + return this.getPrivate('sapi/v1/convert/assetInfo'); } - closeSpotUserDataListenKey(listenKey: string): Promise<{}> { - return this.delete(`api/v3/userDataStream?listenKey=${listenKey}`); + /** + * + * CONVERT Endpoints - Trade + * + **/ + + convertQuoteRequest(params: ConvertQuoteRequestParams): Promise { + return this.postPrivate('sapi/v1/convert/getQuote', params); } - // margin - getMarginUserDataListenKey(): Promise<{ listenKey: string }> { - return this.post('sapi/v1/userDataStream'); + acceptQuoteRequest(params: AcceptQuoteRequestParams): Promise { + return this.postPrivate('sapi/v1/convert/acceptQuote', params); } - keepAliveMarginUserDataListenKey(listenKey: string): Promise<{}> { - return this.put(`sapi/v1/userDataStream?listenKey=${listenKey}`); + getConvertTradeHistory(params: GetConvertTradeHistoryParams): Promise { + return this.getPrivate('sapi/v1/convert/tradeFlow', params); } - closeMarginUserDataListenKey(listenKey: string): Promise<{}> { - return this.delete(`sapi/v1/userDataStream?listenKey=${listenKey}`); + getOrderStatus(params: GetOrderStatusParams): Promise { + return this.getPrivate('sapi/v1/convert/orderStatus', params); } - // isolated margin - getIsolatedMarginUserDataListenKey(params: { - symbol: string; - }): Promise<{ listenKey: string }> { - return this.post( - `sapi/v1/userDataStream/isolated?${serialiseParams(params)}`, - ); + submitConvertLimitOrder(params: SubmitConvertLimitOrderParams): Promise { + return this.postPrivate('sapi/v1/convert/limit/placeOrder', params); } - keepAliveIsolatedMarginUserDataListenKey(params: { - symbol: string; - listenKey: string; - }): Promise<{}> { - return this.put( - `sapi/v1/userDataStream/isolated?${serialiseParams(params)}`, - ); + cancelConvertLimitOrder(params: { orderId: number }): Promise { + return this.postPrivate('sapi/v1/convert/limit/cancelOrder', params); } - closeIsolatedMarginUserDataListenKey(params: { - symbol: string; - listenKey: string; - }): Promise<{}> { - return this.delete( - `sapi/v1/userDataStream/isolated?${serialiseParams(params)}`, - ); + getConvertLimitOpenOrders(): Promise<{ + list: ConvertLimitOpenOrder[]; + }> { + return this.getPrivate('sapi/v1/convert/limit/queryOpenOrders'); } /** * - * Simple earn Endpoints + * STAKING Endpoints - Account * **/ - getFlexibleSavingProducts(params?: SimpleEarnProductListParams): Promise<{ - rows: SimpleEarnFlexibleProduct[]; - total: number; - }> { - return this.getPrivate(`/sapi/v1/simple-earn/flexible/list`, params); + /** + * @deprecated use getEthStakingAccountV2 instead + **/ + getEthStakingAccount(): Promise { + return this.getPrivate('sapi/v1/eth-staking/account'); } - getSimpleEarnLockedProductList( - params?: SimpleEarnProductListParams, - ): Promise<{ - rows: SimpleEarnLockedProduct[]; - total: number; - }> { - return this.getPrivate(`/sapi/v1/simple-earn/locked/list`, params); + getEthStakingAccountV2(): Promise { + return this.getPrivate('sapi/v2/eth-staking/account'); } - purchaseFlexibleProduct( - params: SimpleEarnSubscribeProductParams, - ): Promise { - return this.postPrivate(`/sapi/v1/simple-earn/flexible/subscribe`, params); + getEthStakingQuota(): Promise { + return this.getPrivate('sapi/v1/eth-staking/eth/quota'); } - subscribeSimpleEarnLockedProduct( - params: SimpleEarnSubscribeProductParams, - ): Promise { - return this.postPrivate(`/sapi/v1/simple-earn/locked/subscribe`, params); - } + /** + * + * STAKING Endpoints - Staking + * + **/ - redeemLockedProduct(params: { - positionId: string; - }): Promise { - return this.postPrivate(`/sapi/v1/simple-earn/locked/redeem`, params); + /** + * @deprecated use subscribeEthStakingV2 instead + **/ + subscribeEthStakingV1(params: { amount: number }): Promise<{ + success: boolean; + }> { + return this.postPrivate('sapi/v1/eth-staking/eth/stake', params); } - redeemFlexibleProduct(params: { - positionId: string; - }): Promise { - return this.postPrivate(`/sapi/v1/simple-earn/flexible/redeem`, params); + subscribeEthStakingV2(params: { + amount: number; + }): Promise { + return this.postPrivate('sapi/v2/eth-staking/eth/stake', params); } - getFlexibleProductPosition( - params?: SimpleEarnFlexibleProductPositionParams, - ): Promise<{ - rows: any[]; - total: number; - }> { - return this.getPrivate(`/sapi/v1/simple-earn/flexible/position`, params); + redeemEth(params: RedeemEthParams): Promise { + return this.postPrivate('sapi/v1/eth-staking/eth/redeem', params); } - getLockedProductPosition( - params?: SimpleEarnLockedProductPositionParams, - ): Promise<{ - rows: SimpleEarnLockedProductPosition[]; - total: number; - }> { - return this.getPrivate(`/sapi/v1/simple-earn/locked/position`, params); + wrapBeth(params: { amount: number }): Promise { + return this.postPrivate('sapi/v1/eth-staking/wbeth/wrap', params); } - getSimpleEarnAccount(): Promise { - return this.getPrivate(`/sapi/v1/simple-earn/account`); - } + /** + * + * STAKING Endpoints - History + * + **/ - getFlexibleSubscriptionRecord( - params: GetFlexibleSubscriptionRecordParams, - ): Promise<{ - rows: GetFlexibleSubscriptionRecordResponse[]; + getEthStakingHistory(params: GetEthStakingHistoryParams): Promise<{ + rows: EthStakingHistory[]; total: number; }> { return this.getPrivate( - 'sapi/v1/simple-earn/flexible/history/subscriptionRecord', + 'sapi/v1/eth-staking/eth/history/stakingHistory', params, ); } - getLockedSubscriptionRecord( - params: GetLockedSubscriptionRecordParams, - ): Promise<{ - rows: LockedSubscriptionRecord[]; + getEthRedemptionHistory(params: GetEthRedemptionHistoryParams): Promise<{ + rows: EthRedemptionHistory[]; total: number; }> { return this.getPrivate( - 'sapi/v1/simple-earn/locked/history/subscriptionRecord', + 'sapi/v1/eth-staking/eth/history/redemptionHistory', params, ); } - getFlexibleRedemptionRecord( - params: GetFlexibleRedemptionRecordParams, - ): Promise<{ - rows: FlexibleRedemptionRecord[]; + getBethRewardsHistory(params: GetBethRewardsHistoryParams): Promise<{ + rows: BethRewardsHistory[]; total: number; }> { return this.getPrivate( - 'sapi/v1/simple-earn/flexible/history/redemptionRecord', + 'sapi/v1/eth-staking/eth/history/rewardsHistory', params, ); } - getLockedRedemptionRecord(params: GetLockedRedemptionRecordParams): Promise<{ - rows: LockedRedemptionRecord[]; - total: number; + getWbethRewardsHistory( + params: GetWrapHistoryParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/eth-staking/eth/history/wbethRewardsHistory', + params, + ); + } + + getEthRateHistory(params: GetETHRateHistoryParams): Promise<{ + rows: ETHRateHistory[]; + total: string; }> { return this.getPrivate( - 'sapi/v1/simple-earn/locked/history/redemptionRecord', + 'sapi/v1/eth-staking/eth/history/rateHistory', params, ); } - getFlexibleRewardsHistory(params: GetFlexibleRewardsHistoryParams): Promise<{ - rows: FlexibleRewardsHistory[]; + getBethWrapHistory(params: GetWrapHistoryParams): Promise<{ + rows: WrapHistory[]; total: number; }> { return this.getPrivate( - 'sapi/v1/simple-earn/flexible/history/rewardsRecord', + 'sapi/v1/eth-staking/wbeth/history/wrapHistory', params, ); } - getLockedRewardsHistory(params: GetLockedRewardsHistoryParams): Promise<{ - rows: GetLockedRewardsHistory[]; + getBethUnwrapHistory(params: GetWrapHistoryParams): Promise<{ + rows: WrapHistory[]; total: number; }> { return this.getPrivate( - 'sapi/v1/simple-earn/locked/history/rewardsRecord', + 'sapi/v1/eth-staking/wbeth/history/unwrapHistory', params, ); } - setFlexibleAutoSubscribe(params: SetAutoSubscribeParams): Promise<{ - success: boolean; - }> { - return this.postPrivate( - 'sapi/v1/simple-earn/flexible/setAutoSubscribe', - params, - ); + /** + * @deprecated as of 2024-01-19 + */ + getStakingProducts( + params: StakingBasicParams & { + asset?: string; + }, + ): Promise { + return this.getPrivate(`sapi/v1/staking/productList`, params); + } + + /** + * @deprecated as of 2024-01-19 + */ + getStakingProductPosition( + params: StakingBasicParams & { + productId?: string; + asset?: string; + }, + ): Promise { + return this.getPrivate('sapi/v1/staking/position', params); + } + + /** + * @deprecated as of 2024-01-19 + */ + getStakingHistory(params: StakingHistoryParams): Promise { + return this.getPrivate('sapi/v1/staking/stakingRecord', params); + } + + /** + * @deprecated as of 2024-01-19 + */ + getPersonalLeftQuotaOfStakingProduct(params: { + product: StakingProductType; + productId: string; + }): Promise { + return this.getPrivate('sapi/v1/staking/personalLeftQuota', params); + } + + /** + * + * COPY TRADING Endpoints - Future copy trading + * + **/ + + getFuturesLeadTraderStatus(): Promise { + return this.getPrivate('sapi/v1/copyTrading/futures/userStatus'); + } + + getFuturesLeadTradingSymbolWhitelist(): Promise< + GetFuturesLeadTradingSymbolWhitelistResponse[] + > { + return this.getPrivate('sapi/v1/copyTrading/futures/leadSymbol'); + } + + /** + * + * MINING Endpoints - rest api + * + **/ + + getMiningAlgos(): Promise { + return this.get('sapi/v1/mining/pub/algoList'); + } + + getMiningCoins(): Promise { + return this.get('sapi/v1/mining/pub/coinList'); } - setLockedAutoSubscribe(params: SetAutoSubscribeParams): Promise<{ - success: boolean; - }> { - return this.postPrivate( - 'sapi/v1/simple-earn/locked/setAutoSubscribe', + getHashrateResales( + params: GetHashrateResaleListParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/mining/hash-transfer/config/details/list', params, ); } - getFlexiblePersonalLeftQuota(params: { productId: string }): Promise<{ - leftPersonalQuota: string; - }> { - return this.getPrivate( - 'sapi/v1/simple-earn/flexible/personalLeftQuota', - params, - ); + getMiners(params: GetMinerListParams): Promise { + return this.getPrivate('sapi/v1/mining/worker/list', params); } - getLockedPersonalLeftQuota(params: { projectId: string }): Promise<{ - leftPersonalQuota: string; - }> { - return this.getPrivate( - 'sapi/v1/simple-earn/locked/personalLeftQuota', - params, - ); + getMinerDetails( + params: GetMinerDetailsParams, + ): Promise { + return this.getPrivate('sapi/v1/mining/worker/detail', params); } - getFlexibleSubscriptionPreview( - params: GetFlexibleSubscriptionPreviewParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/simple-earn/flexible/subscriptionPreview', - params, - ); + getExtraBonuses( + params: GetExtraBonusListParams, + ): Promise { + return this.getPrivate('sapi/v1/mining/payment/other', params); } - getLockedSubscriptionPreview( - params: GetLockedSubscriptionPreviewParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/simple-earn/locked/subscriptionPreview', - params, - ); + getMiningEarnings( + params: GetEarningsListParams, + ): Promise { + return this.getPrivate('sapi/v1/mining/payment/list', params); } - getRateHistory(params: GetRateHistoryParams): Promise<{ - rows: GetRateHistory[]; - total: string; - }> { - return this.getPrivate( - 'sapi/v1/simple-earn/flexible/history/rateHistory', + cancelHashrateResaleConfig( + params: CancelHashrateResaleConfigParams, + ): Promise { + return this.postPrivate( + 'sapi/v1/mining/hash-transfer/config/cancel', params, ); } - getCollateralRecord(params: GetCollateralRecordParams): Promise<{ - rows: CollateralRecord[]; - total: string; - }> { + getHashrateResale( + params: GetHashrateResaleDetailParams, + ): Promise { return this.getPrivate( - 'sapi/v1/simple-earn/flexible/history/collateralRecord', + 'sapi/v1/mining/hash-transfer/profit/details', params, ); } - /** - * - * Dual Investment Endpoints - * - **/ - - getDualInvestmentProducts( - params: GetDualInvestmentProductListParams, - ): Promise<{ - total: number; - list: DualInvestmentProduct[]; - }> { - return this.getPrivate('sapi/v1/dci/product/list', params); - } - - subscribeDualInvestmentProduct( - params: SubscribeDualInvestmentProductParams, - ): Promise { - return this.postPrivate('sapi/v1/dci/product/subscribe', params); + getMiningAccountEarnings( + params: GetMiningAccountEarningParams, + ): Promise { + return this.getPrivate('sapi/v1/mining/payment/uid', params); } - getDualInvestmentPositions( - params: GetDualInvestmentPositionsParams, - ): Promise<{ - total: number; - list: DualInvestmentPosition[]; - }> { - return this.getPrivate('sapi/v1/dci/product/positions', params); + getMiningStatistics( + params: GetStatisticListParams, + ): Promise { + return this.getPrivate('sapi/v1/mining/statistics/user/status', params); } - getDualInvestmentAccounts(): Promise { - return this.getPrivate('sapi/v1/dci/product/accounts'); + submitHashrateResale(params: SubmitHashrateResaleParams): Promise { + return this.postPrivate('sapi/v1/mining/hash-transfer/config', params); } - updateAutoCompoundStatus( - params: ChangeAutoCompoundStatusParams, - ): Promise { - return this.postPrivate( - 'sapi/v1/dci/product/auto_compound/edit-status', - params, - ); + getMiningAccounts( + params: getMiningAccountsListParams, + ): Promise { + return this.getPrivate('sapi/v1/mining/statistics/user/list', params); } /** * - * Auto Invest Enpoints + * ALGO TRADING Endpoints - Future algo * **/ - getAutoInvestTargetAssets( - params: GetTargetAssetListParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/lending/auto-invest/target-asset/list', - params, - ); + submitVpNewOrder( + params: SubmitVpNewOrderParams, + ): Promise { + this.validateOrderId(params, 'clientAlgoId'); + return this.postPrivate('sapi/v1/algo/futures/newOrderVp', params); } - getAutoInvestTargetAssetsROI( - params: GetTargetAssetROIParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/lending/auto-invest/target-asset/roi/list', - params, - ); + submitTwapNewOrder( + params: SubmitTwapNewOrderParams, + ): Promise { + this.validateOrderId(params, 'clientAlgoId'); + return this.postPrivate('sapi/v1/algo/futures/newOrderTwap', params); } - getAutoInvestAssets(): Promise<{ - targetAssets: string[]; - sourceAssets: string[]; - }> { - return this.getPrivate('sapi/v1/lending/auto-invest/all/asset'); + cancelAlgoOrder(params: { + algoId: number; + }): Promise { + return this.deletePrivate('sapi/v1/algo/futures/order', params); } - getAutoInvestSourceAssets( - params: GetSourceAssetListParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/lending/auto-invest/source-asset/list', - params, - ); + getAlgoSubOrders( + params: GetAlgoSubOrdersParams, + ): Promise { + return this.getPrivate('sapi/v1/algo/futures/subOrders', params); } - submitAutoInvestmentPlan( - params: CreateInvestmentPlanParams, - ): Promise { - const { details, ...allParams } = params; - const requestParameters = { ...allParams }; - for (let i = 0; i < details.length; i++) { - requestParameters[`details[${i}].targetAsset`] = details[i].targetAsset; - requestParameters[`details[${i}].percentage`] = details[i].percentage; - } - return this.postPrivate( - 'sapi/v1/lending/auto-invest/plan/add', - requestParameters, - ); + getAlgoOpenOrders(): Promise<{ + total: number; + orders: AlgoOrder[]; + }> { + return this.getPrivate('sapi/v1/algo/futures/openOrders'); } - submitAutoInvestmentPlanOld( - params: CreateInvestmentPlanParams, - ): Promise { - return this.postPrivate('sapi/v1/lending/auto-invest/plan/add', params); + getAlgoHistoricalOrders(params: GetAlgoHistoricalOrdersParams): Promise<{ + total: number; + orders: HistoricalAlgoOrder[]; + }> { + return this.getPrivate('sapi/v1/algo/futures/historicalOrders', params); } - updateAutoInvestmentPlan( - params: EditInvestmentPlanParams, - ): Promise { - const { details, ...allParams } = params; + /** + * + * ALGO TRADING Endpoints - Spot algo + * + **/ - const requestParameters = { ...allParams }; - for (let i = 0; i < details.length; i++) { - requestParameters[`details[${i}].targetAsset`] = details[i].targetAsset; - requestParameters[`details[${i}].percentage`] = details[i].percentage; - } + submitSpotAlgoTwapOrder( + params: SubmitSpotTwapNewOrderParams, + ): Promise { + this.validateOrderId(params, 'clientAlgoId'); + return this.postPrivate('sapi/v1/algo/spot/newOrderTwap', params); + } - return this.postPrivate( - 'sapi/v1/lending/auto-invest/plan/edit', - requestParameters, - ); + cancelSpotAlgoOrder(params: { + algoId: number; + }): Promise { + return this.deletePrivate('sapi/v1/algo/spot/order', params); } - updateAutoInvestmentPlanOld( - params: EditInvestmentPlanParams, - ): Promise { - return this.postPrivate('sapi/v1/lending/auto-invest/plan/edit', params); + getSpotAlgoSubOrders( + params: GetSpotAlgoSubOrdersParams, + ): Promise { + return this.getPrivate('sapi/v1/algo/spot/subOrders', params); } - updateAutoInvestPlanStatus( - params: ChangePlanStatusParams, - ): Promise { - return this.postPrivate( - 'sapi/v1/lending/auto-invest/plan/edit-status', - params, - ); + getSpotAlgoOpenOrders(): Promise<{ + total: number; + orders: SpotAlgoOrder[]; + }> { + return this.getPrivate('sapi/v1/algo/spot/openOrders'); + } + + getSpotAlgoHistoricalOrders( + params: GetSpotAlgoHistoricalOrdersParams, + ): Promise<{ + total: number; + orders: HistoricalSpotAlgoOrder[]; + }> { + return this.getPrivate('sapi/v1/algo/spot/historicalOrders', params); } - getAutoInvestPlans(params: { - planType: 'SINGLE' | 'PORTFOLIO' | 'INDEX'; - }): Promise { - return this.getPrivate('sapi/v1/lending/auto-invest/plan/list', params); + /** + * + * CRYPTO LOAN Endpoints - Flexible rate - Market data + * + **/ + + getCryptoLoanFlexibleCollateralAssets(params: { + collateralCoin?: string; + }): Promise<{ + rows: FlexibleLoanCollateralAssetData[]; + total: number; + }> { + return this.getPrivate('sapi/v2/loan/flexible/collateral/data', params); } - getAutoInvestPlan(params: GetPlanDetailsParams): Promise { - return this.getPrivate('sapi/v1/lending/auto-invest/plan/id', params); + getCryptoLoanFlexibleAssets(params: { loanCoin?: string }): Promise<{ + rows: FlexibleLoanAssetData[]; + total: number; + }> { + return this.getPrivate('sapi/v2/loan/flexible/loanable/data', params); } - getAutoInvestSubscriptionTransactions( - params: GetSubscriptionTransactionHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/lending/auto-invest/history/list', params); + /** + * + * CRYPTO LOAN Endpoints - Flexible rate - Trade + * + **/ + + borrowCryptoLoanFlexible( + params: BorrowFlexibleLoanParams, + ): Promise { + return this.postPrivate('sapi/v2/loan/flexible/borrow', params); } - getAutoInvestIndex(params: { - indexId: number; - }): Promise { - return this.getPrivate('sapi/v1/lending/auto-invest/index/info', params); + repayCryptoLoanFlexible( + params: RepayCryptoFlexibleLoanParams, + ): Promise { + return this.postPrivate('sapi/v2/loan/flexible/repay', params); } - getAutoInvestUserIndex(params: { - indexId: number; - }): Promise { - return this.getPrivate( - 'sapi/v1/lending/auto-invest/index/user-summary', - params, - ); + adjustCryptoLoanFlexibleLTV( + params: AdjustFlexibleCryptoLoanLTVParams, + ): Promise { + return this.postPrivate('sapi/v2/loan/flexible/adjust/ltv', params); } /** - * https://developers.binance.com/docs/auto_invest/trade/One-Time-Transaction * - * @param params - * @returns - */ - submitAutoInvestOneTimeTransaction( - params: SubmitOneTimeTransactionParams, - ): Promise { - const { details, ...allParams } = params; - const requestParameters = { ...allParams }; - for (let i = 0; i < details.length; i++) { - requestParameters[`details[${i}].targetAsset`] = details[i].targetAsset; - requestParameters[`details[${i}].percentage`] = details[i].percentage; - } - - return this.postPrivate( - 'sapi/v1/lending/auto-invest/one-off', - requestParameters, - ); - } + * CRYPTO LOAN Endpoints - Flexible rate - User info + * + **/ - getOneTimeTransactionStatus( - params: GetOneTimeTransactionStatusParams, - ): Promise { + getCryptoLoanFlexibleLTVAdjustmentHistory( + params: GetFlexibleLoanLTVAdjustmentHistoryParams, + ): Promise<{ + rows: FlexibleLoanLTVAdjustmentHistory[]; + total: number; + }> { return this.getPrivate( - 'sapi/v1/lending/auto-invest/one-off/status', + 'sapi/v2/loan/flexible/ltv/adjustment/history', params, ); } - submitAutoInvestRedemption( - params: SubmitIndexLinkedPlanRedemptionParams, + getLoanFlexibleBorrowHistory( + params: GetFlexibleCryptoLoanBorrowHistoryParams, ): Promise<{ - redemptionId: number; + rows: FlexibleCryptoLoanBorrowHistory[]; + total: number; }> { - return this.postPrivate('sapi/v1/lending/auto-invest/redeem', params); + return this.getPrivate('sapi/v2/loan/flexible/borrow/history', params); } - getAutoInvestRedemptionHistory( - params: GetIndexLinkedPlanRedemptionHistoryParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/lending/auto-invest/redeem/history', - params, - ); + getCryptoLoanFlexibleOngoingOrders( + params: GetFlexibleLoanOngoingOrdersParams, + ): Promise<{ + rows: FlexibleLoanOngoingOrder[]; + total: number; + }> { + return this.getPrivate('sapi/v2/loan/flexible/ongoing/orders', params); } - getAutoInvestRebalanceHistory( - params: GetIndexLinkedPlanRebalanceHistoryParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/lending/auto-invest/rebalance/history', - params, - ); + getLoanFlexibleRepaymentHistory( + params: GetLoanRepaymentHistoryParams, + ): Promise<{ + rows: LoanRepaymentHistory[]; + total: number; + }> { + return this.getPrivate('sapi/v2/loan/flexible/repay/history', params); } /** * - * Staking Endpoints + * CRYPTO LOAN Endpoints - Stable rate - Market data * **/ - /** - * @deprecated as of 2024-01-19 - */ - getStakingProducts( - params: StakingBasicParams & { - asset?: string; - }, - ): Promise { - return this.getPrivate(`sapi/v1/staking/productList`, params); + getCryptoLoanLoanableAssets(params: GetLoanableAssetsDataParams): Promise<{ + rows: LoanableAssetData[]; + total: number; + }> { + return this.getPrivate('sapi/v1/loan/loanable/data', params); } - /** - * @deprecated as of 2024-01-19 - */ - getStakingProductPosition( - params: StakingBasicParams & { - productId?: string; - asset?: string; - }, - ): Promise { - return this.getPrivate('sapi/v1/staking/position', params); + getCryptoLoanCollateralRepayRate( + params: CheckCollateralRepayRateParams, + ): Promise { + return this.getPrivate('sapi/v1/loan/repay/collateral/rate', params); } - /** - * @deprecated as of 2024-01-19 - */ - getStakingHistory(params: StakingHistoryParams): Promise { - return this.getPrivate('sapi/v1/staking/stakingRecord', params); + getCryptoLoanCollateralAssetsData( + params: GetCollateralAssetDataParams, + ): Promise<{ + rows: CollateralAssetData[]; + total: number; + }> { + return this.getPrivate('sapi/v1/loan/collateral/data', params); } - /** - * @deprecated as of 2024-01-19 - */ - getPersonalLeftQuotaOfStakingProduct(params: { - product: StakingProductType; - productId: string; - }): Promise { - return this.getPrivate('sapi/v1/staking/personalLeftQuota', params); + getCryptoLoansIncomeHistory( + params: GetCryptoLoansIncomeHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/loan/income', params); } - subscribeEthStakingV1(params: { amount: number }): Promise<{ - success: boolean; - }> { - return this.postPrivate('sapi/v1/eth-staking/eth/stake', params); + /** + * + * CRYPTO LOAN Endpoints - Stable rate - Trade + * + **/ + + borrowCryptoLoan( + params: BorrowCryptoLoanParams, + ): Promise { + return this.postPrivate('sapi/v1/loan/borrow', params); } - subscribeEthStakingV2(params: { - amount: number; - }): Promise { - return this.postPrivate('sapi/v2/eth-staking/eth/stake', params); + repayCryptoLoan( + params: RepayCryptoLoanParams, + ): Promise { + return this.postPrivate('sapi/v1/loan/repay', params); } - redeemEth(params: RedeemEthParams): Promise { - return this.postPrivate('sapi/v1/eth-staking/eth/redeem', params); + adjustCryptoLoanLTV( + params: AdjustCryptoLoanLTVParams, + ): Promise { + return this.postPrivate('sapi/v1/loan/adjust/ltv', params); } - getEthStakingHistory(params: GetEthStakingHistoryParams): Promise<{ - rows: EthStakingHistory[]; + customizeCryptoLoanMarginCall(params: CustomizeMarginCallParams): Promise<{ + rows: CustomizeMarginCall[]; total: number; }> { - return this.getPrivate( - 'sapi/v1/eth-staking/eth/history/stakingHistory', - params, - ); + return this.postPrivate('sapi/v1/loan/customize/margin_call', params); } - getEthRedemptionHistory(params: GetEthRedemptionHistoryParams): Promise<{ - rows: EthRedemptionHistory[]; + /** + * + * CRYPTO LOAN Endpoints - Stable rate - User info + * + **/ + + getCryptoLoanOngoingOrders(params: GetLoanOngoingOrdersParams): Promise<{ + rows: LoanOngoingOrder[]; total: number; }> { - return this.getPrivate( - 'sapi/v1/eth-staking/eth/history/redemptionHistory', - params, - ); + return this.getPrivate('sapi/v1/loan/ongoing/orders', params); } - getBethRewardsHistory(params: GetBethRewardsHistoryParams): Promise<{ - rows: BethRewardsHistory[]; + getCryptoLoanBorrowHistory(params: GetLoanBorrowHistoryParams): Promise<{ + rows: LoanBorrowHistory[]; total: number; }> { - return this.getPrivate( - 'sapi/v1/eth-staking/eth/history/rewardsHistory', - params, - ); + return this.getPrivate('sapi/v1/loan/borrow/history', params); } - getEthStakingQuota(): Promise { - return this.getPrivate('sapi/v1/eth-staking/eth/quota'); + getCryptoLoanLTVAdjustmentHistory( + params: GetLoanLTVAdjustmentHistoryParams, + ): Promise<{ + rows: LoanLTVAdjustmentHistory[]; + total: number; + }> { + return this.getPrivate('sapi/v1/loan/ltv/adjustment/history', params); } - getEthRateHistory(params: GetETHRateHistoryParams): Promise<{ - rows: ETHRateHistory[]; - total: string; - }> { - return this.getPrivate( - 'sapi/v1/eth-staking/eth/history/rateHistory', - params, - ); + getCryptoLoanRepaymentHistory( + params: GetLoanRepaymentHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/loan/repay/history', params); } - getEthStakingAccount(): Promise { - return this.getPrivate('sapi/v1/eth-staking/account'); + /** + * + * SIMPLE EARN Endpoints - Account + * + **/ + + getSimpleEarnAccount(): Promise { + return this.getPrivate(`/sapi/v1/simple-earn/account`); } - getEthStakingAccountV2(): Promise { - return this.getPrivate('sapi/v2/eth-staking/account'); + getFlexibleSavingProducts(params?: SimpleEarnProductListParams): Promise<{ + rows: SimpleEarnFlexibleProduct[]; + total: number; + }> { + return this.getPrivate(`/sapi/v1/simple-earn/flexible/list`, params); } - wrapBeth(params: { amount: number }): Promise { - return this.postPrivate('sapi/v1/eth-staking/wbeth/wrap', params); + getSimpleEarnLockedProductList( + params?: SimpleEarnProductListParams, + ): Promise<{ + rows: SimpleEarnLockedProduct[]; + total: number; + }> { + return this.getPrivate(`/sapi/v1/simple-earn/locked/list`, params); } - getBethWrapHistory(params: GetWrapHistoryParams): Promise<{ - rows: WrapHistory[]; + getFlexibleProductPosition( + params?: SimpleEarnFlexibleProductPositionParams, + ): Promise<{ + rows: any[]; total: number; }> { - return this.getPrivate( - 'sapi/v1/eth-staking/wbeth/history/wrapHistory', - params, - ); + return this.getPrivate(`/sapi/v1/simple-earn/flexible/position`, params); } - getBethUnwrapHistory(params: GetWrapHistoryParams): Promise<{ - rows: WrapHistory[]; + getLockedProductPosition( + params?: SimpleEarnLockedProductPositionParams, + ): Promise<{ + rows: SimpleEarnLockedProductPosition[]; total: number; + }> { + return this.getPrivate(`/sapi/v1/simple-earn/locked/position`, params); + } + + getFlexiblePersonalLeftQuota(params: { productId: string }): Promise<{ + leftPersonalQuota: string; }> { return this.getPrivate( - 'sapi/v1/eth-staking/wbeth/history/unwrapHistory', + 'sapi/v1/simple-earn/flexible/personalLeftQuota', params, ); } - getWbethRewardsHistory( - params: GetWrapHistoryParams, - ): Promise { + getLockedPersonalLeftQuota(params: { projectId: string }): Promise<{ + leftPersonalQuota: string; + }> { return this.getPrivate( - 'sapi/v1/eth-staking/eth/history/wbethRewardsHistory', + 'sapi/v1/simple-earn/locked/personalLeftQuota', params, ); } /** * - * Savings Endpoints - * @deprecated as of 2023-06-22, now Simple Earn + * SIMPLE EARN Endpoints - Earn + * **/ - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - getLeftDailyPurchaseQuotaFlexibleProduct(params: { - productId: string; - }): Promise { - return this.getPrivate(`sapi/v1/lending/daily/userLeftQuota`, params); - } - - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - getLeftDailyRedemptionQuotaFlexibleProduct(params: { - productId: string; - }): Promise< - LeftDailyPurchaseQuotaFlexibleProductResponse & { - dailyQuota: string; - minRedemptionAmount: string; - } - > { - return this.getPrivate(`sapi/v1/lending/daily/userRedemptionQuota`, params); + purchaseFlexibleProduct( + params: SimpleEarnSubscribeProductParams, + ): Promise { + return this.postPrivate(`/sapi/v1/simple-earn/flexible/subscribe`, params); } - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - purchaseFixedAndActivityProject(params: { - projectId: string; - lot: number; - }): Promise { - return this.postPrivate(`sapi/v1/lending/customizedFixed/purchase`, params); + subscribeSimpleEarnLockedProduct( + params: SimpleEarnSubscribeProductParams, + ): Promise { + return this.postPrivate(`/sapi/v1/simple-earn/locked/subscribe`, params); } - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - getFixedAndActivityProjects( - params: FixedAndActivityProjectParams, - ): Promise { - return this.getPrivate(`sapi/v1/lending/project/list`, params); + redeemFlexibleProduct(params: { + positionId: string; + }): Promise { + return this.postPrivate(`/sapi/v1/simple-earn/flexible/redeem`, params); } - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - getFixedAndActivityProductPosition( - params: FixedAndActivityProjectPositionParams, - ): Promise { - return this.getPrivate(`sapi/v1/lending/project/position/list`, params); + redeemLockedProduct(params: { + positionId: string; + }): Promise { + return this.postPrivate(`/sapi/v1/simple-earn/locked/redeem`, params); } - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - getLendingAccount(): Promise { - return this.getPrivate(`sapi/v1/lending/union/account`); + setFlexibleAutoSubscribe(params: SetAutoSubscribeParams): Promise<{ + success: boolean; + }> { + return this.postPrivate( + 'sapi/v1/simple-earn/flexible/setAutoSubscribe', + params, + ); } - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - getPurchaseRecord(params: PurchaseRecordParams): Promise { - return this.getPrivate(`sapi/v1/lending/union/purchaseRecord`, params); + setLockedAutoSubscribe(params: SetAutoSubscribeParams): Promise<{ + success: boolean; + }> { + return this.postPrivate( + 'sapi/v1/simple-earn/locked/setAutoSubscribe', + params, + ); } - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - getRedemptionRecord(params: PurchaseRecordParams): Promise { - return this.getPrivate(`sapi/v1/lending/union/redemptionRecord`, params); + getFlexibleSubscriptionPreview( + params: GetFlexibleSubscriptionPreviewParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/simple-earn/flexible/subscriptionPreview', + params, + ); } - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - getInterestHistory(params: PurchaseRecordParams): Promise { - return this.getPrivate(`sapi/v1/lending/union/interestHistory`, params); + getLockedSubscriptionPreview( + params: GetLockedSubscriptionPreviewParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/simple-earn/locked/subscriptionPreview', + params, + ); } - /** - * @deprecated as of 2023-06-22, now Simple Earn - */ - changeFixedAndActivityPositionToDailyPosition(params: { - projectId: string; - lot: number; - positionId?: number; - }): Promise { - return this.postPrivate(`sapi/v1/lending/positionChanged`, params); + setLockedProductRedeemOption(params: { + positionId: string; + redeemTo: 'SPOT' | 'FLEXIBLE'; + }): Promise<{ + success: boolean; + }> { + return this.postPrivate( + 'sapi/v1/simple-earn/locked/setRedeemOption', + params, + ); } /** * - * Mining Endpoints + * SIMPLE EARN Endpoints - History * **/ - getMiningAlgos(): Promise { - return this.get('sapi/v1/mining/pub/algoList'); - } - - getMiningCoins(): Promise { - return this.get('sapi/v1/mining/pub/coinList'); + getFlexibleSubscriptionRecord( + params: GetFlexibleSubscriptionRecordParams, + ): Promise<{ + rows: GetFlexibleSubscriptionRecordResponse[]; + total: number; + }> { + return this.getPrivate( + 'sapi/v1/simple-earn/flexible/history/subscriptionRecord', + params, + ); } - getMinerDetails( - params: GetMinerDetailsParams, - ): Promise { - return this.getPrivate('sapi/v1/mining/worker/detail', params); + getLockedSubscriptionRecord( + params: GetLockedSubscriptionRecordParams, + ): Promise<{ + rows: LockedSubscriptionRecord[]; + total: number; + }> { + return this.getPrivate( + 'sapi/v1/simple-earn/locked/history/subscriptionRecord', + params, + ); } - getMiners(params: GetMinerListParams): Promise { - return this.getPrivate('sapi/v1/mining/worker/list', params); + getFlexibleRedemptionRecord( + params: GetFlexibleRedemptionRecordParams, + ): Promise<{ + rows: FlexibleRedemptionRecord[]; + total: number; + }> { + return this.getPrivate( + 'sapi/v1/simple-earn/flexible/history/redemptionRecord', + params, + ); } - getMiningEarnings( - params: GetEarningsListParams, - ): Promise { - return this.getPrivate('sapi/v1/mining/payment/list', params); + getLockedRedemptionRecord(params: GetLockedRedemptionRecordParams): Promise<{ + rows: LockedRedemptionRecord[]; + total: number; + }> { + return this.getPrivate( + 'sapi/v1/simple-earn/locked/history/redemptionRecord', + params, + ); } - getExtraBonuses( - params: GetExtraBonusListParams, - ): Promise { - return this.getPrivate('sapi/v1/mining/payment/other', params); + getFlexibleRewardsHistory(params: GetFlexibleRewardsHistoryParams): Promise<{ + rows: FlexibleRewardsHistory[]; + total: number; + }> { + return this.getPrivate( + 'sapi/v1/simple-earn/flexible/history/rewardsRecord', + params, + ); } - getHashrateResales( - params: GetHashrateResaleListParams, - ): Promise { + getLockedRewardsHistory(params: GetLockedRewardsHistoryParams): Promise<{ + rows: GetLockedRewardsHistory[]; + total: number; + }> { return this.getPrivate( - 'sapi/v1/mining/hash-transfer/config/details/list', + 'sapi/v1/simple-earn/locked/history/rewardsRecord', params, ); } - getHashrateResale( - params: GetHashrateResaleDetailParams, - ): Promise { + getCollateralRecord(params: GetCollateralRecordParams): Promise<{ + rows: CollateralRecord[]; + total: string; + }> { return this.getPrivate( - 'sapi/v1/mining/hash-transfer/profit/details', + 'sapi/v1/simple-earn/flexible/history/collateralRecord', params, ); } - submitHashrateResale(params: SubmitHashrateResaleParams): Promise { - return this.postPrivate('sapi/v1/mining/hash-transfer/config', params); - } - - cancelHashrateResaleConfig( - params: CancelHashrateResaleConfigParams, - ): Promise { - return this.postPrivate( - 'sapi/v1/mining/hash-transfer/config/cancel', + getRateHistory(params: GetRateHistoryParams): Promise<{ + rows: GetRateHistory[]; + total: string; + }> { + return this.getPrivate( + 'sapi/v1/simple-earn/flexible/history/rateHistory', params, ); } - getMiningStatistics( - params: GetStatisticListParams, - ): Promise { - return this.getPrivate('sapi/v1/mining/statistics/user/status', params); - } - - getMiningAccounts( - params: getMiningAccountsListParams, - ): Promise { - return this.getPrivate('sapi/v1/mining/statistics/user/list', params); - } - - getMiningAccountEarnings( - params: GetMiningAccountEarningParams, - ): Promise { - return this.getPrivate('sapi/v1/mining/payment/uid', params); - } - /** * - * Futures Management Endpoints: - * https://binance-docs.github.io/apidocs/spot/en/#futures - * - * Note: to trade futures use the usdm-client or coinm-client. - * MainClient only has the futures endpoints listed in the "spot" docs category, primarily used for transfers. + * VIP LOAN Endpoints - Market Data * **/ - /** - * Execute transfer between spot account and futures account. - * - * Type: - * - 1: transfer from spot account to USDT-Ⓜ futures account. - * - 2: transfer from USDT-Ⓜ futures account to spot account. - * - 3: transfer from spot account to COIN-Ⓜ futures account. - * - 4: transfer from COIN-Ⓜ futures account to spot account. - */ - submitNewFutureAccountTransfer( - params: NewFutureAccountTransferParams, - ): Promise<{ tranId: number }> { - return this.postPrivate(`sapi/v1/futures/transfer`, params); - } - - getFutureAccountTransferHistory( - params: GetFutureAccountTransferHistoryParams, - ): Promise> { - return this.getPrivate(`sapi/v1/futures/transfer`, params); + getVipBorrowInterestRate(params: { + loanCoin: string; + }): Promise { + return this.getPrivate('sapi/v1/loan/vip/request/interestRate', params); } - getFuturesTickLevelOrderbookDataLink( - params: GetFutureTickLevelOrderbookDataLinkParams, - ): Promise<{ - data: HistoricalDataLink[]; + getVipLoanableAssets(params: GetLoanableAssetsDataParams): Promise<{ + rows: LoanableAssetData[]; + total: number; }> { - return this.getPrivate('sapi/v1/futures/histDataLink', params); + return this.getPrivate('sapi/v1/loan/vip/loanable/data', params); } - /** - * @deprecated as of 2023-09-25 - */ - getCrossCollateralBorrowHistory(params?: CoinStartEndLimit): Promise { - return this.getPrivate(`sapi/v1/futures/loan/borrow/history`, params); - } - /** - * @deprecated as of 2023-09-25 - */ - getCrossCollateralRepaymentHistory(params?: CoinStartEndLimit): Promise { - return this.getPrivate(`sapi/v1/futures/loan/repay/history`, params); - } - /** - * @deprecated as of 2023-09-25 - */ - getCrossCollateralWalletV2(): Promise { - return this.getPrivate(`sapi/v2/futures/loan/wallet`); - } - /** - * @deprecated as of 2023-09-25 - */ - getAdjustCrossCollateralLTVHistory( - params?: GetLoanCoinPaginatedHistoryParams, - ): Promise { - return this.getPrivate( - `sapi/v1/futures/loan/adjustCollateral/history`, - params, - ); - } - /** - * @deprecated as of 2023-09-25 - */ - getCrossCollateralLiquidationHistory( - params?: GetLoanCoinPaginatedHistoryParams, - ): Promise { - return this.getPrivate(`sapi/v1/futures/loan/liquidationHistory`, params); - } - /** - * @deprecated as of 2023-09-25 - */ - getCrossCollateralInterestHistory( - params?: GetLoanCoinPaginatedHistoryParams, - ): Promise { - return this.getPrivate(`sapi/v1/futures/loan/interestHistory`, params); + getVipCollateralAssets(params: { collateralCoin?: string }): Promise<{ + rows: CollateralAssetData[]; + total: number; + }> { + return this.getPrivate('sapi/v1/loan/vip/collateral/data', params); } /** * - * Futures Algo Endpoints + * VIP LOAN Endpoints - User Info * **/ - submitVpNewOrder( - params: SubmitVpNewOrderParams, - ): Promise { - this.validateOrderId(params, 'clientAlgoId'); - return this.postPrivate('sapi/v1/algo/futures/newOrderVp', params); - } - - submitTwapNewOrder( - params: SubmitTwapNewOrderParams, - ): Promise { - this.validateOrderId(params, 'clientAlgoId'); - return this.postPrivate('sapi/v1/algo/futures/newOrderTwap', params); - } - - cancelAlgoOrder(params: { - algoId: number; - }): Promise { - return this.deletePrivate('sapi/v1/algo/futures/order', params); + getVipLoanOpenOrders(params: GetVipLoanOngoingOrdersParams): Promise<{ + rows: VipOngoingOrder[]; + total: number; + }> { + return this.getPrivate('sapi/v1/loan/vip/ongoing/orders', params); } - getAlgoOpenOrders(): Promise<{ + getVipLoanRepaymentHistory( + params: GetVipLoanRepaymentHistoryParams, + ): Promise<{ + rows: VipLoanRepaymentHistory[]; total: number; - orders: AlgoOrder[]; }> { - return this.getPrivate('sapi/v1/algo/futures/openOrders'); + return this.getPrivate('sapi/v1/loan/vip/repay/history', params); } - getAlgoHistoricalOrders(params: GetAlgoHistoricalOrdersParams): Promise<{ + checkVipCollateralAccount(params: CheckVipCollateralAccountParams): Promise<{ + rows: VipCollateralAccount[]; total: number; - orders: HistoricalAlgoOrder[]; }> { - return this.getPrivate('sapi/v1/algo/futures/historicalOrders', params); + return this.getPrivate('sapi/v1/loan/vip/collateral/account', params); } - getAlgoSubOrders( - params: GetAlgoSubOrdersParams, - ): Promise { - return this.getPrivate('sapi/v1/algo/futures/subOrders', params); + getVipApplicationStatus(params: GetApplicationStatusParams): Promise<{ + rows: ApplicationStatus[]; + total: number; + }> { + return this.getPrivate('sapi/v1/loan/vip/request/data', params); } /** * - * Spot Algo Endpoints + * VIP LOAN Endpoints - Trade * **/ - submitSpotAlgoTwapOrder( - params: SubmitSpotTwapNewOrderParams, - ): Promise { - this.validateOrderId(params, 'clientAlgoId'); - return this.postPrivate('sapi/v1/algo/spot/newOrderTwap', params); + renewVipLoan(params: VipLoanRenewParams): Promise { + return this.postPrivate('sapi/v1/loan/vip/renew', params); } - cancelSpotAlgoOrder(params: { - algoId: number; - }): Promise { - return this.deletePrivate('sapi/v1/algo/spot/order', params); + repayVipLoan(params: VipLoanRepayParams): Promise { + return this.postPrivate('sapi/v1/loan/vip/repay', params); } - getSpotAlgoOpenOrders(): Promise<{ - total: number; - orders: SpotAlgoOrder[]; - }> { - return this.getPrivate('sapi/v1/algo/spot/openOrders'); + borrowVipLoan(params: VipLoanBorrowParams): Promise { + return this.postPrivate('sapi/v1/loan/vip/borrow', params); } - getSpotAlgoHistoricalOrders( - params: GetSpotAlgoHistoricalOrdersParams, + /** + * + * DUAL INVESTMENT Endpoints - Market Data + * + **/ + + getDualInvestmentProducts( + params: GetDualInvestmentProductListParams, ): Promise<{ total: number; - orders: HistoricalSpotAlgoOrder[]; + list: DualInvestmentProduct[]; }> { - return this.getPrivate('sapi/v1/algo/spot/historicalOrders', params); - } - - getSpotAlgoSubOrders( - params: GetSpotAlgoSubOrdersParams, - ): Promise { - return this.getPrivate('sapi/v1/algo/spot/subOrders', params); + return this.getPrivate('sapi/v1/dci/product/list', params); } /** * - * Portfolio Margin Pro + * DUAL INVESTMENT Endpoints - Trade * **/ - getPortfolioMarginProAccountInfo(): Promise { - return this.getPrivate('sapi/v1/portfolio/account'); - } - - getPortfolioMarginProCollateralRate(): Promise< - GetPortfolioMarginProCollateralRateResponse[] - > { - return this.get('sapi/v1/portfolio/collateralRate'); - } - - getPortfolioMarginProBankruptcyLoanAmount(): Promise { - return this.getPrivate('sapi/v1/portfolio/pmLoan'); + subscribeDualInvestmentProduct( + params: SubscribeDualInvestmentProductParams, + ): Promise { + return this.postPrivate('sapi/v1/dci/product/subscribe', params); } - repayPortfolioMarginProBankruptcyLoan(params: { - from?: 'SPOT' | 'MARGIN'; - }): Promise<{ - tranId: number; + getDualInvestmentPositions( + params: GetDualInvestmentPositionsParams, + ): Promise<{ + total: number; + list: DualInvestmentPosition[]; }> { - return this.postPrivate('sapi/v1/portfolio/repay', params); + return this.getPrivate('sapi/v1/dci/product/positions', params); } - getPortfolioMarginProInterestHistory( - params: GetPortfolioMarginProInterestHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/portfolio/interest-history', params); + getDualInvestmentAccounts(): Promise { + return this.getPrivate('sapi/v1/dci/product/accounts'); } - getPortfolioMarginIndexPrice(params?: { - asset?: string; - }): Promise { - return this.get('sapi/v1/portfolio/asset-index-price', params); + updateAutoCompoundStatus( + params: ChangeAutoCompoundStatusParams, + ): Promise { + return this.postPrivate( + 'sapi/v1/dci/product/auto_compound/edit-status', + params, + ); } - submitPortfolioMarginProFullTransfer(): Promise<{ - msg: string; - }> { - return this.postPrivate('sapi/v1/portfolio/auto-collection'); - } + /** + * + * GIFT CARD Endpoints - Market Data + * + **/ - submitPortfolioMarginProSpecificTransfer(params: { asset: string }): Promise<{ - msg: string; - }> { - return this.postPrivate('sapi/v1/portfolio/asset-collection', params); + createGiftCard(params: CreateGiftCardParams): Promise { + return this.postPrivate('sapi/v1/giftcard/createCode', params); } - bnbTransfer(params: BnbTransferParams): Promise<{ - tranId: number; - }> { - return this.postPrivate('sapi/v1/portfolio/bnb-transfer', params); + createDualTokenGiftCard(params: CreateDualTokenGiftCardParams): Promise { + return this.postPrivate('sapi/v1/giftcard/buyCode', params); } - updateAutoRepayFuturesStatus(params: { autoRepay: string }): Promise<{ - msg: string; - }> { - return this.postPrivate('sapi/v1/portfolio/repay-futures-switch', params); + redeemGiftCard(params: RedeemGiftCardParams): Promise { + return this.postPrivate('sapi/v1/giftcard/redeemCode', params); } - getAutoRepayFuturesStatus(): Promise<{ - autoRepay: boolean; - }> { - return this.getPrivate('sapi/v1/portfolio/repay-futures-switch'); + verifyGiftCard(params: { referenceNo: string }): Promise { + return this.getPrivate('sapi/v1/giftcard/verify', params); } - repayFuturesNegativeBalance(): Promise<{ - msg: string; - }> { - return this.postPrivate('sapi/v1/portfolio/repay-futures-negative-balance'); + getTokenLimit(params: { baseToken: string }): Promise { + return this.getPrivate('sapi/v1/giftcard/buyCode/token-limit', params); } - getPortfolioMarginAssetLeverage(): Promise< - GetPortfolioMarginAssetLeverageResponse[] - > { - return this.getPrivate('sapi/v1/portfolio/margin-asset-leverage'); + getRsaPublicKey(): Promise { + return this.getPrivate('sapi/v1/giftcard/cryptography/rsa-public-key'); } /** * - * BLVT Endpoints + * NFT Endpoints - REST api * **/ - getBlvtInfo(params?: { tokenName?: string }): Promise { - return this.get('sapi/v1/blvt/tokenInfo', params); + getNftTransactionHistory(params: GetNftTransactionHistoryParams): Promise<{ + total: number; + list: NftTransaction[]; + }> { + return this.getPrivate('sapi/v1/nft/history/transactions', params); } - subscribeBlvt(params: SubscribeBlvtParams): Promise { - return this.postPrivate('sapi/v1/blvt/subscribe', params); + getNftDepositHistory(params: GetNftDepositHistoryParams): Promise<{ + total: number; + list: NftDeposit[]; + }> { + return this.getPrivate('sapi/v1/nft/history/deposit', params); } - getBlvtSubscriptionRecord( - params: GetBlvtSubscriptionRecordParams, - ): Promise { - return this.getPrivate('sapi/v1/blvt/subscribe/record', params); + getNftWithdrawHistory(params: GetNftWithdrawHistoryParams): Promise<{ + total: number; + list: NftWithdraw[]; + }> { + return this.getPrivate('sapi/v1/nft/history/withdraw', params); } - redeemBlvt(params: RedeemBlvtParams): Promise { - return this.postPrivate('sapi/v1/blvt/redeem', params); + getNftAsset(params: GetNftAssetParams): Promise<{ + total: number; + list: NftAsset[]; + }> { + return this.getPrivate('sapi/v1/nft/user/getAsset', params); } - getBlvtRedemptionRecord( - params: GetBlvtRedemptionRecordParams, - ): Promise { - return this.getPrivate('sapi/v1/blvt/redeem/record', params); - } + /** + * + * C2C Endpoints + * + **/ - getBlvtUserLimitInfo(params: { - tokenName?: string; - }): Promise { - return this.getPrivate('sapi/v1/blvt/userLimit', params); + getC2CTradeHistory( + params: GetC2CTradeHistoryParams, + ): Promise { + return this.getPrivate( + 'sapi/v1/c2c/orderMatch/listUserOrderHistory', + params, + ); } /** * - * Fiat Endpoints + * FIAT Endpoints - REST api * **/ @@ -2923,394 +3030,504 @@ export class MainClient extends BaseRestClient { /** * - * C2C Endpoints + * Rebate Endpoints * **/ - getC2CTradeHistory( - params: GetC2CTradeHistoryParams, - ): Promise { - return this.getPrivate( - 'sapi/v1/c2c/orderMatch/listUserOrderHistory', - params, - ); + getSpotRebateHistoryRecords( + params: GetSpotRebateHistoryRecordsParams, + ): Promise { + return this.getPrivate('sapi/v1/rebate/taxQuery', params); } /** * - * VIP Loans Endpoints + * DERIVATIVES - Portfolio Margin Pro - Market Data + * This is in mainclient because it shares the same base url * **/ - getVipLoanOpenOrders(params: GetVipLoanOngoingOrdersParams): Promise<{ - rows: VipOngoingOrder[]; - total: number; - }> { - return this.getPrivate('sapi/v1/loan/vip/ongoing/orders', params); + getPortfolioMarginIndexPrice(params?: { + asset?: string; + }): Promise { + return this.get('sapi/v1/portfolio/asset-index-price', params); } - repayVipLoan(params: VipLoanRepayParams): Promise { - return this.postPrivate('sapi/v1/loan/vip/repay', params); + getPortfolioMarginAssetLeverage(): Promise< + GetPortfolioMarginAssetLeverageResponse[] + > { + return this.getPrivate('sapi/v1/portfolio/margin-asset-leverage'); } - getVipLoanRepaymentHistory( - params: GetVipLoanRepaymentHistoryParams, - ): Promise<{ - rows: VipLoanRepaymentHistory[]; - total: number; + /** + * + * DERIVATIVES - Portfolio Margin Pro - Account + * This is in mainclient because it shares the same base url + * + **/ + + getPortfolioMarginProCollateralRate(): Promise< + GetPortfolioMarginProCollateralRateResponse[] + > { + return this.get('sapi/v1/portfolio/collateralRate'); + } + + getPortfolioMarginProAccountInfo(): Promise { + return this.getPrivate('sapi/v1/portfolio/account'); + } + + bnbTransfer(params: BnbTransferParams): Promise<{ + tranId: number; }> { - return this.getPrivate('sapi/v1/loan/vip/repay/history', params); + return this.postPrivate('sapi/v1/portfolio/bnb-transfer', params); } - renewVipLoan(params: VipLoanRenewParams): Promise { - return this.postPrivate('sapi/v1/loan/vip/renew', params); + submitPortfolioMarginProFullTransfer(): Promise<{ + msg: string; + }> { + return this.postPrivate('sapi/v1/portfolio/auto-collection'); } - checkVipCollateralAccount(params: CheckVipCollateralAccountParams): Promise<{ - rows: VipCollateralAccount[]; - total: number; + submitPortfolioMarginProSpecificTransfer(params: { asset: string }): Promise<{ + msg: string; }> { - return this.getPrivate('sapi/v1/loan/vip/collateral/account', params); + return this.postPrivate('sapi/v1/portfolio/asset-collection', params); } - borrowVipLoan(params: VipLoanBorrowParams): Promise { - return this.postPrivate('sapi/v1/loan/vip/borrow', params); + repayPortfolioMarginProBankruptcyLoan(params: { + from?: 'SPOT' | 'MARGIN'; + }): Promise<{ + tranId: number; + }> { + return this.postPrivate('sapi/v1/portfolio/repay', params); } - getVipLoanableAssets(params: GetLoanableAssetsDataParams): Promise<{ - rows: LoanableAssetData[]; - total: number; + getPortfolioMarginProBankruptcyLoanAmount(): Promise { + return this.getPrivate('sapi/v1/portfolio/pmLoan'); + } + + repayFuturesNegativeBalance(): Promise<{ + msg: string; }> { - return this.getPrivate('sapi/v1/loan/vip/loanable/data', params); + return this.postPrivate('sapi/v1/portfolio/repay-futures-negative-balance'); } - getVipCollateralAssets(params: { collateralCoin?: string }): Promise<{ - rows: CollateralAssetData[]; - total: number; + updateAutoRepayFuturesStatus(params: { autoRepay: string }): Promise<{ + msg: string; }> { - return this.getPrivate('sapi/v1/loan/vip/collateral/data', params); + return this.postPrivate('sapi/v1/portfolio/repay-futures-switch', params); } - getVipApplicationStatus(params: GetApplicationStatusParams): Promise<{ - rows: ApplicationStatus[]; - total: number; + getAutoRepayFuturesStatus(): Promise<{ + autoRepay: boolean; }> { - return this.getPrivate('sapi/v1/loan/vip/request/data', params); + return this.getPrivate('sapi/v1/portfolio/repay-futures-switch'); } - getVipBorrowInterestRate(params: { - loanCoin: string; - }): Promise { - return this.getPrivate('sapi/v1/loan/vip/request/interestRate', params); + getPortfolioMarginProInterestHistory( + params: GetPortfolioMarginProInterestHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/portfolio/interest-history', params); } /** * - * Crypto Loans Endpoints + * DERIVATIVES - Futures Data - Market + * This is in mainclient because it shares the same base url * **/ - getCryptoLoansIncomeHistory( - params: GetCryptoLoansIncomeHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/loan/income', params); + getFuturesTickLevelOrderbookDataLink( + params: GetFutureTickLevelOrderbookDataLinkParams, + ): Promise<{ + data: HistoricalDataLink[]; + }> { + return this.getPrivate('sapi/v1/futures/histDataLink', params); } - borrowCryptoLoan( - params: BorrowCryptoLoanParams, - ): Promise { - return this.postPrivate('sapi/v1/loan/borrow', params); + /** + * + * BLVT Endpoints + * BLVT category is possibly @deprecated, found only in old docs + **/ + + getBlvtInfo(params?: { tokenName?: string }): Promise { + return this.get('sapi/v1/blvt/tokenInfo', params); } - getCryptoLoanBorrowHistory(params: GetLoanBorrowHistoryParams): Promise<{ - rows: LoanBorrowHistory[]; - total: number; - }> { - return this.getPrivate('sapi/v1/loan/borrow/history', params); + subscribeBlvt(params: SubscribeBlvtParams): Promise { + return this.postPrivate('sapi/v1/blvt/subscribe', params); } - getCryptoLoanOngoingOrders(params: GetLoanOngoingOrdersParams): Promise<{ - rows: LoanOngoingOrder[]; - total: number; - }> { - return this.getPrivate('sapi/v1/loan/ongoing/orders', params); + getBlvtSubscriptionRecord( + params: GetBlvtSubscriptionRecordParams, + ): Promise { + return this.getPrivate('sapi/v1/blvt/subscribe/record', params); } - repayCryptoLoan( - params: RepayCryptoLoanParams, - ): Promise { - return this.postPrivate('sapi/v1/loan/repay', params); + redeemBlvt(params: RedeemBlvtParams): Promise { + return this.postPrivate('sapi/v1/blvt/redeem', params); + } + + getBlvtRedemptionRecord( + params: GetBlvtRedemptionRecordParams, + ): Promise { + return this.getPrivate('sapi/v1/blvt/redeem/record', params); } - getCryptoLoanRepaymentHistory( - params: GetLoanRepaymentHistoryParams, - ): Promise { - return this.getPrivate('sapi/v1/loan/repay/history', params); + getBlvtUserLimitInfo(params: { + tokenName?: string; + }): Promise { + return this.getPrivate('sapi/v1/blvt/userLimit', params); } - adjustCryptoLoanLTV( - params: AdjustCryptoLoanLTVParams, - ): Promise { - return this.postPrivate('sapi/v1/loan/adjust/ltv', params); + /** + * + * Pay endpoints + * Found only in old docs, possibly @deprecated + **/ + getPayTransactions(params: GetPayTradeHistoryParams): Promise { + return this.getPrivate('sapi/v1/pay/transactions', params); } - getCryptoLoanLTVAdjustmentHistory( - params: GetLoanLTVAdjustmentHistoryParams, - ): Promise<{ - rows: LoanLTVAdjustmentHistory[]; - total: number; - }> { - return this.getPrivate('sapi/v1/loan/ltv/adjustment/history', params); + /** + * + * EXCHANGE LINK - Account Endpoints + * https://developers.binance.com/docs/binance_link + */ + + createBrokerSubAccount( + params: CreateBrokerSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/subAccount', params); } - getCryptoLoanLoanableAssets(params: GetLoanableAssetsDataParams): Promise<{ - rows: LoanableAssetData[]; - total: number; - }> { - return this.getPrivate('sapi/v1/loan/loanable/data', params); + getBrokerSubAccount( + params: GetBrokerSubAccountParams, + ): Promise { + return this.getPrivate('sapi/v1/broker/subAccount', params); } - getCryptoLoanCollateralAssetsData( - params: GetCollateralAssetDataParams, - ): Promise<{ - rows: CollateralAssetData[]; - total: number; - }> { - return this.getPrivate('sapi/v1/loan/collateral/data', params); + enableMarginBrokerSubAccount( + params: EnableMarginBrokerSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/subAccount/futures', params); } - getCryptoLoanCollateralRepayRate( - params: CheckCollateralRepayRateParams, - ): Promise { - return this.getPrivate('sapi/v1/loan/repay/collateral/rate', params); + createApiKeyBrokerSubAccount( + params: CreateApiKeyBrokerSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/subAccountApi', params); } - customizeCryptoLoanMarginCall(params: CustomizeMarginCallParams): Promise<{ - rows: CustomizeMarginCall[]; - total: number; - }> { - return this.postPrivate('sapi/v1/loan/customize/margin_call', params); + changePermissionApiKeyBrokerSubAccount( + params: ChangePermissionApiKeyBrokerSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/subAccountApi/permission', params); } - borrowCryptoLoanFlexible( - params: BorrowFlexibleLoanParams, - ): Promise { - return this.postPrivate('sapi/v2/loan/flexible/borrow', params); + changeComissionBrokerSubAccount( + params: ChangePermissionApiKeyBrokerSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/subAccountApi/permission', params); } - getCryptoLoanFlexibleOngoingOrders( - params: GetFlexibleLoanOngoingOrdersParams, - ): Promise<{ - rows: FlexibleLoanOngoingOrder[]; - total: number; - }> { - return this.getPrivate('sapi/v2/loan/flexible/ongoing/orders', params); + enableUniversalTransferApiKeyBrokerSubAccount( + params: EnableUniversalTransferApiKeyBrokerSubAccountParams, + ): Promise { + return this.postPrivate( + 'sapi/v1/broker/subAccountApi/permission/universalTransfer', + params, + ); } - getLoanFlexibleBorrowHistory( - params: GetFlexibleCryptoLoanBorrowHistoryParams, + updateIpRestrictionForSubAccountApiKey( + params: UpdateIpRestrictionForSubApiKey, ): Promise<{ - rows: FlexibleCryptoLoanBorrowHistory[]; - total: number; + status: string; + ipList?: string[]; + updateTime: number; + apiKey: string; }> { - return this.getPrivate('sapi/v2/loan/flexible/borrow/history', params); - } - - repayCryptoLoanFlexible( - params: RepayCryptoFlexibleLoanParams, - ): Promise { - return this.postPrivate('sapi/v2/loan/flexible/repay', params); + return this.postPrivate( + 'sapi/v2/broker/subAccountApi/ipRestriction', + params, + ); } - getLoanFlexibleRepaymentHistory( - params: GetLoanRepaymentHistoryParams, - ): Promise<{ - rows: LoanRepaymentHistory[]; - total: number; + deleteIPRestrictionForSubAccountApiKey(params: { + subAccountId: string; + subAccountApiKey: string; + ipAddress?: string; + }): Promise<{ + subaccountId: string; + apikey: string; + ipList: string[]; + updateTime: number; }> { - return this.getPrivate('sapi/v2/loan/flexible/repay/history', params); + return this.deletePrivate( + 'sapi/v1/broker/subAccountApi/ipRestriction/ipList', + params, + ); } - adjustCryptoLoanFlexibleLTV( - params: AdjustFlexibleCryptoLoanLTVParams, - ): Promise { - return this.postPrivate('sapi/v2/loan/flexible/adjust/ltv', params); + deleteApiKeyBrokerSubAccount( + params: DeleteApiKeyBrokerSubAccountParams, + ): Promise<{}> { + return this.deletePrivate('sapi/v1/broker/subAccountApi', params); } - getCryptoLoanFlexibleLTVAdjustmentHistory( - params: GetFlexibleLoanLTVAdjustmentHistoryParams, - ): Promise<{ - rows: FlexibleLoanLTVAdjustmentHistory[]; - total: number; + getSubAccountBrokerIpRestriction(params: { + subAccountId: string; + subAccountApiKey: string; + }): Promise<{ + subaccountId: string; + ipRestrict: boolean; + apikey: string; + ipList: string[]; + updateTime: number; }> { return this.getPrivate( - 'sapi/v2/loan/flexible/ltv/adjustment/history', + 'sapi/v1/broker/subAccountApi/ipRestriction', params, ); } - getCryptoLoanFlexibleAssets(params: { loanCoin?: string }): Promise<{ - rows: FlexibleLoanAssetData[]; - total: number; - }> { - return this.getPrivate('sapi/v2/loan/flexible/loanable/data', params); + getApiKeyBrokerSubAccount( + params: GetApiKeyBrokerSubAccountParams, + ): Promise { + return this.getPrivate('sapi/v1/broker/subAccountApi', params); } - getCryptoLoanFlexibleCollateralAssets(params: { - collateralCoin?: string; - }): Promise<{ - rows: FlexibleLoanCollateralAssetData[]; - total: number; - }> { - return this.getPrivate('sapi/v2/loan/flexible/collateral/data', params); + getBrokerInfo(): Promise { + return this.getPrivate('sapi/v1/broker/info'); } /** * - * Copy trading endpoints - * - **/ + * EXCHANGE LINK - Account Endpoints + * https://developers.binance.com/docs/binance_link + */ - getFuturesLeadTraderStatus(): Promise { - return this.getPrivate('sapi/v1/copyTrading/futures/userStatus'); + transferBrokerSubAccount( + params: TransferBrokerSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/transfer', params); } - getFuturesLeadTradingSymbolWhitelist(): Promise< - GetFuturesLeadTradingSymbolWhitelistResponse[] - > { - return this.getPrivate('sapi/v1/copyTrading/futures/leadSymbol'); + getBrokerSubAccountHistory( + params: GetBrokerSubAccountHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/broker/transfer', params); } - /** - * - * Pay endpoints - * - **/ - - getPayTransactions(params: GetPayTradeHistoryParams): Promise { - return this.getPrivate('sapi/v1/pay/transactions', params); + submitBrokerSubFuturesTransfer(params: { + fromId?: string; + toId?: string; + futuresType: number; // 1: USDT Futures, 2: COIN Futures + asset: string; + amount: number; + clientTranId?: string; // The max length is 32 characters + }): Promise<{ + success: boolean; + txnId: string; + clientTranId?: string; + }> { + return this.postPrivate('sapi/v1/broker/transfer/futures', params); } - /** - * - * Convert endpoints - * - **/ - - getConvertPairs(params: GetAllConvertPairsParams): Promise { - return this.getPrivate('sapi/v1/convert/exchangeInfo', params); + getSubAccountFuturesTransferHistory(params: { + subAccountId: string; + futuresType: number; // 1: USDT Futures, 2: COIN Futures + clientTranId?: string; + startTime?: number; + endTime?: number; + page?: number; + limit?: number; + }): Promise { + return this.getPrivate('sapi/v1/broker/transfer/futures', params); } - getConvertAssetInfo(): Promise { - return this.getPrivate('sapi/v1/convert/assetInfo'); + universalTransferBroker( + params: UniversalTransferBrokerParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/universalTransfer', params); } - convertQuoteRequest(params: ConvertQuoteRequestParams): Promise { - return this.postPrivate('sapi/v1/convert/getQuote', params); + getUniversalTransferBroker( + params: GetUniversalTransferBrokerParams, + ): Promise { + return this.getPrivate('sapi/v1/broker/universalTransfer', params); } - acceptQuoteRequest(params: AcceptQuoteRequestParams): Promise { - return this.postPrivate('sapi/v1/convert/acceptQuote', params); + /** + * + * EXCHANGE LINK - Fee Endpoints + * https://developers.binance.com/docs/binance_link + */ + + /** + * + * @deprecated + */ + // USD & Coin-M can be found under API getIncome() (find "API rebate" in results) + getBrokerSpotRebateHistory(days: 7 | 30, customerId?: string) { + if (days === 7) { + return this.getPrivate('sapi/v1/apiReferral/rebate/recentRecord', { + customerId, + }); + } + if (days === 30) { + return this.getPrivate('sapi/v1/apiReferral/rebate/historicalRecord', { + customerId, + }); + } } - getOrderStatus(params: GetOrderStatusParams): Promise { - return this.getPrivate('sapi/v1/convert/orderStatus', params); + /** + * Broker Endpoints - only on old docs + * @deprecated, found only in old docs + * Use EXCHANGE LINK endpoints instead - https://developers.binance.com/docs/binance_link + */ + + /** + * @deprecated, found only in old docs + * Use EXCHANGE LINK endpoints instead + **/ + getBrokerIfNewSpotUser(): Promise<{ + rebateWorking: boolean; + ifNewUser: boolean; + }> { + return this.getPrivate('sapi/v1/apiReferral/ifNewUser'); } - submitConvertLimitOrder(params: SubmitConvertLimitOrderParams): Promise { - return this.postPrivate('sapi/v1/convert/limit/placeOrder', params); + /** + * @deprecated, found only in old docs + * Use EXCHANGE LINK endpoints instead + **/ + getBrokerSubAccountDepositHistory( + params?: GetBrokerSubAccountDepositHistoryParams, + ): Promise { + return this.getPrivate('sapi/v1/bv1/apiReferral/ifNewUser', params); } - cancelConvertLimitOrder(params: { orderId: number }): Promise { - return this.postPrivate('sapi/v1/convert/limit/cancelOrder', params); + /** + * @deprecated, found only in old docs + * Use EXCHANGE LINK endpoints instead + **/ + getBrokerUserCustomisedId(market: 'spot' | 'futures') { + const prefix = market === 'spot' ? 'sapi' : 'fapi'; + return this.getPrivate(prefix + '/v1/apiReferral/userCustomization'); } - getConvertLimitOpenOrders(): Promise<{ - list: ConvertLimitOpenOrder[]; - }> { - return this.getPrivate('sapi/v1/convert/limit/queryOpenOrders'); + /** + * @deprecated, found only in old docs + * Use EXCHANGE LINK endpoints instead + **/ + enableFuturesBrokerSubAccount( + params: EnableFuturesBrokerSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/subAccount', params); } - getConvertTradeHistory(params: GetConvertTradeHistoryParams): Promise { - return this.getPrivate('sapi/v1/convert/tradeFlow', params); + /** + * @deprecated, found only in old docs + * Use EXCHANGE LINK endpoints instead + **/ + enableMarginApiKeyBrokerSubAccount( + params: EnableMarginApiKeyBrokerSubAccountParams, + ): Promise { + return this.postPrivate('sapi/v1/broker/subAccount/margin', params); } /** - * - * Rebate Endpoints - * - **/ + * Validate syntax meets requirements set by binance. Log warning if not. + */ + private validateOrderId( + params: + | NewSpotOrderParams + | CancelOrderParams + | NewOCOParams + | CancelOCOParams + | NewOrderListParams, + orderIdProperty: OrderIdProperty, + ): void { + const apiCategory = 'spot'; + if (!params[orderIdProperty]) { + params[orderIdProperty] = generateNewOrderId(apiCategory); + return; + } - getSpotRebateHistoryRecords( - params: GetSpotRebateHistoryRecordsParams, - ): Promise { - return this.getPrivate('sapi/v1/rebate/taxQuery', params); + const expectedOrderIdPrefix = `x-${getOrderIdPrefix(apiCategory)}`; + if (!params[orderIdProperty].startsWith(expectedOrderIdPrefix)) { + logInvalidOrderId(orderIdProperty, expectedOrderIdPrefix, params); + } } /** * - * NFT Endpoints + * User Data Stream Endpoints * **/ - getNftTransactionHistory(params: GetNftTransactionHistoryParams): Promise<{ - total: number; - list: NftTransaction[]; - }> { - return this.getPrivate('sapi/v1/nft/history/transactions', params); - } - - getNftDepositHistory(params: GetNftDepositHistoryParams): Promise<{ - total: number; - list: NftDeposit[]; - }> { - return this.getPrivate('sapi/v1/nft/history/deposit', params); + // spot + getSpotUserDataListenKey(): Promise<{ listenKey: string }> { + return this.post('api/v3/userDataStream'); } - getNftWithdrawHistory(params: GetNftWithdrawHistoryParams): Promise<{ - total: number; - list: NftWithdraw[]; - }> { - return this.getPrivate('sapi/v1/nft/history/withdraw', params); + keepAliveSpotUserDataListenKey(listenKey: string): Promise<{}> { + return this.put(`api/v3/userDataStream?listenKey=${listenKey}`); } - getNftAsset(params: GetNftAssetParams): Promise<{ - total: number; - list: NftAsset[]; - }> { - return this.getPrivate('sapi/v1/nft/user/getAsset', params); + closeSpotUserDataListenKey(listenKey: string): Promise<{}> { + return this.delete(`api/v3/userDataStream?listenKey=${listenKey}`); } - /** - * - * Binance GiftCard Endpoints - * - **/ - - createGiftCard(params: CreateGiftCardParams): Promise { - return this.postPrivate('sapi/v1/giftcard/createCode', params); + // margin + getMarginUserDataListenKey(): Promise<{ listenKey: string }> { + return this.post('sapi/v1/userDataStream'); } - createDualTokenGiftCard(params: CreateDualTokenGiftCardParams): Promise { - return this.postPrivate('sapi/v1/giftcard/buyCode', params); + keepAliveMarginUserDataListenKey(listenKey: string): Promise<{}> { + return this.put(`sapi/v1/userDataStream?listenKey=${listenKey}`); } - redeemGiftCard(params: RedeemGiftCardParams): Promise { - return this.postPrivate('sapi/v1/giftcard/redeemCode', params); + closeMarginUserDataListenKey(listenKey: string): Promise<{}> { + return this.delete(`sapi/v1/userDataStream?listenKey=${listenKey}`); } - verifyGiftCard(params: { referenceNo: string }): Promise { - return this.getPrivate('sapi/v1/giftcard/verify', params); + // isolated margin + getIsolatedMarginUserDataListenKey(params: { + symbol: string; + }): Promise<{ listenKey: string }> { + return this.post( + `sapi/v1/userDataStream/isolated?${serialiseParams(params)}`, + ); } - getRsaPublicKey(): Promise { - return this.getPrivate('sapi/v1/giftcard/cryptography/rsa-public-key'); + keepAliveIsolatedMarginUserDataListenKey(params: { + symbol: string; + listenKey: string; + }): Promise<{}> { + return this.put( + `sapi/v1/userDataStream/isolated?${serialiseParams(params)}`, + ); } - getTokenLimit(params: { baseToken: string }): Promise { - return this.getPrivate('sapi/v1/giftcard/buyCode/token-limit', params); + closeIsolatedMarginUserDataListenKey(params: { + symbol: string; + listenKey: string; + }): Promise<{}> { + return this.delete( + `sapi/v1/userDataStream/isolated?${serialiseParams(params)}`, + ); } + /** + * + * DEPRECATED ENDPOINTS + * + **/ /** * * BSwap Endpoints @@ -3352,27 +3569,131 @@ export class MainClient extends BaseRestClient { } /** - * Validate syntax meets requirements set by binance. Log warning if not. + * + * Savings Endpoints + * @deprecated as of 2023-06-22, now Simple Earn + **/ + + /** + * @deprecated as of 2023-06-22, now Simple Earn */ - private validateOrderId( - params: - | NewSpotOrderParams - | CancelOrderParams - | NewOCOParams - | CancelOCOParams - | NewOrderListParams, - orderIdProperty: OrderIdProperty, - ): void { - const apiCategory = 'spot'; - if (!params[orderIdProperty]) { - params[orderIdProperty] = generateNewOrderId(apiCategory); - return; - } + getLeftDailyPurchaseQuotaFlexibleProduct(params: { + productId: string; + }): Promise { + return this.getPrivate(`sapi/v1/lending/daily/userLeftQuota`, params); + } - const expectedOrderIdPrefix = `x-${getOrderIdPrefix(apiCategory)}`; - if (!params[orderIdProperty].startsWith(expectedOrderIdPrefix)) { - logInvalidOrderId(orderIdProperty, expectedOrderIdPrefix, params); + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + getLeftDailyRedemptionQuotaFlexibleProduct(params: { + productId: string; + }): Promise< + LeftDailyPurchaseQuotaFlexibleProductResponse & { + dailyQuota: string; + minRedemptionAmount: string; } + > { + return this.getPrivate(`sapi/v1/lending/daily/userRedemptionQuota`, params); + } + + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + purchaseFixedAndActivityProject(params: { + projectId: string; + lot: number; + }): Promise { + return this.postPrivate(`sapi/v1/lending/customizedFixed/purchase`, params); + } + + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + getFixedAndActivityProjects( + params: FixedAndActivityProjectParams, + ): Promise { + return this.getPrivate(`sapi/v1/lending/project/list`, params); + } + + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + getFixedAndActivityProductPosition( + params: FixedAndActivityProjectPositionParams, + ): Promise { + return this.getPrivate(`sapi/v1/lending/project/position/list`, params); + } + + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + getLendingAccount(): Promise { + return this.getPrivate(`sapi/v1/lending/union/account`); + } + + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + getPurchaseRecord(params: PurchaseRecordParams): Promise { + return this.getPrivate(`sapi/v1/lending/union/purchaseRecord`, params); + } + + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + getRedemptionRecord(params: PurchaseRecordParams): Promise { + return this.getPrivate(`sapi/v1/lending/union/redemptionRecord`, params); + } + + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + getInterestHistory(params: PurchaseRecordParams): Promise { + return this.getPrivate(`sapi/v1/lending/union/interestHistory`, params); + } + + /** + * @deprecated as of 2023-06-22, now Simple Earn + */ + changeFixedAndActivityPositionToDailyPosition(params: { + projectId: string; + lot: number; + positionId?: number; + }): Promise { + return this.postPrivate(`sapi/v1/lending/positionChanged`, params); + } + + /** + * + * Wallet Endpoints + * @deprecated + **/ + + /** + * @deprecated + */ + enableConvertSubAccount(params: EnableConvertSubAccountParams): Promise { + return this.postPrivate('sapi/v1/broker/subAccount/convert', params); + } + /** + * @deprecated + */ + convertBUSD(params: ConvertTransfer): Promise { + return this.postPrivate('sapi/v1/asset/convert-transfer', params); + } + + /** + * @deprecated + */ + getConvertBUSDHistory(params: GetConvertBUSDHistoryParams): Promise<{ + total: number; + rows: BUSDConversionRecord[]; + }> { + return this.getPrivate( + 'sapi/v1/asset/convert-transfer/queryByPage', + params, + ); } } diff --git a/src/types/futures.ts b/src/types/futures.ts index ad0470a4..e4af9528 100644 --- a/src/types/futures.ts +++ b/src/types/futures.ts @@ -698,6 +698,32 @@ export interface UserCommissionRate { takerCommissionRate: numberInString; } +export interface FuturesAccountConfig { + feeTier: number; + canTrade: boolean; + canDeposit: boolean; + canWithdraw: boolean; + dualSidePosition: boolean; + updateTime: number; + multiAssetsMargin: boolean; + tradeGroupId: number; +} + +export interface SymbolConfig { + symbol: string; + marginType: string; + isAutoAddMargin: string; + leverage: number; + maxNotionalValue: string; +} + +export interface UserForceOrder { + rateLimitType: string; + interval: string; + intervalNum: number; + limit: number; +} + export interface RebateDataOverview { brokerId: string; newTraderRebateCommission: numberInString; diff --git a/src/types/spot.ts b/src/types/spot.ts index f06ce879..c40bee16 100644 --- a/src/types/spot.ts +++ b/src/types/spot.ts @@ -1174,6 +1174,11 @@ export interface CreateSubAccountParams { subAccountString: string; } +export interface EnableOrDisableIPRestrictionForSubAccountParams + extends BasicSubAccount { + ipAddress?: string; +} + export interface GetBrokerSubAccountHistoryParams { fromId?: string; toId?: string; @@ -1215,6 +1220,13 @@ export interface ApiKeyBrokerSubAccount { futuresTrade: boolean; } +export interface UpdateIpRestrictionForSubApiKey { + subAccountId: string; + ipAddress?: string; + subAccountApiKey: string; + status: string; +} + export interface EnableUniversalTransferApiKeyBrokerSubAccountParams { subAccountId: string; subAccountApiKey: string; @@ -1552,11 +1564,6 @@ export interface SubAccountEnableLeverageToken { enableBlvt: boolean; } -export interface EnableOrDisableIPRestrictionForSubAccountParams - extends BasicSubAccount { - ipRestrict: boolean; -} - export interface AddIpRestriction extends BasicSubAccount { status: string; ipAddress: string; diff --git a/src/usdm-client.ts b/src/usdm-client.ts index c395979f..3594a433 100644 --- a/src/usdm-client.ts +++ b/src/usdm-client.ts @@ -77,6 +77,9 @@ import { PortfolioMarginProAccountInfo, GetFuturesOrderModifyHistoryParams, FuturesTradeHistoryDownloadId, + FuturesAccountConfig, + SymbolConfig, + UserForceOrder, } from './types/futures'; import { @@ -116,7 +119,7 @@ export class USDMClient extends BaseRestClient { /** * - * Market Data Endpoints + * MARKET DATA endpoints - Rest API * **/ @@ -148,28 +151,6 @@ export class USDMClient extends BaseRestClient { return this.get('fapi/v1/aggTrades', params); } - getMarkPrice(params: BasicSymbolParam): Promise; - getMarkPrice(): Promise; - - /** - * Index Price and Mark Price - */ - getMarkPrice( - params?: Partial, - ): Promise { - return this.get('fapi/v1/premiumIndex', params); - } - - getFundingRateHistory( - params?: Partial, - ): Promise { - return this.get('fapi/v1/fundingRate', params); - } - - getFundingRates(): Promise { - return this.get('fapi/v1/fundingInfo'); - } - getKlines(params: KlinesParams): Promise { return this.get('fapi/v1/klines', params); } @@ -192,6 +173,25 @@ export class USDMClient extends BaseRestClient { return this.get('fapi/v1/premiumIndexKlines', params); } + getMarkPrice(params: BasicSymbolParam): Promise; + getMarkPrice(): Promise; + + getMarkPrice( + params?: Partial, + ): Promise { + return this.get('fapi/v1/premiumIndex', params); + } + + getFundingRateHistory( + params?: Partial, + ): Promise { + return this.get('fapi/v1/fundingRate', params); + } + + getFundingRates(): Promise { + return this.get('fapi/v1/fundingInfo'); + } + /** * @deprecated use get24hrChangeStatistics() instead (method without the typo) */ @@ -235,6 +235,12 @@ export class USDMClient extends BaseRestClient { return this.get('fapi/v1/ticker/bookTicker', params); } + getQuarterlyContractSettlementPrices(params: { + pair: string; + }): Promise { + return this.get('futures/data/delivery-price', params); + } + getOpenInterest(params: BasicSymbolParam): Promise { return this.get('fapi/v1/openInterest', params); } @@ -245,16 +251,16 @@ export class USDMClient extends BaseRestClient { return this.get('futures/data/openInterestHist', params); } - getTopTradersLongShortAccountRatio( + getTopTradersLongShortPositionRatio( params: FuturesDataPaginatedParams, ): Promise { - return this.get('futures/data/topLongShortAccountRatio', params); + return this.get('futures/data/topLongShortPositionRatio', params); } - getTopTradersLongShortPositionRatio( + getTopTradersLongShortAccountRatio( params: FuturesDataPaginatedParams, ): Promise { - return this.get('futures/data/topLongShortPositionRatio', params); + return this.get('futures/data/topLongShortAccountRatio', params); } getGlobalLongShortAccountRatio( @@ -275,20 +281,20 @@ export class USDMClient extends BaseRestClient { return this.get('fapi/v1/indexInfo', params); } - getQuarterlyContractSettlementPrices(params: { - pair: string; - }): Promise { - return this.get('futures/data/delivery-price', params); + getMultiAssetsModeAssetIndex(params?: { symbol?: string }): Promise { + return this.get('fapi/v1/assetIndex', params); } + /** + * Possibly @deprecated, found only in old docs + **/ getBasis(params: BasisParams): Promise { return this.get('futures/data/basis', params); } - getMultiAssetsModeAssetIndex(params?: { symbol?: string }): Promise { - return this.get('fapi/v1/assetIndex', params); - } - + /** + * Possibly @deprecated, found only in old docs + **/ getIndexPriceConstituents(params: { symbol: string; }): Promise { @@ -297,48 +303,32 @@ export class USDMClient extends BaseRestClient { /** * - * USD-Futures Account/Trade Endpoints + * TRADE endpoints - Rest API * **/ - setPositionMode(params: PositionModeParams): Promise { - return this.postPrivate('fapi/v1/positionSide/dual', params); - } - - getCurrentPositionMode(): Promise { - return this.getPrivate('fapi/v1/positionSide/dual'); - } - - setMultiAssetsMode(params: { - multiAssetsMargin: MultiAssetsMode; - }): Promise { - return this.postPrivate('fapi/v1/multiAssetsMargin', params); - } - - getMultiAssetsMode(): Promise { - return this.getPrivate('fapi/v1/multiAssetsMargin'); - } - - setBNBBurnEnabled(params: { - feeBurn: 'true' | 'false'; - }): Promise<{ code: number; msg: string }> { - return this.postPrivate('fapi/v1/feeBurn', params); - } - - getBNBBurnStatus(): Promise<{ - feeBurn: boolean; - }> { - return this.getPrivate('fapi/v1/feeBurn'); - } - submitNewOrder(params: NewFuturesOrderParams): Promise { this.validateOrderId(params, 'newClientOrderId'); return this.postPrivate('fapi/v1/order', params); } - testOrder(params: NewFuturesOrderParams): Promise { - this.validateOrderId(params, 'newClientOrderId'); - return this.postPrivate('fapi/v1/order/test', params); + /** + * Warning: max 5 orders at a time! This method does not throw, instead it returns individual errors in the response array if any orders were rejected. + * + * Known issue: `quantity` and `price` should be sent as strings + */ + submitMultipleOrders( + orders: NewFuturesOrderParams[], + ): Promise<(NewOrderResult | NewOrderError)[]> { + const stringOrders = orders.map((order) => { + const orderToStringify = { ...order }; + this.validateOrderId(orderToStringify, 'newClientOrderId'); + return JSON.stringify(orderToStringify); + }); + const requestBody = { + batchOrders: `[${stringOrders.join(',')}]`, + }; + return this.postPrivate('fapi/v1/batchOrders', requestBody); } /** @@ -364,39 +354,10 @@ export class USDMClient extends BaseRestClient { return this.getPrivate('fapi/v1/orderAmendment', params); } - /** - * Warning: max 5 orders at a time! This method does not throw, instead it returns individual errors in the response array if any orders were rejected. - * - * Known issue: `quantity` and `price` should be sent as strings - */ - submitMultipleOrders( - orders: NewFuturesOrderParams[], - ): Promise<(NewOrderResult | NewOrderError)[]> { - const stringOrders = orders.map((order) => { - const orderToStringify = { ...order }; - this.validateOrderId(orderToStringify, 'newClientOrderId'); - return JSON.stringify(orderToStringify); - }); - const requestBody = { - batchOrders: `[${stringOrders.join(',')}]`, - }; - return this.postPrivate('fapi/v1/batchOrders', requestBody); - } - - getOrder(params: GetOrderParams): Promise { - return this.getPrivate('fapi/v1/order', params); - } - cancelOrder(params: CancelOrderParams): Promise { return this.deletePrivate('fapi/v1/order', params); } - cancelAllOpenOrders( - params: BasicSymbolParam, - ): Promise { - return this.deletePrivate('fapi/v1/allOpenOrders', params); - } - cancelMultipleOrders( params: CancelMultipleOrdersParams, ): Promise<(CancelFuturesOrderResult | GenericCodeMsgError)[]> { @@ -417,6 +378,12 @@ export class USDMClient extends BaseRestClient { return this.deletePrivate('fapi/v1/batchOrders', requestParams); } + cancelAllOpenOrders( + params: BasicSymbolParam, + ): Promise { + return this.deletePrivate('fapi/v1/allOpenOrders', params); + } + // Auto-cancel all open orders setCancelOrdersOnTimeout( params: CancelOrdersTimeoutParams, @@ -424,32 +391,48 @@ export class USDMClient extends BaseRestClient { return this.postPrivate('fapi/v1/countdownCancelAll', params); } - getCurrentOpenOrder(params: GetOrderParams): Promise { - return this.getPrivate('fapi/v1/openOrder', params); + getOrder(params: GetOrderParams): Promise { + return this.getPrivate('fapi/v1/order', params); + } + + getAllOrders(params: GetAllOrdersParams): Promise { + return this.getPrivate('fapi/v1/allOrders', params); } getAllOpenOrders(params?: Partial): Promise { return this.getPrivate('fapi/v1/openOrders', params); } - getAllOrders(params: GetAllOrdersParams): Promise { - return this.getPrivate('fapi/v1/allOrders', params); + getCurrentOpenOrder(params: GetOrderParams): Promise { + return this.getPrivate('fapi/v1/openOrder', params); } - getBalance(): Promise { - return this.getPrivate('fapi/v2/balance'); + getForceOrders(params?: GetForceOrdersParams): Promise { + return this.getPrivate('fapi/v1/forceOrders', params); } - getAccountInformation(): Promise { - return this.getPrivate('fapi/v2/account'); + getAccountTrades( + params: SymbolFromPaginatedRequestFromId & { orderId?: number }, + ): Promise { + return this.getPrivate('fapi/v1/userTrades', params); + } + + setMarginType(params: SetMarginTypeParams): Promise { + return this.postPrivate('fapi/v1/marginType', params); + } + + setPositionMode(params: PositionModeParams): Promise { + return this.postPrivate('fapi/v1/positionSide/dual', params); } setLeverage(params: SetLeverageParams): Promise { return this.postPrivate('fapi/v1/leverage', params); } - setMarginType(params: SetMarginTypeParams): Promise { - return this.postPrivate('fapi/v1/marginType', params); + setMultiAssetsMode(params: { + multiAssetsMargin: MultiAssetsMode; + }): Promise { + return this.postPrivate('fapi/v1/multiAssetsMargin', params); } setIsolatedPositionMargin( @@ -458,24 +441,62 @@ export class USDMClient extends BaseRestClient { return this.postPrivate('fapi/v1/positionMargin', params); } + getPositions(params?: Partial): Promise { + return this.getPrivate('fapi/v2/positionRisk', params); + } + + getPositionsV3(params?: { symbol?: string }): Promise { + return this.getPrivate('fapi/v3/positionRisk', params); + } + + getADLQuantileEstimation(params?: Partial): Promise { + return this.getPrivate('fapi/v1/adlQuantile', params); + } + getPositionMarginChangeHistory( params: GetPositionMarginChangeHistoryParams, ): Promise { return this.getPrivate('fapi/v1/positionMargin/history', params); } - getPositions(params?: Partial): Promise { - return this.getPrivate('fapi/v2/positionRisk', params); + /** + * + * ACCOUNT endpoints - Rest API + * + **/ + + getBalanceV3(): Promise { + return this.getPrivate('fapi/v3/balance'); } - getAccountTrades( - params: SymbolFromPaginatedRequestFromId & { orderId?: number }, - ): Promise { - return this.getPrivate('fapi/v1/userTrades', params); + getBalance(): Promise { + return this.getPrivate('fapi/v2/balance'); } - getIncomeHistory(params?: GetIncomeHistoryParams): Promise { - return this.getPrivate('fapi/v1/income', params); + getAccountInformationV3(): Promise { + return this.getPrivate('fapi/v3/account'); + } + + getAccountInformation(): Promise { + return this.getPrivate('fapi/v2/account'); + } + + getAccountComissionRate( + params: BasicSymbolParam, + ): Promise { + return this.getPrivate('fapi/v1/commissionRate', params); + } + + getFuturesAccountConfig(): Promise { + return this.getPrivate('fapi/v1/accountConfig'); + } + + getFuturesSymbolConfig(params: { symbol?: string }): Promise { + return this.getPrivate('fapi/v1/symbolConfig', params); + } + + getUserForceOrders(): Promise { + return this.getPrivate('fapi/v1/rateLimit/order'); } /** @@ -487,12 +508,16 @@ export class USDMClient extends BaseRestClient { return this.getPrivate('fapi/v1/leverageBracket', params); } - getADLQuantileEstimation(params?: Partial): Promise { - return this.getPrivate('fapi/v1/adlQuantile', params); + getMultiAssetsMode(): Promise { + return this.getPrivate('fapi/v1/multiAssetsMargin'); } - getForceOrders(params?: GetForceOrdersParams): Promise { - return this.getPrivate('fapi/v1/forceOrders', params); + getCurrentPositionMode(): Promise { + return this.getPrivate('fapi/v1/positionSide/dual'); + } + + getIncomeHistory(params?: GetIncomeHistoryParams): Promise { + return this.getPrivate('fapi/v1/income', params); } getApiQuantitativeRulesIndicators( @@ -501,12 +526,6 @@ export class USDMClient extends BaseRestClient { return this.getPrivate('fapi/v1/apiTradingStatus', params); } - getAccountComissionRate( - params: BasicSymbolParam, - ): Promise { - return this.getPrivate('fapi/v1/commissionRate', params); - } - getFuturesTransactionHistoryDownloadId(params: { startTime: number; endTime: number; @@ -546,6 +565,23 @@ export class USDMClient extends BaseRestClient { return this.getPrivate('fapi/v1/trade/asyn/id', params); } + setBNBBurnEnabled(params: { + feeBurn: 'true' | 'false'; + }): Promise<{ code: number; msg: string }> { + return this.postPrivate('fapi/v1/feeBurn', params); + } + + getBNBBurnStatus(): Promise<{ + feeBurn: boolean; + }> { + return this.getPrivate('fapi/v1/feeBurn'); + } + + testOrder(params: NewFuturesOrderParams): Promise { + this.validateOrderId(params, 'newClientOrderId'); + return this.postPrivate('fapi/v1/order/test', params); + } + /** * * Portfolio Margin Pro Endpoints @@ -561,10 +597,14 @@ export class USDMClient extends BaseRestClient { /** * * Broker Futures Endpoints - * + * Possibly @deprecated, found only in old docs + * All broker endpoints start with /sapi/v1/broker or sapi/v2/broker or sapi/v3/broker + * **/ - // 1 == USDT-Margined, 2 == Coin-margined + /** + * @deprecated + **/ getBrokerIfNewFuturesUser( brokerId: string, type: 1 | 2 = 1, @@ -574,7 +614,9 @@ export class USDMClient extends BaseRestClient { type, }); } - + /** + * @deprecated + **/ setBrokerCustomIdForClient( customerId: string, email: string, @@ -584,7 +626,9 @@ export class USDMClient extends BaseRestClient { email, }); } - + /** + * @deprecated + **/ getBrokerClientCustomIds( customerId: string, email: string, @@ -598,19 +642,25 @@ export class USDMClient extends BaseRestClient { limit, }); } - + /** + * @deprecated + **/ getBrokerUserCustomId(brokerId: string): Promise { return this.getPrivate('fapi/v1/apiReferral/userCustomization', { brokerId, }); } - + /** + * @deprecated + **/ getBrokerRebateDataOverview(type: 1 | 2 = 1): Promise { return this.getPrivate('fapi/v1/apiReferral/overview', { type, }); } - + /** + * @deprecated + **/ getBrokerUserTradeVolume( type: 1 | 2 = 1, startTime?: number, @@ -624,7 +674,9 @@ export class USDMClient extends BaseRestClient { limit, }); } - + /** + * @deprecated + **/ getBrokerRebateVolume( type: 1 | 2 = 1, startTime?: number, @@ -638,7 +690,9 @@ export class USDMClient extends BaseRestClient { limit, }); } - + /** + * @deprecated + **/ getBrokerTradeDetail( type: 1 | 2 = 1, startTime?: number,