From a1705e2e601467e1e5d4e9f933037552dda14ddf Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Sat, 2 Mar 2024 20:37:58 +0700 Subject: [PATCH 1/7] Update websocket baseurl for futures testnet --- src/websocket-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 7a693c91..f711ed35 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -32,7 +32,7 @@ const wsBaseEndpoints: Record = { margin: 'wss://stream.binance.com:9443', isolatedMargin: 'wss://stream.binance.com:9443', usdm: 'wss://fstream.binance.com', - usdmTestnet: 'wss://stream.binancefuture.com', + usdmTestnet: 'wss://fstream.binancefuture.com', coinm: 'wss://dstream.binance.com', coinmTestnet: 'wss://dstream.binancefuture.com', options: 'wss://vstream.binance.com', From 51ebcb699360764513108c7825d556655944ea93 Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Sat, 2 Mar 2024 20:41:11 +0700 Subject: [PATCH 2/7] Fix wrong type in throwUnhandledSwitch --- src/websocket-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/websocket-client.ts b/src/websocket-client.ts index f711ed35..d09a775f 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -124,7 +124,7 @@ interface ListenKeyPersistenceState { keepAliveFailures: number; } -function throwUnhandledSwitch(x: never, msg: string): never { +function throwUnhandledSwitch(x: unknown, msg: string): never { throw new Error(msg); } From ada996a4d026b0f430387106d010e5b5b2232754 Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Sat, 2 Mar 2024 21:21:14 +0700 Subject: [PATCH 3/7] Add support for binance spot test network --- src/main-client.ts | 5 +- src/types/shared.ts | 1 + src/types/websockets.ts | 1 + src/util/requestUtils.ts | 3 ++ src/websocket-client.ts | 108 ++++++++++++++++++++++++++++----------- 5 files changed, 86 insertions(+), 32 deletions(-) diff --git a/src/main-client.ts b/src/main-client.ts index cd92b4b2..58af6e17 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -206,8 +206,11 @@ export class MainClient extends BaseRestClient { constructor( restClientOptions: RestClientOptions = {}, requestOptions: AxiosRequestConfig = {}, + useTestnet?: boolean, ) { - super('spot1', restClientOptions, requestOptions); + const clientId = useTestnet ? 'spottest' : 'spot1'; + + super(clientId, restClientOptions, requestOptions); return this; } diff --git a/src/types/shared.ts b/src/types/shared.ts index c336ef6b..11e647fe 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -9,6 +9,7 @@ export type BooleanStringCapitalised = 'TRUE' | 'FALSE'; export type BinanceBaseUrlKey = | 'spot' + | 'spottest' | 'spot1' | 'spot2' | 'spot3' diff --git a/src/types/websockets.ts b/src/types/websockets.ts index 255819c4..018196e2 100644 --- a/src/types/websockets.ts +++ b/src/types/websockets.ts @@ -22,6 +22,7 @@ import { export type WsMarket = | 'spot' + | 'spotTestnet' | 'margin' | 'isolatedMargin' | 'usdm' diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index dca4c9db..0eb16f9a 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -54,6 +54,7 @@ export type GenericAPIResponse = Promise; export function getOrderIdPrefix(network: BinanceBaseUrlKey): string { switch (network) { case 'spot': + case 'spottest': case 'spot1': case 'spot2': case 'spot3': @@ -156,6 +157,7 @@ export async function getRequestSignature( const BINANCE_BASE_URLS: Record = { // spot/margin/savings/mining spot: 'https://api.binance.com', + spottest: 'https://testnet.binance.vision', spot1: 'https://api.binance.com', spot2: 'https://api1.binance.com', spot3: 'https://api2.binance.com', @@ -177,6 +179,7 @@ const BINANCE_BASE_URLS: Record = { export function getServerTimeEndpoint(urlKey: BinanceBaseUrlKey): string { switch (urlKey) { case 'spot': + case 'spottest': case 'spot1': case 'spot2': case 'spot3': diff --git a/src/websocket-client.ts b/src/websocket-client.ts index d09a775f..9fd428fc 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -29,6 +29,7 @@ import { CoinMClient } from './coinm-client'; const wsBaseEndpoints: Record = { spot: 'wss://stream.binance.com:9443', + spotTestnet: 'wss://testnet.binance.vision', margin: 'wss://stream.binance.com:9443', isolatedMargin: 'wss://stream.binance.com:9443', usdm: 'wss://fstream.binance.com', @@ -753,11 +754,12 @@ export class WebsocketClient extends EventEmitter { this.wsStore.setConnectionState(wsKey, state); } - private getSpotRestClient(): MainClient { + private getSpotRestClient(isTestnet?: boolean): MainClient { if (!this.restClients.spot) { this.restClients.spot = new MainClient( this.getRestClientOptions(), this.options.requestOptions, + isTestnet, ); } return this.restClients.spot; @@ -944,6 +946,10 @@ export class WebsocketClient extends EventEmitter { return this.getSpotRestClient().keepAliveSpotUserDataListenKey( listenKey, ); + case 'spotTestnet': + return this.getSpotRestClient(true).keepAliveSpotUserDataListenKey( + listenKey, + ); case 'margin': return this.getSpotRestClient().keepAliveMarginUserDataListenKey( listenKey, @@ -1096,6 +1102,13 @@ export class WebsocketClient extends EventEmitter { isReconnecting, ); break; + case 'spotTestnet': + ws = await this.subscribeSpotUserDataStream( + forceNewConnection, + isReconnecting, + true, + ); + break; case 'margin': ws = await this.subscribeMarginUserDataStream( forceNewConnection, @@ -1197,7 +1210,7 @@ export class WebsocketClient extends EventEmitter { public subscribeEndpoint( endpoint: string, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const wsKey = getWsKeyWithContext(market, endpoint); @@ -1213,7 +1226,7 @@ export class WebsocketClient extends EventEmitter { */ public subscribeAggregateTrades( symbol: string, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const lowerCaseSymbol = symbol.toLowerCase(); @@ -1232,7 +1245,7 @@ export class WebsocketClient extends EventEmitter { */ public subscribeTrades( symbol: string, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const lowerCaseSymbol = symbol.toLowerCase(); @@ -1311,7 +1324,7 @@ export class WebsocketClient extends EventEmitter { public subscribeKlines( symbol: string, interval: KlineInterval, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const lowerCaseSymbol = symbol.toLowerCase(); @@ -1411,7 +1424,7 @@ export class WebsocketClient extends EventEmitter { */ public subscribeSymbolMini24hrTicker( symbol: string, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const lowerCaseSymbol = symbol.toLowerCase(); @@ -1428,7 +1441,7 @@ export class WebsocketClient extends EventEmitter { * Subscribe to mini 24hr mini ticker in market category. */ public subscribeAllMini24hrTickers( - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const streamName = 'miniTicker'; @@ -1445,7 +1458,7 @@ export class WebsocketClient extends EventEmitter { */ public subscribeSymbol24hrTicker( symbol: string, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const lowerCaseSymbol = symbol.toLowerCase(); @@ -1462,7 +1475,7 @@ export class WebsocketClient extends EventEmitter { * Subscribe to 24hr ticker in any market. */ public subscribeAll24hrTickers( - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const streamName = 'ticker'; @@ -1484,7 +1497,7 @@ export class WebsocketClient extends EventEmitter { * - Supported markets: spot */ public subscribeAllRollingWindowTickers( - market: 'spot', + market: 'spot' | 'spotTestnet', windowSize: '1h' | '4h' | '1d', forceNewConnection?: boolean, ): WebSocket { @@ -1501,7 +1514,7 @@ export class WebsocketClient extends EventEmitter { */ public subscribeSymbolBookTicker( symbol: string, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const lowerCaseSymbol = symbol.toLowerCase(); @@ -1518,7 +1531,7 @@ export class WebsocketClient extends EventEmitter { * Subscribe to best bid/ask for all symbols in spot markets. */ public subscribeAllBookTickers( - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const streamName = 'bookTicker'; @@ -1577,7 +1590,7 @@ export class WebsocketClient extends EventEmitter { symbol: string, levels: 5 | 10 | 20, updateMs: 100 | 250 | 500 | 1000, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const lowerCaseSymbol = symbol.toLowerCase(); @@ -1607,7 +1620,7 @@ export class WebsocketClient extends EventEmitter { public subscribeDiffBookDepth( symbol: string, updateMs: 100 | 250 | 500 | 1000 = 100, - market: 'spot' | 'usdm' | 'coinm', + market: 'spot' | 'spotTestnet' | 'usdm' | 'coinm', forceNewConnection?: boolean, ): WebSocket { const lowerCaseSymbol = symbol.toLowerCase(); @@ -1641,8 +1654,10 @@ export class WebsocketClient extends EventEmitter { public subscribeSpotAggregateTrades( symbol: string, forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { - return this.subscribeAggregateTrades(symbol, 'spot', forceNewConnection); + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + return this.subscribeAggregateTrades(symbol, market, forceNewConnection); } /** @@ -1651,8 +1666,10 @@ export class WebsocketClient extends EventEmitter { public subscribeSpotTrades( symbol: string, forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { - return this.subscribeTrades(symbol, 'spot', forceNewConnection); + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + return this.subscribeTrades(symbol, market, forceNewConnection); } /** @@ -1662,8 +1679,10 @@ export class WebsocketClient extends EventEmitter { symbol: string, interval: KlineInterval, forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { - return this.subscribeKlines(symbol, interval, 'spot', forceNewConnection); + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + return this.subscribeKlines(symbol, interval, market, forceNewConnection); } /** @@ -1672,10 +1691,12 @@ export class WebsocketClient extends EventEmitter { public subscribeSpotSymbolMini24hrTicker( symbol: string, forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; return this.subscribeSymbolMini24hrTicker( symbol, - 'spot', + market, forceNewConnection, ); } @@ -1685,8 +1706,10 @@ export class WebsocketClient extends EventEmitter { */ public subscribeSpotAllMini24hrTickers( forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { - return this.subscribeAllMini24hrTickers('spot', forceNewConnection); + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + return this.subscribeAllMini24hrTickers(market, forceNewConnection); } /** @@ -1695,15 +1718,21 @@ export class WebsocketClient extends EventEmitter { public subscribeSpotSymbol24hrTicker( symbol: string, forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { - return this.subscribeSymbol24hrTicker(symbol, 'spot', forceNewConnection); + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + return this.subscribeSymbol24hrTicker(symbol, market, forceNewConnection); } /** * Subscribe to 24hr ticker in spot markets. */ - public subscribeSpotAll24hrTickers(forceNewConnection?: boolean): WebSocket { - return this.subscribeAll24hrTickers('spot', forceNewConnection); + public subscribeSpotAll24hrTickers( + forceNewConnection?: boolean, + isTestnet?: boolean, + ): WebSocket { + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + return this.subscribeAll24hrTickers(market, forceNewConnection); } /** @@ -1712,15 +1741,18 @@ export class WebsocketClient extends EventEmitter { public subscribeSpotSymbolBookTicker( symbol: string, forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { - return this.subscribeSymbolBookTicker(symbol, 'spot', forceNewConnection); + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + return this.subscribeSymbolBookTicker(symbol, market, forceNewConnection); } /** * Subscribe to best bid/ask for all symbols in spot markets. */ - public subscribeSpotAllBookTickers(forceNewConnection?: boolean): WebSocket { - return this.subscribeAllBookTickers('spot', forceNewConnection); + public subscribeSpotAllBookTickers(forceNewConnection?: boolean, isTestnet?: boolean): WebSocket { + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + return this.subscribeAllBookTickers(market, forceNewConnection); } /** @@ -1731,12 +1763,13 @@ export class WebsocketClient extends EventEmitter { levels: 5 | 10 | 20, updateMs: 1000 | 100 = 1000, forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { return this.subscribePartialBookDepths( symbol, levels, updateMs, - 'spot', + isTestnet ? 'spotTestnet' : 'spot', forceNewConnection, ); } @@ -1748,11 +1781,12 @@ export class WebsocketClient extends EventEmitter { symbol: string, updateMs: 1000 | 100 = 1000, forceNewConnection?: boolean, + isTestnet?: boolean, ): WebSocket { return this.subscribeDiffBookDepth( symbol, updateMs, - 'spot', + isTestnet ? 'spotTestnet' : 'spot', forceNewConnection, ); } @@ -1765,8 +1799,9 @@ export class WebsocketClient extends EventEmitter { listenKey: string, forceNewConnection?: boolean, isReconnecting?: boolean, + isTestnet?: boolean, ): WebSocket | undefined { - const market: WsMarket = 'spot'; + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; const wsKey = getWsKeyWithContext(market, 'userData', undefined, listenKey); if (!forceNewConnection && this.wsStore.isWsConnecting(wsKey)) { @@ -1789,7 +1824,14 @@ export class WebsocketClient extends EventEmitter { ); // Start & store timer to keep alive listen key (and handle expiration) - this.setKeepAliveListenKeyTimer(listenKey, market, ws, wsKey); + this.setKeepAliveListenKeyTimer( + listenKey, + market, + ws, + wsKey, + undefined, + isTestnet, + ); return ws; } @@ -1800,21 +1842,25 @@ export class WebsocketClient extends EventEmitter { public async subscribeSpotUserDataStream( forceNewConnection?: boolean, isReconnecting?: boolean, + isTestnet?: boolean, ): Promise { + const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; + try { const { listenKey } = - await this.getSpotRestClient().getSpotUserDataListenKey(); + await this.getSpotRestClient(isTestnet).getSpotUserDataListenKey(); return this.subscribeSpotUserDataStreamWithListenKey( listenKey, forceNewConnection, isReconnecting, + isTestnet, ); } catch (e) { this.logger.error(`Failed to connect to spot user data`, { ...loggerCategory, error: e, }); - this.emit('error', { wsKey: 'spot' + '_' + 'userData', error: e }); + this.emit('error', { wsKey: market + '_' + 'userData', error: e }); } } From 6fe3c17008cc49dbc7127b494261d5da594dd80d Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:36:11 +0700 Subject: [PATCH 4/7] Update types of NOTIONAL filter in market info response --- src/types/shared.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/types/shared.ts b/src/types/shared.ts index 11e647fe..b885df14 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -281,9 +281,11 @@ export interface SymbolLotSizeFilter { } export interface SymbolMinNotionalFilter { - filterType: 'MIN_NOTIONAL'; + filterType: 'NOTIONAL'; minNotional: numberInString; - applyToMarket: boolean; + maxNotional: numberInString; + applyMinToMarket: boolean; + applyMaxToMarket: boolean; avgPriceMins: number; } From 8cde738447ec68d55e6a308fbcf4fd24e8804ab9 Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:36:28 +0700 Subject: [PATCH 5/7] Revert "Fix wrong type in throwUnhandledSwitch" This reverts commit 51ebcb699360764513108c7825d556655944ea93. --- src/websocket-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 9fd428fc..373f990a 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -125,7 +125,7 @@ interface ListenKeyPersistenceState { keepAliveFailures: number; } -function throwUnhandledSwitch(x: unknown, msg: string): never { +function throwUnhandledSwitch(x: never, msg: string): never { throw new Error(msg); } From f68652fb19b1936a3528188d4dff69082dc63c72 Mon Sep 17 00:00:00 2001 From: Sebastian Boehler Date: Wed, 3 Apr 2024 09:59:35 +0200 Subject: [PATCH 6/7] chore: add NotionalFilter type --- src/types/shared.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/types/shared.ts b/src/types/shared.ts index b885df14..24213d70 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -281,10 +281,17 @@ export interface SymbolLotSizeFilter { } export interface SymbolMinNotionalFilter { + filterType: 'MIN_NOTIONAL'; + minNotional: numberInString; + applyToMarket: boolean; + avgPriceMins: number; +} + +export interface SymbolNotionalFilter { filterType: 'NOTIONAL'; minNotional: numberInString; - maxNotional: numberInString; applyMinToMarket: boolean; + maxNotional: numberInString; applyMaxToMarket: boolean; avgPriceMins: number; } @@ -326,6 +333,7 @@ export type SymbolFilter = | SymbolPercentPriceFilter | SymbolLotSizeFilter | SymbolMinNotionalFilter + | SymbolNotionalFilter | SymbolIcebergPartsFilter | SymbolMarketLotSizeFilter | SymbolMaxOrdersFilter From 086dd7654fad3094a0c03059e1f8dea703321816 Mon Sep 17 00:00:00 2001 From: Sebastian Boehler Date: Wed, 3 Apr 2024 20:08:32 +0200 Subject: [PATCH 7/7] fix: move isTestnet into RestClientOptions --- src/coinm-client.ts | 7 ++----- src/main-client.ts | 3 +-- src/usdm-client.ts | 21 +++++++++------------ src/util/requestUtils.ts | 3 +++ src/websocket-client.ts | 13 +++++++------ 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/coinm-client.ts b/src/coinm-client.ts index bbd580e8..938f52ba 100644 --- a/src/coinm-client.ts +++ b/src/coinm-client.ts @@ -91,9 +91,8 @@ export class CoinMClient extends BaseRestClient { constructor( restClientOptions: RestClientOptions = {}, requestOptions: AxiosRequestConfig = {}, - useTestnet?: boolean, ) { - const clientId = useTestnet ? 'coinmtest' : 'coinm'; + const clientId = restClientOptions.useTestnet ? 'coinmtest' : 'coinm'; super(clientId, restClientOptions, requestOptions); @@ -256,9 +255,7 @@ export class CoinMClient extends BaseRestClient { return this.getPrivate('dapi/v1/positionSide/dual'); } - submitNewOrder( - params: NewFuturesOrderParams, - ): Promise { + submitNewOrder(params: NewFuturesOrderParams): Promise { this.validateOrderId(params, 'newClientOrderId'); return this.postPrivate('dapi/v1/order', params); } diff --git a/src/main-client.ts b/src/main-client.ts index 58af6e17..ea102754 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -206,9 +206,8 @@ export class MainClient extends BaseRestClient { constructor( restClientOptions: RestClientOptions = {}, requestOptions: AxiosRequestConfig = {}, - useTestnet?: boolean, ) { - const clientId = useTestnet ? 'spottest' : 'spot1'; + const clientId = restClientOptions.useTestnet ? 'spottest' : 'spot1'; super(clientId, restClientOptions, requestOptions); return this; diff --git a/src/usdm-client.ts b/src/usdm-client.ts index 2f54ec6d..78414a2e 100644 --- a/src/usdm-client.ts +++ b/src/usdm-client.ts @@ -86,9 +86,8 @@ export class USDMClient extends BaseRestClient { constructor( restClientOptions: RestClientOptions = {}, requestOptions: AxiosRequestConfig = {}, - useTestnet?: boolean, ) { - const clientId = useTestnet ? 'usdmtest' : 'usdm'; + const clientId = restClientOptions.useTestnet ? 'usdmtest' : 'usdm'; super(clientId, restClientOptions, requestOptions); this.clientId = clientId; @@ -272,22 +271,20 @@ export class USDMClient extends BaseRestClient { return this.getPrivate('fapi/v1/multiAssetsMargin'); } - submitNewOrder( - params: NewFuturesOrderParams, - ): Promise { + submitNewOrder(params: NewFuturesOrderParams): Promise { this.validateOrderId(params, 'newClientOrderId'); 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 { - return this.putPrivate('fapi/v1/order', params); - } - + modifyOrder( + params: ModifyFuturesOrderParams, + ): Promise { + 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. * diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index 0eb16f9a..edaeb469 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -47,6 +47,9 @@ export interface RestClientOptions { //Defailt: false, if true will try to filter off undefined values from request params filterUndefinedParams?: boolean; + + //Default: false, if true it will use the testnet otherwise default to mainnet + useTestnet?: boolean; } export type GenericAPIResponse = Promise; diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 373f990a..c1bc5d67 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -759,7 +759,6 @@ export class WebsocketClient extends EventEmitter { this.restClients.spot = new MainClient( this.getRestClientOptions(), this.options.requestOptions, - isTestnet, ); } return this.restClients.spot; @@ -771,7 +770,6 @@ export class WebsocketClient extends EventEmitter { this.restClients.usdmFuturesTestnet = new USDMClient( this.getRestClientOptions(), this.options.requestOptions, - isTestnet, ); } return this.restClients.usdmFuturesTestnet; @@ -791,7 +789,6 @@ export class WebsocketClient extends EventEmitter { this.restClients.coinmFuturesTestnet = new CoinMClient( this.getRestClientOptions(), this.options.requestOptions, - isTestnet, ); } return this.restClients.coinmFuturesTestnet; @@ -1750,7 +1747,10 @@ export class WebsocketClient extends EventEmitter { /** * Subscribe to best bid/ask for all symbols in spot markets. */ - public subscribeSpotAllBookTickers(forceNewConnection?: boolean, isTestnet?: boolean): WebSocket { + public subscribeSpotAllBookTickers( + forceNewConnection?: boolean, + isTestnet?: boolean, + ): WebSocket { const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; return this.subscribeAllBookTickers(market, forceNewConnection); } @@ -1847,8 +1847,9 @@ export class WebsocketClient extends EventEmitter { const market: WsMarket = isTestnet ? 'spotTestnet' : 'spot'; try { - const { listenKey } = - await this.getSpotRestClient(isTestnet).getSpotUserDataListenKey(); + const { listenKey } = await this.getSpotRestClient( + isTestnet, + ).getSpotUserDataListenKey(); return this.subscribeSpotUserDataStreamWithListenKey( listenKey, forceNewConnection,