Skip to content

Commit

Permalink
feat(): mark optional params
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosiebler committed Nov 14, 2023
1 parent 62aad4e commit c45dd5d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
36 changes: 18 additions & 18 deletions src/rest-client-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,6 @@ export class RestClientV2 extends BaseRestClient {
return this.get(`/api/v2/mix/market/vip-fee-rate`);
}

getFuturesMergeDepth(params: object): Promise<APIResponse<any>> {
return this.get(`/api/v2/mix/market/merge-depth`, params);
}

getFuturesTicker(params: object): Promise<APIResponse<any>> {
return this.get(`/api/v2/mix/market/ticker`, params);
}
Expand All @@ -394,12 +390,8 @@ export class RestClientV2 extends BaseRestClient {
return this.get(`/api/v2/mix/market/tickers`, params);
}

getFuturesRecentTrades(params: object): Promise<APIResponse<any>> {
return this.get(`/api/v2/mix/market/fills`, params);
}

getFuturesHistoricTrades(params: object): Promise<APIResponse<any>> {
return this.get(`/api/v2/mix/market/fills-history`, params);
getFuturesMergeDepth(params: object): Promise<APIResponse<any>> {
return this.get(`/api/v2/mix/market/merge-depth`, params);
}

getFuturesCandlestickData(params: object): Promise<APIResponse<any>> {
Expand All @@ -422,6 +414,14 @@ export class RestClientV2 extends BaseRestClient {
return this.get(`/api/v2/mix/market/history-mark-candles`, params);
}

getFuturesRecentTrades(params: object): Promise<APIResponse<any>> {
return this.get(`/api/v2/mix/market/fills`, params);
}

getFuturesHistoricTrades(params: object): Promise<APIResponse<any>> {
return this.get(`/api/v2/mix/market/fills-history`, params);
}

getFuturesOpenInterest(params: object): Promise<APIResponse<any>> {
return this.get(`/api/v2/mix/market/open-interest`, params);
}
Expand Down Expand Up @@ -472,7 +472,7 @@ export class RestClientV2 extends BaseRestClient {
return this.postPrivate(`/api/v2/mix/account/set-leverage`, params);
}

adjustFuturesPositionMargin(params: object): Promise<APIResponse<any>> {
setFuturesPositionMargin(params: object): Promise<APIResponse<any>> {
return this.postPrivate(`/api/v2/mix/account/set-margin`, params);
}

Expand Down Expand Up @@ -520,7 +520,11 @@ export class RestClientV2 extends BaseRestClient {
return this.postPrivate(`/api/v2/mix/order/place-order`, params);
}

futuresSubmitReverseal(params: object): Promise<APIResponse<any>> {
futuresCancelOrder(params: object): Promise<APIResponse<any>> {
return this.postPrivate(`/api/v2/mix/order/cancel-order`, params);
}

futuresSubmitReversal(params: object): Promise<APIResponse<any>> {
return this.postPrivate(`/api/v2/mix/order/click-backhand`, params);
}

Expand All @@ -532,10 +536,6 @@ export class RestClientV2 extends BaseRestClient {
return this.postPrivate(`/api/v2/mix/order/modify-order`, params);
}

futuresCancelOrder(params: object): Promise<APIResponse<any>> {
return this.postPrivate(`/api/v2/mix/order/cancel-order`, params);
}

futuresBatchCancelOrders(params: object): Promise<APIResponse<any>> {
return this.postPrivate(`/api/v2/mix/order/batch-cancel-orders`, params);
}
Expand All @@ -544,11 +544,11 @@ export class RestClientV2 extends BaseRestClient {
return this.postPrivate(`/api/v2/mix/order/close-positions`, params);
}

getFuturesOrderDetail(params: object): Promise<APIResponse<any>> {
getFuturesOrder(params: object): Promise<APIResponse<any>> {
return this.getPrivate(`/api/v2/mix/order/detail`, params);
}

getFuturesOrderFillDetails(params: object): Promise<APIResponse<any>> {
getFuturesFills(params: object): Promise<APIResponse<any>> {
return this.getPrivate(`/api/v2/mix/order/fills`, params);
}

Expand Down
30 changes: 10 additions & 20 deletions src/util/websocket-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,25 @@ type NetworkMap<

export const WS_BASE_URL_MAP: Record<
WsKey,
Record<'all' | 'public' | 'private', NetworkMap<'livenet'>>
Record<'all', NetworkMap<'livenet'>>
> = {
mixv1: {
all: {
livenet: 'wss://ws.bitget.com/mix/v1/stream',
},
public: {
livenet: 'N/A',
},
private: {
livenet: 'N/A',
},
},
spotv1: {
all: {
livenet: 'wss://ws.bitget.com/spot/v1/stream',
},
public: {
livenet: 'N/A',
},
private: {
livenet: 'N/A',
},
},
v2: {
v2Public: {
all: {
livenet: 'N/A',
},
public: {
livenet: 'wss://ws.bitget.com/v2/ws/public',
},
private: {
},
v2Private: {
all: {
livenet: 'wss://ws.bitget.com/v2/ws/private',
},
},
Expand All @@ -60,13 +47,15 @@ export const WS_BASE_URL_MAP: Record<
export const WS_KEY_MAP = {
spotv1: 'spotv1',
mixv1: 'mixv1',
v2: 'v2',
v2Public: 'v2Public',
v2Private: 'v2Private',
} as const;

/** Any WS keys in this list will trigger auth on connect, if credentials are available */
export const WS_AUTH_ON_CONNECT_KEYS: WsKey[] = [
WS_KEY_MAP.spotv1,
WS_KEY_MAP.mixv1,
WS_KEY_MAP.v2Private,
];

/** Any WS keys in this list will ALWAYS skip the authentication process, even if credentials are available */
Expand Down Expand Up @@ -113,7 +102,8 @@ export function getMaxTopicsPerSubscribeEvent(wsKey: WsKey): number | null {
switch (wsKey) {
case 'mixv1':
case 'spotv1':
case 'v2': {
case 'v2Public':
case 'v2Private': {
// Technically there doesn't seem to be a documented cap, but there is a size limit per request. Doesn't hurt to batch requests.
return 15;
}
Expand Down
6 changes: 6 additions & 0 deletions src/websocket-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,12 @@ export class WebsocketClient extends EventEmitter {
case WS_KEY_MAP.mixv1: {
return WS_BASE_URL_MAP.mixv1.all[networkKey];
}
case WS_KEY_MAP.v2Private: {
return WS_BASE_URL_MAP.v2Private.all[networkKey];
}
case WS_KEY_MAP.v2Public: {
return WS_BASE_URL_MAP.v2Public.all[networkKey];
}
default: {
this.logger.error('getWsUrl(): Unhandled wsKey: ', {
...LOGGER_CATEGORY,
Expand Down

0 comments on commit c45dd5d

Please sign in to comment.