Repository navigation
Expand file tree
/
Copy pathtypes.py
More file actions
567 lines (469 loc) · 10.2 KB
/
Copy pathtypes.py
File metadata and controls
567 lines (469 loc) · 10.2 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
import sys
import types
from typing import Union, List, Optional, Any as PythonAny
from decimal import Decimal
if sys.version_info.minor >= 8:
from typing import TypedDict, Literal, Dict
else:
from typing import Dict
from typing_extensions import Literal
TypedDict = Dict
if sys.version_info.minor >= 11:
from typing import NotRequired
else:
from typing_extensions import NotRequired
OrderSide = Literal['buy', 'sell']
OrderType = Literal['limit', 'market']
PositionSide = Literal['long', 'short']
Any = PythonAny
class Entry:
def __init__(self, path, api, method, config):
self.name = None
self.path = path
self.api = api
self.method = method
self.config = config
def unbound_method(_self, params={}):
return _self.request(self.path, self.api, self.method, params, config=self.config)
self.unbound_method = unbound_method
def __get__(self, instance, owner):
if instance is None:
return self.unbound_method
else:
return types.MethodType(self.unbound_method, instance)
def __set_name__(self, owner, name):
self.name = name
IndexType = Union[str, int]
Num = Union[None, str, float, int, Decimal]
Str = Optional[str]
Strings = Optional[List[str]]
Int = Optional[int]
Bool = Optional[bool]
MarketType = Literal['spot', 'margin', 'swap', 'future', 'option']
SubType = Literal['linear', 'inverse']
class FeeInterface(TypedDict):
currency: Str
cost: Num
rate: NotRequired[Num]
Fee = Optional[FeeInterface]
class TradingFeeInterface(TypedDict):
info: Dict[str, Any]
symbol: Str
maker: Num
taker: Num
percentage: Bool
tierBased: Bool
class Balance(TypedDict):
free: Num
used: Num
total: Num
debt: NotRequired[Num]
class BalanceAccount(TypedDict):
free: Str
used: Str
total: Str
class Account(TypedDict):
id: Str
type: Str
code: Str
info: Dict[str, Any]
class Trade(TypedDict):
info: Dict[str, Any]
amount: Num
datetime: Str
id: Str
order: Str
price: Num
timestamp: Int
type: Str
side: Str
symbol: Str
takerOrMaker: Str
cost: Num
fee: Fee
class Position(TypedDict):
info: Dict[str, Any]
symbol: Str
id: Str
timestamp: Int
datetime: Str
contracts: Num
contractSize: Num
side: Str
notional: Num
leverage: Num
unrealizedPnl: Num
realizedPnl: Num
collateral: Num
entryPrice: Num
markPrice: Num
liquidationPrice: Num
hedged: bool
maintenanceMargin: Num
initialMargin: Num
initialMarginPercentage: Num
marginMode: Str
marginRatio: Num
lastUpdateTimestamp: Int
lastPrice: Num
percentage: Num
stopLossPrice: Num
takeProfitPrice: Num
class OrderRequest(TypedDict):
symbol: Str
type: Str
side: Str
amount: Union[None, float]
price: Union[None, float]
params: Dict[str, Any]
class CancellationRequest(TypedDict):
id: Str
symbol: Str
clientOrderId: Str
class Order(TypedDict):
info: Dict[str, Any]
id: Str
clientOrderId: Str
datetime: Str
timestamp: Int
lastTradeTimestamp: Int
lastUpdateTimestamp: Int
status: Str
symbol: Str
type: Str
timeInForce: Str
side: OrderSide
price: Num
average: Num
amount: Num
filled: Num
remaining: Num
stopPrice: Num
takeProfitPrice: Num
stopLossPrice: Num
cost: Num
trades: List[Trade]
reduceOnly: Bool
postOnly: Bool
fee: Fee
class Liquidation(TypedDict):
info: Dict[str, Any]
symbol: Str
timestamp: Int
datetime: Str
price: Num
baseValue: Num
quoteValue: Num
class FundingHistory(TypedDict):
info: Dict[str, Any]
symbol: Str
code: Str
timestamp: Int
datetime: Str
id: Str
amount: Num
class Balances(Dict[str, Balance]):
datetime: Str
timestamp: Int
class OrderBook(TypedDict):
asks: List[List[Num]]
bids: List[List[Num]]
datetime: Str
timestamp: Int
nonce: Int
symbol: Str
class Transaction(TypedDict):
info: Dict[str, any]
id: Str
txid: Str
timestamp: Int
datetime: Str
address: Str
addressFrom: Str
addressTo: Str
tag: Str
tagFrom: Str
tagTo: Str
type: Str
amount: Num
currency: Str
status: Str
updated: Int
fee: Fee
network: Str
comment: Str
internal: Bool
class TransferEntry(TypedDict):
info: Dict[str, any]
id: Str
timestamp: Int
datetime: Str
currency: Str
amount: Num
fromAccount: Str
toAccount: Str
status: Str
class Ticker(TypedDict):
info: Dict[str, Any]
symbol: Str
timestamp: Int
datetime: Str
high: Num
low: Num
bid: Num
bidVolume: Num
ask: Num
askVolume: Num
vwap: Num
open: Num
close: Num
last: Num
previousClose: Num
change: Num
percentage: Num
average: Num
quoteVolume: Num
baseVolume: Num
markPrice: Num
indexPrice: Num
Tickers = Dict[str, Ticker]
class MarginMode(TypedDict):
info: Dict[str, Any]
symbol: Str
marginMode: Str
MarginModes = Dict[str, MarginMode]
class Leverage(TypedDict):
info: Dict[str, Any]
symbol: Str
marginMode: Str
longLeverage: Num
shortLeverage: Num
Leverages = Dict[str, Leverage]
class Greeks(TypedDict):
symbol: Str
timestamp: Int
datetime: Str
delta: Num
gamma: Num
theta: Num
vega: Num
rho: Num
bidSize: Num
askSize: Num
bidImpliedVolatility: Num
askImpliedVolatility: Num
markImpliedVolatility: Num
bidPrice: Num
askPrice: Num
markPrice: Num
lastPrice: Num
underlyingPrice: Num
info: Dict[str, Any]
class Conversion(TypedDict):
info: Dict[str, Any]
timestamp: Int
datetime: Str
id: Str
fromCurrency: Str
fromAmount: Num
toCurrency: Str
toAmount: Num
price: Num
fee: Num
class Option(TypedDict):
info: Dict[str, Any]
currency: Str
symbol: Str
timestamp: Int
datetime: Str
impliedVolatility: Num
openInterest: Num
bidPrice: Num
askPrice: Num
midPrice: Num
markPrice: Num
lastPrice: Num
underlyingPrice: Num
change: Num
percentage: Num
baseVolume: Num
quoteVolume: Num
OptionChain = Dict[str, Option]
class MarketMarginModes(TypedDict):
cross: bool
isolated: bool
class MinMax(TypedDict):
min: Num
max: Num
class MarketLimits(TypedDict):
amount: Optional[MinMax]
cost: Optional[MinMax]
leverage: Optional[MinMax]
price: Optional[MinMax]
market: Optional[MinMax]
class MarketInterface(TypedDict):
info: Dict[str, Any]
id: Str
symbol: Str
base: Str
quote: Str
baseId: Str
quoteId: Str
active: Bool
type: Str
subType: Str
spot: bool
margin: bool
marginModes: MarketMarginModes
swap: bool
future: bool
option: bool
contract: bool
settle: Str
settleId: Str
contractSize: Num
linear: bool
inverse: bool
expiry: Num
expiryDatetime: Str
strike: Num
optionType: Str
taker: Num
maker: Num
percentage: bool
tierBased: bool
feeSide: Str
precision: Any
limits: MarketLimits
created: Int
class Limit(TypedDict):
min: Num
max: Num
class CurrencyLimits(TypedDict):
amount: Limit
withdraw: Limit
class CurrencyInterface(TypedDict):
id: Str
code: Str
numericId: Int
precision: Num
type: Str
margin: Bool
name: Str
active: Bool
deposit: Bool
withdraw: Bool
fee: Num
limits: CurrencyLimits
networks: Dict[str, any]
info: any
class LastPrice(TypedDict):
symbol: Str
timestamp: Int
datetime: Str
price: Num
side: OrderSide
info: Dict[str, Any]
class MarginModification(TypedDict):
info: Dict[str, any]
symbol: str
type: Optional[Literal['add', 'reduce', 'set']]
marginMode: Optional[Literal['isolated', 'cross']]
amount: Optional[float]
code: Str
status: Str
timestamp: Int
datetime: Str
class CrossBorrowRate(TypedDict):
info: Dict[str, any]
currency: Str
rate: float
period: Optional[float]
timestamp: Int
datetime: Str
class IsolatedBorrowRate(TypedDict):
info: Dict[str, any]
symbol: str
base: str
baseRate: float
quote: str
quoteRate: float
period: Int
timestamp: Int
datetime: Str
class FundingRate(TypedDict):
symbol: Str
timestamp: Int
fundingRate: Num
datetime: Str
markPrice: Num
indexPrice: Num
interestRate: Num
estimatedSettlePrice: Num
fundingTimestamp: Int
fundingDatetime: Str
nextFundingTimestamp: Int
nextFundingDatetime: Str
nextFundingRate: Num
previousFundingTimestamp: Int
previousFundingDatetime: Str
previousFundingRate: Num
info: Dict[str, Any]
interval: Str
class LeverageTier:
tier: Num
symbol: Str
currency: Str
minNotional: Num
maxNotional: Num
maintenanceMarginRate: Num
maxLeverage: Num
info: Dict[str, Any]
class LedgerEntry:
id: Str
info: Any
timestamp: Int
datetime: Str
direction: Str
account: Str
referenceId: Str
referenceAccount: Str
type: Str
currency: Str
amount: Str
before: float
after: float
status: Str
fee: Fee
class DepositAddress:
info: Any
currency: Str
network: Optional[Str]
address: Str
tag: Optional[Str]
class LongShortRatio:
info: Any
symbol: Str
timestamp: Optional[Int]
datetime: Optional[Str]
timeframe: Optional[Str]
longShortRatio: float
class BorrowInterest:
info: Any
symbol: Optional[Str]
currency: Optional[Str]
interest: Optional[Num]
interestRate: Optional[Num]
amountBorrowed: Optional[Num]
marginMode: Optional[Str]
timestamp: Optional[Int]
datetime: Optional[Str]
FundingRates = Dict[Str, FundingRate]
LastPrices = Dict[Str, LastPrice]
Currencies = Dict[Str, CurrencyInterface]
TradingFees = Dict[Str, TradingFeeInterface]
IsolatedBorrowRates = Dict[Str, IsolatedBorrowRate]
CrossBorrowRates = Dict[Str, CrossBorrowRate]
LeverageTiers = Dict[Str, List[LeverageTier]]
Market = Optional[MarketInterface]
Currency = Optional[CurrencyInterface]