Skip to content

Commit

Permalink
Merge pull request #387 from t0chk/master
Browse files Browse the repository at this point in the history
Order changing
  • Loading branch information
tiagosiebler authored Jan 24, 2024
2 parents 6fca067 + 86147ff commit 5817027
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
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 5817027

Please sign in to comment.