ccxt 4.5.0__py2.py3-none-any.whl → 4.5.2__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. ccxt/__init__.py +1 -5
  2. ccxt/ascendex.py +1 -1
  3. ccxt/async_support/__init__.py +1 -5
  4. ccxt/async_support/ascendex.py +1 -1
  5. ccxt/async_support/base/exchange.py +1 -1
  6. ccxt/async_support/binance.py +17 -12
  7. ccxt/async_support/bitget.py +1 -1
  8. ccxt/async_support/coinbase.py +46 -34
  9. ccxt/async_support/gate.py +31 -17
  10. ccxt/async_support/gemini.py +1 -1
  11. ccxt/async_support/hibachi.py +1 -1
  12. ccxt/async_support/hyperliquid.py +13 -2
  13. ccxt/async_support/indodax.py +11 -12
  14. ccxt/async_support/kraken.py +1 -8
  15. ccxt/async_support/krakenfutures.py +25 -25
  16. ccxt/async_support/mexc.py +2 -1
  17. ccxt/async_support/okx.py +2 -2
  18. ccxt/async_support/poloniex.py +1 -1
  19. ccxt/async_support/timex.py +35 -0
  20. ccxt/async_support/tradeogre.py +32 -0
  21. ccxt/async_support/wavesexchange.py +33 -0
  22. ccxt/async_support/zonda.py +12 -0
  23. ccxt/base/exchange.py +7 -1
  24. ccxt/binance.py +17 -12
  25. ccxt/bitget.py +1 -1
  26. ccxt/coinbase.py +46 -34
  27. ccxt/gate.py +31 -17
  28. ccxt/gemini.py +1 -1
  29. ccxt/hibachi.py +1 -1
  30. ccxt/hyperliquid.py +13 -2
  31. ccxt/indodax.py +11 -12
  32. ccxt/kraken.py +1 -8
  33. ccxt/krakenfutures.py +25 -25
  34. ccxt/mexc.py +2 -1
  35. ccxt/okx.py +2 -2
  36. ccxt/poloniex.py +1 -1
  37. ccxt/pro/__init__.py +1 -3
  38. ccxt/pro/bitget.py +328 -75
  39. ccxt/pro/bitmart.py +1 -1
  40. ccxt/pro/bybit.py +8 -10
  41. ccxt/pro/gate.py +8 -1
  42. ccxt/pro/gemini.py +6 -2
  43. ccxt/pro/hyperliquid.py +6 -0
  44. ccxt/pro/kraken.py +4 -6
  45. ccxt/pro/lbank.py +56 -2
  46. ccxt/pro/mexc.py +1 -1
  47. ccxt/test/tests_async.py +2 -25
  48. ccxt/test/tests_sync.py +2 -25
  49. ccxt/timex.py +35 -0
  50. ccxt/tradeogre.py +32 -0
  51. ccxt/wavesexchange.py +33 -0
  52. ccxt/zonda.py +12 -0
  53. {ccxt-4.5.0.dist-info → ccxt-4.5.2.dist-info}/METADATA +111 -113
  54. {ccxt-4.5.0.dist-info → ccxt-4.5.2.dist-info}/RECORD +57 -64
  55. ccxt/abstract/ellipx.py +0 -25
  56. ccxt/abstract/vertex.py +0 -19
  57. ccxt/async_support/ellipx.py +0 -2029
  58. ccxt/async_support/vertex.py +0 -3050
  59. ccxt/ellipx.py +0 -2029
  60. ccxt/pro/vertex.py +0 -948
  61. ccxt/vertex.py +0 -3050
  62. {ccxt-4.5.0.dist-info → ccxt-4.5.2.dist-info}/LICENSE.txt +0 -0
  63. {ccxt-4.5.0.dist-info → ccxt-4.5.2.dist-info}/WHEEL +0 -0
  64. {ccxt-4.5.0.dist-info → ccxt-4.5.2.dist-info}/top_level.txt +0 -0
