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 all 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
7 changes: 2 additions & 5 deletions src/coinm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -256,9 +255,7 @@ export class CoinMClient extends BaseRestClient {
return this.getPrivate('dapi/v1/positionSide/dual');
}

submitNewOrder(
params: NewFuturesOrderParams,
): Promise<NewOrderResult> {
submitNewOrder(params: NewFuturesOrderParams): Promise<NewOrderResult> {
this.validateOrderId(params, 'newClientOrderId');
return this.postPrivate('dapi/v1/order', params);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ export class MainClient extends BaseRestClient {
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {},
) {
super('spot1', restClientOptions, requestOptions);
const clientId = restClientOptions.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
21 changes: 9 additions & 12 deletions src/usdm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -272,22 +271,20 @@ export class USDMClient extends BaseRestClient {
return this.getPrivate('fapi/v1/multiAssetsMargin');
}

submitNewOrder(
params: NewFuturesOrderParams,
): Promise<NewOrderResult> {
submitNewOrder(params: NewFuturesOrderParams): Promise<NewOrderResult> {
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<ModifyFuturesOrderResult> {
return this.putPrivate('fapi/v1/order', params);
}
modifyOrder(
params: ModifyFuturesOrderParams,
): Promise<ModifyFuturesOrderResult> {
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.
*
Expand Down
6 changes: 6 additions & 0 deletions src/util/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ 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<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 +160,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 +182,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