feat(): add new futures endpoints & add new req property (clientOid)

This commit is contained in:
Tiago Siebler
2023-03-22 17:00:59 +00:00
parent b92739de97
commit 831689e857
13 changed files with 235 additions and 133 deletions

View File

@@ -1,4 +1,5 @@
{
"tabWidth": 2,
"singleQuote": true
"singleQuote": true,
"trailingComma": "all"
}

View File

@@ -20,6 +20,11 @@ import {
FuturesMarginMode,
FuturesPosition,
NewFuturesPlanTrailingStopOrder,
VIPFeeRate,
SpotMarketTrade,
GetHistoricTradesParams,
FuturesMarketTrade,
FuturesPlanType,
} from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
@@ -40,7 +45,7 @@ export class FuturesClient extends BaseRestClient {
/** Get Symbols : Get basic configuration information of all trading pairs (including rules) */
getSymbols(
productType: FuturesProductType
productType: FuturesProductType,
): Promise<APIResponse<FuturesSymbolRule[]>> {
return this.get('/api/mix/v1/market/contracts', { productType });
}
@@ -60,8 +65,33 @@ export class FuturesClient extends BaseRestClient {
return this.get('/api/mix/v1/market/tickers', { productType });
}
/** Get Market Trades */
getMarketTrades(symbol: string, limit?: string): Promise<APIResponse<any>> {
/** Get VIP fee rates */
getVIPFeeRates(): Promise<APIResponse<VIPFeeRate[]>> {
return this.get('/api/spot/v1/market/spot-vip-level');
}
/** Get most recent trades (up to 500, 100 by default) */
getRecentTrades(
symbol: string,
limit?: string,
): Promise<APIResponse<FuturesMarketTrade[]>> {
return this.get('/api/mix/v1/market/fills', { symbol, limit });
}
/** Get historic trades, up to 30 days at a time. Same-parameter responses are cached for 10 minutes. */
getHistoricTrades(
params: GetHistoricTradesParams,
): Promise<APIResponse<FuturesMarketTrade[]>> {
return this.get('/api/mix/v1/market/fills-history', params);
}
/**
* @deprecated use getRecentTrades() instead. This method will be removed soon.
*/
getMarketTrades(
symbol: string,
limit?: string,
): Promise<APIResponse<FuturesMarketTrade[]>> {
return this.get('/api/mix/v1/market/fills', { symbol, limit });
}
@@ -70,13 +100,15 @@ export class FuturesClient extends BaseRestClient {
symbol: string,
granularity: KlineInterval,
startTime: string,
endTime: string
endTime: string,
limit?: string,
): Promise<any> {
return this.get('/api/mix/v1/market/candles', {
symbol,
granularity,
startTime,
endTime,
limit,
});
}
@@ -95,7 +127,7 @@ export class FuturesClient extends BaseRestClient {
symbol: string,
pageSize?: string,
pageNo?: string,
nextPage?: boolean
nextPage?: boolean,
): Promise<APIResponse<any>> {
return this.get('/api/mix/v1/market/history-fundRate', {
symbol,
@@ -134,7 +166,7 @@ export class FuturesClient extends BaseRestClient {
/** Get Single Account */
getAccount(
symbol: string,
marginCoin: string
marginCoin: string,
): Promise<APIResponse<FuturesAccount>> {
return this.getPrivate('/api/mix/v1/account/account', {
symbol,
@@ -147,6 +179,15 @@ export class FuturesClient extends BaseRestClient {
return this.getPrivate('/api/mix/v1/account/accounts', { productType });
}
/** Get Sub Account Contract Assets */
getSubAccountContractAssets(
productType: FuturesProductType,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/account/sub-account-contract-assets', {
productType,
});
}
/**
* This interface is only used to calculate the maximum number of positions that can be opened when the user does not hold a position by default.
* The result does not represent the actual number of positions opened.
@@ -156,7 +197,7 @@ export class FuturesClient extends BaseRestClient {
marginCoin: string,
openPrice: number,
openAmount: number,
leverage?: number
leverage?: number,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/account/open-count', {
symbol,
@@ -172,7 +213,7 @@ export class FuturesClient extends BaseRestClient {
symbol: string,
marginCoin: string,
leverage: string,
holdSide?: string
holdSide?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/account/setLeverage', {
symbol,
@@ -187,7 +228,7 @@ export class FuturesClient extends BaseRestClient {
symbol: string,
marginCoin: string,
amount: string,
holdSide?: string
holdSide?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/account/setMargin', {
symbol,
@@ -201,7 +242,7 @@ export class FuturesClient extends BaseRestClient {
setMarginMode(
symbol: string,
marginCoin: string,
marginMode: FuturesMarginMode
marginMode: FuturesMarginMode,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/account/setMarginMode', {
symbol,
@@ -210,10 +251,21 @@ export class FuturesClient extends BaseRestClient {
});
}
/** Change Hold Mode */
setHoldMode(
productType: FuturesProductType,
holdMode: 'single_hold' | 'double_hold',
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/account/setPositionMode', {
productType,
holdMode,
});
}
/** Get Symbol Position */
getPosition(
symbol: string,
marginCoin?: string
marginCoin?: string,
): Promise<APIResponse<FuturesPosition[]>> {
return this.getPrivate('/api/mix/v1/position/singlePosition', {
symbol,
@@ -224,7 +276,7 @@ export class FuturesClient extends BaseRestClient {
/** Get All Position */
getPositions(
productType: FuturesProductType,
marginCoin?: string
marginCoin?: string,
): Promise<APIResponse<FuturesPosition[]>> {
return this.getPrivate('/api/mix/v1/position/allPosition', {
productType,
@@ -239,7 +291,7 @@ export class FuturesClient extends BaseRestClient {
/** Get Business Account Bill */
getBusinessBill(
params: FuturesBusinessBillRequest
params: FuturesBusinessBillRequest,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/account/accountBusinessBill', params);
}
@@ -259,7 +311,7 @@ export class FuturesClient extends BaseRestClient {
batchSubmitOrder(
symbol: string,
marginCoin: string,
orders: NewBatchFuturesOrder[]
orders: NewBatchFuturesOrder[],
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/order/batch-orders', {
symbol,
@@ -272,12 +324,14 @@ export class FuturesClient extends BaseRestClient {
cancelOrder(
symbol: string,
marginCoin: string,
orderId: string
orderId?: string,
clientOid?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/order/cancel-order', {
symbol,
marginCoin,
orderId,
clientOid,
});
}
@@ -285,7 +339,7 @@ export class FuturesClient extends BaseRestClient {
batchCancelOrder(
symbol: string,
marginCoin: string,
orderIds: string[]
orderIds: string[],
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/order/cancel-batch-orders', {
symbol,
@@ -294,10 +348,23 @@ export class FuturesClient extends BaseRestClient {
});
}
/**
* Cancel all futures orders for a symbol
*/
cancelSymbolOrders(
symbol: string,
marginCoin: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/order/cancel-symbol-orders', {
symbol,
marginCoin,
});
}
/** Cancel All Order */
cancelAllOrders(
productType: FuturesProductType,
marginCoin: string
marginCoin: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/order/cancel-all-orders', {
productType,
@@ -313,7 +380,7 @@ export class FuturesClient extends BaseRestClient {
/** Get All Open Order */
getOpenOrders(
productType: FuturesProductType,
marginCoin: string
marginCoin: string,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/order/marginCoinCurrent', {
productType,
@@ -328,7 +395,8 @@ export class FuturesClient extends BaseRestClient {
endTime: string,
pageSize: string,
lastEndId?: string,
isPre?: boolean
isPre?: boolean,
clientOid?: string,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/order/history', {
symbol,
@@ -337,6 +405,7 @@ export class FuturesClient extends BaseRestClient {
pageSize,
lastEndId,
isPre,
clientOid,
});
}
@@ -347,7 +416,8 @@ export class FuturesClient extends BaseRestClient {
endTime: string,
pageSize: string,
lastEndId?: string,
isPre?: boolean
isPre?: boolean,
clientOid?: string,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/order/historyProductType', {
productType,
@@ -356,6 +426,7 @@ export class FuturesClient extends BaseRestClient {
pageSize,
lastEndId,
isPre,
clientOid,
});
}
@@ -363,7 +434,7 @@ export class FuturesClient extends BaseRestClient {
getOrder(
symbol: string,
orderId?: string,
clientOid?: string
clientOid?: string,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/order/detail', {
symbol,
@@ -376,7 +447,7 @@ export class FuturesClient extends BaseRestClient {
getOrderFills(
symbol: string,
orderId?: string,
pagination?: FuturesPagination
pagination?: FuturesPagination,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/order/fills', {
symbol,
@@ -388,7 +459,7 @@ export class FuturesClient extends BaseRestClient {
/** Get ProductType Order fill detail */
getProductTypeOrderFills(
productType: FuturesProductType,
pagination?: FuturesPagination
pagination?: FuturesPagination,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/order/allFills', {
productType: productType.toUpperCase(),
@@ -408,7 +479,7 @@ export class FuturesClient extends BaseRestClient {
/** Modify Plan Order TPSL */
modifyPlanOrderTPSL(
params: ModifyFuturesPlanOrderTPSL
params: ModifyFuturesPlanOrderTPSL,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/plan/modifyPlanPreset', params);
}
@@ -420,37 +491,48 @@ export class FuturesClient extends BaseRestClient {
/** Place Trailing Stop order */
submitTrailingStopOrder(
params: NewFuturesPlanTrailingStopOrder
params: NewFuturesPlanTrailingStopOrder,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/plan/placeTrailStop', params);
}
/** Place Position TPSL */
submitPositionTPSL(
params: NewFuturesPlanPositionTPSL
params: NewFuturesPlanPositionTPSL,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/plan/placePositionsTPSL', params);
}
/** Modify Stop Order */
modifyStopOrder(
params: ModifyFuturesPlanStopOrder
params: ModifyFuturesPlanStopOrder,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/plan/modifyTPSLPlan', params);
}
/** Cancel Plan Order TPSL */
cancelPlanOrderTPSL(
params: CancelFuturesPlanTPSL
params: CancelFuturesPlanTPSL,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/plan/cancelPlan', params);
}
/** Cancel All Trigger Order (TPSL) */
cancelAllPlanOrders(
productType: FuturesProductType,
planType: FuturesPlanType,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/plan/cancelAllPlan', {
productType,
planType,
});
}
/** Get Plan Order (TPSL) List */
getPlanOrderTPSLs(
symbol: string,
isPlan?: string,
productType?: FuturesProductType
productType?: FuturesProductType,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/plan/currentPlan', {
symbol,
@@ -461,14 +543,14 @@ export class FuturesClient extends BaseRestClient {
/** Get History Plan Orders (TPSL) */
getHistoricPlanOrdersTPSL(
params: HistoricPlanOrderTPSLRequest
params: HistoricPlanOrderTPSLRequest,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/plan/historyPlan', params);
}
/**
*
* Trade Endpoints
* Copy Trade Endpoints
*
*/
@@ -477,7 +559,7 @@ export class FuturesClient extends BaseRestClient {
symbol: string,
productType: FuturesProductType,
pageSize: number,
pageNo: number
pageNo: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/trace/currentTrack', {
symbol,
@@ -492,7 +574,7 @@ export class FuturesClient extends BaseRestClient {
symbol: string,
productType: FuturesProductType,
pageSize: number,
pageNo: number
pageNo: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/trace/followerOrder', {
symbol,
@@ -505,7 +587,7 @@ export class FuturesClient extends BaseRestClient {
/** Trader Close Position */
closeCopyTraderPosition(
symbol: string,
trackingNo: string
trackingNo: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/trace/closeTrackOrder', {
symbol,
@@ -520,7 +602,7 @@ export class FuturesClient extends BaseRestClient {
changes?: {
stopProfitPrice?: number;
stopLossPrice?: number;
}
},
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/trace/modifyTPSL', {
symbol,
@@ -534,7 +616,7 @@ export class FuturesClient extends BaseRestClient {
startTime: string,
endTime: string,
pageSize: number,
pageNo: number
pageNo: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/trace/historyTrack', {
startTime,
@@ -559,7 +641,7 @@ export class FuturesClient extends BaseRestClient {
marginCoin: string,
dateMs: string,
pageSize: number,
pageNo: number
pageNo: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/trace/profitDateGroupList', {
marginCoin,
@@ -574,7 +656,7 @@ export class FuturesClient extends BaseRestClient {
marginCoin: string,
dateMs: string,
pageSize: number,
pageNo: number
pageNo: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/trace/profitDateList', {
marginCoin,
@@ -587,7 +669,7 @@ export class FuturesClient extends BaseRestClient {
/** Get Trader Profits Details */
getCopyTraderProfitDetails(
pageSize: number,
pageNo: number
pageNo: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/mix/v1/trace/waitProfitDateList', {
pageSize,
@@ -603,7 +685,7 @@ export class FuturesClient extends BaseRestClient {
/** Trader Change CopyTrade symbol */
setCopyTraderSymbols(
symbol: string,
operation: 'add' | 'delete'
operation: 'add' | 'delete',
): Promise<APIResponse<any>> {
return this.postPrivate('/api/mix/v1/trace/setUpCopySymbols', {
symbol,

View File

@@ -20,7 +20,7 @@ import {
GetHistoricPlanOrdersParams,
SpotMarketTrade,
GetHistoricTradesParams,
SpotVIPFeeRate,
VIPFeeRate,
} from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
@@ -83,14 +83,14 @@ export class SpotClient extends BaseRestClient {
/** Get most recent trades (up to 500, 100 by default) */
getRecentTrades(
symbol: string,
limit?: string
limit?: string,
): Promise<APIResponse<SpotMarketTrade[]>> {
return this.get('/api/spot/v1/market/fills', { symbol, limit });
}
/** Get historic trades, up to 30 days at a time. Same-parameter responses are cached for 10 minutes. */
getHistoricTrades(
params: GetHistoricTradesParams
params: GetHistoricTradesParams,
): Promise<APIResponse<SpotMarketTrade[]>> {
return this.get('/api/spot/v1/market/fills-history', params);
}
@@ -100,7 +100,7 @@ export class SpotClient extends BaseRestClient {
*/
getMarketTrades(
symbol: string,
limit?: string
limit?: string,
): Promise<APIResponse<SpotMarketTrade[]>> {
return this.get('/api/spot/v1/market/fills', { symbol, limit });
}
@@ -109,7 +109,7 @@ export class SpotClient extends BaseRestClient {
getCandles(
symbol: string,
period: KlineInterval,
pagination?: Pagination
pagination?: Pagination,
): Promise<APIResponse<any>> {
return this.get('/api/spot/v1/market/candles', {
symbol,
@@ -122,13 +122,13 @@ export class SpotClient extends BaseRestClient {
getDepth(
symbol: string,
type: 'step0' | 'step1' | 'step2' | 'step3' | 'step4' | 'step5',
limit?: string
limit?: string,
): Promise<APIResponse<any>> {
return this.get('/api/spot/v1/market/depth', { symbol, type, limit });
}
/** Get VIP fee rates */
getVIPFeeRates(): Promise<APIResponse<SpotVIPFeeRate[]>> {
getVIPFeeRates(): Promise<APIResponse<VIPFeeRate[]>> {
return this.get('/api/spot/v1/market/spot-vip-level');
}
@@ -178,7 +178,7 @@ export class SpotClient extends BaseRestClient {
coin: string,
toUid: string,
amount: string,
clientOid?: string
clientOid?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/withdrawal-inner', {
coin,
@@ -193,7 +193,7 @@ export class SpotClient extends BaseRestClient {
coin: string,
toUid: string,
amount: string,
clientOid?: string
clientOid?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/withdrawal-inner-v2', {
coin,
@@ -210,7 +210,7 @@ export class SpotClient extends BaseRestClient {
endTime: string,
pageSize?: string,
pageNo?: string,
clientOid?: string
clientOid?: string,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/spot/v1/wallet/withdrawal-list', {
coin,
@@ -228,7 +228,7 @@ export class SpotClient extends BaseRestClient {
startTime: string,
endTime: string,
pageSize?: string,
pageNo?: string
pageNo?: string,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/spot/v1/wallet/deposit-list', {
coin,
@@ -298,7 +298,7 @@ export class SpotClient extends BaseRestClient {
/** Place orders in batches, up to 50 at a time */
batchSubmitOrder(
symbol: string,
orderList: NewBatchSpotOrder[]
orderList: NewBatchSpotOrder[],
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/batch-orders', {
symbol,
@@ -331,7 +331,7 @@ export class SpotClient extends BaseRestClient {
/** Cancel order in batch (per symbol) */
batchCancelOrder(
symbol: string,
orderIds: string[]
orderIds: string[],
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/cancel-batch-orders', {
symbol,
@@ -341,11 +341,11 @@ export class SpotClient extends BaseRestClient {
/** Cancel order in batch (per symbol). V2 endpoint, supports orderIds or clientOids. */
batchCancelOrderV2(
params: BatchCancelSpotOrderV2
params: BatchCancelSpotOrderV2,
): Promise<APIResponse<any>> {
return this.postPrivate(
'/api/spot/v1/trade/cancel-batch-orders-v2',
params
params,
);
}
@@ -353,7 +353,7 @@ export class SpotClient extends BaseRestClient {
getOrder(
symbol: string,
orderId: string,
clientOrderId?: string
clientOrderId?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/orderInfo', {
symbol,
@@ -370,7 +370,7 @@ export class SpotClient extends BaseRestClient {
/** Get order history for a symbol */
getOrderHistory(
symbol: string,
pagination?: Pagination
pagination?: Pagination,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/history', {
symbol,
@@ -382,7 +382,7 @@ export class SpotClient extends BaseRestClient {
getOrderFills(
symbol: string,
orderId: string,
pagination?: Pagination
pagination?: Pagination,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/fills', {
symbol,
@@ -393,21 +393,21 @@ export class SpotClient extends BaseRestClient {
/** Place plan order */
submitPlanOrder(
params: NewSpotPlanOrder
params: NewSpotPlanOrder,
): Promise<APIResponse<SpotOrderResult>> {
return this.postPrivate('/api/spot/v1/plan/placePlan', params);
}
/** Modify plan order */
modifyPlanOrder(
params: ModifySpotPlanOrder
params: ModifySpotPlanOrder,
): Promise<APIResponse<SpotOrderResult>> {
return this.postPrivate('/api/spot/v1/plan/modifyPlan', params);
}
/** Cancel plan order */
cancelPlanOrder(
params: CancelSpotPlanOrderParams
params: CancelSpotPlanOrderParams,
): Promise<APIResponse<string>> {
return this.postPrivate('/api/spot/v1/plan/cancelPlan', params);
}

View File

@@ -51,6 +51,8 @@ export interface NewFuturesOrder {
orderType: FuturesOrderType;
timeInForceValue?: OrderTimeInForce;
clientOid?: string;
reduceOnly?: boolean;
reverse?: boolean;
presetTakeProfitPrice?: string;
presetStopLossPrice?: string;
}
@@ -82,6 +84,7 @@ export interface NewFuturesPlanOrder {
clientOid?: string;
presetTakeProfitPrice?: string;
presetStopLossPrice?: string;
reduceOnly?: string;
}
export interface ModifyFuturesPlanOrder {
@@ -90,12 +93,13 @@ export interface ModifyFuturesPlanOrder {
symbol: string;
executePrice?: string;
triggerPrice: string;
triggerType: string;
triggerType: 'fill_price' | 'market_price';
orderType: FuturesOrderType;
}
export interface ModifyFuturesPlanOrderTPSL {
orderId: string;
orderId?: string;
clientOid?: string;
marginCoin: string;
symbol: string;
presetTakeProfitPrice?: string;
@@ -113,6 +117,7 @@ export interface NewFuturesPlanStopOrder {
holdSide: FuturesHoldSide;
size?: string;
rangeRate?: string;
clientOid?: string;
}
export interface NewFuturesPlanTrailingStopOrder {
@@ -123,6 +128,7 @@ export interface NewFuturesPlanTrailingStopOrder {
size?: string;
side: FuturesOrderSide;
rangeRate?: string;
clientOid?: string;
}
export interface NewFuturesPlanPositionTPSL {
@@ -130,18 +136,23 @@ export interface NewFuturesPlanPositionTPSL {
marginCoin: string;
planType: FuturesPlanType;
triggerPrice: string;
triggerType?: 'fill_price' | 'market_price';
holdSide: FuturesHoldSide;
clientOid?: string;
}
export interface ModifyFuturesPlanStopOrder {
orderId: string;
orderId?: string;
clientOid?: string;
marginCoin: string;
symbol: string;
triggerPrice?: string;
planType: FuturesPlanType;
}
export interface CancelFuturesPlanTPSL {
orderId: string;
orderId?: string;
clientOid?: string;
symbol: string;
marginCoin: string;
planType: FuturesPlanType;

View File

@@ -9,3 +9,11 @@ export interface Pagination {
}
export type OrderTimeInForce = 'normal' | 'post_only' | 'fok' | 'ioc';
export interface GetHistoricTradesParams {
symbol: string;
limit?: string;
tradeId?: string;
startTime?: string;
endTime?: string;
}

View File

@@ -1,13 +1,5 @@
import { OrderTimeInForce } from './shared';
export interface GetHistoricTradesParams {
symbol: string;
limit?: string;
tradeId?: string;
startTime?: string;
endTime?: string;
}
export type WalletType = 'spot' | 'mix_usdt' | 'mix_usd';
export interface NewWalletTransfer {

View File

@@ -4,6 +4,15 @@ import {
FuturesMarginMode,
} from '../request';
export interface FuturesMarketTrade {
tradeId: string;
price: string;
size: string;
side: 'buy' | 'sell';
timestamp: string;
symbol: string;
}
export interface FuturesAccount {
marginCoin: string;
locked: number;

View File

@@ -4,3 +4,13 @@ export interface APIResponse<T> {
msg: 'success' | string;
requestTime: number;
}
export interface VIPFeeRate {
level: number;
dealAmount: string;
assetAmount: string;
takerFeeRate?: string;
makerFeeRate?: number;
withdrawAmount: string;
withdrawAmountUSDT: string;
}

View File

@@ -20,17 +20,6 @@ export interface SymbolRules {
quantityScale: string;
status: string;
}
export interface SpotVIPFeeRate {
level: number;
dealAmount: string;
assetAmount: string;
takerFeeRate?: string;
makerFeeRate?: number;
withdrawAmount: string;
withdrawAmountUSDT: string;
}
export interface SpotOrderResult {
orderId: string;
clientOrderId: string;

View File

@@ -44,7 +44,7 @@ export default abstract class BaseRestClient {
*/
constructor(
restOptions: RestClientOptions = {},
networkOptions: AxiosRequestConfig = {}
networkOptions: AxiosRequestConfig = {},
) {
this.options = {
recvWindow: 5000,
@@ -77,7 +77,7 @@ export default abstract class BaseRestClient {
credentials.some((v) => typeof v === 'string')
) {
throw new Error(
'API Key, Secret & Passphrase are ALL required to use the authenticated REST client'
'API Key, Secret & Passphrase are ALL required to use the authenticated REST client',
);
}
}
@@ -109,11 +109,11 @@ export default abstract class BaseRestClient {
method: Method,
endpoint: string,
params?: any,
isPublicApi?: boolean
isPublicApi?: boolean,
): Promise<any> {
// Sanity check to make sure it's only ever prefixed by one forward slash
const requestUrl = [this.baseUrl, endpoint].join(
endpoint.startsWith('/') ? '' : '/'
endpoint.startsWith('/') ? '' : '/',
);
// Build a request and handle signature process
@@ -122,7 +122,7 @@ export default abstract class BaseRestClient {
endpoint,
requestUrl,
params,
isPublicApi
isPublicApi,
);
// console.log('full request: ', options);
@@ -188,7 +188,7 @@ export default abstract class BaseRestClient {
data: T,
endpoint: string,
method: Method,
signMethod: SignMethod
signMethod: SignMethod,
): Promise<SignedRequest<T>> {
const timestamp = Date.now();
@@ -228,7 +228,7 @@ export default abstract class BaseRestClient {
console.error(
new Date(),
neverGuard(signMethod, `Unhandled sign method: "${signMessage}"`)
neverGuard(signMethod, `Unhandled sign method: "${signMessage}"`),
);
return res;
@@ -239,21 +239,21 @@ export default abstract class BaseRestClient {
endpoint: string,
signMethod: SignMethod,
params?: TParams,
isPublicApi?: true
isPublicApi?: true,
): Promise<UnsignedRequest<TParams>>;
private async prepareSignParams<TParams extends object | undefined>(
method: Method,
endpoint: string,
signMethod: SignMethod,
params?: TParams,
isPublicApi?: false | undefined
isPublicApi?: false | undefined,
): Promise<SignedRequest<TParams>>;
private async prepareSignParams<TParams extends object | undefined>(
method: Method,
endpoint: string,
signMethod: SignMethod,
params?: TParams,
isPublicApi?: boolean
isPublicApi?: boolean,
) {
if (isPublicApi) {
return {
@@ -275,7 +275,7 @@ export default abstract class BaseRestClient {
endpoint: string,
url: string,
params?: any,
isPublicApi?: boolean
isPublicApi?: boolean,
): Promise<AxiosRequestConfig> {
const options: AxiosRequestConfig = {
...this.globalRequestOptions,
@@ -301,7 +301,7 @@ export default abstract class BaseRestClient {
endpoint,
'bitget',
params,
isPublicApi
isPublicApi,
);
const authHeaders = {

View File

@@ -61,7 +61,7 @@ interface WebsocketClientEvents {
export declare interface WebsocketClient {
on<U extends keyof WebsocketClientEvents>(
event: U,
listener: WebsocketClientEvents[U]
listener: WebsocketClientEvents[U],
): this;
emit<U extends keyof WebsocketClientEvents>(
@@ -77,7 +77,7 @@ export class WebsocketClient extends EventEmitter {
constructor(
options: WSClientConfigurableOptions,
logger?: typeof DefaultLogger
logger?: typeof DefaultLogger,
) {
super();
@@ -100,7 +100,7 @@ export class WebsocketClient extends EventEmitter {
*/
public subscribe(
wsTopics: WsTopicSubscribeEventArgs[] | WsTopicSubscribeEventArgs,
isPrivateTopic?: boolean
isPrivateTopic?: boolean,
) {
const topics = Array.isArray(wsTopics) ? wsTopics : [wsTopics];
@@ -122,7 +122,7 @@ export class WebsocketClient extends EventEmitter {
if (!isAuthenticated) {
return this.requestSubscribeTopics(
wsKey,
topics.filter((topic) => !isPrivateChannel(topic.channel))
topics.filter((topic) => !isPrivateChannel(topic.channel)),
);
}
return this.requestSubscribeTopics(wsKey, topics);
@@ -132,11 +132,11 @@ export class WebsocketClient extends EventEmitter {
if (
!this.wsStore.isConnectionState(
wsKey,
WsConnectionStateEnum.CONNECTING
WsConnectionStateEnum.CONNECTING,
) &&
!this.wsStore.isConnectionState(
wsKey,
WsConnectionStateEnum.RECONNECTING
WsConnectionStateEnum.RECONNECTING,
)
) {
return this.connect(wsKey);
@@ -151,11 +151,11 @@ export class WebsocketClient extends EventEmitter {
*/
public unsubscribe(
wsTopics: WsTopicSubscribeEventArgs[] | WsTopicSubscribeEventArgs,
isPrivateTopic?: boolean
isPrivateTopic?: boolean,
) {
const topics = Array.isArray(wsTopics) ? wsTopics : [wsTopics];
topics.forEach((topic) =>
this.wsStore.deleteTopic(getWsKeyForTopic(topic, isPrivateTopic), topic)
this.wsStore.deleteTopic(getWsKeyForTopic(topic, isPrivateTopic), topic),
);
// TODO: should this really happen on each wsKey?? seems weird
@@ -207,7 +207,7 @@ export class WebsocketClient extends EventEmitter {
if (this.wsStore.isWsOpen(wsKey)) {
this.logger.error(
'Refused to connect to ws with existing active connection',
{ ...LOGGER_CATEGORY, wsKey }
{ ...LOGGER_CATEGORY, wsKey },
);
return this.wsStore.getWs(wsKey);
}
@@ -217,7 +217,7 @@ export class WebsocketClient extends EventEmitter {
) {
this.logger.error(
'Refused to connect to ws, connection attempt already active',
{ ...LOGGER_CATEGORY, wsKey }
{ ...LOGGER_CATEGORY, wsKey },
);
return;
}
@@ -260,7 +260,7 @@ export class WebsocketClient extends EventEmitter {
`${context} due to unexpected response error: "${
error?.msg || error?.message || error
}"`,
{ ...LOGGER_CATEGORY, wsKey, error }
{ ...LOGGER_CATEGORY, wsKey, error },
);
break;
}
@@ -278,7 +278,7 @@ export class WebsocketClient extends EventEmitter {
apiKey,
apiSecret,
apiPass,
recvWindow
recvWindow,
);
this.logger.info(`Sending auth request...`, {
@@ -375,7 +375,7 @@ export class WebsocketClient extends EventEmitter {
*/
private requestSubscribeTopics(
wsKey: WsKey,
topics: WsTopicSubscribeEventArgs[]
topics: WsTopicSubscribeEventArgs[],
) {
if (!topics.length) {
return;
@@ -384,7 +384,7 @@ export class WebsocketClient extends EventEmitter {
const maxTopicsPerEvent = getMaxTopicsPerSubscribeEvent(wsKey);
if (maxTopicsPerEvent && topics.length > maxTopicsPerEvent) {
this.logger.silly(
`Subscribing to topics in batches of ${maxTopicsPerEvent}`
`Subscribing to topics in batches of ${maxTopicsPerEvent}`,
);
for (var i = 0; i < topics.length; i += maxTopicsPerEvent) {
const batch = topics.slice(i, i + maxTopicsPerEvent);
@@ -392,7 +392,7 @@ export class WebsocketClient extends EventEmitter {
this.requestSubscribeTopics(wsKey, batch);
}
this.logger.silly(
`Finished batch subscribing to ${topics.length} topics`
`Finished batch subscribing to ${topics.length} topics`,
);
return;
}
@@ -410,7 +410,7 @@ export class WebsocketClient extends EventEmitter {
*/
private requestUnsubscribeTopics(
wsKey: WsKey,
topics: WsTopicSubscribeEventArgs[]
topics: WsTopicSubscribeEventArgs[],
) {
if (!topics.length) {
return;
@@ -419,7 +419,7 @@ export class WebsocketClient extends EventEmitter {
const maxTopicsPerEvent = getMaxTopicsPerSubscribeEvent(wsKey);
if (maxTopicsPerEvent && topics.length > maxTopicsPerEvent) {
this.logger.silly(
`Unsubscribing to topics in batches of ${maxTopicsPerEvent}`
`Unsubscribing to topics in batches of ${maxTopicsPerEvent}`,
);
for (var i = 0; i < topics.length; i += maxTopicsPerEvent) {
const batch = topics.slice(i, i + maxTopicsPerEvent);
@@ -427,7 +427,7 @@ export class WebsocketClient extends EventEmitter {
this.requestUnsubscribeTopics(wsKey, batch);
}
this.logger.silly(
`Finished batch unsubscribing to ${topics.length} topics`
`Finished batch unsubscribing to ${topics.length} topics`,
);
return;
}
@@ -449,13 +449,13 @@ export class WebsocketClient extends EventEmitter {
});
if (!wsKey) {
throw new Error(
'Cannot send message due to no known websocket for this wsKey'
'Cannot send message due to no known websocket for this wsKey',
);
}
const ws = this.getWs(wsKey);
if (!ws) {
throw new Error(
`${wsKey} socket not connected yet, call "connectAll()" first then try again when the "open" event arrives`
`${wsKey} socket not connected yet, call "connectAll()" first then try again when the "open" event arrives`,
);
}
ws.send(wsMessage);
@@ -512,13 +512,13 @@ export class WebsocketClient extends EventEmitter {
// Private topics will be resubscribed to once reconnected
const topics = [...this.wsStore.getTopics(wsKey)];
const publicTopics = topics.filter(
(topic) => !isPrivateChannel(topic.channel)
(topic) => !isPrivateChannel(topic.channel),
);
this.requestSubscribeTopics(wsKey, publicTopics);
this.wsStore.get(wsKey, true)!.activePingTimer = setInterval(
() => this.ping(wsKey),
this.options.pingInterval
this.options.pingInterval,
);
}
@@ -529,7 +529,7 @@ export class WebsocketClient extends EventEmitter {
const topics = [...this.wsStore.getTopics(wsKey)];
const privateTopics = topics.filter((topic) =>
isPrivateChannel(topic.channel)
isPrivateChannel(topic.channel),
);
if (privateTopics.length) {
@@ -665,7 +665,7 @@ export class WebsocketClient extends EventEmitter {
public subscribeTopic(
instType: BitgetInstType,
topic: WsTopic,
instId: string = 'default'
instId: string = 'default',
) {
return this.subscribe({
instType,
@@ -683,7 +683,7 @@ export class WebsocketClient extends EventEmitter {
public unsubscribeTopic(
instType: BitgetInstType,
topic: WsTopic,
instId: string = 'default'
instId: string = 'default',
) {
return this.unsubscribe({
instType,

View File

@@ -163,7 +163,7 @@ describe('Private Spot REST API GET Endpoints', () => {
it('getCurrentPlanOrders()', async () => {
try {
expect(
await api.getCurrentPlanOrders({ symbol, pageSize: '20' })
await api.getCurrentPlanOrders({ symbol, pageSize: '20' }),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {
@@ -185,7 +185,7 @@ describe('Private Spot REST API GET Endpoints', () => {
pageSize: '20',
startTime: '1667889483000',
endTime: '1668134732000',
})
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {

View File

@@ -30,7 +30,7 @@ describe('Private Spot REST API POST Endpoints', () => {
coin,
fromType: 'spot',
toType: 'mix_usdt',
})
}),
).toStrictEqual('');
} catch (e) {
// console.error('transfer: ', e);
@@ -49,7 +49,7 @@ describe('Private Spot REST API POST Endpoints', () => {
coin,
fromType: 'spot',
toType: 'mix_usdt',
})
}),
).toStrictEqual('');
} catch (e) {
// console.error('transferV2: ', e);
@@ -71,7 +71,7 @@ describe('Private Spot REST API POST Endpoints', () => {
coin,
fromType: 'spot',
toType: 'mix_usdt',
})
}),
).toStrictEqual('');
} catch (e) {
// console.error('transferV2: ', e);
@@ -90,7 +90,7 @@ describe('Private Spot REST API POST Endpoints', () => {
coin,
chain: 'TRC20',
address: `123456`,
})
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
@@ -110,7 +110,7 @@ describe('Private Spot REST API POST Endpoints', () => {
coin,
chain: 'TRC20',
address: `123456`,
})
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
@@ -158,7 +158,7 @@ describe('Private Spot REST API POST Endpoints', () => {
orderType: 'market',
quantity: '1',
force: 'normal',
})
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
@@ -180,7 +180,7 @@ describe('Private Spot REST API POST Endpoints', () => {
quantity: '1',
force: 'normal',
},
])
]),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {
@@ -251,7 +251,7 @@ describe('Private Spot REST API POST Endpoints', () => {
orderType: 'market',
triggerPrice: 100,
orderId: '123456',
})
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
@@ -268,7 +268,7 @@ describe('Private Spot REST API POST Endpoints', () => {
expect(
await api.cancelPlanOrder({
orderId: planOrderId || '123456',
})
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(String),