From 5f8933f4dde2f903626e7416ccf1f3e57424df60 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:22:29 +0200 Subject: [PATCH 1/3] feat(): Added new convert and PMPro endpoints --- package-lock.json | 4 ++-- package.json | 2 +- src/main-client.ts | 16 ++++++++++------ src/types/futures.ts | 38 ++++++++++++++++++++++++++++++++++++++ src/usdm-client.ts | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4b3fbb0..1da920d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "binance", - "version": "2.13.2", + "version": "2.13.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "binance", - "version": "2.13.2", + "version": "2.13.3", "license": "MIT", "dependencies": { "axios": "^1.6.2", diff --git a/package.json b/package.json index 8a805b2..e1702a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "binance", - "version": "2.13.2", + "version": "2.13.3", "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/main-client.ts b/src/main-client.ts index ccbc03d..5a2d2e5 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -3080,6 +3080,16 @@ export class MainClient extends BaseRestClient { return this.getPrivate('sapi/v1/portfolio/margin-asset-leverage'); } + getPortfolioMarginProCollateralRate(): Promise< + GetPortfolioMarginProCollateralRateResponse[] + > { + return this.get('sapi/v1/portfolio/collateralRate'); + } + + getPortfolioMarginProTieredCollateralRate(): Promise { + return this.get('sapi/v2/portfolio/collateralRate'); + } + /** * * DERIVATIVES - Portfolio Margin Pro - Account @@ -3087,12 +3097,6 @@ export class MainClient extends BaseRestClient { * **/ - getPortfolioMarginProCollateralRate(): Promise< - GetPortfolioMarginProCollateralRateResponse[] - > { - return this.get('sapi/v1/portfolio/collateralRate'); - } - getPortfolioMarginProAccountInfo(): Promise { return this.getPrivate('sapi/v1/portfolio/account'); } diff --git a/src/types/futures.ts b/src/types/futures.ts index e4af952..a76dbf1 100644 --- a/src/types/futures.ts +++ b/src/types/futures.ts @@ -870,3 +870,41 @@ export interface PortfolioMarginProAccountInfo { asset: string; maxWithdrawAmount: string; // This field will be ignored in the response } + +export interface ConvertPair { + fromAsset: string; + toAsset: string; + fromAssetMinAmount: string; + fromAssetMaxAmount: string; + toAssetMinAmount: string; + toAssetMaxAmount: string; +} + +export interface ConvertQuoteParams { + fromAsset: string; + toAsset: string; + fromAmount?: number; + toAmount?: number; + validTime?: '10s' | '30s' | '1m' | '2m'; +} + +export interface ConvertQuote { + quoteId: string; + ratio: string; + inverseRatio: string; + validTimestamp: number; + toAmount: string; + fromAmount: string; +} + +export interface ConvertOrderStatus { + orderId: string; + orderStatus: 'PROCESS' | 'ACCEPT_SUCCESS' | 'SUCCESS' | 'FAIL'; + fromAsset: string; + fromAmount: string; + toAsset: string; + toAmount: string; + ratio: string; + inverseRatio: string; + createTime: number; +} diff --git a/src/usdm-client.ts b/src/usdm-client.ts index 36e1027..eae99e8 100644 --- a/src/usdm-client.ts +++ b/src/usdm-client.ts @@ -80,6 +80,10 @@ import { FuturesAccountConfig, SymbolConfig, UserForceOrder, + ConvertPair, + ConvertQuote, + ConvertQuoteParams, + ConvertOrderStatus, } from './types/futures'; import { @@ -594,6 +598,38 @@ export class USDMClient extends BaseRestClient { return this.postPrivate('fapi/v1/order/test', params); } + /** + * + * Convert Endpoints + * + **/ + + getAllConvertPairs(params?: { + fromAsset?: string; + toAsset?: string; + }): Promise { + return this.get('fapi/v1/convert/exchangeInfo', params); + } + + submitConvertQuoteRequest(params: ConvertQuoteParams): Promise { + return this.postPrivate('fapi/v1/convert/getQuote', params); + } + + acceptConvertQuote(params: { quoteId: string }): Promise<{ + orderId: string; + createTime: number; + orderStatus: 'PROCESS' | 'ACCEPT_SUCCESS' | 'SUCCESS' | 'FAIL'; + }> { + return this.postPrivate('fapi/v1/convert/acceptQuote', params); + } + + getConvertOrderStatus(params: { + orderId?: string; + quoteId?: string; + }): Promise { + return this.getPrivate('fapi/v1/convert/orderStatus', params); + } + /** * * Portfolio Margin Pro Endpoints From 452f9150b630525812d9990af755eaf531c405b4 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:43:57 +0200 Subject: [PATCH 2/3] feat(): updated websockets --- src/types/websockets.ts | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/types/websockets.ts b/src/types/websockets.ts index 278161a..bab31bf 100644 --- a/src/types/websockets.ts +++ b/src/types/websockets.ts @@ -50,7 +50,8 @@ export type WsMessageFuturesUserDataEventRaw = | WsMessageFuturesUserDataMarginCallRaw | WsMessageFuturesUserDataOrderTradeUpdateEventRaw | WsMessageFuturesUserDataAccountConfigUpdateEventRaw - | WsMessageFuturesUserDataCondOrderTriggerRejectEventRaw; + | WsMessageFuturesUserDataCondOrderTriggerRejectEventRaw + | WsMessageFuturesUserDataTradeLiteEventRaw; // TODO: consistent across USDM vs COINM? export type WsMessageFuturesUserDataEventFormatted = @@ -59,7 +60,8 @@ export type WsMessageFuturesUserDataEventFormatted = | WsMessageFuturesUserDataMarginCallFormatted | WsMessageFuturesUserDataTradeUpdateEventFormatted | WsMessageFuturesUserDataAccountConfigUpdateEventFormatted - | WsMessageFuturesUserDataCondOrderTriggerRejectEventFormatted; + | WsMessageFuturesUserDataCondOrderTriggerRejectEventFormatted + | WsMessageFuturesUserDataTradeLiteEventFormatted; export type WsRawMessage = | WsMessageKlineRaw @@ -755,6 +757,39 @@ export interface WsMessageFuturesUserDataOrderTradeUpdateEventRaw ss: numberInString; // ignore }; } +export interface WsMessageFuturesUserDataTradeLiteEventRaw + extends WsSharedBase { + e: 'TRADE_LITE'; // Event Type + E: number; // Event Time + T: number; // Transaction Time + s: string; // Symbol + q: string; // Original Quantity + p: string; // Original Price + m: boolean; // Is this trade the maker side? + c: string; // Client Order Id + S: 'BUY' | 'SELL'; // Side + L: string; // Last Filled Price + l: string; // Order Last Filled Quantity + t: number; // Trade Id + i: number; // Order Id +} + +export interface WsMessageFuturesUserDataTradeLiteEventFormatted + extends WsSharedBase { + eventType: 'TRADE_LITE'; + eventTime: number; + transactionTime: number; + symbol: string; + originalQuantity: number; + originalPrice: number; + isMakerSide: boolean; + clientOrderId: string; + side: 'BUY' | 'SELL'; + lastFilledPrice: number; + lastFilledQuantity: number; + tradeId: number; + orderId: number; +} export interface WsMessageFuturesUserDataTradeUpdateEventFormatted extends WsSharedBase { From f1fca6bc4de5b039ea53547f0b5660a133aa5ab2 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:16:56 +0200 Subject: [PATCH 3/3] chore(): updated type names, updated endpoint map --- docs/endpointFunctionList.md | 5 +++++ src/types/futures.ts | 8 ++++---- src/usdm-client.ts | 16 +++++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/endpointFunctionList.md b/docs/endpointFunctionList.md index d5b59a4..e9773df 100644 --- a/docs/endpointFunctionList.md +++ b/docs/endpointFunctionList.md @@ -369,6 +369,7 @@ This table includes all endpoints from the official Exchange API docs and corres | `getPortfolioMarginIndexPrice()` | | GET | `sapi/v1/portfolio/asset-index-price` | | `getPortfolioMarginAssetLeverage()` | :closed_lock_with_key: | GET | `sapi/v1/portfolio/margin-asset-leverage` | | `getPortfolioMarginProCollateralRate()` | | GET | `sapi/v1/portfolio/collateralRate` | +| `getPortfolioMarginProTieredCollateralRate()` | | GET | `sapi/v2/portfolio/collateralRate` | | `getPortfolioMarginProAccountInfo()` | :closed_lock_with_key: | GET | `sapi/v1/portfolio/account` | | `bnbTransfer()` | :closed_lock_with_key: | POST | `sapi/v1/portfolio/bnb-transfer` | | `submitPortfolioMarginProFullTransfer()` | :closed_lock_with_key: | POST | `sapi/v1/portfolio/auto-collection` | @@ -534,6 +535,10 @@ This table includes all endpoints from the official Exchange API docs and corres | `setBNBBurnEnabled()` | :closed_lock_with_key: | POST | `fapi/v1/feeBurn` | | `getBNBBurnStatus()` | :closed_lock_with_key: | GET | `fapi/v1/feeBurn` | | `testOrder()` | :closed_lock_with_key: | POST | `fapi/v1/order/test` | +| `getAllConvertPairs()` | | GET | `fapi/v1/convert/exchangeInfo` | +| `submitConvertQuoteRequest()` | :closed_lock_with_key: | POST | `fapi/v1/convert/getQuote` | +| `acceptConvertQuote()` | :closed_lock_with_key: | POST | `fapi/v1/convert/acceptQuote` | +| `getConvertOrderStatus()` | :closed_lock_with_key: | GET | `fapi/v1/convert/orderStatus` | | `getPortfolioMarginProAccountInfo()` | :closed_lock_with_key: | GET | `fapi/v1/pmAccountInfo` | | `getBrokerIfNewFuturesUser()` | :closed_lock_with_key: | GET | `fapi/v1/apiReferral/ifNewUser` | | `setBrokerCustomIdForClient()` | :closed_lock_with_key: | POST | `fapi/v1/apiReferral/customization` | diff --git a/src/types/futures.ts b/src/types/futures.ts index a76dbf1..4d0fd45 100644 --- a/src/types/futures.ts +++ b/src/types/futures.ts @@ -871,7 +871,7 @@ export interface PortfolioMarginProAccountInfo { maxWithdrawAmount: string; // This field will be ignored in the response } -export interface ConvertPair { +export interface FuturesConvertPair { fromAsset: string; toAsset: string; fromAssetMinAmount: string; @@ -880,7 +880,7 @@ export interface ConvertPair { toAssetMaxAmount: string; } -export interface ConvertQuoteParams { +export interface FuturesConvertQuoteRequest { fromAsset: string; toAsset: string; fromAmount?: number; @@ -888,7 +888,7 @@ export interface ConvertQuoteParams { validTime?: '10s' | '30s' | '1m' | '2m'; } -export interface ConvertQuote { +export interface FuturesConvertQuote { quoteId: string; ratio: string; inverseRatio: string; @@ -897,7 +897,7 @@ export interface ConvertQuote { fromAmount: string; } -export interface ConvertOrderStatus { +export interface FuturesConvertOrderStatus { orderId: string; orderStatus: 'PROCESS' | 'ACCEPT_SUCCESS' | 'SUCCESS' | 'FAIL'; fromAsset: string; diff --git a/src/usdm-client.ts b/src/usdm-client.ts index eae99e8..6de3f01 100644 --- a/src/usdm-client.ts +++ b/src/usdm-client.ts @@ -80,10 +80,10 @@ import { FuturesAccountConfig, SymbolConfig, UserForceOrder, - ConvertPair, - ConvertQuote, - ConvertQuoteParams, - ConvertOrderStatus, + FuturesConvertPair, + FuturesConvertQuote, + FuturesConvertOrderStatus, + FuturesConvertQuoteRequest, } from './types/futures'; import { @@ -607,11 +607,13 @@ export class USDMClient extends BaseRestClient { getAllConvertPairs(params?: { fromAsset?: string; toAsset?: string; - }): Promise { + }): Promise { return this.get('fapi/v1/convert/exchangeInfo', params); } - submitConvertQuoteRequest(params: ConvertQuoteParams): Promise { + submitConvertQuoteRequest( + params: FuturesConvertQuoteRequest, + ): Promise { return this.postPrivate('fapi/v1/convert/getQuote', params); } @@ -626,7 +628,7 @@ export class USDMClient extends BaseRestClient { getConvertOrderStatus(params: { orderId?: string; quoteId?: string; - }): Promise { + }): Promise { return this.getPrivate('fapi/v1/convert/orderStatus', params); }