-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
copy-trading-client.ts
162 lines (142 loc) · 3.82 KB
/
copy-trading-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
158
159
160
161
162
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
APIResponseV3,
APIResponseWithTime,
CopyTradingCancelOrderRequest,
CopyTradingCloseOrderRequest,
CopyTradingOrderListRequest,
CopyTradingOrderRequest,
CopyTradingTradingStopRequest,
CopyTradingTransferRequest,
} from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
/**
* REST API client for USDC Perpetual APIs
* @deprecated WARNING
* These endpoints are being switched off gradually and are expected to be completely turned off by the end of 2024.
* They may stop working at any point before then.
* Please update your code as soon as possible to use the V5 APIs instead.
*/
export class CopyTradingClient extends BaseRestClient {
getClientType() {
// Follows the same authentication mechanism as USDC APIs
return REST_CLIENT_TYPE_ENUM.v3;
}
async fetchServerTime(): Promise<number> {
const res = await this.getServerTime();
return Number(res.time_now);
}
/**
*
* Market Data Endpoints
*
*/
getSymbols(): Promise<APIResponseV3<any>> {
return this.get('/contract/v3/public/copytrading/symbol/list');
}
/**
*
* Account Data Endpoints
*
*/
/** -> Order API */
/** Create order */
submitOrder(params: CopyTradingOrderRequest): Promise<APIResponseV3<any>> {
return this.postPrivate(
'/contract/v3/private/copytrading/order/create',
params,
);
}
/** Set Trading Stop */
setTradingStop(
params: CopyTradingTradingStopRequest,
): Promise<APIResponseV3<any>> {
return this.postPrivate(
'/contract/v3/private/copytrading/order/trading-stop',
params,
);
}
/** Query Order List */
getActiveOrders(
params?: CopyTradingOrderListRequest,
): Promise<APIResponseV3<any>> {
return this.getPrivate(
'/contract/v3/private/copytrading/order/list',
params,
);
}
/** Cancel order */
cancelOrder(
params: CopyTradingCancelOrderRequest,
): Promise<APIResponseV3<any>> {
return this.postPrivate(
'/contract/v3/private/copytrading/order/cancel',
params,
);
}
/** Close Order.
* This endpoint's rate_limit will decrease by 10 per request;
* ie, one request to this endpoint consumes 10 from the limit allowed per minute.
*/
closeOrder(
params: CopyTradingCloseOrderRequest,
): Promise<APIResponseV3<any>> {
return this.postPrivate(
'/contract/v3/private/copytrading/order/close',
params,
);
}
/** -> Positions API */
/** Position List */
getPositions(symbol?: string): Promise<APIResponseV3<any>> {
return this.getPrivate('/contract/v3/private/copytrading/position/list', {
symbol,
});
}
/** Close Position */
closePosition(
symbol: string,
positionIdx: string,
): Promise<APIResponseV3<any>> {
return this.postPrivate('/contract/v3/private/copytrading/position/close', {
symbol,
positionIdx,
});
}
/** Only integers can be set to set the leverage */
setLeverage(
symbol: string,
buyLeverage: string,
sellLeverage: string,
): Promise<APIResponseV3<any>> {
return this.postPrivate(
'/contract/v3/private/copytrading/position/set-leverage',
{ symbol, buyLeverage, sellLeverage },
);
}
/**
*
* Wallet Data Endpoints
*
*/
/** Get Wallet Balance */
getBalances(): Promise<APIResponseV3<any>> {
return this.getPrivate('/contract/v3/private/copytrading/wallet/balance');
}
/** Transfer */
transfer(params: CopyTradingTransferRequest): Promise<APIResponseV3<any>> {
return this.postPrivate(
'/contract/v3/private/copytrading/wallet/transfer',
params,
);
}
/**
*
* API Data Endpoints
*
*/
getServerTime(): Promise<APIResponseWithTime> {
return this.get('/v2/public/time');
}
}