remove silly logger from ws by default. Expand spot and linear types
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "bybit-api",
|
||||
"version": "2.3.0",
|
||||
"version": "2.3.1",
|
||||
"description": "Node.js connector for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
||||
@@ -40,3 +40,13 @@ export const API_ERROR_CODE = {
|
||||
SAME_SLTP_MODE_LINEAR: 130150,
|
||||
RISK_ID_NOT_MODIFIED: 134026,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Position idx, used to identify positions in different position modes.
|
||||
* Required if you are under One-Way Mode:
|
||||
*/
|
||||
export enum LinearPositionIdx {
|
||||
OneWayMode = 0,
|
||||
BuySide = 1,
|
||||
SellSide = 2,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ export * from './linear-client';
|
||||
export * from './spot-client';
|
||||
export * from './websocket-client';
|
||||
export * from './logger';
|
||||
export * from './types/shared';
|
||||
export * from './types/spot';
|
||||
export * from './types';
|
||||
export * from './util/WsStore';
|
||||
export * from './constants/enum';
|
||||
|
||||
@@ -9,14 +9,19 @@ import {
|
||||
APIResponseWithTime,
|
||||
AssetExchangeRecordsReq,
|
||||
CoinParam,
|
||||
LinearOrder,
|
||||
NewLinearOrder,
|
||||
PerpPosition,
|
||||
PerpPositionRoot,
|
||||
SymbolInfo,
|
||||
SymbolIntervalFromLimitParam,
|
||||
SymbolLimitParam,
|
||||
SymbolParam,
|
||||
SymbolPeriodLimitParam,
|
||||
WalletBalances,
|
||||
WalletFundRecordsReq,
|
||||
WithdrawRecordsReq,
|
||||
} from './types/shared';
|
||||
} from './types';
|
||||
import { linearPositionModeEnum, positionTpSlModeEnum } from './constants/enum';
|
||||
import BaseRestClient from './util/BaseRestClient';
|
||||
|
||||
@@ -150,7 +155,7 @@ export class LinearClient extends BaseRestClient {
|
||||
|
||||
getWalletBalance(
|
||||
params?: Partial<CoinParam>
|
||||
): Promise<APIResponseWithTime<any>> {
|
||||
): Promise<APIResponseWithTime<WalletBalances>> {
|
||||
return this.getPrivate('v2/private/wallet/balance', params);
|
||||
}
|
||||
|
||||
@@ -192,22 +197,9 @@ export class LinearClient extends BaseRestClient {
|
||||
*
|
||||
*/
|
||||
|
||||
placeActiveOrder(params: {
|
||||
side: string;
|
||||
symbol: string;
|
||||
order_type: string;
|
||||
qty: number;
|
||||
price?: number;
|
||||
time_in_force: string;
|
||||
take_profit?: number;
|
||||
stop_loss?: number;
|
||||
tp_trigger_by?: string;
|
||||
sl_trigger_by?: string;
|
||||
reduce_only: boolean;
|
||||
close_on_trigger: boolean;
|
||||
order_link_id?: string;
|
||||
position_idx?: number;
|
||||
}): Promise<APIResponseWithTime<any>> {
|
||||
placeActiveOrder(
|
||||
params: NewLinearOrder
|
||||
): Promise<APIResponseWithTime<LinearOrder | null>> {
|
||||
return this.postPrivate('private/linear/order/create', params);
|
||||
}
|
||||
|
||||
@@ -337,9 +329,14 @@ export class LinearClient extends BaseRestClient {
|
||||
* Position
|
||||
*/
|
||||
|
||||
getPosition(): Promise<APIResponseWithTime<PerpPositionRoot[]>>;
|
||||
getPosition(
|
||||
params: Partial<SymbolParam>
|
||||
): Promise<APIResponseWithTime<PerpPosition[]>>;
|
||||
|
||||
getPosition(
|
||||
params?: Partial<SymbolParam>
|
||||
): Promise<APIResponseWithTime<any>> {
|
||||
): Promise<APIResponseWithTime<PerpPosition[] | PerpPositionRoot[]>> {
|
||||
return this.getPrivate('private/linear/position/list', params);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ export type LogParams = null | any;
|
||||
|
||||
export const DefaultLogger = {
|
||||
silly: (...params: LogParams): void => {
|
||||
console.log(params);
|
||||
// console.log(params);
|
||||
},
|
||||
debug: (...params: LogParams): void => {
|
||||
console.log(params);
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { AxiosRequestConfig } from 'axios';
|
||||
import { APIResponse, KlineInterval } from './types/shared';
|
||||
import {
|
||||
NewSpotOrder,
|
||||
APIResponse,
|
||||
KlineInterval,
|
||||
OrderSide,
|
||||
OrderTypeSpot,
|
||||
SpotBalances,
|
||||
SpotLastPrice,
|
||||
SpotOrderQueryById,
|
||||
SpotSymbolInfo,
|
||||
} from './types/spot';
|
||||
} from './types';
|
||||
import BaseRestClient from './util/BaseRestClient';
|
||||
import {
|
||||
agentSource,
|
||||
@@ -109,7 +112,11 @@ export class SpotClient extends BaseRestClient {
|
||||
return this.get('/spot/quote/v1/ticker/24hr', { symbol });
|
||||
}
|
||||
|
||||
getLastTradedPrice(symbol?: string): Promise<APIResponse<any>> {
|
||||
getLastTradedPrice(): Promise<APIResponse<SpotLastPrice[]>>;
|
||||
getLastTradedPrice(symbol: string): Promise<APIResponse<SpotLastPrice>>;
|
||||
getLastTradedPrice(
|
||||
symbol?: string
|
||||
): Promise<APIResponse<SpotLastPrice | SpotLastPrice[]>> {
|
||||
return this.get('/spot/quote/v1/ticker/price', { symbol });
|
||||
}
|
||||
|
||||
@@ -192,7 +199,7 @@ export class SpotClient extends BaseRestClient {
|
||||
* Wallet Data Endpoints
|
||||
*/
|
||||
|
||||
getBalances(): Promise<APIResponse<any>> {
|
||||
getBalances(): Promise<APIResponse<SpotBalances>> {
|
||||
return this.getPrivate('/spot/v1/account');
|
||||
}
|
||||
}
|
||||
|
||||
4
src/types/index.ts
Normal file
4
src/types/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './response';
|
||||
export * from './request';
|
||||
export * from './shared';
|
||||
export * from './spot';
|
||||
1
src/types/request/index.ts
Normal file
1
src/types/request/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './usdt-perp';
|
||||
27
src/types/request/usdt-perp.ts
Normal file
27
src/types/request/usdt-perp.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { LinearPositionIdx } from '../../constants/enum';
|
||||
import { OrderSide } from '../shared';
|
||||
|
||||
export type LinearOrderType = 'Limit' | 'Market';
|
||||
|
||||
export type LinearTimeInForce =
|
||||
| 'GoodTillCancel'
|
||||
| 'ImmediateOrCancel'
|
||||
| 'FillOrKill'
|
||||
| 'PostOnly';
|
||||
|
||||
export interface NewLinearOrder {
|
||||
side: OrderSide;
|
||||
symbol: string;
|
||||
order_type: LinearOrderType;
|
||||
qty: number;
|
||||
price?: number;
|
||||
time_in_force: LinearTimeInForce;
|
||||
take_profit?: number;
|
||||
stop_loss?: number;
|
||||
tp_trigger_by?: string;
|
||||
sl_trigger_by?: string;
|
||||
reduce_only: boolean;
|
||||
close_on_trigger: boolean;
|
||||
order_link_id?: string;
|
||||
position_idx?: LinearPositionIdx;
|
||||
}
|
||||
3
src/types/response/index.ts
Normal file
3
src/types/response/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './shared';
|
||||
export * from './spot';
|
||||
export * from './usdt-perp';
|
||||
19
src/types/response/shared.ts
Normal file
19
src/types/response/shared.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export interface SymbolWalletBalance {
|
||||
equity: number;
|
||||
available_balance: number;
|
||||
used_margin: number;
|
||||
order_margin: number;
|
||||
position_margin: number;
|
||||
occ_closing_fee: number;
|
||||
occ_funding_fee: number;
|
||||
wallet_balance: number;
|
||||
realised_pnl: number;
|
||||
unrealised_pnl: number;
|
||||
cum_realised_pnl: number;
|
||||
given_cash: number;
|
||||
service_cash: number;
|
||||
}
|
||||
|
||||
export interface WalletBalances {
|
||||
[symbol: string]: SymbolWalletBalance | undefined;
|
||||
}
|
||||
17
src/types/response/spot.ts
Normal file
17
src/types/response/spot.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export interface SpotBalances {
|
||||
balances: SpotBalance[];
|
||||
}
|
||||
|
||||
export interface SpotBalance {
|
||||
coin: string;
|
||||
coinId: string;
|
||||
coinName: string;
|
||||
total: string;
|
||||
free: string;
|
||||
locked: string;
|
||||
}
|
||||
|
||||
export interface SpotLastPrice {
|
||||
symbol: string;
|
||||
price: string;
|
||||
}
|
||||
58
src/types/response/usdt-perp.ts
Normal file
58
src/types/response/usdt-perp.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
export interface PerpPosition {
|
||||
user_id: number;
|
||||
symbol: string;
|
||||
side: string;
|
||||
size: number;
|
||||
position_value: number;
|
||||
entry_price: number;
|
||||
liq_price: number;
|
||||
bust_price: number;
|
||||
leverage: number;
|
||||
auto_add_margin: number;
|
||||
is_isolated: boolean;
|
||||
position_margin: number;
|
||||
occ_closing_fee: number;
|
||||
realised_pnl: number;
|
||||
cum_realised_pnl: number;
|
||||
free_qty: number;
|
||||
tp_sl_mode: string;
|
||||
unrealised_pnl: number;
|
||||
deleverage_indicator: number;
|
||||
risk_id: number;
|
||||
stop_loss: number;
|
||||
take_profit: number;
|
||||
trailing_stop: number;
|
||||
position_idx: number;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
export interface PerpPositionRoot {
|
||||
data: PerpPosition;
|
||||
is_valid: boolean;
|
||||
}
|
||||
|
||||
export interface LinearOrder {
|
||||
order_id: string;
|
||||
user_id: number;
|
||||
symbol: string;
|
||||
side: string;
|
||||
order_type: string;
|
||||
price: number;
|
||||
qty: number;
|
||||
time_in_force: string;
|
||||
order_status: string;
|
||||
last_exec_price: number;
|
||||
cum_exec_qty: number;
|
||||
cum_exec_value: number;
|
||||
cum_exec_fee: number;
|
||||
reduce_only: boolean;
|
||||
close_on_trigger: boolean;
|
||||
order_link_id: string;
|
||||
created_time: string;
|
||||
updated_time: string;
|
||||
take_profit: number;
|
||||
stop_loss: number;
|
||||
tp_trigger_by: string;
|
||||
sl_trigger_by: string;
|
||||
position_idx: number;
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
export type numberInString = string;
|
||||
|
||||
export type OrderSide = 'Buy' | 'Sell';
|
||||
|
||||
export type KlineInterval =
|
||||
| '1m'
|
||||
| '3m'
|
||||
@@ -13,8 +17,6 @@ export type KlineInterval =
|
||||
| '1w'
|
||||
| '1M';
|
||||
|
||||
export type numberInString = string;
|
||||
|
||||
export interface APIResponse<T> {
|
||||
ret_code: number;
|
||||
ret_msg: 'OK' | string;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { numberInString } from './shared';
|
||||
import { numberInString, OrderSide } from './shared';
|
||||
|
||||
export type OrderSide = 'Buy' | 'Sell';
|
||||
export type OrderTypeSpot = 'LIMIT' | 'MARKET' | 'LIMIT_MAKER';
|
||||
export type OrderTimeInForce = 'GTC' | 'FOK' | 'IOC';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user