Skip to content

Commit 9786f9c

Browse files
authored
Merge pull request #970 from ccxt/update-types-2
fix(client): avoid breaking types checking + new algo order types
2 parents e37d8b2 + 5b6b263 commit 9786f9c

File tree

2 files changed

+68
-22
lines changed

2 files changed

+68
-22
lines changed

src/node-binance-api.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import nodeFetch from 'node-fetch';
1616
import zip from 'lodash.zipobject';
1717
import stringHash from 'string-hash';
1818
// eslint-disable-next-line
19-
import { Interval, PositionRisk, Order, FuturesOrder, PositionSide, WorkingType, OrderType, OrderStatus, TimeInForce, Callback, IConstructorArgs, OrderSide, FundingRate, CancelOrder, AggregatedTrade, Trade, MyTrade, WithdrawHistoryResponse, DepositHistoryResponse, DepositAddress, WithdrawResponse, Candle, FuturesCancelAllOpenOrder, OrderBook, Ticker, FuturesUserTrade, Account, FuturesAccountInfo, FuturesBalance, QueryOrder, HttpMethod, BookTicker, DailyStats, PremiumIndex, OpenInterest, IWebsocketsMethods, SymbolConfig, OCOOrder } from './types.js';
19+
import { Interval, PositionRisk, Order, FuturesOrder, PositionSide, WorkingType, OrderType, OrderStatus, TimeInForce, Callback, IConstructorArgs, OrderSide, FundingRate, CancelOrder, AggregatedTrade, Trade, MyTrade, WithdrawHistoryResponse, DepositHistoryResponse, DepositAddress, WithdrawResponse, Candle, FuturesCancelAllOpenOrder, OrderBook, Ticker, FuturesUserTrade, Account, FuturesAccountInfo, FuturesBalance, QueryOrder, HttpMethod, BookTicker, DailyStats, PremiumIndex, OpenInterest, IWebsocketsMethods, SymbolConfig, OCOOrder, FuturesAlgoOrder, CancelAlgoOrder } from './types.js';
2020
// export { Interval, PositionRisk, Order, FuturesOrder, PositionSide, WorkingType, OrderType, OrderStatus, TimeInForce, Callback, IConstructorArgs, OrderSide, FundingRate, CancelOrder, AggregatedTrade, Trade, MyTrade, WithdrawHistoryResponse, DepositHistoryResponse, DepositAddress, WithdrawResponse, Candle, FuturesCancelAllOpenOrder, OrderBook, Ticker, FuturesUserTrade, FuturesAccountInfo, FuturesBalance, QueryOrder } from './types';
2121

