v1.0.6: fix() fix type differences for spot vs futures candles. Add example for fetching last 1k futures candles

This commit is contained in:
Tiago Siebler
2023-04-04 11:58:09 +01:00
parent f367061665
commit f3d837bde6
11 changed files with 131 additions and 9 deletions

View File

@@ -13,6 +13,7 @@ export const API_ERROR_CODE = {
QTY_LESS_THAN_MINIMUM: '43006',
/** Parameter verification exception margin mode == FIXED */
PARAMETER_EXCEPTION: '40808',
PLAN_ORDER_REACHED_UPPER_LIMIT: '40889',
ORDER_NOT_FOUND: '43001',
FUTURES_ORDER_TPSL_NOT_FOUND: '43020',
PLAN_ORDER_NOT_FOUND: '43025',

View File

@@ -1,6 +1,5 @@
import {
APIResponse,
KlineInterval,
FuturesProductType,
FuturesAccountBillRequest,
FuturesBusinessBillRequest,
@@ -24,6 +23,7 @@ import {
GetHistoricTradesParams,
FuturesMarketTrade,
FuturesPlanType,
FuturesKlineInterval,
} from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
@@ -97,7 +97,7 @@ export class FuturesClient extends BaseRestClient {
/** Get Candle Data */
getCandles(
symbol: string,
granularity: KlineInterval,
granularity: FuturesKlineInterval,
startTime: string,
endTime: string,
limit?: string,

View File

@@ -4,7 +4,6 @@ import {
NewWalletTransfer,
Pagination,
APIResponse,
KlineInterval,
CoinBalance,
SymbolRules,
NewSpotSubTransfer,
@@ -21,6 +20,7 @@ import {
SpotMarketTrade,
GetHistoricTradesParams,
VIPFeeRate,
SpotKlineInterval,
} from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
@@ -108,7 +108,7 @@ export class SpotClient extends BaseRestClient {
/** Get Candle Data */
getCandles(
symbol: string,
period: KlineInterval,
period: SpotKlineInterval,
pagination?: Pagination,
): Promise<APIResponse<any>> {
return this.get('/api/spot/v1/market/candles', {

View File

@@ -8,6 +8,28 @@ export type FuturesProductType =
| 'sdmcbl'
| 'scmcbl';
export type FuturesKlineInterval =
| '1m'
| '3m'
| '5m'
| '15m'
| '30m'
| '1H'
| '2H'
| '4H'
| '6H'
| '12H'
| '1D'
| '3D'
| '1W'
| '1M'
| '6Hutc'
| '12Hutc'
| '1Dutc'
| '3Dutc'
| '1Wutc'
| '1Mutc';
export type FuturesHoldSide = 'long' | 'short';
export type FuturesMarginMode = 'fixed' | 'crossed';

View File

@@ -2,6 +2,25 @@ import { OrderTimeInForce } from './shared';
export type WalletType = 'spot' | 'mix_usdt' | 'mix_usd';
export type SpotKlineInterval =
| '1min'
| '5min'
| '15min'
| '30min'
| '1h'
| '4h'
| '6h'
| '12h'
| '1M'
| '1W'
| '1week'
| '6Hutc'
| '12Hutc'
| '1Dutc'
| '3Dutc'
| '1Wutc'
| '1Mutc';
export interface NewWalletTransfer {
fromType: WalletType;
toType: WalletType;

View File

@@ -4,6 +4,9 @@ export type numberInString = string;
export type OrderSide = 'Buy' | 'Sell';
/**
* @deprecated use SpotKlineInterval or FuturesKlineInterval, depending on which API group you're using
*/
export type KlineInterval =
| '1min'
| '5min'

View File

@@ -26,6 +26,47 @@ interface UnsignedRequest<T extends object | undefined = {}> {
type SignMethod = 'bitget';
if (
typeof process === 'object' &&
typeof process.env === 'object' &&
process.env.BITGETTRACE
) {
axios.interceptors.request.use((request) => {
console.log(
new Date(),
'Starting Request',
JSON.stringify(
{
url: request.url,
method: request.method,
params: request.params,
data: request.data,
},
null,
2,
),
);
return request;
});
axios.interceptors.response.use((response) => {
console.log(new Date(), 'Response:', {
// request: {
// url: response.config.url,
// method: response.config.method,
// data: response.config.data,
// headers: response.config.headers,
// },
response: {
status: response.status,
statusText: response.statusText,
headers: response.headers,
data: response.data,
},
});
return response;
});
}
export default abstract class BaseRestClient {
private options: RestClientOptions;
private baseUrl: string;