Skip to content

Commit 5f47498

Browse files
committed
v2.10.2: feat(#411) add spot SOR order endpoints
1 parent 2bb5172 commit 5f47498

File tree

4 files changed

+128
-16
lines changed

4 files changed

+128
-16
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "binance",
3-
"version": "2.10.1",
3+
"version": "2.10.2",
44
"description": "Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/main-client.ts

+38
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ import {
189189
ReplaceSpotOrderParams,
190190
ReplaceSpotOrderResultError,
191191
ReplaceSpotOrderResultSuccess,
192+
NewSpotSOROrderParams,
193+
SOROrderResponseFull,
194+
SORTestOrderResponse,
192195
} from './types/spot';
193196

194197
import {
@@ -859,10 +862,45 @@ export class MainClient extends BaseRestClient {
859862
return this.getPrivate('api/v3/allOrderList', params);
860863
}
861864

865+
/**
866+
* Query open OCO
867+
*/
862868
getAllOpenOCO(): Promise<any> {
863869
return this.getPrivate('api/v3/openOrderList');
864870
}
865871

872+
/**
873+
* Places an order using smart order routing (SOR).
874+
*/
875+
submitNewSOROrder(
876+
params: NewSpotSOROrderParams,
877+
): Promise<SOROrderResponseFull> {
878+
this.validateOrderId(params, 'newClientOrderId');
879+
return this.postPrivate('api/v3/sor/order', params);
880+
}
881+
882+
/**
883+
* Test new order creation and signature/recvWindow using smart order routing (SOR).
884+
* Creates and validates a new order but does not send it into the matching engine.
885+
*/
886+
testNewSOROrder(
887+
params: NewSpotSOROrderParams & { computeCommissionRates?: boolean },
888+
): Promise<{} | SORTestOrderResponse> {
889+
this.validateOrderId(params, 'newClientOrderId');
890+
return this.postPrivate('api/v3/sor/order/test', params);
891+
}
892+
893+
/**
894+
*
895+
*
896+
* Spot Account Endpoints
897+
*
898+
*
899+
*/
900+
901+
/**
902+
* Get current account information
903+
*/
866904
getAccountInformation(): Promise<AccountInformation> {
867905
return this.getPrivate('api/v3/account');
868906
}

src/types/spot.ts

+87-13
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,25 @@ export interface GetOCOParams {
436436
origClientOrderId?: string;
437437
}
438438

439+
export interface NewSpotSOROrderParams {
440+
symbol: string;
441+
side: OrderSide;
442+
type: OrderType;
443+
timeInForce?: OrderTimeInForce;
444+
quantity: number;
445+
price?: number;
446+
newClientOrderId?: string;
447+
strategyId?: number;
448+
strategyType?: number;
449+
icebergQty?: number;
450+
newOrderRespType?: OrderResponseType;
451+
selfTradePreventionMode?:
452+
| 'EXPIRE_TAKER'
453+
| 'EXPIRE_MAKER'
454+
| 'EXPIRE_BOTH'
455+
| 'NONE';
456+
}
457+
439458
export type APILockTriggerCondition = 'GCR' | 'IFER' | 'UFR';
440459

441460
export interface APITriggerConditionSymbolStatus {
@@ -653,42 +672,97 @@ export interface OrderResponseFull {
653672
fills: OrderFill[];
654673
}
655674

656-
export interface GenericReplaceSpotOrderResult<C,N> {
675+
export interface SOROrderFill {
676+
matchType: string;
677+
price: numberInString;
678+
qty: numberInString;
679+
commission: numberInString;
680+
commissionAsset: string;
681+
tradeId: number;
682+
allocId: number;
683+
}
684+
685+
export type SOROrderResponseFull = OrderResponseFull & {
686+
workingTime: number;
687+
fills: SOROrderFill[];
688+
workingFloor: string;
689+
selfTradePreventionMode: string;
690+
usedSor: true;
691+
};
692+
693+
export interface SORTestOrderResponse {
694+
standardCommissionForOrder: {
695+
//Standard commission rates on trades from the order.
696+
maker: numberInString;
697+
taker: numberInString;
698+
};
699+
taxCommissionForOrder: {
700+
//Tax commission rates for trades from the order.
701+
maker: numberInString;
702+
taker: numberInString;
703+
};
704+
discount: {
705+
//Discount on standard commissions when paying in BNB.
706+
enabledForAccount: boolean;
707+
enabledForSymbol: boolean;
708+
discountAsset: string;
709+
discount: numberInString; //Standard commission is reduced by this rate when paying commission in BNB.
710+
};
711+
}
712+
713+
export interface GenericReplaceSpotOrderResult<C, N> {
657714
cancelResult: 'SUCCESS' | 'FAILURE';
658715
newOrderResult: 'SUCCESS' | 'FAILURE' | 'NOT_ATTEMPTED';
659716
cancelResponse: C;
660717
newOrderResponse: N;
661718
}
662719

663-
export interface ReplaceSpotOrderCancelStopFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, null> {
720+
export interface ReplaceSpotOrderCancelStopFailure
721+
extends GenericReplaceSpotOrderResult<GenericCodeMsgError, null> {
664722
cancelResult: 'FAILURE';
665723
newOrderResult: 'NOT_ATTEMPTED';
666724
}
667725

668-
export interface ReplaceSpotOrderNewFailure extends GenericReplaceSpotOrderResult<CancelSpotOrderResult, GenericCodeMsgError> {
726+
export interface ReplaceSpotOrderNewFailure
727+
extends GenericReplaceSpotOrderResult<
728+
CancelSpotOrderResult,
729+
GenericCodeMsgError
730+
> {
669731
cancelResult: 'SUCCESS';
670732
newOrderResult: 'FAILURE';
671733
}
672734

673-
export interface ReplaceSpotOrderCancelAllowFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, OrderResponseACK | OrderResponseResult | OrderResponseFull> {
735+
export interface ReplaceSpotOrderCancelAllowFailure
736+
extends GenericReplaceSpotOrderResult<
737+
GenericCodeMsgError,
738+
OrderResponseACK | OrderResponseResult | OrderResponseFull
739+
> {
674740
cancelResult: 'FAILURE';
675741
newOrderResult: 'SUCCESS';
676742
}
677743

678-
export interface ReplaceSpotOrderCancelAllFailure extends GenericReplaceSpotOrderResult<GenericCodeMsgError, GenericCodeMsgError> {
744+
export interface ReplaceSpotOrderCancelAllFailure
745+
extends GenericReplaceSpotOrderResult<
746+
GenericCodeMsgError,
747+
GenericCodeMsgError
748+
> {
679749
cancelResult: 'FAILURE';
680750
newOrderResult: 'FAILURE';
681751
}
682752

683753
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> {
754+
data:
755+
| ReplaceSpotOrderCancelStopFailure
756+
| ReplaceSpotOrderNewFailure
757+
| ReplaceSpotOrderCancelAllowFailure
758+
| ReplaceSpotOrderCancelAllFailure;
759+
}
760+
761+
export interface ReplaceSpotOrderResultSuccess
762+
extends GenericReplaceSpotOrderResult<
763+
CancelSpotOrderResult,
764+
OrderResponseACK | OrderResponseResult | OrderResponseFull
765+
> {
692766
cancelResult: 'SUCCESS';
693767
newOrderResult: 'SUCCESS';
694768
}

0 commit comments

Comments
 (0)