From 0086e8c622c6e2ae0a3a174596a4c5e6c3ebc064 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:40:48 +0200 Subject: [PATCH] feat(): updated Margin endpoints --- package-lock.json | 4 +- package.json | 2 +- src/main-client.ts | 78 ++++++++++++++++++++- src/types/spot.ts | 171 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 251 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index b2507b4f..35135de5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "binance", - "version": "2.13.3", + "version": "2.13.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "binance", - "version": "2.13.3", + "version": "2.13.5", "license": "MIT", "dependencies": { "axios": "^1.6.2", diff --git a/package.json b/package.json index 8be890c4..7e44dba5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "binance", - "version": "2.13.4", + "version": "2.13.5", "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 5a2d2e5b..a65a12ac 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -220,7 +220,6 @@ import { TradingDayTickerParams, RollingWindowTickerParams, NewOrderListOTOParams, - NewOrderListOTOResponse, NewOrderListOTOCOParams, NewOrderListOTOCOResponse, PreventedMatchesParams, @@ -512,6 +511,14 @@ import { SubAccountDeposit, SubaccountBrokerSpotAsset, SubAccountBrokerMarginAsset, + SubmitMarginOTOOrderParams, + MarginOTOOrder, + MarginOTOCOOrder, + SubmitMarginOTOCOOrderParams, + NewOrderListOTOResponse, + CreateSpecialLowLatencyKeyParams, + SpecialLowLatencyKeyResponse, + SpecialLowLatencyKeyInfo, } from './types/spot'; import { @@ -1041,6 +1048,75 @@ export class MainClient extends BaseRestClient { return this.postPrivate('sapi/v1/margin/manual-liquidation', params); } + /** + * Post a new OTO order for margin account + */ + submitMarginOTOOrder( + params: SubmitMarginOTOOrderParams, + ): Promise { + this.validateOrderId(params, 'listClientOrderId'); + this.validateOrderId(params, 'workingClientOrderId'); + this.validateOrderId(params, 'pendingClientOrderId'); + return this.postPrivate('sapi/v1/margin/order/oto', params); + } + + /** + * Submit a new OTOCO order for margin account + */ + submitMarginOTOCOOrder( + params: SubmitMarginOTOCOOrderParams, + ): Promise { + this.validateOrderId(params, 'listClientOrderId'); + this.validateOrderId(params, 'workingClientOrderId'); + this.validateOrderId(params, 'pendingAboveClientOrderId'); + this.validateOrderId(params, 'pendingBelowClientOrderId'); + return this.postPrivate('sapi/v1/margin/order/otoco', params); + } + + /** + * Create a special key for low-latency trading (VIP 4+ only) + */ + createMarginSpecialLowLatencyKey( + params: CreateSpecialLowLatencyKeyParams, + ): Promise { + return this.postPrivate('sapi/v1/margin/apiKey', params); + } + + deleteMarginSpecialLowLatencyKey(params?: { + apiKey?: string; + apiName?: string; + symbol?: string; + }): Promise { + return this.deletePrivate('sapi/v1/margin/apiKey', params); + } + + updateMarginIPForSpecialLowLatencyKey(params: { + apiKey: string; + symbol?: string; + ip: string; + }): Promise<{}> { + return this.putPrivate('sapi/v1/margin/apiKey/ip', params); + } + + /** + * Query the list of special keys for low-latency trading + */ + getMarginSpecialLowLatencyKeys(params: { + symbol?: string; + }): Promise { + return this.getPrivate('sapi/v1/margin/api-key-list', params); + } + + /** + * Query information for a specific special key used in low-latency trading + */ + getMarginSpecialLowLatencyKey(params: { + apiKey: string; + symbol?: string; + }): Promise { + return this.getPrivate('sapi/v1/margin/apiKey', params); + } + /** * * MARGIN TRADING Endpoints - Transfer endpoints diff --git a/src/types/spot.ts b/src/types/spot.ts index a258ca90..b6108ddb 100644 --- a/src/types/spot.ts +++ b/src/types/spot.ts @@ -5119,3 +5119,174 @@ export interface QueryBrokerFuturesCommissionRebateParams { recvWindow?: number; timestamp: number; } + +export interface SubmitMarginOTOOrderParams { + symbol: string; + isIsolated?: 'TRUE' | 'FALSE'; + listClientOrderId?: string; + newOrderRespType?: 'ACK' | 'RESULT' | 'FULL'; + sideEffectType?: 'NO_SIDE_EFFECT' | 'MARGIN_BUY'; + selfTradePreventionMode?: + | 'EXPIRE_TAKER' + | 'EXPIRE_MAKER' + | 'EXPIRE_BOTH' + | 'NONE'; + autoRepayAtCancel?: boolean; + workingType: 'LIMIT' | 'LIMIT_MAKER'; + workingSide: 'BUY' | 'SELL'; + workingClientOrderId?: string; + workingPrice: number; + workingQuantity: number; + workingIcebergQty?: number; + workingTimeInForce?: 'GTC' | 'IOC' | 'FOK'; + pendingType: OrderType; + pendingSide: 'BUY' | 'SELL'; + pendingClientOrderId?: string; + pendingPrice?: number; + pendingStopPrice?: number; + pendingTrailingDelta?: number; + pendingQuantity: number; + pendingIcebergQty?: number; + pendingTimeInForce?: 'GTC' | 'IOC' | 'FOK'; +} + +export interface MarginOTOOrder { + orderListId: number; + contingencyType: string; + listStatusType: string; + listOrderStatus: string; + listClientOrderId: string; + transactionTime: number; + symbol: string; + isIsolated: boolean; + orders: { + symbol: string; + orderId: number; + clientOrderId: string; + }[]; + orderReports: { + symbol: string; + orderId: number; + orderListId: number; + clientOrderId: string; + transactTime: number; + price: string; + origQty: string; + executedQty: string; + cummulativeQuoteQty: string; + status: string; + timeInForce: string; + type: string; + side: string; + selfTradePreventionMode: string; + }[]; +} + +export interface SubmitMarginOTOCOOrderParams { + symbol: string; + isIsolated?: 'TRUE' | 'FALSE'; + sideEffectType?: 'NO_SIDE_EFFECT' | 'MARGIN_BUY'; + autoRepayAtCancel?: boolean; + listClientOrderId?: string; + newOrderRespType?: 'ACK' | 'RESULT' | 'FULL'; + selfTradePreventionMode?: + | 'EXPIRE_TAKER' + | 'EXPIRE_MAKER' + | 'EXPIRE_BOTH' + | 'NONE'; + workingType: 'LIMIT' | 'LIMIT_MAKER'; + workingSide: 'BUY' | 'SELL'; + workingClientOrderId?: string; + workingPrice: string; + workingQuantity: string; + workingIcebergQty?: string; + workingTimeInForce?: 'GTC' | 'IOC' | 'FOK'; + pendingSide: 'BUY' | 'SELL'; + pendingQuantity: string; + pendingAboveType: 'LIMIT_MAKER' | 'STOP_LOSS' | 'STOP_LOSS_LIMIT'; + pendingAboveClientOrderId?: string; + pendingAbovePrice?: string; + pendingAboveStopPrice?: string; + pendingAboveTrailingDelta?: string; + pendingAboveIcebergQty?: string; + pendingAboveTimeInForce?: 'GTC' | 'IOC' | 'FOK'; + pendingBelowType: 'LIMIT_MAKER' | 'STOP_LOSS' | 'STOP_LOSS_LIMIT'; + pendingBelowClientOrderId?: string; + pendingBelowPrice?: string; + pendingBelowStopPrice?: string; + pendingBelowTrailingDelta?: string; + pendingBelowIcebergQty?: string; + pendingBelowTimeInForce?: 'GTC' | 'IOC' | 'FOK'; +} + +export interface MarginOTOCOOrder { + orderListId: number; + contingencyType: 'OTO'; + listStatusType: 'EXEC_STARTED'; + listOrderStatus: 'EXECUTING'; + listClientOrderId: string; + transactionTime: number; + symbol: string; + isIsolated: boolean; + orders: { + symbol: string; + orderId: number; + clientOrderId: string; + }[]; + orderReports: { + symbol: string; + orderId: number; + orderListId: number; + clientOrderId: string; + transactTime: number; + price: string; + origQty: string; + executedQty: string; + cummulativeQuoteQty: string; + status: + | 'NEW' + | 'PARTIALLY_FILLED' + | 'FILLED' + | 'CANCELED' + | 'PENDING_CANCEL' + | 'REJECTED' + | 'EXPIRED' + | 'PENDING_NEW'; + timeInForce: 'GTC' | 'IOC' | 'FOK'; + type: + | 'LIMIT' + | 'MARKET' + | 'STOP_LOSS' + | 'STOP_LOSS_LIMIT' + | 'TAKE_PROFIT' + | 'TAKE_PROFIT_LIMIT' + | 'LIMIT_MAKER'; + side: 'BUY' | 'SELL'; + stopPrice?: string; + selfTradePreventionMode: + | 'EXPIRE_TAKER' + | 'EXPIRE_MAKER' + | 'EXPIRE_BOTH' + | 'NONE'; + }[]; +} + +export interface CreateSpecialLowLatencyKeyParams { + apiName: string; + symbol?: string; + ip?: string; + publicKey?: string; +} + +export interface SpecialLowLatencyKeyResponse { + apiKey: string; + secretKey: string | null; + type: 'HMAC_SHA256' | 'RSA' | 'Ed25519'; +} + +export interface SpecialLowLatencyKeyInfo { + apiName: string; + apiKey: string; + ip: string; + type: 'HMAC_SHA256' | 'RSA' | 'Ed25519'; +} \ No newline at end of file