From 86147ff8f905d906d105f0dfc1344422c3f42c8b Mon Sep 17 00:00:00 2001 From: t0chk <86585817+t0chk@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:33:46 +0300 Subject: [PATCH] Order changing -Add change order in usdm-m -Add cancel-and-replace on spot. --- package.json | 2 +- src/main-client.ts | 9 +++++++++ src/types/spot.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++++ src/usdm-client.ts | 11 +++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 82d779ca..19748c7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "binance", - "version": "2.9.1", + "version": "2.9.2", "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 06d2ee8b..192a3998 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -186,6 +186,9 @@ import { GetOrderStatusParams, EnableConvertSubAccountParams, AcceptQuoteRequestParams, + ReplaceSpotOrderParams, + ReplaceSpotOrderResultError, + ReplaceSpotOrderResultSuccess, } from './types/spot'; import { @@ -801,6 +804,12 @@ export class MainClient extends BaseRestClient { return this.postPrivate('api/v3/order/test', params); } + replaceOrder( + params: ReplaceSpotOrderParams, + ): Promise { + return this.postPrivate('api/v3/order/cancelReplace', params); + } + submitNewOrder( params: NewSpotOrderParams, ): Promise { diff --git a/src/types/spot.ts b/src/types/spot.ts index 6a88cf5e..6f162d8b 100644 --- a/src/types/spot.ts +++ b/src/types/spot.ts @@ -1,6 +1,7 @@ import { ExchangeFilter, ExchangeSymbol, + GenericCodeMsgError, numberInString, OrderBookRow, OrderResponseType, @@ -420,6 +421,14 @@ export interface NewSpotOrderParams { sideEffectType?: SideEffects; } +export interface ReplaceSpotOrderParams extends NewSpotOrderParams { + cancelReplaceMode: 'STOP_ON_FAILURE' | 'ALLOW_FAILURE'; + cancelNewClientOrderId?: string; + cancelOrigClientOrderId?: string; + cancelOrderId?: number; + cancelRestrictions?: 'ONLY_NEW' | 'ONLY_PARTIALLY_FILLED'; +} + export interface GetOCOParams { symbol?: string; isIsolated?: StringBoolean; @@ -644,6 +653,46 @@ export interface OrderResponseFull { fills: OrderFill[]; } +export interface GenericReplaceSpotOrderResult { + cancelResult: 'SUCCESS' | 'FAILURE'; + newOrderResult: 'SUCCESS' | 'FAILURE' | 'NOT_ATTEMPTED'; + cancelResponse: C; + newOrderResponse: N; +} + +export interface ReplaceSpotOrderCancelStopFailure extends GenericReplaceSpotOrderResult { + cancelResult: 'FAILURE'; + newOrderResult: 'NOT_ATTEMPTED'; +} + +export interface ReplaceSpotOrderNewFailure extends GenericReplaceSpotOrderResult { + cancelResult: 'SUCCESS'; + newOrderResult: 'FAILURE'; +} + +export interface ReplaceSpotOrderCancelAllowFailure extends GenericReplaceSpotOrderResult { + cancelResult: 'FAILURE'; + newOrderResult: 'SUCCESS'; +} + +export interface ReplaceSpotOrderCancelAllFailure extends GenericReplaceSpotOrderResult { + cancelResult: 'FAILURE'; + newOrderResult: 'FAILURE'; +} + +export interface ReplaceSpotOrderResultError { + data: + | ReplaceSpotOrderCancelStopFailure + | ReplaceSpotOrderNewFailure + | ReplaceSpotOrderCancelAllowFailure + | ReplaceSpotOrderCancelAllFailure +} + +export interface ReplaceSpotOrderResultSuccess extends GenericReplaceSpotOrderResult { + cancelResult: 'SUCCESS'; + newOrderResult: 'SUCCESS'; +} + export interface CancelSpotOrderResult { symbol: string; origClientOrderId: string; diff --git a/src/usdm-client.ts b/src/usdm-client.ts index aa642de7..2f54ec6d 100644 --- a/src/usdm-client.ts +++ b/src/usdm-client.ts @@ -66,6 +66,8 @@ import { MarkPrice, HistoricOpenInterest, UserCommissionRate, + ModifyFuturesOrderParams, + ModifyFuturesOrderResult, } from './types/futures'; import { @@ -277,6 +279,15 @@ export class USDMClient extends BaseRestClient { return this.postPrivate('fapi/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('fapi/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. *