ccxt/vertex.py DELETED
@@ -1,3050 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
- # https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
-
6
- from ccxt.base.exchange import Exchange
7
- from ccxt.abstract.vertex import ImplicitAPI
8
- from ccxt.base.types import Any, Balances, Currencies, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, FundingRates, Trade, TradingFees, Transaction
9
- from typing import List
10
- from ccxt.base.errors import ExchangeError
11
- from ccxt.base.errors import AuthenticationError
12
- from ccxt.base.errors import PermissionDenied
13
- from ccxt.base.errors import ArgumentsRequired
14
- from ccxt.base.errors import BadRequest
15
- from ccxt.base.errors import InsufficientFunds
16
- from ccxt.base.errors import InvalidOrder
17
- from ccxt.base.errors import NotSupported
18
- from ccxt.base.errors import RateLimitExceeded
19
- from ccxt.base.decimal_to_precision import TICK_SIZE
20
- from ccxt.base.precise import Precise
21
-
22
-
23
- class vertex(Exchange, ImplicitAPI):
24
-
25
- def describe(self) -> Any:
26
- return self.deep_extend(super(vertex, self).describe(), {
27
- 'id': 'vertex',
28
- 'name': 'Vertex',
29
- 'countries': [],
30
- 'version': 'v1',
31
- 'rateLimit': 50,
32
- 'certified': False,
33
- 'pro': True,
34
- 'dex': True,
35
- 'has': {
36
- 'CORS': None,
37
- 'spot': True,
38
- 'margin': False,
39
- 'swap': True,
40
- 'future': True,
41
- 'option': False,
42
- 'addMargin': False,
43
- 'borrowCrossMargin': False,
44
- 'borrowIsolatedMargin': False,
45
- 'cancelAllOrders': True,
46
- 'cancelAllOrdersAfter': False,
47
- 'cancelOrder': True,
48
- 'cancelOrders': True,
49
- 'cancelOrdersForSymbols': False,
50
- 'closeAllPositions': False,
51
- 'closePosition': False,
52
- 'createMarketBuyOrderWithCost': False,
53
- 'createMarketOrderWithCost': False,
54
- 'createMarketSellOrderWithCost': False,
55
- 'createOrder': True,
56
- 'createOrders': True,
57
- 'createReduceOnlyOrder': True,
58
- 'createStopOrder': True,
59
- 'createTriggerOrder': True,
60
- 'editOrder': False,
61
- 'fetchAccounts': False,
62
- 'fetchBalance': True,
63
- 'fetchBorrowInterest': False,
64
- 'fetchBorrowRateHistories': False,
65
- 'fetchBorrowRateHistory': False,
66
- 'fetchCanceledOrders': False,
67
- 'fetchClosedOrders': False,
68
- 'fetchCrossBorrowRate': False,
69
- 'fetchCrossBorrowRates': False,
70
- 'fetchCurrencies': True,
71
- 'fetchDepositAddress': False,
72
- 'fetchDepositAddresses': False,
73
- 'fetchDeposits': False,
74
- 'fetchDepositWithdrawFee': False,
75
- 'fetchDepositWithdrawFees': False,
76
- 'fetchFundingHistory': False,
77
- 'fetchFundingRate': True,
78
- 'fetchFundingRateHistory': False,
79
- 'fetchFundingRates': True,
80
- 'fetchIndexOHLCV': False,
81
- 'fetchIsolatedBorrowRate': False,
82
- 'fetchIsolatedBorrowRates': False,
83
- 'fetchLedger': False,
84
- 'fetchLeverage': False,
85
- 'fetchLeverageTiers': False,
86
- 'fetchLiquidations': False,
87
- 'fetchMarginMode': None,
88
- 'fetchMarketLeverageTiers': False,
89
- 'fetchMarkets': True,
90
- 'fetchMarkOHLCV': False,
91
- 'fetchMyLiquidations': False,
92
- 'fetchMyTrades': True,
93
- 'fetchOHLCV': True,
94
- 'fetchOpenInterest': True,
95
- 'fetchOpenInterestHistory': False,
96
- 'fetchOpenInterests': True,
97
- 'fetchOpenOrders': True,
98
- 'fetchOrder': True,
99
- 'fetchOrderBook': True,
100
- 'fetchOrders': True,
101
- 'fetchOrderTrades': False,
102
- 'fetchPosition': False,
103
- 'fetchPositionMode': False,
104
- 'fetchPositions': True,
105
- 'fetchPositionsRisk': False,
106
- 'fetchPremiumIndexOHLCV': False,
107
- 'fetchStatus': True,
108
- 'fetchTicker': False,
109
- 'fetchTickers': True,
110
- 'fetchTime': True,
111
- 'fetchTrades': True,
112
- 'fetchTradingFee': False,
113
- 'fetchTradingFees': True,
114
- 'fetchTransfer': False,
115
- 'fetchTransfers': False,
116
- 'fetchWithdrawal': False,
117
- 'fetchWithdrawals': False,
118
- 'reduceMargin': False,
119
- 'repayCrossMargin': False,
120
- 'repayIsolatedMargin': False,
121
- 'sandbox': True,
122
- 'setLeverage': False,
123
- 'setMarginMode': False,
124
- 'setPositionMode': False,
125
- 'transfer': False,
126
- 'withdraw': True,
127
- },
128
- 'timeframes': {
129
- '1m': 60,
130
- '5m': 300,
131
- '15m': 900,
132
- '1h': 3600,
133
- '2h': 7200,
134
- '4h': 14400,
135
- '1d': 86400,
136
- '1w': 604800,
137
- '1M': 604800,
138
- },
139
- 'hostname': 'vertexprotocol.com',
140
- 'urls': {
141
- 'logo': 'https://github.com/ccxt/ccxt/assets/43336371/bd04a0fa-3b48-47b6-9d8b-124954d520a8',
142
- 'api': {
143
- 'v1': {
144
- 'archive': 'https://archive.prod.{hostname}/v1',
145
- 'gateway': 'https://gateway.prod.{hostname}/v1',
146
- 'trigger': 'https://trigger.prod.{hostname}/v1',
147
- },
148
- 'v2': {
149
- 'archive': 'https://archive.prod.{hostname}/v2',
150
- 'gateway': 'https://gateway.prod.{hostname}/v2',
151
- },
152
- },
153
- 'test': {
154
- 'v1': {
155
- 'archive': 'https://archive.sepolia-test.{hostname}/v1',
156
- 'gateway': 'https://gateway.sepolia-test.{hostname}/v1',
157
- 'trigger': 'https://trigger.sepolia-test.{hostname}/v1',
158
- },
159
- 'v2': {
160
- 'archive': 'https://archive.sepolia-test.{hostname}/v2',
161
- 'gateway': 'https://gateway.sepolia-test.{hostname}/v2',
162
- },
163
- },
164
- 'www': 'https://vertexprotocol.com/',
165
- 'doc': 'https://docs.vertexprotocol.com/',
166
- 'fees': 'https://docs.vertexprotocol.com/basics/fees',
167
- 'referral': 'https://app.vertexprotocol.com?referrer=0xCfC9BaB96a2eA3d3c3F031c005e82E1D9F295aC1',
168
- },
169
- 'api': {
170
- 'v1': {
171
- 'archive': {
172
- 'post': {
173
- '': 1,
174
- },
175
- },
176
- 'gateway': {
177
- 'get': {
178
- 'query': 1,
179
- 'symbols': 1,
180
- 'time': 1,
181
- },
182
- 'post': {
183
- 'query': 1,
184
- 'execute': 1,
185
- },
186
- },
187
- 'trigger': {
188
- 'post': {
189
- 'execute': 1,
190
- 'query': 1,
191
- },
192
- },
193
- },
194
- 'v2': {
195
- 'archive': {
196
- 'get': {
197
- 'tickers': 1,
198
- 'contracts': 1,
199
- 'trades': 1,
200
- 'vrtx': 1,
201
- },
202
- },
203
- 'gateway': {
204
- 'get': {
205
- 'assets': 0.6667,
206
- 'pairs': 1,
207
- 'orderbook': 1,
208
- },
209
- },
210
- },
211
- },
212
- 'fees': {
213
- 'swap': {
214
- 'taker': self.parse_number('0.0002'),
215
- 'maker': self.parse_number('0.0002'),
216
- },
217
- 'spot': {
218
- 'taker': self.parse_number('0.0002'),
219
- 'maker': self.parse_number('0.0002'),
220
- },
221
- },
222
- 'requiredCredentials': {
223
- 'apiKey': False,
224
- 'secret': False,
225
- 'walletAddress': True,
226
- 'privateKey': True,
227
- },
228
- 'exceptions': {
229
- 'exact': {
230
- '1000': RateLimitExceeded,
231
- '1015': RateLimitExceeded,
232
- '1001': PermissionDenied,
233
- '1002': PermissionDenied,
234
- '1003': PermissionDenied,
235
- '2000': InvalidOrder,
236
- '2001': InvalidOrder,
237
- '2002': InvalidOrder,
238
- '2003': InvalidOrder,
239
- '2004': InvalidOrder,
240
- '2005': InvalidOrder,
241
- '2006': InvalidOrder,
242
- '2007': InvalidOrder,
243
- '2008': InvalidOrder,
244
- '2009': InvalidOrder,
245
- '2010': InvalidOrder,
246
- '2011': BadRequest,
247
- '2012': BadRequest,
248
- '2013': InvalidOrder,
249
- '2014': PermissionDenied,
250
- '2015': InvalidOrder,
251
- '2016': InvalidOrder,
252
- '2017': InvalidOrder,
253
- '2019': InvalidOrder,
254
- '2020': InvalidOrder,
255
- '2021': InvalidOrder,
256
- '2022': InvalidOrder,
257
- '2023': InvalidOrder,
258
- '2024': InsufficientFunds,
259
- '2025': InsufficientFunds,
260
- '2026': BadRequest,
261
- '2027': AuthenticationError,
262
- '2028': AuthenticationError,
263
- '2029': AuthenticationError,
264
- '2030': BadRequest,
265
- '2031': InvalidOrder,
266
- '2033': InvalidOrder,
267
- '2034': InvalidOrder,
268
- '2035': InvalidOrder,
269
- '2036': InvalidOrder,
270
- '2037': InvalidOrder,
271
- '2038': InvalidOrder,
272
- '2039': InvalidOrder,
273
- '2040': InvalidOrder,
274
- '2041': InvalidOrder,
275
- '2042': InvalidOrder,
276
- '2043': InvalidOrder,
277
- '2044': InvalidOrder,
278
- '2045': InvalidOrder,
279
- '2046': InvalidOrder,
280
- '2047': InvalidOrder,
281
- '2048': InvalidOrder,
282
- '2049': ExchangeError,
283
- '2050': PermissionDenied,
284
- '2051': InvalidOrder,
285
- '2052': InvalidOrder,
286
- '2053': InvalidOrder,
287
- '2054': InvalidOrder,
288
- '2055': InvalidOrder,
289
- '2056': InvalidOrder,
290
- '2057': InvalidOrder,
291
- '2058': InvalidOrder,
292
- '2059': InvalidOrder,
293
- '2060': InvalidOrder,
294
- '2061': InvalidOrder,
295
- '2062': InvalidOrder,
296
- '2063': InvalidOrder,
297
- '2064': InvalidOrder,
298
- '2065': InvalidOrder,
299
- '2066': InvalidOrder,
300
- '2067': InvalidOrder,
301
- '2068': InvalidOrder,
302
- '2069': InvalidOrder,
303
- '2070': InvalidOrder,
304
- '2071': InvalidOrder,
305
- '2072': InvalidOrder,
306
- '2073': InvalidOrder,
307
- '2074': InvalidOrder,
308
- '2075': InvalidOrder,
309
- '2076': InvalidOrder,
310
- '3000': BadRequest,
311
- '3001': BadRequest,
312
- '3002': BadRequest,
313
- '3003': BadRequest,
314
- '4000': BadRequest,
315
- '4001': ExchangeError,
316
- '4002': ExchangeError,
317
- '4003': ExchangeError,
318
- '4004': InvalidOrder,
319
- '5000': ExchangeError,
320
- },
321
- 'broad': {
322
- },
323
- },
324
- 'precisionMode': TICK_SIZE,
325
- 'commonCurrencies': {
326
- },
327
- 'options': {
328
- 'defaultType': 'swap',
329
- 'sandboxMode': False,
330
- 'timeDifference': 0, # the difference between system clock and exchange server clock
331
- 'brokerId': 5930043274845996,
332
- },
333
- 'features': {
334
- 'default': {
335
- 'sandbox': True,
336
- 'createOrder': {
337
- 'marginMode': False,
338
- 'triggerPrice': True, # todo
339
- 'triggerDirection': False,
340
- 'triggerPriceType': None,
341
- 'stopLossPrice': True, # todo
342
- 'takeProfitPrice': True, # todo
343
- 'attachedStopLossTakeProfit': None,
344
- 'timeInForce': {
345
- 'IOC': False,
346
- 'FOK': False,
347
- 'PO': True,
348
- 'GTD': True,
349
- },
350
- 'hedged': False,
351
- 'trailing': False,
352
- 'leverage': False,
353
- 'marketBuyByCost': True, # todo
354
- 'marketBuyRequiresPrice': True, # todo fix implementation
355
- 'selfTradePrevention': False,
356
- 'iceberg': False,
357
- },
358
- 'createOrders': None,
359
- 'fetchMyTrades': {
360
- 'marginMode': False,
361
- 'limit': 500,
362
- 'daysBack': 100000, # todo
363
- 'untilDays': None,
364
- 'symbolRequired': False,
365
- },
366
- 'fetchOrder': {
367
- 'marginMode': False,
368
- 'trigger': False,
369
- 'trailing': False,
370
- 'symbolRequired': True,
371
- },
372
- 'fetchOpenOrders': {
373
- 'marginMode': False,
374
- 'limit': 500,
375
- 'trigger': True,
376
- 'trailing': False,
377
- 'symbolRequired': False,
378
- },
379
- 'fetchOrders': None, # todo, only for trigger
380
- 'fetchClosedOrders': None, # todo through fetchOrders
381
- 'fetchOHLCV': {
382
- 'limit': 1000,
383
- },
384
- },
385
- 'spot': {
386
- 'extends': 'default',
387
- },
388
- 'swap': {
389
- 'linear': {
390
- 'extends': 'default',
391
- },
392
- 'inverse': None,
393
- },
394
- 'future': {
395
- 'linear': None,
396
- 'inverse': None,
397
- },
398
- },
399
- })
400
-
401
- def set_sandbox_mode(self, enabled):
402
- super(vertex, self).set_sandbox_mode(enabled)
403
- self.options['sandboxMode'] = enabled
404
-
405
- def convert_to_x18(self, num):
406
- if isinstance(num, str):
407
- return Precise.string_mul(num, '1000000000000000000')
408
- numStr = self.number_to_string(num)
409
- return Precise.string_mul(numStr, '1000000000000000000')
410
-
411
- def convert_from_x18(self, num):
412
- if isinstance(num, str):
413
- return Precise.string_div(num, '1000000000000000000')
414
- numStr = self.number_to_string(num)
415
- return Precise.string_div(numStr, '1000000000000000000')
416
-
417
- def fetch_currencies(self, params={}) -> Currencies:
418
- """
419
- fetches all available currencies on an exchange
420
-
421
- https://docs.vertexprotocol.com/developer-resources/api/v2/assets
422
-
423
- :param dict [params]: extra parameters specific to the exchange API endpoint
424
- :returns dict: an associative dictionary of currencies
425
- """
426
- request = {}
427
- response = self.v2GatewayGetAssets(self.extend(request, params))
428
- #
429
- # [
430
- # {
431
- # "product_id": 2,
432
- # "ticker_id": "BTC-PERP_USDC",
433
- # "market_type": "perp",
434
- # "name": "Bitcoin Perp",
435
- # "symbol": "BTC-PERP",
436
- # "maker_fee": 0.0002,
437
- # "taker_fee": 0,
438
- # "can_withdraw": False,
439
- # "can_deposit": False
440
- # },
441
- # {
442
- # "product_id": 1,
443
- # "ticker_id": "BTC_USDC",
444
- # "market_type": "spot",
445
- # "name": "Bitcoin",
446
- # "symbol": "BTC",
447
- # "taker_fee": 0.0003,
448
- # "maker_fee": 0,
449
- # "can_withdraw": True,
450
- # "can_deposit": True
451
- # }
452
- # ]
453
- #
454
- result = {}
455
- for i in range(0, len(response)):
456
- data = self.safe_dict(response, i, {})
457
- tickerId = self.safe_string(data, 'ticker_id')
458
- if (tickerId is not None) and (tickerId.find('PERP') > 0):
459
- continue
460
- name = self.safe_string(data, 'symbol')
461
- code = self.safe_currency_code(name)
462
- result[code] = self.safe_currency_structure({
463
- 'id': self.safe_string(data, 'product_id'),
464
- 'name': name,
465
- 'code': code,
466
- 'precision': None,
467
- 'info': data,
468
- 'active': None,
469
- 'deposit': self.safe_bool(data, 'can_deposit'),
470
- 'withdraw': self.safe_bool(data, 'can_withdraw'),
471
- 'networks': None,
472
- 'fee': None,
473
- 'limits': {
474
- 'amount': {
475
- 'min': None,
476
- 'max': None,
477
- },
478
- 'withdraw': {
479
- 'min': None,
480
- 'max': None,
481
- },
482
- },
483
- })
484
- return result
485
-
486
- def parse_market(self, market) -> Market:
487
- #
488
- # {
489
- # "type": "spot",
490
- # "product_id": 3,
491
- # "symbol": "WETH",
492
- # "price_increment_x18": "100000000000000000",
493
- # "size_increment": "10000000000000000",
494
- # "min_size": "100000000000000000",
495
- # "min_depth_x18": "5000000000000000000000",
496
- # "max_spread_rate_x18": "2000000000000000",
497
- # "maker_fee_rate_x18": "0",
498
- # "taker_fee_rate_x18": "300000000000000",
499
- # "long_weight_initial_x18": "900000000000000000",
500
- # "long_weight_maintenance_x18": "950000000000000000"
501
- # }
502
- #
503
- marketType = self.safe_string(market, 'type')
504
- quoteId = 'USDC'
505
- quote = self.safe_currency_code(quoteId)
506
- baseId = self.safe_string(market, 'symbol')
507
- base = self.safe_currency_code(baseId)
508
- settleId = quoteId
509
- settle = self.safe_currency_code(settleId)
510
- symbol = base + '/' + quote
511
- spot = marketType == 'spot'
512
- contract = not spot
513
- swap = not spot
514
- if swap:
515
- splitSymbol = base.split('-')
516
- symbol = splitSymbol[0] + '/' + quote + ':' + settle
517
- priceIncrementX18 = self.safe_string(market, 'price_increment_x18')
518
- sizeIncrementX18 = self.safe_string(market, 'size_increment')
519
- minSizeX18 = self.safe_string(market, 'min_size')
520
- takerX18 = self.safe_number(market, 'taker_fee_rate_x18')
521
- makerX18 = self.safe_number(market, 'maker_fee_rate_x18')
522
- isInverse = None if (spot) else False
523
- isLinear = None if (spot) else True
524
- contractSize = None if (spot) else self.parse_number('1')
525
- return {
526
- 'id': self.safe_string(market, 'product_id'),
527
- 'symbol': symbol,
528
- 'base': base,
529
- 'quote': quote,
530
- 'settle': None if (spot) else settle,
531
- 'baseId': baseId,
532
- 'quoteId': quoteId,
533
- 'settleId': None if (spot) else settleId,
534
- 'type': 'spot' if (spot) else 'swap',
535
- 'spot': spot,
536
- 'margin': None,
537
- 'swap': swap,
538
- 'future': False,
539
- 'option': False,
540
- 'active': True,
541
- 'contract': contract,
542
- 'linear': isLinear,
543
- 'inverse': isInverse,
544
- 'taker': self.parse_number(self.convert_from_x18(takerX18)),
545
- 'maker': self.parse_number(self.convert_from_x18(makerX18)),
546
- 'contractSize': contractSize,
547
- 'expiry': None,
548
- 'expiryDatetime': None,
549
- 'strike': None,
550
- 'optionType': None,
551
- 'precision': {
552
- 'amount': self.parse_number(self.convert_from_x18(sizeIncrementX18)),
553
- 'price': self.parse_number(self.convert_from_x18(priceIncrementX18)),
554
- },
555
- 'limits': {
556
- 'leverage': {
557
- 'min': None,
558
- 'max': None,
559
- },
560
- 'amount': {
561
- 'min': self.parse_number(self.convert_from_x18(minSizeX18)),
562
- 'max': None,
563
- },
564
- 'price': {
565
- 'min': None,
566
- 'max': None,
567
- },
568
- 'cost': {
569
- 'min': None,
570
- 'max': None,
571
- },
572
- },
573
- 'created': None,
574
- 'info': market,
575
- }
576
-
577
- def fetch_markets(self, params={}) -> List[Market]:
578
- """
579
- retrieves data on all markets for vertex
580
-
581
- https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/symbols
582
-
583
- :param dict [params]: extra parameters specific to the exchange API endpoint
584
- :returns dict[]: an array of objects representing market data
585
- """
586
- request = {
587
- 'type': 'symbols',
588
- }
589
- response = self.v1GatewayGetQuery(self.extend(request, params))
590
- #
591
- # {
592
- # "status": "success",
593
- # "data": {
594
- # "symbols": {
595
- # "WETH": {
596
- # "type": "spot",
597
- # "product_id": 3,
598
- # "symbol": "WETH",
599
- # "price_increment_x18": "100000000000000000",
600
- # "size_increment": "10000000000000000",
601
- # "min_size": "100000000000000000",
602
- # "min_depth_x18": "5000000000000000000000",
603
- # "max_spread_rate_x18": "2000000000000000",
604
- # "maker_fee_rate_x18": "0",
605
- # "taker_fee_rate_x18": "300000000000000",
606
- # "long_weight_initial_x18": "900000000000000000",
607
- # "long_weight_maintenance_x18": "950000000000000000"
608
- # }
609
- # }
610
- # },
611
- # "request_type": "query_symbols"
612
- # }
613
- #
614
- data = self.safe_dict(response, 'data', {})
615
- markets = self.safe_dict(data, 'symbols', {})
616
- symbols = list(markets.keys())
617
- result = []
618
- for i in range(0, len(symbols)):
619
- symbol = symbols[i]
620
- rawMarket = self.safe_dict(markets, symbol, {})
621
- result.append(self.parse_market(rawMarket))
622
- return result
623
-
624
- def fetch_time(self, params={}) -> Int:
625
- """
626
- fetches the current integer timestamp in milliseconds from the exchange server
627
- :param dict [params]: extra parameters specific to the exchange API endpoint
628
- :returns int: the current integer timestamp in milliseconds from the exchange server
629
- """
630
- response = self.v1GatewayGetTime(params)
631
- # 1717481623452
632
- return self.parse_to_int(response)
633
-
634
- def fetch_status(self, params={}):
635
- """
636
- the latest known information on the availability of the exchange API
637
-
638
- https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/status
639
-
640
- :param dict [params]: extra parameters specific to the exchange API endpoint
641
- :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
642
- """
643
- request = {
644
- 'type': 'status',
645
- }
646
- response = self.v1GatewayGetQuery(self.extend(request, params))
647
- #
648
- # {
649
- # "status": "success",
650
- # "data": "active",
651
- # "request_type": "query_status",
652
- # }
653
- #
654
- status = self.safe_string(response, 'data')
655
- if status == 'active':
656
- status = 'ok'
657
- else:
658
- status = 'error'
659
- return {
660
- 'status': status,
661
- 'updated': None,
662
- 'eta': None,
663
- 'url': None,
664
- 'info': response,
665
- }
666
-
667
- def parse_trade(self, trade, market: Market = None) -> Trade:
668
- #
669
- # {
670
- # "ticker_id": "ARB_USDC",
671
- # "trade_id": 999994,
672
- # "price": 1.1366122408151016,
673
- # "base_filled": 175,
674
- # "quote_filled": -198.90714214264278,
675
- # "timestamp": 1691068943,
676
- # "trade_type": "buy"
677
- # }
678
- # fetchMytrades
679
- # {
680
- # "digest": "0x80ce789702b670b7d33f2aa67e12c85f124395c3f9acdb422dde3b4973ccd50c",
681
- # "order": {
682
- # "sender": "0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000",
683
- # "priceX18": "27544000000000000000000",
684
- # "amount": "2000000000000000000",
685
- # "expiration": "4611686020107119633",
686
- # "nonce": "1761322608857448448"
687
- # },
688
- # "base_filled": "736000000000000000",
689
- # "quote_filled": "-20276464287857571514302",
690
- # "fee": "4055287857571514302",
691
- # "sequencer_fee": "0"
692
- # "cumulative_fee": "4055287857571514302",
693
- # "cumulative_base_filled": "736000000000000000",
694
- # "cumulative_quote_filled": "-20276464287857571514302",
695
- # "submission_idx": "563012",
696
- # "pre_balance": {
697
- # "base": {
698
- # "perp": {
699
- # "product_id": 2,
700
- # "lp_balance": {
701
- # "amount": "0",
702
- # "last_cumulative_funding_x18": "1823351297710837"
703
- # },
704
- # "balance": {
705
- # "amount": "2686684000000000000000",
706
- # "v_quote_balance": "-76348662407149297671587247",
707
- # "last_cumulative_funding_x18": "134999841911604906604576"
708
- # }
709
- # }
710
- # },
711
- # "quote": null
712
- # },
713
- # "post_balance": {
714
- # "base": {
715
- # "perp": {
716
- # "product_id": 2,
717
- # "lp_balance": {
718
- # "amount": "0",
719
- # "last_cumulative_funding_x18": "1823351297710837"
720
- # },
721
- # "balance": {
722
- # "amount": "2686013000000000000000",
723
- # "v_quote_balance": "-76328351274188497671587247",
724
- # "last_cumulative_funding_x18": "134999841911604906604576"
725
- # }
726
- # }
727
- # },
728
- # "quote": null
729
- # }
730
- # }
731
- price = None
732
- amount = None
733
- side = None
734
- fee = None
735
- feeCost = self.convert_from_x18(self.safe_string(trade, 'fee'))
736
- if feeCost is not None:
737
- fee = {
738
- 'cost': feeCost,
739
- 'currency': None,
740
- }
741
- id = self.safe_string_2(trade, 'trade_id', 'submission_idx')
742
- order = self.safe_string(trade, 'digest')
743
- timestamp = self.safe_timestamp(trade, 'timestamp')
744
- if timestamp is None:
745
- # fetchMyTrades
746
- baseBalance = self.safe_dict(self.safe_dict(trade, 'pre_balance', {}), 'base', {})
747
- marketId = None
748
- if 'perp' in baseBalance:
749
- marketId = self.safe_string(self.safe_dict(baseBalance, 'perp', {}), 'product_id')
750
- else:
751
- marketId = self.safe_string(self.safe_dict(baseBalance, 'spot', {}), 'product_id')
752
- market = self.safe_market(marketId)
753
- subOrder = self.safe_dict(trade, 'order', {})
754
- price = self.convert_from_x18(self.safe_string(subOrder, 'priceX18'))
755
- amount = self.convert_from_x18(self.safe_string(trade, 'base_filled'))
756
- if Precise.string_lt(amount, '0'):
757
- side = 'sell'
758
- else:
759
- side = 'buy'
760
- else:
761
- tickerId = self.safe_string(trade, 'ticker_id')
762
- splitTickerId = tickerId.split('_')
763
- splitSymbol = splitTickerId[0].split('-')
764
- marketId = splitSymbol[0] + splitTickerId[1]
765
- market = self.safe_market(marketId, market)
766
- price = self.safe_string(trade, 'price')
767
- amount = self.safe_string(trade, 'base_filled')
768
- side = self.safe_string_lower(trade, 'trade_type')
769
- amount = Precise.string_abs(amount)
770
- symbol = market['symbol']
771
- return self.safe_trade({
772
- 'id': id,
773
- 'timestamp': timestamp,
774
- 'datetime': self.iso8601(timestamp),
775
- 'symbol': symbol,
776
- 'side': side,
777
- 'price': price,
778
- 'amount': amount,
779
- 'cost': None,
780
- 'order': order,
781
- 'takerOrMaker': None,
782
- 'type': None,
783
- 'fee': fee,
784
- 'info': trade,
785
- }, market)
786
-
787
- def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
788
- """
789
- get the list of most recent trades for a particular symbol
790
-
791
- https://docs.vertexprotocol.com/developer-resources/api/v2/trades
792
-
793
- :param str symbol: unified symbol of the market to fetch trades for
794
- :param int [since]: timestamp in ms of the earliest trade to fetch
795
- :param int [limit]: the maximum amount of trades to fetch
796
- :param dict [params]: extra parameters specific to the exchange API endpoint
797
- :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
798
- """
799
- self.load_markets()
800
- market = self.market(symbol)
801
- marketId = market['baseId'] + '_USDC'
802
- request = {
803
- 'ticker_id': marketId,
804
- }
805
- if limit is not None:
806
- request['limit'] = limit
807
- response = self.v2ArchiveGetTrades(self.extend(request, params))
808
- #
809
- # [
810
- # {
811
- # "ticker_id": "ARB_USDC",
812
- # "trade_id": 999994,
813
- # "price": 1.1366122408151016,
814
- # "base_filled": 175,
815
- # "quote_filled": -198.90714214264278,
816
- # "timestamp": 1691068943,
817
- # "trade_type": "buy"
818
- # },
819
- # {
820
- # "ticker_id": "ARB_USDC",
821
- # "trade_id": 999978,
822
- # "price": 1.136512210806099,
823
- # "base_filled": 175,
824
- # "quote_filled": -198.8896368910673,
825
- # "timestamp": 1691068882,
826
- # "trade_type": "buy"
827
- # }
828
- # ]
829
- #
830
- return self.parse_trades(response, market, since, limit)
831
-
832
- def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
833
- """
834
- fetch all trades made by the user
835
-
836
- https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/matches
837
-
838
- :param str symbol: unified market symbol
839
- :param int [since]: the earliest time in ms to fetch trades for
840
- :param int [limit]: the maximum number of trades structures to retrieve
841
- :param dict [params]: extra parameters specific to the exchange API endpoint
842
- :param str [params.user]: user address, will default to self.walletAddress if not provided
843
- :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
844
- """
845
- self.load_markets()
846
- userAddress = None
847
- userAddress, params = self.handle_public_address('fetchMyTrades', params)
848
- market: Market = None
849
- matchesRequest = {
850
- 'subaccount': self.convert_address_to_sender(userAddress),
851
- }
852
- if symbol is not None:
853
- market = self.market(symbol)
854
- matchesRequest['product_ids'] = [self.parse_to_numeric(market['id'])]
855
- until = self.safe_integer(params, 'until')
856
- if until is not None:
857
- params = self.omit(params, 'until')
858
- matchesRequest['max_time'] = until
859
- if limit is not None:
860
- matchesRequest['limit'] = limit
861
- request = {
862
- 'matches': matchesRequest,
863
- }
864
- response = self.v1ArchivePost(self.extend(request, params))
865
- #
866
- # {
867
- # "matches": [
868
- # {
869
- # "digest": "0x80ce789702b670b7d33f2aa67e12c85f124395c3f9acdb422dde3b4973ccd50c",
870
- # "order": {
871
- # "sender": "0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000",
872
- # "priceX18": "27544000000000000000000",
873
- # "amount": "2000000000000000000",
874
- # "expiration": "4611686020107119633",
875
- # "nonce": "1761322608857448448"
876
- # },
877
- # "base_filled": "736000000000000000",
878
- # "quote_filled": "-20276464287857571514302",
879
- # "fee": "4055287857571514302",
880
- # "sequencer_fee": "0"
881
- # "cumulative_fee": "4055287857571514302",
882
- # "cumulative_base_filled": "736000000000000000",
883
- # "cumulative_quote_filled": "-20276464287857571514302",
884
- # "submission_idx": "563012",
885
- # "pre_balance": {
886
- # "base": {
887
- # "perp": {
888
- # "product_id": 2,
889
- # "lp_balance": {
890
- # "amount": "0",
891
- # "last_cumulative_funding_x18": "1823351297710837"
892
- # },
893
- # "balance": {
894
- # "amount": "2686684000000000000000",
895
- # "v_quote_balance": "-76348662407149297671587247",
896
- # "last_cumulative_funding_x18": "134999841911604906604576"
897
- # }
898
- # }
899
- # },
900
- # "quote": null
901
- # },
902
- # "post_balance": {
903
- # "base": {
904
- # "perp": {
905
- # "product_id": 2,
906
- # "lp_balance": {
907
- # "amount": "0",
908
- # "last_cumulative_funding_x18": "1823351297710837"
909
- # },
910
- # "balance": {
911
- # "amount": "2686013000000000000000",
912
- # "v_quote_balance": "-76328351274188497671587247",
913
- # "last_cumulative_funding_x18": "134999841911604906604576"
914
- # }
915
- # }
916
- # },
917
- # "quote": null
918
- # }
919
- # },
920
- # {
921
- # "digest": "0x0f6e5a0434e36d8e6d4fed950d3624b0d8c91a8a84efd156bb25c1382561c0c2",
922
- # "order": {
923
- # "sender": "0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000",
924
- # "priceX18": "27540000000000000000000",
925
- # "amount": "2000000000000000000",
926
- # "expiration": "4611686020107119623",
927
- # "nonce": "1761322602510417920"
928
- # },
929
- # "base_filled": "723999999999999999",
930
- # "quote_filled": "-19944943483044913474043",
931
- # "fee": "5983483044913474042",
932
- # "cumulative_fee": "11958484645393618085",
933
- # "cumulative_base_filled": "1446999999999999998",
934
- # "cumulative_quote_filled": "-39861640484645393618087",
935
- # "submission_idx": "563011",
936
- # "pre_balance": {
937
- # "base": {
938
- # "perp": {
939
- # "product_id": 2,
940
- # "lp_balance": {
941
- # "amount": "0",
942
- # "last_cumulative_funding_x18": "1823351297710837"
943
- # },
944
- # "balance": {
945
- # "amount": "2686684000000000000000",
946
- # "v_quote_balance": "-76348662407149297671587247",
947
- # "last_cumulative_funding_x18": "134999841911604906604576"
948
- # }
949
- # }
950
- # },
951
- # "quote": null
952
- # },
953
- # "post_balance": {
954
- # "base": {
955
- # "perp": {
956
- # "product_id": 2,
957
- # "lp_balance": {
958
- # "amount": "0",
959
- # "last_cumulative_funding_x18": "1823351297710837"
960
- # },
961
- # "balance": {
962
- # "amount": "2686013000000000000000",
963
- # "v_quote_balance": "-76328351274188497671587247",
964
- # "last_cumulative_funding_x18": "134999841911604906604576"
965
- # }
966
- # }
967
- # },
968
- # "quote": null
969
- # }
970
- # }
971
- # ],
972
- # "txs": [
973
- # {
974
- # "tx": {
975
- # "match_orders": {
976
- # "product_id": 2,
977
- # "amm": True,
978
- # "taker": {
979
- # "order": {
980
- # "sender": "0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000",
981
- # "price_x18": "27544000000000000000000",
982
- # "amount": "2000000000000000000",
983
- # "expiration": 4611686020107120000,
984
- # "nonce": 1761322608857448400
985
- # },
986
- # "signature": "0xe8fa7151bde348afa3b46dc52798046b7c8318f1b0a7f689710debbc094658cc1bf5a7e478ccc8278b625da0b9402c86b580d2e31e13831337dfd6153f4b37811b"
987
- # },
988
- # "maker": {
989
- # "order": {
990
- # "sender": "0xebdbbcdbd2646c5f23a1e0806027eee5f71b074664656661756c740000000000",
991
- # "price_x18": "27544000000000000000000",
992
- # "amount": "-736000000000000000",
993
- # "expiration": 1679731669,
994
- # "nonce": 1761322585591644200
995
- # },
996
- # "signature": "0x47f9d47f0777f3ca0b13f07b7682dbeea098c0e377b87dcb025754fe34c900e336b8c7744e021fb9c46a4f8c6a1478bafa28bf0d023ae496aa3efa4d8e81df181c"
997
- # }
998
- # }
999
- # },
1000
- # "submission_idx": "563012",
1001
- # "timestamp": "1679728133"
1002
- # },
1003
- # {
1004
- # "tx": {
1005
- # "match_orders": {
1006
- # "product_id": 1,
1007
- # "amm": True,
1008
- # "taker": {
1009
- # "order": {
1010
- # "sender": "0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000",
1011
- # "price_x18": "27540000000000000000000",
1012
- # "amount": "2000000000000000000",
1013
- # "expiration": 4611686020107120000,
1014
- # "nonce": 1761322602510418000
1015
- # },
1016
- # "signature": "0x826c68f1a3f76d9ffbe8041f8d45e969d31f1ab6f2ae2f6379d1493e479e56436091d6cf4c72e212dd2f1d2fa17c627c4c21bd6d281c77172b8af030488478b71c"
1017
- # },
1018
- # "maker": {
1019
- # "order": {
1020
- # "sender": "0xf8d240d9514c9a4715d66268d7af3b53d619642564656661756c740000000000",
1021
- # "price_x18": "27540000000000000000000",
1022
- # "amount": "-724000000000000000",
1023
- # "expiration": 1679731656,
1024
- # "nonce": 1761322565506171000
1025
- # },
1026
- # "signature": "0xd8b6505b8d9b8c3cbfe793080976388035682c02a27893fb26b48a5b2bfe943f4162dea3a42e24e0dff5e2f74fbf77e33d83619140a2a581117c55e6cc236bdb1c"
1027
- # }
1028
- # }
1029
- # },
1030
- # "submission_idx": "563011",
1031
- # "timestamp": "1679728127"
1032
- # }
1033
- # ]
1034
- # }
1035
- #
1036
- trades = self.safe_list(response, 'matches', [])
1037
- return self.parse_trades(trades, market, since, limit, params)
1038
-
1039
- def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
1040
- """
1041
- fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
1042
-
1043
- https://docs.vertexprotocol.com/developer-resources/api/v2/orderbook
1044
-
1045
- :param str symbol: unified symbol of the market to fetch the order book for
1046
- :param int [limit]: the maximum amount of order book entries to return
1047
- :param dict [params]: extra parameters specific to the exchange API endpoint
1048
- :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
1049
- """
1050
- self.load_markets()
1051
- market = self.market(symbol)
1052
- marketId = market['baseId'] + '_USDC'
1053
- if limit is None:
1054
- limit = 100
1055
- request = {
1056
- 'ticker_id': marketId,
1057
- 'depth': limit,
1058
- }
1059
- response = self.v2GatewayGetOrderbook(self.extend(request, params))
1060
- #
1061
- # {
1062
- # "ticker_id": "ETH-PERP_USDC",
1063
- # "bids": [
1064
- # [
1065
- # 1612.3,
1066
- # 0.31
1067
- # ],
1068
- # [
1069
- # 1612.0,
1070
- # 0.93
1071
- # ],
1072
- # [
1073
- # 1611.5,
1074
- # 1.55
1075
- # ],
1076
- # [
1077
- # 1610.8,
1078
- # 2.17
1079
- # ]
1080
- # ],
1081
- # "asks": [
1082
- # [
1083
- # 1612.9,
1084
- # 0.93
1085
- # ],
1086
- # [
1087
- # 1613.4,
1088
- # 1.55
1089
- # ],
1090
- # [
1091
- # 1614.1,
1092
- # 2.17
1093
- # ]
1094
- # ],
1095
- # "timestamp": 1694375362016
1096
- # }
1097
- #
1098
- timestamp = self.safe_integer(response, 'timestamp')
1099
- return self.parse_order_book(response, symbol, timestamp, 'bids', 'asks')
1100
-
1101
- def fetch_trading_fees(self, params={}) -> TradingFees:
1102
- """
1103
- fetch the trading fees for multiple markets
1104
-
1105
- https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/fee-rates
1106
-
1107
- :param dict [params]: extra parameters specific to the exchange API endpoint
1108
- :param str [params.user]: user address, will default to self.walletAddress if not provided
1109
- :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
1110
- """
1111
- self.load_markets()
1112
- userAddress = None
1113
- userAddress, params = self.handle_public_address('fetchTradingFees', params)
1114
- request = {
1115
- 'type': 'fee_rates',
1116
- 'sender': self.convert_address_to_sender(userAddress),
1117
- }
1118
- response = self.v1GatewayGetQuery(self.extend(request, params))
1119
- #
1120
- # {
1121
- # "status": "success",
1122
- # "data": {
1123
- # "taker_fee_rates_x18": [
1124
- # "0",
1125
- # "300000000000000",
1126
- # "200000000000000",
1127
- # "300000000000000",
1128
- # "200000000000000"
1129
- # ],
1130
- # "maker_fee_rates_x18": [
1131
- # "0",
1132
- # "0",
1133
- # "0",
1134
- # "0",
1135
- # "0"
1136
- # ],
1137
- # "liquidation_sequencer_fee": "250000000000000000",
1138
- # "health_check_sequencer_fee": "100000000000000000",
1139
- # "taker_sequencer_fee": "25000000000000000",
1140
- # "withdraw_sequencer_fees": [
1141
- # "10000000000000000",
1142
- # "40000000000000",
1143
- # "0",
1144
- # "600000000000000",
1145
- # "0"
1146
- # ]
1147
- # },
1148
- # "request_type": "query_fee_rates",
1149
- # }
1150
- #
1151
- data = self.safe_dict(response, 'data', {})
1152
- maker = self.safe_list(data, 'maker_fee_rates_x18', [])
1153
- taker = self.safe_list(data, 'taker_fee_rates_x18', [])
1154
- result = {}
1155
- for i in range(0, len(taker)):
1156
- market = self.safe_market(self.number_to_string(i))
1157
- if market['id'] is None:
1158
- continue
1159
- symbol = market['symbol']
1160
- result[symbol] = {
1161
- 'info': response,
1162
- 'symbol': symbol,
1163
- 'maker': self.parse_number(self.convert_from_x18(maker[i])),
1164
- 'taker': self.parse_number(self.convert_from_x18(taker[i])),
1165
- 'percentage': True,
1166
- 'tierBased': False,
1167
- }
1168
- return result
1169
-
1170
- def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
1171
- # example response in fetchOHLCV
1172
- return [
1173
- self.safe_timestamp(ohlcv, 'timestamp'),
1174
- self.parse_number(self.convert_from_x18(self.safe_string(ohlcv, 'open_x18'))),
1175
- self.parse_number(self.convert_from_x18(self.safe_string(ohlcv, 'high_x18'))),
1176
- self.parse_number(self.convert_from_x18(self.safe_string(ohlcv, 'low_x18'))),
1177
- self.parse_number(self.convert_from_x18(self.safe_string(ohlcv, 'close_x18'))),
1178
- self.parse_number(self.convert_from_x18(self.safe_string(ohlcv, 'volume'))),
1179
- ]
1180
-
1181
- def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
1182
- """
1183
-
1184
- https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/candlesticks
1185
-
1186
- fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1187
- :param str symbol: unified symbol of the market to fetch OHLCV data for
1188
- :param str timeframe: the length of time each candle represents
1189
- :param int [since]: timestamp in ms of the earliest candle to fetch
1190
- :param int [limit]: max=1000, max=100 when since is defined and is less than(now - (999 * (timeframe in ms)))
1191
- :param dict [params]: extra parameters specific to the exchange API endpoint
1192
- :returns int[][]: A list of candles ordered, open, high, low, close, volume
1193
- """
1194
- self.load_markets()
1195
- market = self.market(symbol)
1196
- ohlcvRequest = {
1197
- 'product_id': self.parse_to_int(market['id']),
1198
- 'granularity': self.safe_integer(self.timeframes, timeframe),
1199
- }
1200
- until = self.safe_integer(params, 'until')
1201
- if until is not None:
1202
- params = self.omit(params, 'until')
1203
- ohlcvRequest['max_time'] = until
1204
- if limit is not None:
1205
- ohlcvRequest['limit'] = min(limit, 1000)
1206
- request = {
1207
- 'candlesticks': ohlcvRequest,
1208
- }
1209
- response = self.v1ArchivePost(self.extend(request, params))
1210
- #
1211
- # {
1212
- # "candlesticks": [
1213
- # {
1214
- # "product_id": 1,
1215
- # "granularity": 60,
1216
- # "submission_idx": "627709",
1217
- # "timestamp": "1680118140",
1218
- # "open_x18": "27235000000000000000000",
1219
- # "high_x18": "27298000000000000000000",
1220
- # "low_x18": "27235000000000000000000",
1221
- # "close_x18": "27298000000000000000000",
1222
- # "volume": "1999999999999999998"
1223
- # },
1224
- # {
1225
- # "product_id": 1,
1226
- # "granularity": 60,
1227
- # "submission_idx": "627699",
1228
- # "timestamp": "1680118080",
1229
- # "open_x18": "27218000000000000000000",
1230
- # "high_x18": "27245000000000000000000",
1231
- # "low_x18": "27218000000000000000000",
1232
- # "close_x18": "27245000000000000000000",
1233
- # "volume": "11852999999999999995"
1234
- # }
1235
- # ]
1236
- # }
1237
- #
1238
- rows = self.safe_list(response, 'candlesticks', [])
1239
- return self.parse_ohlcvs(rows, market, timeframe, since, limit)
1240
-
1241
- def parse_funding_rate(self, ticker, market: Market = None) -> FundingRate:
1242
- #
1243
- # {
1244
- # "product_id": 4,
1245
- # "funding_rate_x18": "2447900598160952",
1246
- # "update_time": "1680116326"
1247
- # }
1248
- #
1249
- # {
1250
- # "ETH-PERP_USDC": {
1251
- # "ticker_id": "ETH-PERP_USDC",
1252
- # "base_currency": "ETH-PERP",
1253
- # "quote_currency": "USDC",
1254
- # "last_price": 1620.3,
1255
- # "base_volume": 1309.2,
1256
- # "quote_volume": 2117828.093867611,
1257
- # "product_type": "perpetual",
1258
- # "contract_price": 1620.372642114429,
1259
- # "contract_price_currency": "USD",
1260
- # "open_interest": 1635.2,
1261
- # "open_interest_usd": 2649633.3443855145,
1262
- # "index_price": 1623.293496279935,
1263
- # "mark_price": 1623.398589416731,
1264
- # "funding_rate": 0.000068613217104332,
1265
- # "next_funding_rate_timestamp": 1694379600,
1266
- # "price_change_percent_24h": -0.6348599635253989
1267
- # }
1268
- # }
1269
- #
1270
- fundingRate = self.safe_number(ticker, 'funding_rate')
1271
- if fundingRate is None:
1272
- fundingRateX18 = self.safe_string(ticker, 'funding_rate_x18')
1273
- fundingRate = self.parse_number(self.convert_from_x18(fundingRateX18))
1274
- fundingTimestamp = self.safe_timestamp_2(ticker, 'update_time', 'next_funding_rate_timestamp')
1275
- markPrice = self.safe_number(ticker, 'mark_price')
1276
- indexPrice = self.safe_number(ticker, 'index_price')
1277
- return {
1278
- 'info': ticker,
1279
- 'symbol': market['symbol'],
1280
- 'markPrice': markPrice,
1281
- 'indexPrice': indexPrice,
1282
- 'interestRate': None,
1283
- 'estimatedSettlePrice': None,
1284
- 'timestamp': None,
1285
- 'datetime': None,
1286
- 'fundingRate': fundingRate,
1287
- 'fundingTimestamp': fundingTimestamp,
1288
- 'fundingDatetime': self.iso8601(fundingTimestamp),
1289
- 'nextFundingRate': None,
1290
- 'nextFundingTimestamp': None,
1291
- 'nextFundingDatetime': None,
1292
- 'previousFundingRate': None,
1293
- 'previousFundingTimestamp': None,
1294
- 'previousFundingDatetime': None,
1295
- 'interval': None,
1296
- }
1297
-
1298
- def fetch_funding_rate(self, symbol: str, params={}) -> FundingRate:
1299
- """
1300
- fetch the current funding rate
1301
-
1302
- https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/funding-rate
1303
-
1304
- :param str symbol: unified market symbol
1305
- :param dict [params]: extra parameters specific to the exchange API endpoint
1306
- :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
1307
- """
1308
- self.load_markets()
1309
- market = self.market(symbol)
1310
- request = {
1311
- 'funding_rate': {
1312
- 'product_id': self.parse_to_int(market['id']),
1313
- },
1314
- }
1315
- response = self.v1ArchivePost(self.extend(request, params))
1316
- #
1317
- # {
1318
- # "product_id": 4,
1319
- # "funding_rate_x18": "2447900598160952",
1320
- # "update_time": "1680116326"
1321
- # }
1322
- #
1323
- return self.parse_funding_rate(response, market)
1324
-
1325
- def fetch_funding_rates(self, symbols: Strings = None, params={}) -> FundingRates:
1326
- """
1327
- fetches funding rates for multiple markets
1328
-
1329
- https://docs.vertexprotocol.com/developer-resources/api/v2/contracts
1330
-
1331
- :param str[] symbols: unified symbols of the markets to fetch the funding rates for, all market funding rates are returned if not assigned
1332
- :param dict [params]: extra parameters specific to the exchange API endpoint
1333
- :returns dict[]: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
1334
- """
1335
- self.load_markets()
1336
- request = {}
1337
- if symbols is not None:
1338
- symbols = self.market_symbols(symbols)
1339
- response = self.v2ArchiveGetContracts(self.extend(request, params))
1340
- #
1341
- # {
1342
- # "ETH-PERP_USDC": {
1343
- # "ticker_id": "ETH-PERP_USDC",
1344
- # "base_currency": "ETH-PERP",
1345
- # "quote_currency": "USDC",
1346
- # "last_price": 1620.3,
1347
- # "base_volume": 1309.2,
1348
- # "quote_volume": 2117828.093867611,
1349
- # "product_type": "perpetual",
1350
- # "contract_price": 1620.372642114429,
1351
- # "contract_price_currency": "USD",
1352
- # "open_interest": 1635.2,
1353
- # "open_interest_usd": 2649633.3443855145,
1354
- # "index_price": 1623.293496279935,
1355
- # "mark_price": 1623.398589416731,
1356
- # "funding_rate": 0.000068613217104332,
1357
- # "next_funding_rate_timestamp": 1694379600,
1358
- # "price_change_percent_24h": -0.6348599635253989
1359
- # }
1360
- # }
1361
- #
1362
- keys = list(response.keys())
1363
- fundingRates = {}
1364
- for i in range(0, len(keys)):
1365
- tickerId = keys[i]
1366
- parsedTickerId = tickerId.split('-')
1367
- data = response[tickerId]
1368
- marketId = parsedTickerId[0] + '/USDC:USDC'
1369
- market = self.market(marketId)
1370
- ticker = self.parse_funding_rate(data, market)
1371
- symbol = ticker['symbol']
1372
- fundingRates[symbol] = ticker
1373
- return self.filter_by_array(fundingRates, 'symbol', symbols)
1374
-
1375
- def parse_open_interest(self, interest, market: Market = None):
1376
- #
1377
- # {
1378
- # "ETH-PERP_USDC": {
1379
- # "ticker_id": "ETH-PERP_USDC",
1380
- # "base_currency": "ETH-PERP",
1381
- # "quote_currency": "USDC",
1382
- # "last_price": 1620.3,
1383
- # "base_volume": 1309.2,
1384
- # "quote_volume": 2117828.093867611,
1385
- # "product_type": "perpetual",
1386
- # "contract_price": 1620.372642114429,
1387
- # "contract_price_currency": "USD",
1388
- # "open_interest": 1635.2,
1389
- # "open_interest_usd": 2649633.3443855145,
1390
- # "index_price": 1623.293496279935,
1391
- # "mark_price": 1623.398589416731,
1392
- # "funding_rate": 0.000068613217104332,
1393
- # "next_funding_rate_timestamp": 1694379600,
1394
- # "price_change_percent_24h": -0.6348599635253989
1395
- # }
1396
- # }
1397
- #
1398
- marketId = self.safe_string(interest, 'ticker_id')
1399
- return self.safe_open_interest({
1400
- 'symbol': self.safe_symbol(marketId, market),
1401
- 'openInterestAmount': self.safe_number(interest, 'open_interest'),
1402
- 'openInterestValue': self.safe_number(interest, 'open_interest_usd'),
1403
- 'timestamp': None,
1404
- 'datetime': None,
1405
- 'info': interest,
1406
- }, market)
1407
-
1408
- def fetch_open_interests(self, symbols: Strings = None, params={}):
1409
- """
1410
- Retrieves the open interest for a list of symbols
1411
-
1412
- https://docs.vertexprotocol.com/developer-resources/api/v2/contracts
1413
-
1414
- :param str[] [symbols]: a list of unified CCXT market symbols
1415
- :param dict [params]: exchange specific parameters
1416
- :returns dict[]: a list of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
1417
- """
1418
- self.load_markets()
1419
- symbols = self.market_symbols(symbols)
1420
- response = self.v2ArchiveGetContracts(params)
1421
- #
1422
- # {
1423
- # "ADA-PERP_USDC": {
1424
- # "ticker_id": "ADA-PERP_USDC",
1425
- # "base_currency": "ADA-PERP",
1426
- # "quote_currency": "USDC",
1427
- # "last_price": 0.85506,
1428
- # "base_volume": 1241320.0,
1429
- # "quote_volume": 1122670.9080057142,
1430
- # "product_type": "perpetual",
1431
- # "contract_price": 0.8558601432685385,
1432
- # "contract_price_currency": "USD",
1433
- # "open_interest": 104040.0,
1434
- # "open_interest_usd": 89043.68930565874,
1435
- # "index_price": 0.8561952606869176,
1436
- # "mark_price": 0.856293781088936,
1437
- # "funding_rate": 0.000116153806226841,
1438
- # "next_funding_rate_timestamp": 1734685200,
1439
- # "price_change_percent_24h": -12.274325340321374
1440
- # },
1441
- # }
1442
- #
1443
- parsedSymbols = []
1444
- results = []
1445
- markets = list(response.keys())
1446
- if symbols is None:
1447
- symbols = []
1448
- for y in range(0, len(markets)):
1449
- tickerId = markets[y]
1450
- parsedTickerId = tickerId.split('-')
1451
- currentSymbol = parsedTickerId[0] + '/USDC:USDC'
1452
- if not self.in_array(currentSymbol, symbols):
1453
- symbols.append(currentSymbol)
1454
- for i in range(0, len(markets)):
1455
- marketId = markets[i]
1456
- marketInner = self.safe_market(marketId)
1457
- openInterest = self.safe_dict(response, marketId, {})
1458
- for j in range(0, len(symbols)):
1459
- market = self.market(symbols[j])
1460
- tickerId = market['base'] + '_USDC'
1461
- if marketInner['marketId'] == tickerId:
1462
- parsedSymbols.append(market['symbol'])
1463
- results.append(self.parse_open_interest(openInterest, market))
1464
- return self.filter_by_array(results, 'symbol', parsedSymbols)
1465
-
1466
- def fetch_open_interest(self, symbol: str, params={}):
1467
- """
1468
- Retrieves the open interest of a derivative trading pair
1469
-
1470
- https://docs.vertexprotocol.com/developer-resources/api/v2/contracts
1471
-
1472
- :param str symbol: Unified CCXT market symbol
1473
- :param dict [params]: exchange specific parameters
1474
- :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
1475
- """
1476
- self.load_markets()
1477
- market = self.market(symbol)
1478
- if not market['contract']:
1479
- raise BadRequest(self.id + ' fetchOpenInterest() supports contract markets only')
1480
- request = {}
1481
- response = self.v2ArchiveGetContracts(self.extend(request, params))
1482
- #
1483
- # {
1484
- # "ETH-PERP_USDC": {
1485
- # "ticker_id": "ETH-PERP_USDC",
1486
- # "base_currency": "ETH-PERP",
1487
- # "quote_currency": "USDC",
1488
- # "last_price": 1620.3,
1489
- # "base_volume": 1309.2,
1490
- # "quote_volume": 2117828.093867611,
1491
- # "product_type": "perpetual",
1492
- # "contract_price": 1620.372642114429,
1493
- # "contract_price_currency": "USD",
1494
- # "open_interest": 1635.2,
1495
- # "open_interest_usd": 2649633.3443855145,
1496
- # "index_price": 1623.293496279935,
1497
- # "mark_price": 1623.398589416731,
1498
- # "funding_rate": 0.000068613217104332,
1499
- # "next_funding_rate_timestamp": 1694379600,
1500
- # "price_change_percent_24h": -0.6348599635253989
1501
- # }
1502
- # }
1503
- #
1504
- tickerId = market['base'] + '_USDC'
1505
- openInterest = self.safe_dict(response, tickerId, {})
1506
- return self.parse_open_interest(openInterest, market)
1507
-
1508
- def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
1509
- #
1510
- # {
1511
- # "ticker_id": "BTC_USDC",
1512
- # "base_currency": "BTC",
1513
- # "quote_currency": "USDC",
1514
- # "last_price": 25728.0,
1515
- # "base_volume": 552.048,
1516
- # "quote_volume": 14238632.207250029,
1517
- # "price_change_percent_24h": -0.6348599635253989
1518
- # }
1519
- #
1520
- base = self.safe_string(ticker, 'base_currency')
1521
- quote = self.safe_string(ticker, 'quote_currency')
1522
- marketId = base + '/' + quote
1523
- if base.find('PERP') > 0:
1524
- marketId = marketId.replace('-PERP', '') + ':USDC'
1525
- market = self.safe_market(marketId, market)
1526
- last = self.safe_string(ticker, 'last_price')
1527
- return self.safe_ticker({
1528
- 'symbol': market['symbol'],
1529
- 'timestamp': None,
1530
- 'datetime': None,
1531
- 'high': None,
1532
- 'low': None,
1533
- 'bid': None,
1534
- 'bidVolume': None,
1535
- 'ask': None,
1536
- 'askVolume': None,
1537
- 'vwap': None,
1538
- 'open': None,
1539
- 'close': last,
1540
- 'last': last,
1541
- 'previousClose': None,
1542
- 'change': None,
1543
- 'percentage': self.safe_string(ticker, 'price_change_percent_24h'),
1544
- 'average': None,
1545
- 'baseVolume': self.safe_string(ticker, 'base_volume'),
1546
- 'quoteVolume': self.safe_string(ticker, 'quote_volume'),
1547
- 'info': ticker,
1548
- }, market)
1549
-
1550
- def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
1551
- """
1552
- fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1553
-
1554
- https://docs.vertexprotocol.com/developer-resources/api/v2/tickers
1555
-
1556
- :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1557
- :param dict [params]: extra parameters specific to the exchange API endpoint
1558
- :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
1559
- """
1560
- self.load_markets()
1561
- symbols = self.market_symbols(symbols, None, True, True, True)
1562
- request = {}
1563
- response = self.v2ArchiveGetTickers(self.extend(request, params))
1564
- #
1565
- # {
1566
- # "ETH_USDC": {
1567
- # "ticker_id": "ETH_USDC",
1568
- # "base_currency": "ETH",
1569
- # "quote_currency": "USDC",
1570
- # "last_price": 1619.1,
1571
- # "base_volume": 1428.32,
1572
- # "quote_volume": 2310648.316391866,
1573
- # "price_change_percent_24h": -1.0509394462969588
1574
- # },
1575
- # "BTC_USDC": {
1576
- # "ticker_id": "BTC_USDC",
1577
- # "base_currency": "BTC",
1578
- # "quote_currency": "USDC",
1579
- # "last_price": 25728.0,
1580
- # "base_volume": 552.048,
1581
- # "quote_volume": 14238632.207250029,
1582
- # "price_change_percent_24h": -0.6348599635253989
1583
- # }
1584
- # }
1585
- #
1586
- tickers = list(response.values())
1587
- return self.parse_tickers(tickers, symbols)
1588
-
1589
- def query_contracts(self, params={}) -> Currencies:
1590
- # query contract addresses for sending order
1591
- cachedContracts = self.safe_dict(self.options, 'v1contracts')
1592
- if cachedContracts is not None:
1593
- return cachedContracts
1594
- request = {
1595
- 'type': 'contracts',
1596
- }
1597
- response = self.v1GatewayGetQuery(self.extend(request, params))
1598
- data = self.safe_dict(response, 'data', {})
1599
- self.options['v1contracts'] = data
1600
- return data
1601
-
1602
- def nonce(self):
1603
- return self.milliseconds() - self.options['timeDifference']
1604
-
1605
- def hash_message(self, message):
1606
- return '0x' + self.hash(message, 'keccak', 'hex')
1607
-
1608
- def sign_hash(self, hash, privateKey):
1609
- signature = self.ecdsa(hash[-64:], privateKey[-64:], 'secp256k1', None)
1610
- r = signature['r']
1611
- s = signature['s']
1612
- v = self.int_to_base16(self.sum(27, signature['v']))
1613
- return '0x' + r.rjust(64, '0') + s.rjust(64, '0') + v
1614
-
1615
- def sign_message(self, message, privateKey):
1616
- return self.sign_hash(self.hash_message(message), privateKey[-64:])
1617
-
1618
- def build_sig(self, chainId, messageTypes, message, verifyingContractAddress=''):
1619
- domain = {
1620
- 'chainId': chainId,
1621
- 'name': 'Vertex',
1622
- 'verifyingContract': verifyingContractAddress,
1623
- 'version': '0.0.1',
1624
- }
1625
- msg = self.eth_encode_structured_data(domain, messageTypes, message)
1626
- signature = self.sign_message(msg, self.privateKey)
1627
- return signature
1628
-
1629
- def build_create_order_sig(self, message, chainId, verifyingContractAddress):
1630
- messageTypes = {
1631
- 'Order': [
1632
- {'name': 'sender', 'type': 'bytes32'},
1633
- {'name': 'priceX18', 'type': 'int128'},
1634
- {'name': 'amount', 'type': 'int128'},
1635
- {'name': 'expiration', 'type': 'uint64'},
1636
- {'name': 'nonce', 'type': 'uint64'},
1637
- ],
1638
- }
1639
- return self.build_sig(chainId, messageTypes, message, verifyingContractAddress)
1640
-
1641
- def build_list_trigger_tx_sig(self, message, chainId, verifyingContractAddress):
1642
- messageTypes = {
1643
- 'ListTriggerOrders': [
1644
- {'name': 'sender', 'type': 'bytes32'},
1645
- {'name': 'recvTime', 'type': 'uint64'},
1646
- ],
1647
- }
1648
- return self.build_sig(chainId, messageTypes, message, verifyingContractAddress)
1649
-
1650
- def build_cancel_all_orders_sig(self, message, chainId, verifyingContractAddress):
1651
- messageTypes = {
1652
- 'CancellationProducts': [
1653
- {'name': 'sender', 'type': 'bytes32'},
1654
- {'name': 'productIds', 'type': 'uint32[]'},
1655
- {'name': 'nonce', 'type': 'uint64'},
1656
- ],
1657
- }
1658
- return self.build_sig(chainId, messageTypes, message, verifyingContractAddress)
1659
-
1660
- def build_cancel_orders_sig(self, message, chainId, verifyingContractAddress):
1661
- messageTypes = {
1662
- 'Cancellation': [
1663
- {'name': 'sender', 'type': 'bytes32'},
1664
- {'name': 'productIds', 'type': 'uint32[]'},
1665
- {'name': 'digests', 'type': 'bytes32[]'},
1666
- {'name': 'nonce', 'type': 'uint64'},
1667
- ],
1668
- }
1669
- return self.build_sig(chainId, messageTypes, message, verifyingContractAddress)
1670
-
1671
- def build_withdraw_sig(self, message, chainId, verifyingContractAddress):
1672
- messageTypes = {
1673
- 'WithdrawCollateral': [
1674
- {'name': 'sender', 'type': 'bytes32'},
1675
- {'name': 'productId', 'type': 'uint32'},
1676
- {'name': 'amount', 'type': 'uint128'},
1677
- {'name': 'nonce', 'type': 'uint64'},
1678
- ],
1679
- }
1680
- return self.build_sig(chainId, messageTypes, message, verifyingContractAddress)
1681
-
1682
- def convert_address_to_sender(self, address: str):
1683
- sender = address + '64656661756c74'
1684
- return sender.ljust(66, '0')
1685
-
1686
- def get_nonce(self, now, expiration):
1687
- if now is None:
1688
- now = self.nonce()
1689
- # nonce = ((now + expiration) << 20) + 1000
1690
- # 1 << 20 = 1048576
1691
- return Precise.string_add(Precise.string_mul(Precise.string_add(self.number_to_string(now), self.number_to_string(expiration)), '1048576'), '1000')
1692
-
1693
- def get_expiration(self, now, timeInForce, postOnly, reduceOnly):
1694
- expiration = Precise.string_add(self.number_to_string(now), '86400')
1695
- if timeInForce == 'ioc':
1696
- # 1 << 62 = 4611686018427387904
1697
- expiration = Precise.string_or(expiration, '4611686018427387904')
1698
- elif timeInForce == 'fok':
1699
- # 2 << 62 = 9223372036854775808
1700
- expiration = Precise.string_or(expiration, '9223372036854775808')
1701
- elif postOnly:
1702
- # 3 << 62 = 13835058055282163712
1703
- expiration = Precise.string_or(expiration, '13835058055282163712')
1704
- if reduceOnly:
1705
- # 1 << 61 = 2305843009213693952
1706
- expiration = Precise.string_or(expiration, '2305843009213693952')
1707
- return expiration
1708
-
1709
- def get_amount(self, amount, side):
1710
- amountString = self.number_to_string(amount)
1711
- if side == 'sell':
1712
- if amount > 0:
1713
- # amount *= -1
1714
- amountString = Precise.string_mul(amountString, '-1')
1715
- else:
1716
- if amount < 0:
1717
- # amount *= -1
1718
- amountString = Precise.string_mul(amountString, '-1')
1719
- return amountString
1720
-
1721
- def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
1722
- """
1723
- create a trade order
1724
-
1725
- https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/place-order
1726
- https://docs.vertexprotocol.com/developer-resources/api/trigger/executes/place-order
1727
-
1728
- :param str symbol: unified symbol of the market to create an order in
1729
- :param str type: 'market' or 'limit'
1730
- :param str side: 'buy' or 'sell'
1731
- :param float amount: how much of currency you want to trade in units of base currency
1732
- :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1733
- :param dict [params]: extra parameters specific to the exchange API endpoint
1734
- :param str [params.timeInForce]: ioc, fok
1735
- :param bool [params.postOnly]: True or False whether the order is post-only
1736
- :param bool [params.reduceOnly]: True or False whether the order is reduce-only, only works for ioc and fok order
1737
- :param float [params.triggerPrice]: The price at which a trigger order is triggered at
1738
- :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1739
- """
1740
- self.check_required_credentials()
1741
- marketType = type.lower()
1742
- isMarketOrder = marketType == 'market'
1743
- if isMarketOrder and price is None:
1744
- raise ArgumentsRequired(self.id + ' createOrder() requires a price argument for market order')
1745
- self.load_markets()
1746
- market = self.market(symbol)
1747
- marketId = self.parse_to_int(market['id'])
1748
- contracts = self.query_contracts()
1749
- chainId = self.safe_string(contracts, 'chain_id')
1750
- bookAddresses = self.safe_list(contracts, 'book_addrs', [])
1751
- verifyingContractAddress = self.safe_string(bookAddresses, marketId)
1752
- defaultTimeInForce = 'fok' if (isMarketOrder) else None
1753
- timeInForce = self.safe_string_lower(params, 'timeInForce', defaultTimeInForce)
1754
- postOnly = self.safe_bool(params, 'postOnly', False)
1755
- reduceOnly = self.safe_bool(params, 'reduceOnly', False)
1756
- triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
1757
- stopLossPrice = self.safe_string(params, 'stopLossPrice', triggerPrice)
1758
- takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
1759
- isTrigger = (stopLossPrice or takeProfitPrice)
1760
- now = self.nonce()
1761
- nonce = self.get_nonce(now, 90000)
1762
- if postOnly and reduceOnly:
1763
- raise NotSupported(self.id + ' reduceOnly not supported when postOnly is enabled')
1764
- expiration = self.get_expiration(now, timeInForce, postOnly, reduceOnly)
1765
- if isTrigger:
1766
- # 1 << 63 = 9223372036854775808
1767
- nonce = Precise.string_or(nonce, '9223372036854775808')
1768
- amountString = self.get_amount(amount, side)
1769
- order = {
1770
- 'sender': self.convert_address_to_sender(self.walletAddress),
1771
- 'priceX18': self.convert_to_x18(self.price_to_precision(symbol, price)),
1772
- 'amount': self.convert_to_x18(self.amount_to_precision(symbol, amountString)),
1773
- 'expiration': expiration,
1774
- 'nonce': nonce,
1775
- }
1776
- request = {
1777
- 'place_order': {
1778
- 'product_id': marketId,
1779
- 'order': {
1780
- 'sender': order['sender'],
1781
- 'priceX18': order['priceX18'],
1782
- 'amount': order['amount'],
1783
- 'expiration': self.number_to_string(order['expiration']),
1784
- 'nonce': order['nonce'],
1785
- },
1786
- 'signature': self.build_create_order_sig(order, chainId, verifyingContractAddress),
1787
- 'id': self.safe_integer(self.options, 'brokerId', 5930043274845996),
1788
- },
1789
- }
1790
- params = self.omit(params, ['timeInForce', 'reduceOnly', 'postOnly', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice'])
1791
- response = None
1792
- if isTrigger:
1793
- trigger = {}
1794
- if stopLossPrice is not None:
1795
- trigger['last_price_below'] = self.convert_to_x18(stopLossPrice)
1796
- elif takeProfitPrice is not None:
1797
- trigger['last_price_above'] = self.convert_to_x18(takeProfitPrice)
1798
- request['place_order']['trigger'] = trigger
1799
- response = self.v1TriggerPostExecute(self.extend(request, params))
1800
- else:
1801
- response = self.v1GatewayPostExecute(self.extend(request, params))
1802
- #
1803
- # {
1804
- # "status": "success",
1805
- # "signature": {signature},
1806
- # "data": {
1807
- # "digest": {order digest}
1808
- # },
1809
- # "request_type": "execute_place_order"
1810
- # "id": 100
1811
- # }
1812
- #
1813
- data = self.safe_dict(response, 'data', {})
1814
- return self.safe_order({
1815
- 'id': self.safe_string(data, 'digest'),
1816
- })
1817
-
1818
- def edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
1819
- """
1820
- edit a trade order
1821
-
1822
- https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/cancel-and-place
1823
-
1824
- :param str id: cancel order id
1825
- :param str symbol: unified symbol of the market to create an order in
1826
- :param str type: 'market' or 'limit'
1827
- :param str side: 'buy' or 'sell'
1828
- :param float amount: how much of currency you want to trade in units of base currency
1829
- :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1830
- :param dict [params]: extra parameters specific to the exchange API endpoint
1831
- :param str [params.timeInForce]: ioc, fok
1832
- :param bool [params.postOnly]: True or False whether the order is post-only
1833
- :param bool [params.reduceOnly]: True or False whether the order is reduce-only, only works for ioc and fok order
1834
- :param float [params.triggerPrice]: The price at which a trigger order is triggered at
1835
- :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1836
- """
1837
- self.check_required_credentials()
1838
- marketType = type.lower()
1839
- isMarketOrder = marketType == 'market'
1840
- if isMarketOrder and price is None:
1841
- raise ArgumentsRequired(self.id + ' editOrder() requires a price argument for market order')
1842
- self.load_markets()
1843
- market = self.market(symbol)
1844
- marketId = self.parse_to_int(market['id'])
1845
- defaultTimeInForce = 'fok' if (isMarketOrder) else None
1846
- timeInForce = self.safe_string_lower(params, 'timeInForce', defaultTimeInForce)
1847
- postOnly = self.safe_bool(params, 'postOnly', False)
1848
- reduceOnly = self.safe_bool(params, 'reduceOnly', False)
1849
- triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
1850
- stopLossPrice = self.safe_string(params, 'stopLossPrice', triggerPrice)
1851
- takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
1852
- isTrigger = (stopLossPrice or takeProfitPrice)
1853
- contracts = self.query_contracts()
1854
- chainId = self.safe_string(contracts, 'chain_id')
1855
- bookAddresses = self.safe_list(contracts, 'book_addrs', [])
1856
- verifyingContractAddressOrder = self.safe_string(bookAddresses, marketId)
1857
- verifyingContractAddressCancel = self.safe_string(contracts, 'endpoint_addr')
1858
- now = self.nonce()
1859
- nonce = self.get_nonce(now, 90000)
1860
- sender = self.convert_address_to_sender(self.walletAddress)
1861
- if postOnly and reduceOnly:
1862
- raise NotSupported(self.id + ' reduceOnly not supported when postOnly is enabled')
1863
- if isTrigger:
1864
- raise NotSupported(self.id + ' editOrder() not supported for trigger order')
1865
- expiration = self.get_expiration(now, timeInForce, postOnly, reduceOnly)
1866
- amountString = self.get_amount(amount, side)
1867
- order = {
1868
- 'sender': sender,
1869
- 'priceX18': self.convert_to_x18(self.price_to_precision(symbol, price)),
1870
- 'amount': self.convert_to_x18(self.amount_to_precision(symbol, amountString)),
1871
- 'expiration': expiration,
1872
- 'nonce': nonce,
1873
- }
1874
- cancels = {
1875
- 'sender': sender,
1876
- 'productIds': [marketId],
1877
- 'digests': [id],
1878
- 'nonce': nonce,
1879
- }
1880
- request = {
1881
- 'cancel_and_place': {
1882
- 'cancel_tx': {
1883
- 'sender': cancels['sender'],
1884
- 'productIds': cancels['productIds'],
1885
- 'digests': cancels['digests'],
1886
- 'nonce': self.number_to_string(cancels['nonce']),
1887
- },
1888
- 'cancel_signature': self.build_cancel_orders_sig(cancels, chainId, verifyingContractAddressCancel),
1889
- 'place_order': {
1890
- 'product_id': marketId,
1891
- 'order': {
1892
- 'sender': order['sender'],
1893
- 'priceX18': order['priceX18'],
1894
- 'amount': order['amount'],
1895
- 'expiration': self.number_to_string(order['expiration']),
1896
- 'nonce': order['nonce'],
1897
- },
1898
- 'signature': self.build_create_order_sig(order, chainId, verifyingContractAddressOrder),
1899
- 'id': self.safe_integer(self.options, 'brokerId', 5930043274845996),
1900
- },
1901
- },
1902
- }
1903
- params = self.omit(params, ['timeInForce', 'reduceOnly', 'postOnly', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice'])
1904
- response = self.v1GatewayPostExecute(self.extend(request, params))
1905
- #
1906
- # {
1907
- # "status": "success",
1908
- # "signature": {signature},
1909
- # "data": {
1910
- # "digest": {order digest}
1911
- # },
1912
- # "request_type": "execute_cancel_and_place"
1913
- # }
1914
- #
1915
- data = self.safe_dict(response, 'data', {})
1916
- return self.safe_order({
1917
- 'id': self.safe_string(data, 'digest'),
1918
- })
1919
-
1920
- def parse_order_status(self, status):
1921
- if status is not None:
1922
- statuses = {
1923
- 'pending': 'open',
1924
- }
1925
- if isinstance(status, str):
1926
- return self.safe_string(statuses, status, status)
1927
- statusCancelled = self.safe_dict(status, 'cancelled')
1928
- if statusCancelled is not None:
1929
- return 'canceled'
1930
- statusTriggered = self.safe_dict(status, 'triggered', {})
1931
- triggeredStatus = self.safe_string(statusTriggered, 'status', 'failure')
1932
- if triggeredStatus == 'success':
1933
- return 'closed'
1934
- return 'canceled'
1935
- return status
1936
-
1937
- def parse_order(self, order, market: Market = None) -> Order:
1938
- #
1939
- # {
1940
- # "product_id": 1,
1941
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
1942
- # "price_x18": "1000000000000000000",
1943
- # "amount": "1000000000000000000",
1944
- # "expiration": "2000000000",
1945
- # "nonce": "1",
1946
- # "unfilled_amount": "1000000000000000000",
1947
- # "digest": "0x0000000000000000000000000000000000000000000000000000000000000000",
1948
- # "placed_at": 1681951347,
1949
- # "order_type": "ioc"
1950
- # }
1951
- # stop order
1952
- # {
1953
- # "order": {
1954
- # "order": {
1955
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
1956
- # "priceX18": "1000000000000000000",
1957
- # "amount": "1000000000000000000",
1958
- # "expiration": "2000000000",
1959
- # "nonce": "1",
1960
- # },
1961
- # "signature": "0x...",
1962
- # "product_id": 1,
1963
- # "spot_leverage": True,
1964
- # "trigger": {
1965
- # "price_above": "1000000000000000000"
1966
- # },
1967
- # "digest": "0x..."
1968
- # },
1969
- # "status": "pending",
1970
- # "updated_at": 1688768157050
1971
- # }
1972
- #
1973
- marketId = self.safe_string(order, 'product_id')
1974
- timestamp = self.safe_timestamp(order, 'placed_at')
1975
- amount = self.safe_string(order, 'amount')
1976
- price = self.safe_string(order, 'price_x18')
1977
- remaining = self.safe_string(order, 'unfilled_amount')
1978
- triggerPriceNum = None
1979
- status = self.safe_value(order, 'status')
1980
- if status is not None:
1981
- # trigger order
1982
- outerOrder = self.safe_dict(order, 'order', {})
1983
- innerOrder = self.safe_dict(outerOrder, 'order', {})
1984
- marketId = self.safe_string(outerOrder, 'product_id')
1985
- amount = self.safe_string(innerOrder, 'amount')
1986
- price = self.safe_string(innerOrder, 'priceX18')
1987
- timestamp = self.safe_timestamp(order, 'updated_at')
1988
- trigger = self.safe_dict(outerOrder, 'trigger', {})
1989
- triggerPrice = self.safe_string_n(trigger, ['price_above', 'price_below', 'last_price_above', 'last_price_below'])
1990
- if triggerPrice is not None:
1991
- triggerPriceNum = self.parse_to_numeric(self.convert_from_x18(triggerPrice))
1992
- market = self.safe_market(marketId, market)
1993
- symbol = market['symbol']
1994
- priceNum = None
1995
- if price is not None:
1996
- priceNum = self.parse_to_numeric(self.convert_from_x18(price))
1997
- amountNum = None
1998
- if amount is not None:
1999
- amountNum = self.parse_to_numeric(self.convert_from_x18(amount))
2000
- remainingNum = None
2001
- if remaining is not None:
2002
- remainingNum = self.parse_to_numeric(self.convert_from_x18(remaining))
2003
- side = None
2004
- if amountNum is not None and remainingNum is not None:
2005
- side = 'sell' if (amountNum < 0 or remainingNum < 0) else 'buy'
2006
- tif = self.parse_time_in_force(self.safe_string(order, 'order_type'))
2007
- isPostOnly = (tif == 'PO')
2008
- return self.safe_order({
2009
- 'info': order,
2010
- 'id': self.safe_string(order, 'digest'),
2011
- 'clientOrderId': None,
2012
- 'timestamp': timestamp,
2013
- 'datetime': self.iso8601(timestamp),
2014
- 'lastTradeTimestamp': None,
2015
- 'lastUpdateTimestamp': None,
2016
- 'symbol': symbol,
2017
- 'type': None,
2018
- 'timeInForce': tif,
2019
- 'postOnly': isPostOnly,
2020
- 'reduceOnly': None,
2021
- 'side': side,
2022
- 'price': priceNum,
2023
- 'triggerPrice': triggerPriceNum,
2024
- 'amount': amountNum,
2025
- 'cost': None,
2026
- 'average': None,
2027
- 'filled': None,
2028
- 'remaining': remainingNum,
2029
- 'status': self.parse_order_status(status),
2030
- 'fee': None,
2031
- 'trades': None,
2032
- }, market)
2033
-
2034
- def parse_time_in_force(self, timeInForce):
2035
- timeInForces = {
2036
- 'POST_ONLY': 'PO',
2037
- }
2038
- return self.safe_string_upper(timeInForces, timeInForce, timeInForce)
2039
-
2040
- def fetch_order(self, id: str, symbol: Str = None, params={}):
2041
- """
2042
- fetches information on an order made by the user
2043
-
2044
- https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/order
2045
-
2046
- :param str id: the order id
2047
- :param str symbol: unified symbol of the market the order was made in
2048
- :param dict [params]: extra parameters specific to the exchange API endpoint
2049
- :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2050
- """
2051
- self.load_markets()
2052
- market = self.market(symbol)
2053
- request = {
2054
- 'type': 'order',
2055
- 'product_id': self.parse_to_int(market['id']),
2056
- 'digest': id,
2057
- }
2058
- response = self.v1GatewayGetQuery(self.extend(request, params))
2059
- #
2060
- # {
2061
- # "status": "success",
2062
- # "data": {
2063
- # "product_id": 1,
2064
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
2065
- # "price_x18": "1000000000000000000",
2066
- # "amount": "1000000000000000000",
2067
- # "expiration": "2000000000",
2068
- # "nonce": "1",
2069
- # "unfilled_amount": "1000000000000000000",
2070
- # "digest": "0x0000000000000000000000000000000000000000000000000000000000000000",
2071
- # "placed_at": 1681951347,
2072
- # "order_type": "ioc"
2073
- # },
2074
- # "request_type": "query_order",
2075
- # }
2076
- #
2077
- data = self.safe_dict(response, 'data')
2078
- return self.parse_order(data, market)
2079
-
2080
- def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
2081
- """
2082
- fetch all unfilled currently open orders
2083
-
2084
- https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/orders
2085
- https://docs.vertexprotocol.com/developer-resources/api/trigger/queries/list-trigger-orders
2086
-
2087
- :param str symbol: unified market symbol
2088
- :param int [since]: the earliest time in ms to fetch open orders for
2089
- :param int [limit]: the maximum number of open orders structures to retrieve
2090
- :param dict [params]: extra parameters specific to the exchange API endpoint
2091
- :param boolean [params.trigger]: whether the order is a trigger/algo order
2092
- :param str [params.user]: user address, will default to self.walletAddress if not provided
2093
- :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2094
- """
2095
- self.check_required_credentials()
2096
- self.load_markets()
2097
- userAddress = None
2098
- userAddress, params = self.handle_public_address('fetchOpenOrders', params)
2099
- request = {}
2100
- market: Market = None
2101
- trigger = self.safe_bool_2(params, 'stop', 'trigger')
2102
- params = self.omit(params, ['stop', 'trigger'])
2103
- if symbol is not None:
2104
- market = self.market(symbol)
2105
- request['product_id'] = self.parse_to_numeric(market['id'])
2106
- response = None
2107
- if trigger:
2108
- contracts = self.query_contracts()
2109
- chainId = self.safe_string(contracts, 'chain_id')
2110
- verifyingContractAddress = self.safe_string(contracts, 'endpoint_addr')
2111
- tx = {
2112
- 'sender': self.convert_address_to_sender(userAddress),
2113
- 'recvTime': self.nonce() + 90000,
2114
- }
2115
- request['signature'] = self.build_list_trigger_tx_sig(tx, chainId, verifyingContractAddress)
2116
- request['tx'] = {
2117
- 'sender': tx['sender'],
2118
- 'recvTime': self.number_to_string(tx['recvTime']),
2119
- }
2120
- request['type'] = 'list_trigger_orders'
2121
- request['pending'] = True
2122
- until = self.safe_integer(params, 'until')
2123
- params = self.omit(params, 'until')
2124
- if until is not None:
2125
- request['max_update_time'] = until
2126
- if limit is not None:
2127
- request['limit'] = limit
2128
- response = self.v1TriggerPostQuery(self.extend(request, params))
2129
- #
2130
- # {
2131
- # "status": "success",
2132
- # "data": {
2133
- # "orders": [
2134
- # {
2135
- # "order": {
2136
- # "order": {
2137
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
2138
- # "priceX18": "1000000000000000000",
2139
- # "amount": "1000000000000000000",
2140
- # "expiration": "2000000000",
2141
- # "nonce": "1",
2142
- # },
2143
- # "signature": "0x...",
2144
- # "product_id": 1,
2145
- # "spot_leverage": True,
2146
- # "trigger": {
2147
- # "price_above": "1000000000000000000"
2148
- # },
2149
- # "digest": "0x..."
2150
- # },
2151
- # "status": "pending",
2152
- # "updated_at": 1688768157050
2153
- # }
2154
- # ]
2155
- # },
2156
- # "request_type": "query_list_trigger_orders"
2157
- # }
2158
- #
2159
- else:
2160
- self.check_required_argument('fetchOpenOrders', symbol, 'symbol')
2161
- request['type'] = 'subaccount_orders'
2162
- request['sender'] = self.convert_address_to_sender(userAddress)
2163
- response = self.v1GatewayPostQuery(self.extend(request, params))
2164
- #
2165
- # {
2166
- # "status": "success",
2167
- # "data": {
2168
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
2169
- # "product_id": 1,
2170
- # "orders": [
2171
- # {
2172
- # "product_id": 2,
2173
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
2174
- # "price_x18": "1000000000000000000",
2175
- # "amount": "1000000000000000000",
2176
- # "expiration": "2000000000",
2177
- # "nonce": "1",
2178
- # "order_type": "default",
2179
- # "unfilled_amount": "1000000000000000000",
2180
- # "digest": "0x0000000000000000000000000000000000000000000000000000000000000000",
2181
- # "placed_at": 1682437737,
2182
- # "order_type": "ioc"
2183
- # }
2184
- # ]
2185
- # },
2186
- # "request_type": "query_subaccount_orders"
2187
- # }
2188
- #
2189
- data = self.safe_dict(response, 'data', {})
2190
- orders = self.safe_list(data, 'orders')
2191
- return self.parse_orders(orders, market, since, limit)
2192
-
2193
- def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
2194
- """
2195
- fetches information on multiple orders made by the user
2196
-
2197
- https://docs.vertexprotocol.com/developer-resources/api/trigger/queries/list-trigger-orders
2198
-
2199
- :param str symbol: unified market symbol
2200
- :param int [since]: the earliest time in ms to fetch open orders for
2201
- :param int [limit]: the maximum number of open orders structures to retrieve
2202
- :param dict [params]: extra parameters specific to the exchange API endpoint
2203
- :param boolean [params.trigger]: whether the order is a trigger/algo order
2204
- :param str [params.user]: user address, will default to self.walletAddress if not provided
2205
- :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2206
- """
2207
- self.check_required_credentials()
2208
- trigger = self.safe_bool_2(params, 'stop', 'trigger')
2209
- params = self.omit(params, ['stop', 'trigger'])
2210
- if not trigger:
2211
- raise NotSupported(self.id + ' fetchOrders only support trigger orders')
2212
- userAddress = None
2213
- userAddress, params = self.handle_public_address('fetchOrders', params)
2214
- self.load_markets()
2215
- market: Market = None
2216
- request = {
2217
- 'type': 'list_trigger_orders',
2218
- 'pending': False,
2219
- }
2220
- if symbol is not None:
2221
- market = self.market(symbol)
2222
- request['product_id'] = self.parse_to_numeric(market['id'])
2223
- contracts = self.query_contracts()
2224
- chainId = self.safe_string(contracts, 'chain_id')
2225
- verifyingContractAddress = self.safe_string(contracts, 'endpoint_addr')
2226
- tx = {
2227
- 'sender': self.convert_address_to_sender(userAddress),
2228
- 'recvTime': self.nonce() + 90000,
2229
- }
2230
- request['signature'] = self.build_list_trigger_tx_sig(tx, chainId, verifyingContractAddress)
2231
- request['tx'] = {
2232
- 'sender': tx['sender'],
2233
- 'recvTime': self.number_to_string(tx['recvTime']),
2234
- }
2235
- until = self.safe_integer(params, 'until')
2236
- params = self.omit(params, 'until')
2237
- if until is not None:
2238
- request['max_update_time'] = until
2239
- if limit is not None:
2240
- request['limit'] = limit
2241
- response = self.v1TriggerPostQuery(self.extend(request, params))
2242
- #
2243
- # {
2244
- # "status": "success",
2245
- # "data": {
2246
- # "orders": [
2247
- # {
2248
- # "order": {
2249
- # "order": {
2250
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
2251
- # "priceX18": "1000000000000000000",
2252
- # "amount": "1000000000000000000",
2253
- # "expiration": "2000000000",
2254
- # "nonce": "1",
2255
- # },
2256
- # "signature": "0x...",
2257
- # "product_id": 1,
2258
- # "spot_leverage": True,
2259
- # "trigger": {
2260
- # "price_above": "1000000000000000000"
2261
- # },
2262
- # "digest": "0x..."
2263
- # },
2264
- # "status": "pending",
2265
- # "updated_at": 1688768157050
2266
- # }
2267
- # ]
2268
- # },
2269
- # "request_type": "query_list_trigger_orders"
2270
- # }
2271
- #
2272
- data = self.safe_dict(response, 'data', {})
2273
- orders = self.safe_list(data, 'orders')
2274
- return self.parse_orders(orders, market, since, limit)
2275
-
2276
- def cancel_all_orders(self, symbol: Str = None, params={}):
2277
- """
2278
-
2279
- https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/cancel-product-orders
2280
- https://docs.vertexprotocol.com/developer-resources/api/trigger/executes/cancel-product-orders
2281
-
2282
- cancel all open orders in a market
2283
- :param str symbol: unified market symbol
2284
- :param dict [params]: extra parameters specific to the exchange API endpoint
2285
- :param boolean [params.trigger]: whether the order is a trigger/algo order
2286
- :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2287
- """
2288
- self.check_required_credentials()
2289
- self.load_markets()
2290
- if symbol is None:
2291
- raise ArgumentsRequired(self.id + ' cancelAllOrders() requires a symbol argument')
2292
- market = self.market(symbol)
2293
- marketId = market['id']
2294
- contracts = self.query_contracts()
2295
- chainId = self.safe_string(contracts, 'chain_id')
2296
- verifyingContractAddress = self.safe_string(contracts, 'endpoint_addr')
2297
- now = self.nonce()
2298
- nonce = self.get_nonce(now, 90000)
2299
- cancels = {
2300
- 'sender': self.convert_address_to_sender(self.walletAddress),
2301
- 'productIds': [
2302
- self.parse_to_numeric(marketId),
2303
- ],
2304
- 'nonce': nonce,
2305
- }
2306
- request = {
2307
- 'cancel_product_orders': {
2308
- 'tx': {
2309
- 'sender': cancels['sender'],
2310
- 'productIds': cancels['productIds'],
2311
- 'nonce': self.number_to_string(cancels['nonce']),
2312
- },
2313
- 'signature': self.build_cancel_all_orders_sig(cancels, chainId, verifyingContractAddress),
2314
- },
2315
- }
2316
- trigger = self.safe_bool_2(params, 'stop', 'trigger')
2317
- params = self.omit(params, ['stop', 'trigger'])
2318
- response = None
2319
- if trigger:
2320
- response = self.v1TriggerPostExecute(self.extend(request, params))
2321
- #
2322
- # {
2323
- # "status": "success",
2324
- # "signature": {signature},
2325
- # "request_type": "execute_cancel_product_orders"
2326
- # }
2327
- #
2328
- else:
2329
- response = self.v1GatewayPostExecute(self.extend(request, params))
2330
- #
2331
- # {
2332
- # "status": "success",
2333
- # "signature": {signature},
2334
- # "data": {
2335
- # "cancelled_orders": [
2336
- # {
2337
- # "product_id": 2,
2338
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000",
2339
- # "price_x18": "20000000000000000000000",
2340
- # "amount": "-100000000000000000",
2341
- # "expiration": "1686332748",
2342
- # "order_type": "post_only",
2343
- # "nonce": "1768248100142339392",
2344
- # "unfilled_amount": "-100000000000000000",
2345
- # "digest": "0x3195a7929feb8307edecf9c045j5ced68925108f0aa305f0ee5773854159377c",
2346
- # "placed_at": 1686332708
2347
- # },
2348
- # ...
2349
- # ]
2350
- # },
2351
- # "request_type": "execute_cancel_product_orders"
2352
- # }
2353
- #
2354
- return [self.safe_order({'info': response})]
2355
-
2356
- def cancel_order(self, id: str, symbol: Str = None, params={}):
2357
- """
2358
- cancels an open order
2359
-
2360
- https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/cancel-orders
2361
- https://docs.vertexprotocol.com/developer-resources/api/trigger/executes/cancel-orders
2362
-
2363
- :param str id: order id
2364
- :param str symbol: unified symbol of the market the order was made in
2365
- :param dict [params]: extra parameters specific to the exchange API endpoint
2366
- :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2367
- """
2368
- order = self.cancel_orders([id], symbol, params)
2369
- return self.safe_order({'info': order})
2370
-
2371
- def cancel_orders(self, ids: List[str], symbol: Str = None, params={}):
2372
- """
2373
- cancel multiple orders
2374
-
2375
- https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/cancel-orders
2376
- https://docs.vertexprotocol.com/developer-resources/api/trigger/executes/cancel-orders
2377
-
2378
- :param str[] ids: order ids
2379
- :param str [symbol]: unified market symbol
2380
- :param dict [params]: extra parameters specific to the exchange API endpoint
2381
- :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2382
- """
2383
- self.check_required_credentials()
2384
- if symbol is None:
2385
- raise ArgumentsRequired(self.id + ' cancelOrders() requires a symbol argument')
2386
- self.load_markets()
2387
- market = self.market(symbol)
2388
- marketId = market['id']
2389
- contracts = self.query_contracts()
2390
- chainId = self.safe_string(contracts, 'chain_id')
2391
- verifyingContractAddress = self.safe_string(contracts, 'endpoint_addr')
2392
- now = self.nonce()
2393
- nonce = self.get_nonce(now, 90000)
2394
- cancels = {
2395
- 'sender': self.convert_address_to_sender(self.walletAddress),
2396
- 'productIds': [],
2397
- 'digests': ids,
2398
- 'nonce': nonce,
2399
- }
2400
- productIds = cancels['productIds']
2401
- marketIdNum = self.parse_to_numeric(marketId)
2402
- for i in range(0, len(ids)):
2403
- productIds.append(marketIdNum)
2404
- request = {
2405
- 'cancel_orders': {
2406
- 'tx': {
2407
- 'sender': cancels['sender'],
2408
- 'productIds': productIds,
2409
- 'digests': cancels['digests'],
2410
- 'nonce': self.number_to_string(cancels['nonce']),
2411
- },
2412
- 'signature': self.build_cancel_orders_sig(cancels, chainId, verifyingContractAddress),
2413
- },
2414
- }
2415
- trigger = self.safe_bool_2(params, 'stop', 'trigger')
2416
- params = self.omit(params, ['stop', 'trigger'])
2417
- response = None
2418
- if trigger:
2419
- response = self.v1TriggerPostExecute(self.extend(request, params))
2420
- #
2421
- # {
2422
- # "status": "success",
2423
- # "signature": {signature},
2424
- # "request_type": "execute_cancel_orders"
2425
- # }
2426
- #
2427
- else:
2428
- response = self.v1GatewayPostExecute(self.extend(request, params))
2429
- #
2430
- # {
2431
- # "status": "success",
2432
- # "signature": {signature},
2433
- # "data": {
2434
- # "cancelled_orders": [
2435
- # {
2436
- # "product_id": 2,
2437
- # "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000",
2438
- # "price_x18": "20000000000000000000000",
2439
- # "amount": "-100000000000000000",
2440
- # "expiration": "1686332748",
2441
- # "order_type": "post_only",
2442
- # "nonce": "1768248100142339392",
2443
- # "unfilled_amount": "-100000000000000000",
2444
- # "digest": "0x3195a7929feb8307edecf9c045j5ced68925108f0aa305f0ee5773854159377c",
2445
- # "placed_at": 1686332708
2446
- # },
2447
- # ...
2448
- # ]
2449
- # },
2450
- # "request_type": "execute_cancel_orders"
2451
- # }
2452
- #
2453
- return response
2454
-
2455
- def fetch_balance(self, params={}) -> Balances:
2456
- """
2457
- query for balance and get the amount of funds available for trading or funds locked in orders
2458
-
2459
- https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/subaccount-info
2460
-
2461
- :param dict [params]: extra parameters specific to the exchange API endpoint
2462
- :param str [params.user]: user address, will default to self.walletAddress if not provided
2463
- :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
2464
- """
2465
- userAddress = None
2466
- userAddress, params = self.handle_public_address('fetchBalance', params)
2467
- request = {
2468
- 'type': 'subaccount_info',
2469
- 'subaccount': self.convert_address_to_sender(userAddress),
2470
- }
2471
- response = self.v1GatewayGetQuery(self.extend(request, params))
2472
- #
2473
- # {
2474
- # "status": "success",
2475
- # "data": {
2476
- # "subaccount": "0x265167ddfac55365d6ff07fc5943276319aa6b9f64656661756c740000000000",
2477
- # "exists": True,
2478
- # "healths": [
2479
- # {
2480
- # "assets": "75323297691833342306",
2481
- # "liabilities": "46329556869051092241",
2482
- # "health": "28993740822782250065"
2483
- # },
2484
- # {
2485
- # "assets": "75323297691833342306",
2486
- # "liabilities": "35968911700887320741",
2487
- # "health": "39354385990946021565"
2488
- # },
2489
- # {
2490
- # "assets": "80796966663601107565",
2491
- # "liabilities": "0",
2492
- # "health": "80796966663601107565"
2493
- # }
2494
- # ],
2495
- # "health_contributions": [
2496
- # [
2497
- # "75323297691833340000",
2498
- # "75323297691833340000",
2499
- # "75323297691833340000"
2500
- # ],
2501
- # [
2502
- # "0",
2503
- # "0",
2504
- # "0"
2505
- # ],
2506
- # [
2507
- # "0",
2508
- # "0",
2509
- # "0"
2510
- # ],
2511
- # [
2512
- # "0",
2513
- # "0",
2514
- # "0"
2515
- # ],
2516
- # [
2517
- # "-46329556869051090000",
2518
- # "-35968911700887323000",
2519
- # "5473668971767765000"
2520
- # ]
2521
- # ],
2522
- # "spot_count": 3,
2523
- # "perp_count": 2,
2524
- # "spot_balances": [
2525
- # {
2526
- # "product_id": 1,
2527
- # "lp_balance": {
2528
- # "amount": "0"
2529
- # },
2530
- # "balance": {
2531
- # "amount": "0",
2532
- # "last_cumulative_multiplier_x18": "1003419811982007193"
2533
- # }
2534
- # },
2535
- # {
2536
- # "product_id": 3,
2537
- # "lp_balance": {
2538
- # "amount": "0"
2539
- # },
2540
- # "balance": {
2541
- # "amount": "0",
2542
- # "last_cumulative_multiplier_x18": "1007584195035969404"
2543
- # }
2544
- # },
2545
- # {
2546
- # "product_id": 0,
2547
- # "lp_balance": {
2548
- # "amount": "0"
2549
- # },
2550
- # "balance": {
2551
- # "amount": "75323297691833342306",
2552
- # "last_cumulative_multiplier_x18": "1000000002391497578"
2553
- # }
2554
- # }
2555
- # ],
2556
- # "perp_balances": [
2557
- # {
2558
- # "product_id": 2,
2559
- # "lp_balance": {
2560
- # "amount": "0",
2561
- # "last_cumulative_funding_x18": "-284321955122859921"
2562
- # },
2563
- # "balance": {
2564
- # "amount": "0",
2565
- # "v_quote_balance": "0",
2566
- # "last_cumulative_funding_x18": "6363466629611946777168"
2567
- # }
2568
- # },
2569
- # {
2570
- # "product_id": 4,
2571
- # "lp_balance": {
2572
- # "amount": "0",
2573
- # "last_cumulative_funding_x18": "-90979748449893411"
2574
- # },
2575
- # "balance": {
2576
- # "amount": "-200000000000000000",
2577
- # "v_quote_balance": "419899475698318625259",
2578
- # "last_cumulative_funding_x18": "141182516563970577208"
2579
- # }
2580
- # }
2581
- # ],
2582
- # "spot_products": [
2583
- # {
2584
- # "product_id": 1,
2585
- # "oracle_price_x18": "30217830336443750750000",
2586
- # "risk": {
2587
- # "long_weight_initial_x18": "750000000000000000",
2588
- # "short_weight_initial_x18": "1250000000000000000",
2589
- # "long_weight_maintenance_x18": "800000000000000000",
2590
- # "short_weight_maintenance_x18": "1200000000000000000",
2591
- # "large_position_penalty_x18": "0"
2592
- # },
2593
- # "config": {
2594
- # "token": "0x5cc7c91690b2cbaee19a513473d73403e13fb431",
2595
- # "interest_inflection_util_x18": "800000000000000000",
2596
- # "interest_floor_x18": "10000000000000000",
2597
- # "interest_small_cap_x18": "40000000000000000",
2598
- # "interest_large_cap_x18": "1000000000000000000"
2599
- # },
2600
- # "state": {
2601
- # "cumulative_deposits_multiplier_x18": "1001304691727847318",
2602
- # "cumulative_borrows_multiplier_x18": "1003419811982007193",
2603
- # "total_deposits_normalized": "213107447159798397806318",
2604
- # "total_borrows_normalized": "4907820740150097483532"
2605
- # },
2606
- # "lp_state": {
2607
- # "supply": "1304981417419495030893348",
2608
- # "quote": {
2609
- # "amount": "2048495687410669565222259",
2610
- # "last_cumulative_multiplier_x18": "1000000002391497578"
2611
- # },
2612
- # "base": {
2613
- # "amount": "67623029247538886515",
2614
- # "last_cumulative_multiplier_x18": "1001304691727847318"
2615
- # }
2616
- # },
2617
- # "book_info": {
2618
- # "size_increment": "1000000000000000",
2619
- # "price_increment_x18": "1000000000000000000",
2620
- # "min_size": "10000000000000000",
2621
- # "collected_fees": "8865582805773573662738183",
2622
- # "lp_spread_x18": "3000000000000000"
2623
- # }
2624
- # },
2625
- # {
2626
- # "product_id": 3,
2627
- # "oracle_price_x18": "2075217009708333333333",
2628
- # "risk": {
2629
- # "long_weight_initial_x18": "750000000000000000",
2630
- # "short_weight_initial_x18": "1250000000000000000",
2631
- # "long_weight_maintenance_x18": "800000000000000000",
2632
- # "short_weight_maintenance_x18": "1200000000000000000",
2633
- # "large_position_penalty_x18": "0"
2634
- # },
2635
- # "config": {
2636
- # "token": "0xcc59686e3a32fb104c8ff84dd895676265efb8a6",
2637
- # "interest_inflection_util_x18": "800000000000000000",
2638
- # "interest_floor_x18": "10000000000000000",
2639
- # "interest_small_cap_x18": "40000000000000000",
2640
- # "interest_large_cap_x18": "1000000000000000000"
2641
- # },
2642
- # "state": {
2643
- # "cumulative_deposits_multiplier_x18": "1003722507760089346",
2644
- # "cumulative_borrows_multiplier_x18": "1007584195035969404",
2645
- # "total_deposits_normalized": "232750303205807326418622",
2646
- # "total_borrows_normalized": "110730726549469855171025"
2647
- # },
2648
- # "lp_state": {
2649
- # "supply": "902924999999999999774268",
2650
- # "quote": {
2651
- # "amount": "1165328092090344104989049",
2652
- # "last_cumulative_multiplier_x18": "1000000002391497578"
2653
- # },
2654
- # "base": {
2655
- # "amount": "563265647183403990588",
2656
- # "last_cumulative_multiplier_x18": "1003722507760089346"
2657
- # }
2658
- # },
2659
- # "book_info": {
2660
- # "size_increment": "10000000000000000",
2661
- # "price_increment_x18": "100000000000000000",
2662
- # "min_size": "100000000000000000",
2663
- # "collected_fees": "1801521329724633001446457",
2664
- # "lp_spread_x18": "3000000000000000"
2665
- # }
2666
- # },
2667
- # {
2668
- # "product_id": 0,
2669
- # "oracle_price_x18": "1000000000000000000",
2670
- # "risk": {
2671
- # "long_weight_initial_x18": "1000000000000000000",
2672
- # "short_weight_initial_x18": "1000000000000000000",
2673
- # "long_weight_maintenance_x18": "1000000000000000000",
2674
- # "short_weight_maintenance_x18": "1000000000000000000",
2675
- # "large_position_penalty_x18": "0"
2676
- # },
2677
- # "config": {
2678
- # "token": "0x179522635726710dd7d2035a81d856de4aa7836c",
2679
- # "interest_inflection_util_x18": "800000000000000000",
2680
- # "interest_floor_x18": "10000000000000000",
2681
- # "interest_small_cap_x18": "40000000000000000",
2682
- # "interest_large_cap_x18": "1000000000000000000"
2683
- # },
2684
- # "state": {
2685
- # "cumulative_deposits_multiplier_x18": "1000000002391497578",
2686
- # "cumulative_borrows_multiplier_x18": "1001593395547514024",
2687
- # "total_deposits_normalized": "60000256267437588885818752247843",
2688
- # "total_borrows_normalized": "391445043137305055810336885"
2689
- # },
2690
- # "lp_state": {
2691
- # "supply": "0",
2692
- # "quote": {
2693
- # "amount": "0",
2694
- # "last_cumulative_multiplier_x18": "0"
2695
- # },
2696
- # "base": {
2697
- # "amount": "0",
2698
- # "last_cumulative_multiplier_x18": "0"
2699
- # }
2700
- # },
2701
- # "book_info": {
2702
- # "size_increment": "0",
2703
- # "price_increment_x18": "0",
2704
- # "min_size": "0",
2705
- # "collected_fees": "0",
2706
- # "lp_spread_x18": "0"
2707
- # }
2708
- # }
2709
- # ],
2710
- # "perp_products": [
2711
- # {
2712
- # "product_id": 2,
2713
- # "oracle_price_x18": "30219079716463070000000",
2714
- # "risk": {
2715
- # "long_weight_initial_x18": "875000000000000000",
2716
- # "short_weight_initial_x18": "1125000000000000000",
2717
- # "long_weight_maintenance_x18": "900000000000000000",
2718
- # "short_weight_maintenance_x18": "1100000000000000000",
2719
- # "large_position_penalty_x18": "0"
2720
- # },
2721
- # "state": {
2722
- # "cumulative_funding_long_x18": "6363466629611946777168",
2723
- # "cumulative_funding_short_x18": "6363466629611946777168",
2724
- # "available_settle": "100612314098927536086702448",
2725
- # "open_interest": "57975708279961875623240"
2726
- # },
2727
- # "lp_state": {
2728
- # "supply": "783207415944433511804197",
2729
- # "last_cumulative_funding_x18": "6363466629611946777168",
2730
- # "cumulative_funding_per_lp_x18": "-284321955122859921",
2731
- # "base": "37321000000000000000",
2732
- # "quote": "1150991638943862165224593"
2733
- # },
2734
- # "book_info": {
2735
- # "size_increment": "1000000000000000",
2736
- # "price_increment_x18": "1000000000000000000",
2737
- # "min_size": "10000000000000000",
2738
- # "collected_fees": "7738341933653651206856235",
2739
- # "lp_spread_x18": "3000000000000000"
2740
- # }
2741
- # },
2742
- # {
2743
- # "product_id": 4,
2744
- # "oracle_price_x18": "2072129033632754300000",
2745
- # "risk": {
2746
- # "long_weight_initial_x18": "875000000000000000",
2747
- # "short_weight_initial_x18": "1125000000000000000",
2748
- # "long_weight_maintenance_x18": "900000000000000000",
2749
- # "short_weight_maintenance_x18": "1100000000000000000",
2750
- # "large_position_penalty_x18": "0"
2751
- # },
2752
- # "state": {
2753
- # "cumulative_funding_long_x18": "141182516563970577208",
2754
- # "cumulative_funding_short_x18": "141182516563970577208",
2755
- # "available_settle": "33807443862986950288685582",
2756
- # "open_interest": "316343836992291503987611"
2757
- # },
2758
- # "lp_state": {
2759
- # "supply": "541756546038144467864559",
2760
- # "last_cumulative_funding_x18": "141182516563970577208",
2761
- # "cumulative_funding_per_lp_x18": "-90979748449893411",
2762
- # "base": "362320000000000000000",
2763
- # "quote": "750080187685127907834038"
2764
- # },
2765
- # "book_info": {
2766
- # "size_increment": "10000000000000000",
2767
- # "price_increment_x18": "100000000000000000",
2768
- # "min_size": "100000000000000000",
2769
- # "collected_fees": "1893278317732551619694831",
2770
- # "lp_spread_x18": "3000000000000000"
2771
- # }
2772
- # }
2773
- # ]
2774
- # },
2775
- # "request_type": "query_subaccount_info"
2776
- # }
2777
- #
2778
- data = self.safe_dict(response, 'data', {})
2779
- balances = self.safe_list(data, 'spot_balances', [])
2780
- result = {'info': response}
2781
- for i in range(0, len(balances)):
2782
- balance = balances[i]
2783
- marketId = self.safe_string(balance, 'product_id')
2784
- market = self.safe_market(marketId)
2785
- isUsdcMarketId = marketId == '0'
2786
- if market['id'] is None and not isUsdcMarketId:
2787
- continue
2788
- baseId = 'USDC' if (isUsdcMarketId) else self.safe_string(market, 'baseId')
2789
- code = self.safe_currency_code(baseId)
2790
- account = self.account()
2791
- tokenBalance = self.safe_dict(balance, 'balance', {})
2792
- total = self.convert_from_x18(self.safe_string(tokenBalance, 'amount'))
2793
- account['total'] = total
2794
- result[code] = account
2795
- return self.safe_balance(result)
2796
-
2797
- def parse_position(self, position, market: Market = None):
2798
- #
2799
- # {
2800
- # "product_id": 2,
2801
- # "lp_balance": {
2802
- # "amount": "0",
2803
- # "last_cumulative_funding_x18": "-284321955122859921"
2804
- # },
2805
- # "balance": {
2806
- # "amount": "0",
2807
- # "v_quote_balance": "0",
2808
- # "last_cumulative_funding_x18": "6363466629611946777168"
2809
- # }
2810
- # },
2811
- # {
2812
- # "product_id": 4,
2813
- # "lp_balance": {
2814
- # "amount": "0",
2815
- # "last_cumulative_funding_x18": "-90979748449893411"
2816
- # },
2817
- # "balance": {
2818
- # "amount": "-200000000000000000",
2819
- # "v_quote_balance": "419899475698318625259",
2820
- # "last_cumulative_funding_x18": "141182516563970577208"
2821
- # }
2822
- # }
2823
- #
2824
- marketId = self.safe_string(position, 'product_id')
2825
- market = self.safe_market(marketId)
2826
- balance = self.safe_dict(position, 'balance', {})
2827
- contractSize = self.convert_from_x18(self.safe_string(balance, 'amount'))
2828
- side = 'buy'
2829
- if Precise.string_lt(contractSize, '1'):
2830
- side = 'sell'
2831
- return self.safe_position({
2832
- 'info': position,
2833
- 'id': None,
2834
- 'symbol': self.safe_string(market, 'symbol'),
2835
- 'timestamp': None,
2836
- 'datetime': None,
2837
- 'lastUpdateTimestamp': None,
2838
- 'initialMargin': None,
2839
- 'initialMarginPercentage': None,
2840
- 'maintenanceMargin': None,
2841
- 'maintenanceMarginPercentage': None,
2842
- 'entryPrice': None,
2843
- 'notional': None,
2844
- 'leverage': None,
2845
- 'unrealizedPnl': None,
2846
- 'contracts': None,
2847
- 'contractSize': self.parse_to_numeric(contractSize),
2848
- 'marginRatio': None,
2849
- 'liquidationPrice': None,
2850
- 'markPrice': None,
2851
- 'lastPrice': None,
2852
- 'collateral': None,
2853
- 'marginMode': 'cross',
2854
- 'marginType': None,
2855
- 'side': side,
2856
- 'percentage': None,
2857
- 'hedged': None,
2858
- 'stopLossPrice': None,
2859
- 'takeProfitPrice': None,
2860
- })
2861
-
2862
- def fetch_positions(self, symbols: Strings = None, params={}) -> List[Position]:
2863
- """
2864
- fetch all open positions
2865
-
2866
- https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/subaccount-info
2867
-
2868
- :param str[] [symbols]: list of unified market symbols
2869
- :param dict [params]: extra parameters specific to the exchange API endpoint
2870
- :param str [params.user]: user address, will default to self.walletAddress if not provided
2871
- :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
2872
- """
2873
- userAddress = None
2874
- userAddress, params = self.handle_public_address('fetchPositions', params)
2875
- request = {
2876
- 'type': 'subaccount_info',
2877
- 'subaccount': self.convert_address_to_sender(userAddress),
2878
- }
2879
- response = self.v1GatewayGetQuery(self.extend(request, params))
2880
- # the response is the same
2881
- data = self.safe_dict(response, 'data', {})
2882
- positions = self.safe_list(data, 'perp_balances', [])
2883
- symbols = self.market_symbols(symbols)
2884
- result = []
2885
- for i in range(0, len(positions)):
2886
- position = self.extend(self.parse_position(positions[i], None), params)
2887
- if position['contractSize'] == 0:
2888
- continue
2889
- result.append(position)
2890
- return self.filter_by_array_positions(result, 'symbol', symbols, False)
2891
-
2892
- def query_nonces(self):
2893
- request = {
2894
- 'type': 'nonces',
2895
- 'address': self.walletAddress,
2896
- }
2897
- response = self.v1GatewayGetQuery(request)
2898
- #
2899
- # {
2900
- # "status":"success",
2901
- # "data":{
2902
- # "tx_nonce": 0,
2903
- # "order_nonce": 1753048133299863552
2904
- # },
2905
- # "request_type": "query_nonces",
2906
- # }
2907
- #
2908
- return self.safe_dict(response, 'data', {})
2909
-
2910
- def withdraw(self, code: str, amount: float, address: str, tag: Str = None, params={}) -> Transaction:
2911
- """
2912
- make a withdrawal
2913
-
2914
- https://docs.vertexprotocol.com/developer-resources/api/withdrawing-on-chain
2915
-
2916
- :param str code: unified currency code
2917
- :param float amount: the amount to withdraw
2918
- :param str address: the address to withdraw to
2919
- :param str tag:
2920
- :param dict [params]: extra parameters specific to the exchange API endpoint
2921
- :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
2922
- """
2923
- self.check_required_credentials()
2924
- self.load_markets()
2925
- currency = self.currency(code)
2926
- contracts = self.query_contracts()
2927
- chainId = self.safe_string(contracts, 'chain_id')
2928
- verifyingContractAddress = self.safe_string(contracts, 'endpoint_addr')
2929
- nonces = self.query_nonces()
2930
- nonce = self.safe_number(nonces, 'tx_nonce')
2931
- withdraw = {
2932
- 'sender': self.convert_address_to_sender(self.walletAddress),
2933
- 'productId': self.parse_to_numeric(currency['id']),
2934
- 'amount': str(amount),
2935
- 'nonce': nonce,
2936
- }
2937
- request = {
2938
- 'withdraw_collateral': {
2939
- 'tx': {
2940
- 'sender': withdraw['sender'],
2941
- 'productId': withdraw['productId'],
2942
- 'amount': withdraw['amount'],
2943
- 'nonce': self.number_to_string(withdraw['nonce']),
2944
- },
2945
- 'signature': self.build_withdraw_sig(withdraw, chainId, verifyingContractAddress),
2946
- },
2947
- }
2948
- response = self.v1GatewayPostExecute(self.extend(request, params))
2949
- #
2950
- # {
2951
- # "status": "success",
2952
- # "signature": {signature},
2953
- # "request_type": "execute_withdraw_collateral"
2954
- # }
2955
- #
2956
- transaction = self.parse_transaction(response, currency)
2957
- return self.extend(transaction, {
2958
- 'amount': amount,
2959
- 'address': address,
2960
- })
2961
-
2962
- def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
2963
- #
2964
- # {
2965
- # "status": "success",
2966
- # "signature": {signature},
2967
- # "request_type": "execute_withdraw_collateral"
2968
- # }
2969
- #
2970
- code = None
2971
- if currency is not None:
2972
- code = currency['code']
2973
- return {
2974
- 'info': transaction,
2975
- 'id': None,
2976
- 'txid': None,
2977
- 'timestamp': None,
2978
- 'datetime': None,
2979
- 'addressFrom': None,
2980
- 'address': None,
2981
- 'addressTo': None,
2982
- 'tagFrom': None,
2983
- 'tag': None,
2984
- 'tagTo': None,
2985
- 'type': 'withdrawal',
2986
- 'amount': None,
2987
- 'currency': code,
2988
- 'status': self.parse_transaction_status(self.safe_string(transaction, 'status')),
2989
- 'updated': None,
2990
- 'network': None,
2991
- 'comment': None,
2992
- 'internal': None,
2993
- 'fee': None,
2994
- }
2995
-
2996
- def parse_transaction_status(self, status: Str):
2997
- statuses: dict = {
2998
- 'success': 'ok',
2999
- }
3000
- return self.safe_string(statuses, status, status)
3001
-
3002
- def handle_public_address(self, methodName: str, params: dict):
3003
- userAux = None
3004
- userAux, params = self.handle_option_and_params(params, methodName, 'user')
3005
- user = userAux
3006
- user, params = self.handle_option_and_params(params, methodName, 'address', userAux)
3007
- if (user is not None) and (user != ''):
3008
- return [user, params]
3009
- if (self.walletAddress is not None) and (self.walletAddress != ''):
3010
- return [self.walletAddress, params]
3011
- raise ArgumentsRequired(self.id + ' ' + methodName + '() requires a user parameter inside \'params\' or the wallet address set')
3012
-
3013
- def handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody):
3014
- if not response:
3015
- return None # fallback to default error handler
3016
- #
3017
- #
3018
- status = self.safe_string(response, 'status', '')
3019
- if status == 'failure':
3020
- message = self.safe_string(response, 'error')
3021
- feedback = self.id + ' ' + body
3022
- errorCode = self.safe_string(response, 'error_code')
3023
- self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
3024
- self.throw_broadly_matched_exception(self.exceptions['broad'], message, feedback)
3025
- raise ExchangeError(feedback)
3026
- return None
3027
-
3028
- def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
3029
- version = self.safe_string(api, 0)
3030
- type = self.safe_string(api, 1)
3031
- url = self.implode_hostname(self.urls['api'][version][type])
3032
- if version != 'v1' or type != 'archive':
3033
- url = url + '/' + path
3034
- if method == 'POST':
3035
- headers = {
3036
- 'Content-Type': 'application/json',
3037
- }
3038
- body = self.json(params)
3039
- else:
3040
- if params:
3041
- url += '?' + self.urlencode(params)
3042
- if path != 'execute':
3043
- # required encoding for public methods
3044
- if headers is not None:
3045
- headers['Accept-Encoding'] = 'gzip'
3046
- else:
3047
- headers = {
3048
- 'Accept-Encoding': 'gzip',
3049
- }
3050
- return {'url': url, 'method': method, 'body': body, 'headers': headers}