2222
export interface Dictionary<T> {
@@ -1158,6 +1158,7 @@ export default class Binance {
11581158
// Futures internal functions
11591159
/**
11601160
* @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Order
1161+
* @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Algo-Order
11611162
* @param type
11621163
* @param side
11631164
* @param symbol symbol if the market
@@ -1223,7 +1224,7 @@ export default class Binance {
12231224
* @param params extra parameters to be sent in the request
12241225
* @returns
12251226
*/
1226-
async futuresAlgoOrder(type: OrderType, side: string, symbol: string, quantity: number, price?: number, params: Dict = {}): Promise<FuturesOrder> {
1227+
async futuresAlgoOrder(type: OrderType, side: string, symbol: string, quantity: number, price?: number, params: Dict = {}): Promise<FuturesAlgoOrder> {
12271228
params.symbol = symbol;
12281229
params.side = side;
12291230
params.type = type;
@@ -4584,7 +4585,7 @@ export default class Binance {
45844585
* @param params extra parameters to be sent in the request
45854586
* @returns
45864587
*/
4587-
async futuresAlgoOrderStatus(symbol: string, params: Dict = {}): Promise<FuturesOrder> { // Either orderId or origClientOrderId must be sent
4588+
async futuresAlgoOrderStatus(symbol: string, params: Dict = {}): Promise<FuturesAlgoOrder> { // Either orderId or origClientOrderId must be sent
45884589
params.symbol = symbol;
45894590
return await this.privateFuturesRequest('v1/algoOrder', params);
45904591
}
@@ -4616,7 +4617,7 @@ export default class Binance {
46164617
* @param params extra parameters to be sent in the request
46174618
* @returns
46184619
*/
4619-
async futuresCancelAlgoOrder(symbol: string, orderId?: number | string, params: Dict = {}): Promise<CancelOrder> { // Either orderId or origClientOrderId must be sent
4620+
async futuresCancelAlgoOrder(symbol: string, orderId?: number | string, params: Dict = {}): Promise<CancelAlgoOrder> { // Either orderId or origClientOrderId must be sent
46204621
params.symbol = symbol;
46214622
if (orderId) params.algoid = orderId;
46224623
return await this.privateFuturesRequest('v1/algoOrder', params, 'DELETE');
@@ -4706,7 +4707,7 @@ export default class Binance {
47064707
* @param params extra parameters to be sent in the request
47074708
* @returns
47084709
*/
4709-
async futuresAllAlgoOrders(symbol?: string, params: Dict = {}): Promise<FuturesOrder[]> { // Get all account orders; active, canceled, or filled.
4710+
async futuresAllAlgoOrders(symbol?: string, params: Dict = {}): Promise<FuturesAlgoOrder[]> { // Get all account orders; active, canceled, or filled.
47104711
if (symbol) params.symbol = symbol;
47114712
return await this.privateFuturesRequest('v1/allAlgoOrders', params);
47124713
}

src/types.ts

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,28 @@ export interface Order {
9696
}
9797

9898
export interface FuturesOrder {
99-
clientOrderId?: string
100-
cumQty?: string
101-
cumQuote?: string
102-
executedQty?: string
103-
orderId?: number
104-
avgPrice?: string
105-
origQty?: string
99+
clientOrderId: string
100+
cumQty: string
101+
cumQuote: string
102+
executedQty: string
103+
orderId: number
104+
avgPrice: string
105+
origQty: string
106106
price: string
107107
reduceOnly: boolean
108108
side: OrderSide
109109
positionSide: PositionSide
110-
status?: OrderStatus
111-
stopPrice?: string
112-
closePosition?: boolean
110+
status: OrderStatus
111+
stopPrice: string
112+
closePosition: boolean
113113
symbol: string
114-
timeInForce?: TimeInForce
115-
type?: OrderType
116-
origType?: OrderType
117-
activatePrice?: string
118-
priceRate?: string
119-
updateTime?: number
120-
workingType?: WorkingType
114+
timeInForce: TimeInForce
115+
type: OrderType
116+
origType: OrderType
117+
activatePrice: string
118+
priceRate: string
119+
updateTime: number
120+
workingType: WorkingType
121121
// algo orders fields
122122
algoId?: number;
123123
triggerPrice?: string;
@@ -132,6 +132,46 @@ export interface FuturesOrder {
132132
slPrice?: string;
133133
tpOrderType?: string;
134134
slOrderType?: string;
135+
algoType?: string;
136+
orderType?: OrderType;
137+
quantity?: string;
138+
icebergQuantity?: string;
139+
selfTradePreventionMode?: string;
140+
priceMatch?: string;
141+
priceProtect?: boolean;
142+
callbackRate?: string; //TRAILING_STOP_MARKET order
143+
createTime?: number;
144+
triggerTime?: number;
145+
goodTillDate?: number;
146+
}
147+
148+
export interface FuturesAlgoOrder {
149+
algoId: number;
150+
clientOrderId: string;
151+
clientAlgoId: string;
152+
algoType: string;
153+
orderType: OrderType;
154+
symbol: string;
155+
side: OrderSide;
156+
positionSide: PositionSide;
157+
timeInForce: TimeInForce;
158+
quantity: string;
159+
algoStatus: string;
160+
triggerPrice: string;
161+
price: string;
162+
icebergQuantity: string | null;
163+
selfTradePreventionMode: string;
164+
workingType: WorkingType;
165+
priceMatch: string;
166+
closePosition: boolean;
167+
priceProtect: boolean;
168+
reduceOnly: boolean;
169+
activatePrice: string; //TRAILING_STOP_MARKET order
170+
callbackRate: string; //TRAILING_STOP_MARKET order
171+
createTime: number;
172+
updateTime: number;
173+
triggerTime: number;
174+
goodTillDate: number;
135175
}
136176

137177
export type PositionSide = 'BOTH' | 'SHORT' | 'LONG'
@@ -359,6 +399,11 @@ export interface CancelOrder {
359399
side: OrderSide
360400
}
361401

402+
export interface CancelAlgoOrder {
403+
algoId: number;
404+
clientAlgoId: string;
405+
}
406+
362407
export interface FuturesUserTrade {
363408
buyer: boolean
364409
commission: string

0 commit comments

Comments
 (0)