forked from tiagosiebler/bybit-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spot-client.ts
157 lines (134 loc) · 3.89 KB
/
spot-client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { AxiosRequestConfig } from 'axios';
import { KlineInterval } from './types/shared';
import { NewSpotOrder, OrderSide, OrderTypeSpot, SpotOrderQueryById } from './types/spot';
import BaseRestClient from './util/BaseRestClient';
import { GenericAPIResponse, getRestBaseUrl, RestClientOptions } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper';
export class SpotClient extends BaseRestClient {
protected requestWrapper: RequestWrapper;
/**
* @public Creates an instance of the Spot REST API client.
*
* @param {string} key - your API key
* @param {string} secret - your API secret
* @param {boolean} [useLivenet=false]
* @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity
* @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios
*/
constructor(
key?: string | undefined,
secret?: string | undefined,
useLivenet: boolean = false,
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {}
) {
super(key, secret, getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions);
// this.requestWrapper = new RequestWrapper(
// key,
// secret,
// getRestBaseUrl(useLivenet, restClientOptions),
// restClientOptions,
// requestOptions
// );
return this;
}
async getServerTime(urlKeyOverride?: string): Promise<number> {
const result = await this.get('/spot/v1/time');
return result.serverTime;
}
/**
*
* Market Data Endpoints
*
**/
getSymbols() {
return this.get('/spot/v1/symbols');
}
getOrderBook(symbol: string, limit?: number) {
return this.get('/spot/quote/v1/depth', {
symbol, limit
});
}
getMergedOrderBook(symbol: string, scale?: number, limit?: number) {
return this.get('/spot/quote/v1/depth/merged', {
symbol,
scale,
limit,
});
}
getTrades(symbol: string, limit?: number) {
return this.get('/spot/v1/trades', {
symbol,
limit,
});
}
getCandles(symbol: string, interval: KlineInterval, limit?: number, startTime?: number, endTime?: number) {
return this.get('/spot/quote/v1/kline', {
symbol,
interval,
limit,
startTime,
endTime,
});
}
get24hrTicker(symbol?: string) {
return this.get('/spot/quote/v1/ticker/24hr', { symbol });
}
getLastTradedPrice(symbol?: string) {
return this.get('/spot/quote/v1/ticker/price', { symbol });
}
getBestBidAskPrice(symbol?: string) {
return this.get('/spot/quote/v1/ticker/book_ticker', { symbol });
}
/**
* Account Data Endpoints
*/
submitOrder(params: NewSpotOrder) {
return this.postPrivate('/spot/v1/order', params);
}
getOrder(params: SpotOrderQueryById) {
return this.getPrivate('/spot/v1/order', params);
}
cancelOrder(params: SpotOrderQueryById) {
return this.deletePrivate('/spot/v1/order', params);
}
cancelOrderBatch(params: {
symbol: string;
side?: OrderSide;
orderTypes: OrderTypeSpot[]
}) {
const orderTypes = params.orderTypes ? params.orderTypes.join(',') : undefined;
return this.deletePrivate('/spot/order/batch-cancel', {
...params,
orderTypes,
});
}
getOpenOrders(symbol?: string, orderId?: string, limit?: number) {
return this.getPrivate('/spot/v1/open-orders', {
symbol,
orderId,
limit,
});
}
getPastOrders(symbol?: string, orderId?: string, limit?: number) {
return this.getPrivate('/spot/v1/history-orders', {
symbol,
orderId,
limit,
});
}
getMyTrades(symbol?: string, limit?: number, fromId?: number, toId?: number) {
return this.getPrivate('/spot/v1/myTrades', {
symbol,
limit,
fromId,
toId,
});
}
/**
* Wallet Data Endpoints
*/
getBalances() {
return this.getPrivate('/spot/v1/account');
}
}