Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement spot test network #420

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ export class MainClient extends BaseRestClient {
constructor(
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {},
useTestnet?: boolean,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this into RestClientOptions?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also wondering about the WS client. Anything where there's a boolean for testnet or the user has to choose spottest instead of spot, maybe it's simpler to have a useTestnet?: boolean in WSClientConfigurableOptions.

The rest of the logic in the WS client could then automatically know whether to use testnet or not, and the user just says "spot" instead of needing to know "spottest" is an option. Simpler that way perhaps...less for anyone using the SDK to think about - thoughts? @SebastianBoehler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it into the RestClientOptions, havent touched ws client tho would be breaking changes there as it is pased as param in some public methods

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not expecting any breaking changes from the WS update, lemme comment in-line, one sec

Copy link
Contributor Author

@SebastianBoehler SebastianBoehler Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/tiagosiebler/binance/blob/master/src/websocket-client.ts?plain=1#L1940 subscribeUsdFuturesUserDataStream would be breaking change if isTestnet would be removed since used in the constructor then. Or we use it in the WSOptions and keep it in such places

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah man, you're completely right, and these methods are inconsistent with the other subscribe*UserDataStream methods (the others don't have that param at the start). Seems these are the only two methods that expose this param, unless I missed anything else.

I think I'd prefer to implement this in the WS options but keep it in these places for now, so avoiding the breaking change for now but not making it worse.

In a future breaking change / major release I'll want to consolidate these to the unified standard. Would you mind working through that as part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah had to double check everything as well until I got through all.

Lets keep this PR open then and I might work through all of this on the weekend. Can we merge the other one then in the meantime? #419

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, no rush here - very much appreciate the help. Let me take another look at #419 in the meantime!

) {
super('spot1', restClientOptions, requestOptions);
const clientId = useTestnet ? 'spottest' : 'spot1';

super(clientId, restClientOptions, requestOptions);
return this;
}

Expand Down
11 changes: 11 additions & 0 deletions src/types/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type BooleanStringCapitalised = 'TRUE' | 'FALSE';

export type BinanceBaseUrlKey =
| 'spot'
| 'spottest'
| 'spot1'
| 'spot2'
| 'spot3'
Expand Down Expand Up @@ -286,6 +287,15 @@ export interface SymbolMinNotionalFilter {
avgPriceMins: number;
}

export interface SymbolNotionalFilter {
filterType: 'NOTIONAL';
minNotional: numberInString;
applyMinToMarket: boolean;
maxNotional: numberInString;
applyMaxToMarket: boolean;
avgPriceMins: number;
}

export interface SymbolIcebergPartsFilter {
filterType: 'ICEBERG_PARTS';
limit: number;
Expand Down Expand Up @@ -323,6 +333,7 @@ export type SymbolFilter =
| SymbolPercentPriceFilter
| SymbolLotSizeFilter
| SymbolMinNotionalFilter
| SymbolNotionalFilter
| SymbolIcebergPartsFilter
| SymbolMarketLotSizeFilter
| SymbolMaxOrdersFilter
Expand Down
1 change: 1 addition & 0 deletions src/types/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

export type WsMarket =
| 'spot'
| 'spotTestnet'
| 'margin'
| 'isolatedMargin'
| 'usdm'
Expand Down
3 changes: 3 additions & 0 deletions src/util/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type GenericAPIResponse<T = any> = Promise<T>;
export function getOrderIdPrefix(network: BinanceBaseUrlKey): string {
switch (network) {
case 'spot':
case 'spottest':
case 'spot1':
case 'spot2':
case 'spot3':
Expand Down Expand Up @@ -156,6 +157,7 @@ export async function getRequestSignature(
const BINANCE_BASE_URLS: Record<BinanceBaseUrlKey, string> = {
// 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',
Expand All @@ -177,6 +179,7 @@ const BINANCE_BASE_URLS: Record<BinanceBaseUrlKey, string> = {
export function getServerTimeEndpoint(urlKey: BinanceBaseUrlKey): string {
switch (urlKey) {
case 'spot':
case 'spottest':
case 'spot1':
case 'spot2':
case 'spot3':
Expand Down
Loading