-
Notifications
You must be signed in to change notification settings - Fork 319
Expand file tree
/
Copy pathAccount.py
More file actions
335 lines (285 loc) · 14.3 KB
/
Account.py
File metadata and controls
335 lines (285 loc) · 14.3 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
from .consts import *
from .okxclient import OkxClient
class AccountAPI(OkxClient):
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1',
domain='https://www.okx.com', debug=False, proxy=None):
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
# Get Positions
def get_position_risk(self, instType=''):
params = {}
if instType:
params['instType'] = instType
return self._request_with_params(GET, POSITION_RISK, params)
# Get Balance
def get_account_balance(self, ccy=''):
params = {}
if ccy:
params['ccy'] = ccy
return self._request_with_params(GET, ACCOUNT_INFO, params)
# Get Positions
def get_positions(self, instType='', instId='', posId=''):
params = {'instType': instType, 'instId': instId, 'posId': posId}
return self._request_with_params(GET, POSITION_INFO, params)
def position_builder(self, acctLv=None, inclRealPosAndEq=None, lever=None, greeksType=None, simPos=None,
simAsset=None, idxVol=None):
params = {}
if acctLv is not None:
params['acctLv'] = acctLv
if inclRealPosAndEq is not None:
params['inclRealPosAndEq'] = inclRealPosAndEq
if lever is not None:
params['lever'] = lever
if greeksType is not None:
params['greeksType'] = greeksType
if simPos is not None:
params['simPos'] = simPos
if simAsset is not None:
params['simAsset'] = simAsset
if idxVol is not None:
params['idxVol'] = idxVol
return self._request_with_params(POST, POSITION_BUILDER, params)
# Get Bills Details (recent 7 days)
def get_account_bills(self, instType='', ccy='', mgnMode='', ctType='', type='', subType='', after='', before='',
limit=''):
params = {'instType': instType, 'ccy': ccy, 'mgnMode': mgnMode, 'ctType': ctType, 'type': type,
'subType': subType, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, BILLS_DETAIL, params)
# Get Bills Details (recent 3 months)
def get_account_bills_archive(self, instType='', ccy='', mgnMode='', ctType='', type='', subType='', after='',
before='',
limit='', begin='', end=''):
params = {'instType': instType, 'ccy': ccy, 'mgnMode': mgnMode, 'ctType': ctType, 'type': type,
'subType': subType, 'after': after, 'before': before, 'limit': limit, 'begin': begin, 'end': end}
return self._request_with_params(GET, BILLS_ARCHIVE, params)
# Get Account Configuration
def get_account_config(self):
return self._request_without_params(GET, ACCOUNT_CONFIG)
# Get Account Configuration
def set_position_mode(self, posMode):
params = {'posMode': posMode}
return self._request_with_params(POST, POSITION_MODE, params)
# Get Account Configuration
def set_leverage(self, lever, mgnMode, instId='', ccy='', posSide=''):
params = {'lever': lever, 'mgnMode': mgnMode, 'instId': instId, 'ccy': ccy, 'posSide': posSide}
return self._request_with_params(POST, SET_LEVERAGE, params)
# Get Maximum Tradable Size For Instrument
def get_max_order_size(self, instId, tdMode, ccy='', px=''):
params = {'instId': instId, 'tdMode': tdMode, 'ccy': ccy, 'px': px}
return self._request_with_params(GET, MAX_TRADE_SIZE, params)
# Get Maximum Available Tradable Amount
def get_max_avail_size(self, instId, tdMode, ccy='', reduceOnly='', unSpotOffset='', quickMgnType=''):
params = {'instId': instId, 'tdMode': tdMode, 'ccy': ccy, 'reduceOnly': reduceOnly,
'unSpotOffset': unSpotOffset, 'quickMgnType': quickMgnType}
return self._request_with_params(GET, MAX_AVAIL_SIZE, params)
# Increase / Decrease margin
def adjustment_margin(self, instId, posSide, type, amt, loanTrans=''):
params = {'instId': instId, 'posSide': posSide, 'type': type, 'amt': amt, 'loanTrans': loanTrans}
return self._request_with_params(POST, ADJUSTMENT_MARGIN, params)
# Get Leverage
def get_leverage(self, mgnMode, ccy='', instId=''):
params = {'instId': instId, 'mgnMode': mgnMode, 'ccy': ccy}
return self._request_with_params(GET, GET_LEVERAGE, params)
# Get instruments
def get_instruments(self, instType='', ugly='', instFamily='', instId=''):
params = {'instType': instType, 'ugly': ugly, 'instFamily': instFamily, 'instId': instId}
return self._request_with_params(GET, GET_INSTRUMENTS, params)
# Get the maximum loan of isolated MARGIN
def get_max_loan(self, instId, mgnMode, mgnCcy='', tradeQuoteCcy=None):
params = {'instId': instId, 'mgnMode': mgnMode, 'mgnCcy': mgnCcy}
if tradeQuoteCcy is not None:
params['tradeQuoteCcy'] = tradeQuoteCcy
return self._request_with_params(GET, MAX_LOAN, params)
# Get Fee Rates
def get_fee_rates(self, instType, instId='', uly='', category='', instFamily=''):
params = {'instType': instType, 'instId': instId, 'uly': uly, 'category': category, 'instFamily': instFamily}
return self._request_with_params(GET, FEE_RATES, params)
# Get interest-accrued
def get_interest_accrued(self, instId='', ccy='', mgnMode='', after='', before='', limit=''):
params = {'instId': instId, 'ccy': ccy, 'mgnMode': mgnMode, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, INTEREST_ACCRUED, params)
# Get interest-accrued
def get_interest_rate(self, ccy=''):
params = {'ccy': ccy}
return self._request_with_params(GET, INTEREST_RATE, params)
# Set Greeks (PA/BS)
def set_greeks(self, greeksType):
params = {'greeksType': greeksType}
return self._request_with_params(POST, SET_GREEKS, params)
# Set Isolated Mode
def set_isolated_mode(self, isoMode, type):
params = {'isoMode': isoMode, 'type': type}
return self._request_with_params(POST, ISOLATED_MODE, params)
# Get Maximum Withdrawals
def get_max_withdrawal(self, ccy=''):
params = {'ccy': ccy}
return self._request_with_params(GET, MAX_WITHDRAWAL, params)
# Get borrow repay
def borrow_repay(self, ccy='', side='', amt='', ordId=''):
params = {'ccy': ccy, 'side': side, 'amt': amt, 'ordId': ordId}
return self._request_with_params(POST, BORROW_REPAY, params)
# Get borrow repay history
def get_borrow_repay_history(self, ccy='', after='', before='', limit=''):
params = {'ccy': ccy, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, BORROW_REPAY_HISTORY, params)
# Get Obtain borrowing rate and limit
def get_interest_limits(self, type='', ccy=''):
params = {'type': type, 'ccy': ccy}
return self._request_with_params(GET, INTEREST_LIMITS, params)
# Get Simulated Margin
def get_simulated_margin(self, instType='', inclRealPos=True, spotOffsetType='', simPos=[]):
params = {'instType': instType, 'inclRealPos': inclRealPos, 'spotOffsetType': spotOffsetType, 'simPos': simPos}
return self._request_with_params(POST, SIMULATED_MARGIN, params)
# Get Greeks
def get_greeks(self, ccy=''):
params = {'ccy': ccy}
return self._request_with_params(GET, GREEKS, params)
# GET /api/v5/account/risk-state
def get_account_position_risk(self):
return self._request_without_params(GET, ACCOUNT_RISK)
# GET /api/v5/account/positions-history
def get_positions_history(self, instType='', instId='', mgnMode='', type='', posId='', after='', before='',
limit=''):
params = {
'instType': instType,
'instId': instId,
'mgnMode': mgnMode,
'type': type,
'posId': posId,
'after': after,
'before': before,
'limit': limit
}
return self._request_with_params(GET, POSITIONS_HISTORY, params)
# GET /api/v5/account/position-tiers
def get_account_position_tiers(self, instType='', uly='', instFamily=''):
params = {
'instType': instType,
'uly': uly,
'instFamily': instFamily
}
return self._request_with_params(GET, GET_PM_LIMIT, params)
# - Get VIP interest accrued data
def get_VIP_interest_accrued_data(self, ccy='', ordId='', after='', before='', limit=''):
params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_VIP_INTEREST_ACCRUED_DATA, params)
# - Get VIP interest deducted data
def get_VIP_interest_deducted_data(self, ccy='', ordId='', after='', before='', limit=''):
params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_VIP_INTEREST_DEDUCTED_DATA, params)
# - Get VIP loan order list
def get_VIP_loan_order_list(self, ordId='', state='', ccy='', after='', before='', limit=''):
params = {'ordId': ordId, 'state': state, 'ccy': ccy, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_VIP_LOAN_ORDER_LIST, params)
# - Get VIP loan order detail
def get_VIP_loan_order_detail(self, ccy='', ordId='', after='', before='', limit=''):
params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_VIP_LOAN_ORDER_DETAIL, params)
# - Set risk offset type
def set_risk_offset_typel(self, type=''):
params = {'type': type}
return self._request_with_params(POST, SET_RISK_OFFSET_TYPE, params)
# - Set auto loan
def set_auto_loan(self, autoLoan=''):
params = {
'autoLoan': autoLoan
}
return self._request_with_params(POST, SET_AUTO_LOAN, params)
# - Set auto loan
def set_account_level(self, acctLv):
params = {
'acctLv': acctLv
}
return self._request_with_params(POST, SET_ACCOUNT_LEVEL, params)
# - Activate option
def activate_option(self):
return self._request_without_params(POST, ACTIVSTE_OPTION)
def get_fix_loan_borrowing_limit(self):
return self._request_without_params(GET, BORROWING_LIMIT)
def get_fix_loan_borrowing_quote(self, type=None, ccy=None, amt=None, maxRate=None, term=None, ordId=None):
params = {}
if type is not None:
params['type'] = type
if ccy is not None:
params['ccy'] =ccy
if amt is not None:
params['amt'] = amt
if maxRate is not None:
params['maxRate'] = maxRate
if term is not None:
params['term'] = term
if ordId is not None:
params['ordId'] = ordId
return self._request_with_params(GET, BORROWING_QUOTE, params)
def place_fix_loan_borrowing_order(self, ccy=None, amt=None, maxRate=None, term=None, reborrow=False, reborrowRate=None):
params = {}
if ccy is not None:
params['ccy'] =ccy
if amt is not None:
params['amt'] = amt
if maxRate is not None:
params['maxRate'] = maxRate
if term is not None:
params['term'] = term
if reborrow is not None:
params['reborrow'] = reborrow
if reborrowRate is not None:
params['reborrowRate'] = reborrowRate
return self._request_with_params(POST, PLACE_BORROWING_ORDER, params)
def amend_fix_loan_borrowing_order(self, ordId=None, reborrow=None, renewMaxRate=None):
params = {}
if ordId is not None:
params['ordId'] = ordId
if reborrow is not None:
params['reborrow'] = reborrow
if renewMaxRate is not None:
params['renewMaxRate'] = renewMaxRate
return self._request_with_params(POST, AMEND_BORROWING_ORDER, params)
def fix_loan_manual_reborrow(self, ordId=None, maxRate=None):
params = {}
if ordId is not None:
params['ordId'] = ordId
if maxRate is not None:
params['maxRate'] = maxRate
return self._request_with_params(POST, MANUAL_REBORROW, params)
def repay_fix_loan_borrowing_order(self, ordId=None):
params = {}
if ordId is not None:
params['ordId'] = ordId
return self._request_with_params(POST, REPAY_BORROWING_ORDER, params)
def get_fix_loan_borrowing_orders_list(self, ordId=None, ccy=None, state=None, after=None, before=None, limit=None):
params = {}
if ordId is not None:
params['ordId'] = ordId
if ccy is not None:
params['ccy'] =ccy
if state is not None:
params['state'] = state
if after is not None:
params['after'] = after
if before is not None:
params['before'] = before
if limit is not None:
params['limit'] = limit
return self._request_with_params(GET, BORROWING_ORDERS_LIST, params)
def spot_manual_borrow_repay(self, ccy=None, side=None, amt=None):
params = {}
if ccy is not None:
params['ccy'] = ccy
if side is not None:
params['side'] = side
if amt is not None:
params['amt'] = amt
return self._request_with_params(POST, MANUAL_REBORROW_REPAY, params)
def set_auto_repay(self, autoRepay=False):
params = {}
if autoRepay is not None:
params['autoRepay'] = autoRepay
return self._request_with_params(POST, SET_AUTO_REPAY, params)
def spot_borrow_repay_history(self, ccy='', type='', after='', before='', limit=''):
params = {'ccy': ccy, 'type': type, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_BORROW_REPAY_HISTORY, params)
def set_auto_earn(self, ccy, action, earnType=None):
params = {'ccy': ccy, 'action': action}
if earnType is not None:
params['earnType'] = earnType
return self._request_with_params(POST, SET_AUTO_EARN, params)