Skip to content

Commit 0bec996

Browse files
authored
fix(types): add runtime enum exports, WebSocket types, and futuresOrder algo response (#696)
- Add runtime exports for OrderSide, OrderType, TimeInForce, OrderStatus, RateLimitType, RateLimitInterval, TradingType so enum values work at runtime - Add types/websocket.d.ts with event interfaces and BinanceWebSocket interface - Add ws property to BinanceRest and export websocket types from index.d.ts - Add FuturesAlgoOrderResponse type and union return for futuresOrder - Add missing futuresOrder payload fields (triggerPrice, positionSide, etc.) - Add top-level "types" field to package.json for older TS moduleResolution
1 parent 2b2cda9 commit 0bec996

File tree

5 files changed

+450
-24
lines changed

5 files changed

+450
-24
lines changed

index.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PortfolioMarginEndpoints } from './types/portfolio-margin';
1212
import { SavingsEndpoints } from './types/savings';
1313
import { MiningEndpoints } from './types/mining';
1414
import { UtilityEndpoints } from './types/utility';
15+
import { BinanceWebSocket } from './types/websocket';
1516

1617
export interface BinanceRest extends
1718
GenericEndpoints,
@@ -26,7 +27,9 @@ export interface BinanceRest extends
2627
PortfolioMarginEndpoints,
2728
SavingsEndpoints,
2829
MiningEndpoints,
29-
UtilityEndpoints {}
30+
UtilityEndpoints {
31+
ws: BinanceWebSocket;
32+
}
3033

3134
export * from './types/base';
3235

@@ -143,6 +146,8 @@ export * from './types/utility';
143146

144147
// } from './types/utility';
145148

149+
export * from './types/websocket';
150+
146151

147152
declare function Binance(options?: BinanceRestClient.BinanceRestOptions): BinanceRest;
148153
export default Binance;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.13.6",
44
"description": "A node API wrapper for Binance",
55
"main": "dist",
6+
"types": "index.d.ts",
67
"browser": {
78
"crypto": false,
89
"./dist/http-client.js": "./dist/http-client.js"

src/index.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,60 @@ export const PayStatus = {
118118
SUCCESS: 'SUCCESS',
119119
FAILED: 'FAILED',
120120
}
121+
122+
export const OrderSide = {
123+
BUY: 'BUY',
124+
SELL: 'SELL',
125+
}
126+
127+
export const OrderType = {
128+
LIMIT: 'LIMIT',
129+
MARKET: 'MARKET',
130+
STOP_LOSS: 'STOP_LOSS',
131+
STOP_LOSS_LIMIT: 'STOP_LOSS_LIMIT',
132+
TAKE_PROFIT: 'TAKE_PROFIT',
133+
TAKE_PROFIT_LIMIT: 'TAKE_PROFIT_LIMIT',
134+
LIMIT_MAKER: 'LIMIT_MAKER',
135+
STOP_MARKET: 'STOP_MARKET',
136+
TAKE_PROFIT_MARKET: 'TAKE_PROFIT_MARKET',
137+
TRAILING_STOP_MARKET: 'TRAILING_STOP_MARKET',
138+
}
139+
140+
export const TimeInForce = {
141+
GTC: 'GTC',
142+
IOC: 'IOC',
143+
FOK: 'FOK',
144+
RPI: 'RPI',
145+
}
146+
147+
export const OrderStatus = {
148+
NEW: 'NEW',
149+
PARTIALLY_FILLED: 'PARTIALLY_FILLED',
150+
FILLED: 'FILLED',
151+
CANCELED: 'CANCELED',
152+
PENDING_CANCEL: 'PENDING_CANCEL',
153+
REJECTED: 'REJECTED',
154+
EXPIRED: 'EXPIRED',
155+
ACCEPTED: 'ACCEPTED',
156+
TRIGGERING: 'TRIGGERING',
157+
TRIGGERED: 'TRIGGERED',
158+
FINISHED: 'FINISHED',
159+
}
160+
161+
export const RateLimitType = {
162+
REQUEST_WEIGHT: 'REQUEST_WEIGHT',
163+
ORDERS: 'ORDERS',
164+
RAW_REQUESTS: 'RAW_REQUESTS',
165+
}
166+
167+
export const RateLimitInterval = {
168+
SECOND: 'SECOND',
169+
MINUTE: 'MINUTE',
170+
HOUR: 'HOUR',
171+
DAY: 'DAY',
172+
}
173+
174+
export const TradingType = {
175+
SPOT: 'SPOT',
176+
MARGIN: 'MARGIN',
177+
}

types/futures.d.ts

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
import { BinanceRestClient, OrderSide, OrderStatus, OrderType, TimeInForce } from './base';
22

3+
export interface FuturesOrderResponse {
4+
symbol: string;
5+
orderId: number;
6+
orderListId: number;
7+
clientOrderId: string;
8+
transactTime: number;
9+
price: string;
10+
origQty: string;
11+
executedQty: string;
12+
cumQuote: string;
13+
status: OrderStatus;
14+
timeInForce: TimeInForce;
15+
type: OrderType;
16+
side: OrderSide;
17+
marginBuyBorrowAmount: string;
18+
marginBuyBorrowAsset: string;
19+
fills: Array<{
20+
price: string;
21+
qty: string;
22+
commission: string;
23+
commissionAsset: string;
24+
}>;
25+
}
26+
27+
export interface FuturesAlgoOrderResponse {
28+
symbol: string;
29+
algoId: number;
30+
clientAlgoId: string;
31+
transactTime: number;
32+
algoType: string;
33+
side: OrderSide;
34+
type: string;
35+
status: OrderStatus;
36+
}
37+
338
export interface FuturesEndpoints extends BinanceRestClient {
439
futuresPing(): Promise<boolean>;
540
futuresTime(): Promise<{
@@ -156,34 +191,21 @@ export interface FuturesEndpoints extends BinanceRestClient {
156191
price?: string;
157192
newClientOrderId?: string;
158193
stopPrice?: string;
194+
triggerPrice?: string;
159195
trailingDelta?: number;
160196
trailingTime?: number;
161197
icebergQty?: string;
162198
newOrderRespType?: string;
163199
timeInForce?: TimeInForce;
164-
}): Promise<{
165-
symbol: string;
166-
orderId: number;
167-
orderListId: number;
168-
clientOrderId: string;
169-
transactTime: number;
170-
price: string;
171-
origQty: string;
172-
executedQty: string;
173-
cumQuote: string;
174-
status: OrderStatus;
175-
timeInForce: TimeInForce;
176-
type: OrderType;
177-
side: OrderSide;
178-
marginBuyBorrowAmount: string;
179-
marginBuyBorrowAsset: string;
180-
fills: Array<{
181-
price: string;
182-
qty: string;
183-
commission: string;
184-
commissionAsset: string;
185-
}>;
186-
}>;
200+
positionSide?: 'BOTH' | 'LONG' | 'SHORT';
201+
reduceOnly?: string;
202+
closePosition?: boolean;
203+
workingType?: 'MARK_PRICE' | 'CONTRACT_PRICE';
204+
priceProtect?: string;
205+
activationPrice?: string;
206+
callbackRate?: string;
207+
clientAlgoId?: string;
208+
}): Promise<FuturesOrderResponse | FuturesAlgoOrderResponse>;
187209
futuresUpdateOrder(payload: {
188210
orderId?: number;
189211
origClientOrderId?: string;

0 commit comments

Comments
 (0)