spot v3 request types

This commit is contained in:
tiagosiebler
2022-09-10 12:33:51 +01:00
parent 3a984594dc
commit c287495052
5 changed files with 121 additions and 44 deletions

View File

@@ -5,6 +5,12 @@ import {
OrderSide,
OrderTypeSpot,
SpotBalances,
KlineInterval,
NewSpotOrderV3,
SpotMyTradesRequest,
SpotLeveragedTokenPRHistoryRequest,
SpotCrossMarginBorrowingInfoRequest,
SpotCrossMarginRepaymentHistoryRequest,
} from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
@@ -40,8 +46,16 @@ export class SpotV3Client extends BaseRestClient {
}
/** Get merged orderbook for symbol */
getOrderBookMerged(params: unknown): Promise<APIResponseV3<any>> {
return this.get('/spot/v3/public/quote/depth/merged', params);
getOrderBookMerged(
symbol: string,
scale?: number,
limit?: number
): Promise<APIResponseV3<any>> {
return this.get('/spot/v3/public/quote/depth/merged', {
symbol,
scale,
limit,
});
}
/** Get public trading records (raw trades) */
@@ -50,8 +64,20 @@ export class SpotV3Client extends BaseRestClient {
}
/** Get candles/klines */
getCandles(params: unknown): Promise<APIResponseV3<any>> {
return this.get('/spot/v3/public/quote/kline', params);
getCandles(
symbol: string,
interval: KlineInterval,
limit?: number,
startTime?: number,
endTime?: number
): Promise<APIResponseV3<any>> {
return this.get('/spot/v3/public/quote/kline', {
symbol,
interval,
limit,
startTime,
endTime,
});
}
/** Get latest information for symbol (24hr ticker) */
@@ -78,7 +104,7 @@ export class SpotV3Client extends BaseRestClient {
/** -> Order API */
/** Create order */
submitOrder(params: unknown): Promise<APIResponseV3<any>> {
submitOrder(params: NewSpotOrderV3): Promise<APIResponseV3<any>> {
return this.postPrivate('/spot/v3/private/order', params);
}
@@ -147,7 +173,7 @@ export class SpotV3Client extends BaseRestClient {
* If startTime is not specified, you can only query for records in the last 7 days.
* If you want to query for records older than 7 days, startTime is required.
*/
getMyTrades(params?: unknown): Promise<APIResponseV3<any>> {
getMyTrades(params?: SpotMyTradesRequest): Promise<APIResponseV3<any>> {
return this.getPrivate('/spot/v3/private/my-trades', params);
}
@@ -215,7 +241,9 @@ export class SpotV3Client extends BaseRestClient {
}
/** Get leveraged token purchase/redemption history */
getLeveragedTokenPRHistory(params: unknown): Promise<APIResponseV3<any>> {
getLeveragedTokenPRHistory(
params?: SpotLeveragedTokenPRHistoryRequest
): Promise<APIResponseV3<any>> {
return this.getPrivate('/spot/v3/private/record', params);
}
@@ -245,7 +273,9 @@ export class SpotV3Client extends BaseRestClient {
}
/** Query borrowing info */
getCrossMarginBorrowingInfo(params?: unknown): Promise<APIResponseV3<any>> {
getCrossMarginBorrowingInfo(
params?: SpotCrossMarginBorrowingInfoRequest
): Promise<APIResponseV3<any>> {
return this.getPrivate('/spot/v3/private/cross-margin-orders', params);
}
@@ -261,7 +291,7 @@ export class SpotV3Client extends BaseRestClient {
/** Query repayment history */
getCrossMarginRepaymentHistory(
params?: unknown
params?: SpotCrossMarginRepaymentHistoryRequest
): Promise<APIResponseV3<any>> {
return this.getPrivate(
'/spot/v3/private/cross-margin-repay-history',

View File

@@ -1,4 +1,3 @@
export * from './response';
export * from './request';
export * from './shared';
export * from './spot';

View File

@@ -1,5 +1,6 @@
export * from './account-asset';
export * from './copy-trading';
export * from './spot';
export * from './usdt-perp';
export * from './usdc-perp';
export * from './usdc-options';

81
src/types/request/spot.ts Normal file
View File

@@ -0,0 +1,81 @@
import { numberInString, OrderSide } from '../shared';
export type OrderTypeSpot = 'LIMIT' | 'MARKET' | 'LIMIT_MAKER';
export type OrderTimeInForce = 'GTC' | 'FOK' | 'IOC';
export interface NewSpotOrder {
symbol: string;
qty: number;
side: OrderSide;
type: OrderTypeSpot;
timeInForce?: OrderTimeInForce;
price?: number;
orderLinkId?: string;
}
export interface NewSpotOrderV3 {
symbol: string;
orderQty: string;
side: OrderSide;
orderType: OrderTypeSpot;
timeInForce?: OrderTimeInForce;
orderPrice?: string;
orderLinkId?: string;
orderCategory?: 0 | 1;
triggerPrice?: string;
}
export interface SpotOrderQueryById {
orderId?: string;
orderLinkId?: string;
}
export interface SpotSymbolInfo {
name: string;
alias: string;
baseCurrency: string;
quoteCurrency: string;
basePrecision: numberInString;
quotePrecision: numberInString;
minTradeQuantity: numberInString;
minTradeAmount: numberInString;
minPricePrecision: numberInString;
maxTradeQuantity: numberInString;
maxTradeAmount: numberInString;
category: numberInString;
}
export interface SpotMyTradesRequest {
symbol?: string;
orderId?: string;
limit?: string;
startTime?: number;
endTime?: number;
fromTradeId?: string;
toTradeId?: string;
}
export interface SpotLeveragedTokenPRHistoryRequest {
ltCode?: string;
orderId?: string;
startTime?: number;
endTime?: number;
limit?: number;
orderType?: 1 | 2;
serialNo?: string;
}
export interface SpotCrossMarginBorrowingInfoRequest {
startTime?: number;
endTime?: number;
coin?: string;
status?: 0 | 1 | 2;
limit?: number;
}
export interface SpotCrossMarginRepaymentHistoryRequest {
startTime?: number;
endTime?: number;
coin?: string;
limit?: number;
}

View File

@@ -1,34 +0,0 @@
import { numberInString, OrderSide } from './shared';
export type OrderTypeSpot = 'LIMIT' | 'MARKET' | 'LIMIT_MAKER';
export type OrderTimeInForce = 'GTC' | 'FOK' | 'IOC';
export interface NewSpotOrder {
symbol: string;
qty: number;
side: OrderSide;
type: OrderTypeSpot;
timeInForce?: OrderTimeInForce;
price?: number;
orderLinkId?: string;
}
export interface SpotOrderQueryById {
orderId?: string;
orderLinkId?: string;
}
export interface SpotSymbolInfo {
name: string;
alias: string;
baseCurrency: string;
quoteCurrency: string;
basePrecision: numberInString;
quotePrecision: numberInString;
minTradeQuantity: numberInString;
minTradeAmount: numberInString;
minPricePrecision: numberInString;
maxTradeQuantity: numberInString;
maxTradeAmount: numberInString;
category: numberInString;
}