From 947a6b0494ed12e4412f32e82fd8c830e9506730 Mon Sep 17 00:00:00 2001 From: Andrew Zolotukhin Date: Sun, 21 Apr 2024 05:37:18 +0300 Subject: [PATCH] Add margin capital flow and interest history endpoints --- index.d.ts | 129 +++++++++++++++++++++++++++++++++++++++++++++ src/http-client.js | 4 ++ 2 files changed, 133 insertions(+) diff --git a/index.d.ts b/index.d.ts index 30599ade..f1f21ede 100644 --- a/index.d.ts +++ b/index.d.ts @@ -53,6 +53,36 @@ declare module 'binance-api-node' { | -2014 | -2015 + export type CapitalFlowType = + | 'TRANSFER' + | 'BORROW' + | 'REPAY' + | 'BUY_INCOME' + | 'BUY_EXPENSE' + | 'SELL_INCOME' + | 'SELL_EXPENSE' + | 'TRADING_COMMISSION' + | 'BUY_LIQUIDATION' + | 'SELL_LIQUIDATION' + | 'REPAY_LIQUIDATION' + | 'OTHER_LIQUIDATION' + | 'LIQUIDATION_FEE' + | 'SMALL_BALANCE_CONVERT' + | 'COMMISSION_RETURN' + | 'SMALL_CONVERT' + + export type MarginInterestHistory = { + txId: string + interestAccuredTime: number + asset: string + rawAsset?: string + principal: string + interest: string + interestRate: string + type: string + isolatedSymbol: string + } + export const enum ErrorCodes { UNKNOWN = -1000, DISCONNECTED = -1001, @@ -766,10 +796,48 @@ declare module 'binance-api-node' { marginRepay(options: MarginBorrowOptions): Promise<{ tranId: number }> marginLoan(options: MarginBorrowOptions): Promise<{ tranId: number }> marginAccountInfo(options?: { recvWindow?: number }): Promise + marginCapitalFlow(options?: { + asset?: string + /** + * Required when querying isolated data + */ + symbol?: string + type?: CapitalFlowType + /** + * Only supports querying the data of the last 90 days + */ + startTime?: number + endTime?: number + fromId?: number + /** + * The number of data items returned each time is limited. Default 500; Max 1000. + */ + limit?: number + recvWindow?: number + }): Promise< + { + id: number + tranId: number + timestamp: number + asset: string + symbol: string + type: CapitalFlowType + amount: number + }[] + > marginIsolatedAccount(options?: { symbols?: string recvWindow?: number }): Promise + marginInterestHistory(options: { + asset?: string + isolatedSymbol?: string + startTime?: number + endTime?: number + current?: number + size?: number + timestamp?: number + }): Promise<{ total: number; rows: MarginInterestHistory[] }> marginMaxBorrow(options: { asset: string isolatedSymbol?: string @@ -796,6 +864,67 @@ declare module 'binance-api-node' { privateRequest(method: HttpMethod, url: string, payload: object): Promise disableMarginAccount(options: { symbol: string }): Promise<{ success: boolean; symbol: string }> enableMarginAccount(options: { symbol: string }): Promise<{ success: boolean; symbol: string }> + isolatedMarginAllPairs(options: { + symbol?: string + }): Promise< + { + base: string + isBuyAllowed: boolean + isMarginTrade: boolean + isSellAllowed: boolean + quote: string + symbol: string + }[] + > + isolatedMarginAccount(options: { + /** + * Max 5 symbols can be sent; separated by ",". e.g. "BTCUSDT,BNBUSDT,ADAUSDT" + */ + symbols?: string + recvWindow?: number + }): Promise<{ + assets: { + baseAsset: { + asset: string + borrowEnabled: boolean + borrowed: number + free: number + interest: number + locked: number + netAsset: number + netAssetOfBtc: number + repayEnabled: boolean + totalAsset: number + } + quoteAsset: { + asset: string + borrowEnabled: boolean + borrowed: number + free: number + interest: number + locked: number + netAsset: number + netAssetOfBtc: number + repayEnabled: boolean + totalAsset: number + } + symbol: string + isolatedCreated: boolean + enabled: boolean + marginLevel: number + marginLevelStatus: + | 'EXCESSIVE' + | 'NORMAL' + | 'MARGIN_CALL' + | 'PRE_LIQUIDATION' + | 'FORCE_LIQUIDATION' + marginRatio: number + indexPrice: number + liquidatePrice: number + liquidateRate: number + tradeEnabled: boolean + }[] + }> getPortfolioMarginAccountInfo(): Promise<{ uniMMR: string accountEquity: string diff --git a/src/http-client.js b/src/http-client.js index 7156d6a1..536b2550 100644 --- a/src/http-client.js +++ b/src/http-client.js @@ -443,6 +443,8 @@ export default opts => { marginMyTrades: payload => privCall('/sapi/v1/margin/myTrades', payload), marginRepay: payload => privCall('/sapi/v1/margin/repay', payload, 'POST'), marginLoan: payload => privCall('/sapi/v1/margin/loan', payload, 'POST'), + marginCapitalFlow: payload => privCall('/sapi/v1/margin/capital-flow', payload), + marginInterestHistory: payload => privCall('/sapi/v1/margin/interestHistory', payload), marginIsolatedAccount: payload => privCall('/sapi/v1/margin/isolated/account', payload), marginMaxBorrow: payload => privCall('/sapi/v1/margin/maxBorrowable', payload), marginCreateIsolated: payload => privCall('/sapi/v1/margin/isolated/create', payload, 'POST'), @@ -453,6 +455,8 @@ export default opts => { disableMarginAccount: payload => privCall('/sapi/v1/margin/isolated/account', payload, 'DELETE'), enableMarginAccount: payload => privCall('/sapi/v1/margin/isolated/account', payload, 'POST'), + isolatedMarginAllPairs: payload => privCall('/sapi/v1/margin/isolated/allPairs', payload), + isolatedMarginAccount: payload => privCall('/sapi/v1/margin/isolated/account', payload), getPortfolioMarginAccountInfo: () => privCall('/sapi/v1/portfolio/account'), futuresPing: () => pubCall('/fapi/v1/ping').then(() => true),