Skip to content

Commit 5817027

Browse files
authored
Merge pull request #387 from t0chk/master
Order changing
2 parents 6fca067 + 86147ff commit 5817027

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/main-client.ts

+9
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ import {
186186
GetOrderStatusParams,
187187
EnableConvertSubAccountParams,
188188
AcceptQuoteRequestParams,
189+
ReplaceSpotOrderParams,
190+
ReplaceSpotOrderResultError,
191+
ReplaceSpotOrderResultSuccess,
189192
} from './types/spot';
190193

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

807+
replaceOrder(
808+
params: ReplaceSpotOrderParams,
809+
): Promise<ReplaceSpotOrderResultSuccess> {
810+
return this.postPrivate('api/v3/order/cancelReplace', params);
811+
}
812+
804813
submitNewOrder(
805814
params: NewSpotOrderParams,
806815
): Promise<OrderResponseACK | OrderResponseResult | OrderResponseFull> {

src/types/spot.ts

+49
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ExchangeFilter,
33
ExchangeSymbol,
4+
GenericCodeMsgError,
45
numberInString,
56
OrderBookRow,
67
OrderResponseType,
@@ -420,6 +421,14 @@ export interface NewSpotOrderParams {
420421
sideEffectType?: SideEffects;
421422
}
422423

424+
export interface ReplaceSpotOrderParams extends NewSpotOrderParams {
425+
cancelReplaceMode: 'STOP_ON_FAILURE' | 'ALLOW_FAILURE';
426+
cancelNewClientOrderId?: string;
427+
cancelOrigClientOrderId?: string;
428+
cancelOrderId?: number;
429+
cancelRestrictions?: 'ONLY_NEW' | 'ONLY_PARTIALLY_FILLED';
430+
}
431+
423432
export interface GetOCOParams {
424433
symbol?: string;
425434
isIsolated?: StringBoolean;
@@ -644,6 +653,46 @@ export interface OrderResponseFull {
644653
fills: OrderFill[];
645654
}
646655

656+
export interface GenericReplaceSpotOrderResult<C,N> {
657+
cancelResult: 'SUCCESS' | 'FAILURE';
658+
newOrderResult: 'SUCCESS' | 'FAILURE' | 'NOT_ATTEMPTED';
659+
cancelResponse: C;
660+
newOrderResponse: N;
661+
}
662+
663+
export interface ReplaceSpotOrderCancelStopFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, null> {
664+
cancelResult: 'FAILURE';
665+
newOrderResult: 'NOT_ATTEMPTED';
666+
}
667+
668+
export interface ReplaceSpotOrderNewFailure extends GenericReplaceSpotOrderResult<CancelSpotOrderResult, GenericCodeMsgError> {
669+
cancelResult: 'SUCCESS';
670+
newOrderResult: 'FAILURE';
671+
}
672+
673+
export interface ReplaceSpotOrderCancelAllowFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, OrderResponseACK | OrderResponseResult | OrderResponseFull> {
674+
cancelResult: 'FAILURE';
675+
newOrderResult: 'SUCCESS';
676+
}
677+
678+
export interface ReplaceSpotOrderCancelAllFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, GenericCodeMsgError> {
679+
cancelResult: 'FAILURE';
680+
newOrderResult: 'FAILURE';
681+
}
682+
683+
export interface ReplaceSpotOrderResultError {
684+
data:
685+
| ReplaceSpotOrderCancelStopFailure
686+
| ReplaceSpotOrderNewFailure
687+
| ReplaceSpotOrderCancelAllowFailure
688+
| ReplaceSpotOrderCancelAllFailure
689+
}
690+
691+
export interface ReplaceSpotOrderResultSuccess extends GenericReplaceSpotOrderResult<CancelSpotOrderResult, OrderResponseACK | OrderResponseResult | OrderResponseFull> {
692+
cancelResult: 'SUCCESS';
693+
newOrderResult: 'SUCCESS';
694+
}
695+
647696
export interface CancelSpotOrderResult {
648697
symbol: string;
649698
origClientOrderId: string;

src/usdm-client.ts

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import {
6666
MarkPrice,
6767
HistoricOpenInterest,
6868
UserCommissionRate,
69+
ModifyFuturesOrderParams,
70+
ModifyFuturesOrderResult,
6971
} from './types/futures';
7072

7173
import {
@@ -277,6 +279,15 @@ export class USDMClient extends BaseRestClient {
277279
return this.postPrivate('fapi/v1/order', params);
278280
}
279281

282+
/**
283+
* Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue
284+
*/
285+
modifyOrder(
286+
params: ModifyFuturesOrderParams,
287+
): Promise<ModifyFuturesOrderResult> {
288+
return this.putPrivate('fapi/v1/order', params);
289+
}
290+
280291
/**
281292
* 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.
282293
*

0 commit comments

Comments
 (0)