Skip to content

Commit

Permalink
Order changing
Browse files Browse the repository at this point in the history
-Add change order in usdm-m
-Add cancel-and-replace on spot.
  • Loading branch information
t0chk committed Jan 24, 2024
1 parent 023c46f commit 86147ff
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 9 additions & 0 deletions src/main-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ import {
GetOrderStatusParams,
EnableConvertSubAccountParams,
AcceptQuoteRequestParams,
ReplaceSpotOrderParams,
ReplaceSpotOrderResultError,
ReplaceSpotOrderResultSuccess,
} from './types/spot';

import {
Expand Down Expand Up @@ -801,6 +804,12 @@ export class MainClient extends BaseRestClient {
return this.postPrivate('api/v3/order/test', params);
}

replaceOrder(
params: ReplaceSpotOrderParams,
): Promise<ReplaceSpotOrderResultSuccess> {
return this.postPrivate('api/v3/order/cancelReplace', params);
}

submitNewOrder(
params: NewSpotOrderParams,
): Promise<OrderResponseACK | OrderResponseResult | OrderResponseFull> {
Expand Down
49 changes: 49 additions & 0 deletions src/types/spot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ExchangeFilter,
ExchangeSymbol,
GenericCodeMsgError,
numberInString,
OrderBookRow,
OrderResponseType,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -644,6 +653,46 @@ export interface OrderResponseFull {
fills: OrderFill[];
}

export interface GenericReplaceSpotOrderResult<C,N> {
cancelResult: 'SUCCESS' | 'FAILURE';
newOrderResult: 'SUCCESS' | 'FAILURE' | 'NOT_ATTEMPTED';
cancelResponse: C;
newOrderResponse: N;
}

export interface ReplaceSpotOrderCancelStopFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, null> {
cancelResult: 'FAILURE';
newOrderResult: 'NOT_ATTEMPTED';
}

export interface ReplaceSpotOrderNewFailure extends GenericReplaceSpotOrderResult<CancelSpotOrderResult, GenericCodeMsgError> {
cancelResult: 'SUCCESS';
newOrderResult: 'FAILURE';
}

export interface ReplaceSpotOrderCancelAllowFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, OrderResponseACK | OrderResponseResult | OrderResponseFull> {
cancelResult: 'FAILURE';
newOrderResult: 'SUCCESS';
}

export interface ReplaceSpotOrderCancelAllFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, GenericCodeMsgError> {
cancelResult: 'FAILURE';
newOrderResult: 'FAILURE';
}

export interface ReplaceSpotOrderResultError {
data:
| ReplaceSpotOrderCancelStopFailure
| ReplaceSpotOrderNewFailure
| ReplaceSpotOrderCancelAllowFailure
| ReplaceSpotOrderCancelAllFailure
}

export interface ReplaceSpotOrderResultSuccess extends GenericReplaceSpotOrderResult<CancelSpotOrderResult, OrderResponseACK | OrderResponseResult | OrderResponseFull> {
cancelResult: 'SUCCESS';
newOrderResult: 'SUCCESS';
}

export interface CancelSpotOrderResult {
symbol: string;
origClientOrderId: string;
Expand Down
11 changes: 11 additions & 0 deletions src/usdm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import {
MarkPrice,
HistoricOpenInterest,
UserCommissionRate,
ModifyFuturesOrderParams,
ModifyFuturesOrderResult,
} from './types/futures';

import {
Expand Down Expand Up @@ -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<ModifyFuturesOrderResult> {
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.
*
Expand Down

0 comments on commit 86147ff

Please sign in to comment.