ccxt 4.4.97__py2.py3-none-any.whl → 4.4.99__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.
- ccxt/__init__.py +4 -1
- ccxt/abstract/bitget.py +6 -0
- ccxt/abstract/hibachi.py +26 -0
- ccxt/async_support/__init__.py +4 -1
- ccxt/async_support/base/exchange.py +1 -1
- ccxt/async_support/binance.py +7 -6
- ccxt/async_support/bitget.py +2032 -559
- ccxt/async_support/bybit.py +5 -1
- ccxt/async_support/coinex.py +64 -3
- ccxt/async_support/coinmetro.py +2 -3
- ccxt/async_support/cryptocom.py +2 -1
- ccxt/async_support/gate.py +1 -2
- ccxt/async_support/hibachi.py +2080 -0
- ccxt/async_support/ndax.py +8 -0
- ccxt/async_support/novadax.py +34 -0
- ccxt/async_support/okx.py +2 -0
- ccxt/base/decimal_to_precision.py +7 -9
- ccxt/base/errors.py +6 -6
- ccxt/base/exchange.py +1 -1
- ccxt/binance.py +7 -6
- ccxt/bitget.py +2032 -559
- ccxt/bybit.py +5 -1
- ccxt/coinex.py +64 -3
- ccxt/coinmetro.py +2 -3
- ccxt/cryptocom.py +2 -1
- ccxt/gate.py +1 -2
- ccxt/hibachi.py +2079 -0
- ccxt/ndax.py +8 -0
- ccxt/novadax.py +34 -0
- ccxt/okx.py +2 -0
- ccxt/pro/__init__.py +2 -1
- ccxt/pro/alpaca.py +2 -2
- ccxt/pro/apex.py +2 -2
- ccxt/pro/ascendex.py +2 -2
- ccxt/pro/binance.py +2 -4
- ccxt/pro/bitget.py +3 -3
- ccxt/pro/bithumb.py +2 -2
- ccxt/pro/bitmart.py +2 -2
- ccxt/pro/bitmex.py +3 -3
- ccxt/pro/bitstamp.py +3 -3
- ccxt/pro/bittrade.py +2 -2
- ccxt/pro/bitvavo.py +4 -2
- ccxt/pro/bybit.py +4 -4
- ccxt/pro/cex.py +3 -2
- ccxt/pro/coinbaseexchange.py +4 -4
- ccxt/pro/coinbaseinternational.py +2 -2
- ccxt/pro/coincatch.py +1 -1
- ccxt/pro/coinone.py +2 -2
- ccxt/pro/cryptocom.py +2 -2
- ccxt/pro/derive.py +2 -2
- ccxt/pro/gate.py +3 -3
- ccxt/pro/hollaex.py +2 -2
- ccxt/pro/htx.py +3 -3
- ccxt/pro/hyperliquid.py +2 -2
- ccxt/pro/kraken.py +2 -2
- ccxt/pro/krakenfutures.py +4 -3
- ccxt/pro/kucoin.py +3 -2
- ccxt/pro/kucoinfutures.py +3 -2
- ccxt/pro/modetrade.py +2 -2
- ccxt/pro/okcoin.py +2 -2
- ccxt/pro/okx.py +5 -5
- ccxt/pro/onetrading.py +2 -2
- ccxt/pro/p2b.py +2 -2
- ccxt/pro/paradex.py +2 -2
- ccxt/pro/poloniex.py +2 -2
- ccxt/pro/probit.py +2 -2
- ccxt/pro/vertex.py +2 -2
- ccxt/pro/whitebit.py +2 -2
- ccxt/pro/woo.py +2 -2
- ccxt/pro/woofipro.py +2 -2
- ccxt/test/tests_async.py +1 -1
- ccxt/test/tests_sync.py +1 -1
- {ccxt-4.4.97.dist-info → ccxt-4.4.99.dist-info}/METADATA +7 -6
- {ccxt-4.4.97.dist-info → ccxt-4.4.99.dist-info}/RECORD +77 -74
- {ccxt-4.4.97.dist-info → ccxt-4.4.99.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.4.97.dist-info → ccxt-4.4.99.dist-info}/WHEEL +0 -0
- {ccxt-4.4.97.dist-info → ccxt-4.4.99.dist-info}/top_level.txt +0 -0
ccxt/hibachi.py
ADDED
@@ -0,0 +1,2079 @@
|
|
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.hibachi import ImplicitAPI
|
8
|
+
import hashlib
|
9
|
+
from ccxt.base.types import Any, Balances, Currencies, Currency, DepositAddress, Int, LedgerEntry, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, FundingRate, Trade, TradingFees, Transaction
|
10
|
+
from typing import List
|
11
|
+
from ccxt.base.errors import ExchangeError
|
12
|
+
from ccxt.base.errors import BadRequest
|
13
|
+
from ccxt.base.errors import OrderNotFound
|
14
|
+
from ccxt.base.decimal_to_precision import TICK_SIZE
|
15
|
+
from ccxt.base.precise import Precise
|
16
|
+
|
17
|
+
|
18
|
+
class hibachi(Exchange, ImplicitAPI):
|
19
|
+
|
20
|
+
def describe(self) -> Any:
|
21
|
+
return self.deep_extend(super(hibachi, self).describe(), {
|
22
|
+
'id': 'hibachi',
|
23
|
+
'name': 'Hibachi',
|
24
|
+
'countries': ['US'],
|
25
|
+
'rateLimit': 100,
|
26
|
+
'userAgent': self.userAgents['chrome'],
|
27
|
+
'certified': False,
|
28
|
+
'pro': False,
|
29
|
+
'dex': True,
|
30
|
+
'has': {
|
31
|
+
'CORS': None,
|
32
|
+
'spot': False,
|
33
|
+
'margin': False,
|
34
|
+
'swap': True,
|
35
|
+
'future': False,
|
36
|
+
'option': False,
|
37
|
+
'addMargin': False,
|
38
|
+
'cancelAllOrders': True,
|
39
|
+
'cancelOrder': True,
|
40
|
+
'cancelOrders': True,
|
41
|
+
'cancelWithdraw': False,
|
42
|
+
'closeAllPositions': False,
|
43
|
+
'closePosition': False,
|
44
|
+
'createConvertTrade': False,
|
45
|
+
'createDepositAddress': False,
|
46
|
+
'createMarketBuyOrderWithCost': False,
|
47
|
+
'createMarketOrder': False,
|
48
|
+
'createMarketOrderWithCost': False,
|
49
|
+
'createMarketSellOrderWithCost': False,
|
50
|
+
'createOrder': True,
|
51
|
+
'createOrders': True,
|
52
|
+
'createOrderWithTakeProfitAndStopLoss': False,
|
53
|
+
'createReduceOnlyOrder': False,
|
54
|
+
'createStopLimitOrder': False,
|
55
|
+
'createStopLossOrder': False,
|
56
|
+
'createStopMarketOrder': False,
|
57
|
+
'createStopOrder': False,
|
58
|
+
'createTakeProfitOrder': False,
|
59
|
+
'createTrailingAmountOrder': False,
|
60
|
+
'createTrailingPercentOrder': False,
|
61
|
+
'createTriggerOrder': False,
|
62
|
+
'editOrder': True,
|
63
|
+
'editOrders': True,
|
64
|
+
'fetchAccounts': False,
|
65
|
+
'fetchBalance': True,
|
66
|
+
'fetchCanceledOrders': False,
|
67
|
+
'fetchClosedOrder': False,
|
68
|
+
'fetchClosedOrders': False,
|
69
|
+
'fetchConvertCurrencies': False,
|
70
|
+
'fetchConvertQuote': False,
|
71
|
+
'fetchCurrencies': True,
|
72
|
+
'fetchDepositAddress': True,
|
73
|
+
'fetchDeposits': True,
|
74
|
+
'fetchDepositsWithdrawals': False,
|
75
|
+
'fetchFundingHistory': False,
|
76
|
+
'fetchFundingInterval': False,
|
77
|
+
'fetchFundingIntervals': False,
|
78
|
+
'fetchFundingRate': True,
|
79
|
+
'fetchFundingRateHistory': True,
|
80
|
+
'fetchFundingRates': False,
|
81
|
+
'fetchIndexOHLCV': False,
|
82
|
+
'fetchLedger': True,
|
83
|
+
'fetchLeverage': False,
|
84
|
+
'fetchMarginAdjustmentHistory': False,
|
85
|
+
'fetchMarginMode': False,
|
86
|
+
'fetchMarkets': True,
|
87
|
+
'fetchMyTrades': True,
|
88
|
+
'fetchOHLCV': True,
|
89
|
+
'fetchOpenInterest': True,
|
90
|
+
'fetchOpenInterestHistory': False,
|
91
|
+
'fetchOpenOrder': False,
|
92
|
+
'fetchOpenOrders': True,
|
93
|
+
'fetchOrder': True,
|
94
|
+
'fetchOrderBook': True,
|
95
|
+
'fetchOrders': False,
|
96
|
+
'fetchOrderTrades': False,
|
97
|
+
'fetchPosition': False,
|
98
|
+
'fetchPositionMode': False,
|
99
|
+
'fetchPositions': True,
|
100
|
+
'fetchPremiumIndexOHLCV': False,
|
101
|
+
'fetchStatus': False,
|
102
|
+
'fetchTicker': True,
|
103
|
+
'fetchTickers': False,
|
104
|
+
'fetchTime': True,
|
105
|
+
'fetchTrades': True,
|
106
|
+
'fetchTradingFee': False,
|
107
|
+
'fetchTradingFees': True,
|
108
|
+
'fetchTradingLimits': False,
|
109
|
+
'fetchTransactions': 'emulated',
|
110
|
+
'fetchTransfers': False,
|
111
|
+
'fetchWithdrawals': True,
|
112
|
+
'reduceMargin': False,
|
113
|
+
'setLeverage': False,
|
114
|
+
'setMargin': False,
|
115
|
+
'setPositionMode': False,
|
116
|
+
'transfer': False,
|
117
|
+
'withdraw': True,
|
118
|
+
},
|
119
|
+
'timeframes': {
|
120
|
+
'1m': '1min',
|
121
|
+
'5m': '5min',
|
122
|
+
'15m': '15min',
|
123
|
+
'1h': '1h',
|
124
|
+
'4h': '4h',
|
125
|
+
'1d': '1d',
|
126
|
+
'1w': '1w',
|
127
|
+
},
|
128
|
+
'urls': {
|
129
|
+
'logo': 'https://github.com/user-attachments/assets/7301bbb1-4f27-4167-8a55-75f74b14e973',
|
130
|
+
'api': {
|
131
|
+
'public': 'https://data-api.hibachi.xyz',
|
132
|
+
'private': 'https://api.hibachi.xyz',
|
133
|
+
},
|
134
|
+
'www': 'https://www.hibachi.xyz/',
|
135
|
+
'referral': {
|
136
|
+
'url': 'hibachi.xyz/r/ZBL2YFWIHU',
|
137
|
+
},
|
138
|
+
},
|
139
|
+
'api': {
|
140
|
+
'public': {
|
141
|
+
'get': {
|
142
|
+
'market/exchange-info': 1,
|
143
|
+
'market/data/trades': 1,
|
144
|
+
'market/data/prices': 1,
|
145
|
+
'market/data/stats': 1,
|
146
|
+
'market/data/klines': 1,
|
147
|
+
'market/data/orderbook': 1,
|
148
|
+
'market/data/open-interest': 1,
|
149
|
+
'market/data/funding-rates': 1,
|
150
|
+
'exchange/utc-timestamp': 1,
|
151
|
+
},
|
152
|
+
},
|
153
|
+
'private': {
|
154
|
+
'get': {
|
155
|
+
'capital/deposit-info': 1,
|
156
|
+
'capital/history': 1,
|
157
|
+
'trade/account/trading_history': 1,
|
158
|
+
'trade/account/info': 1,
|
159
|
+
'trade/order': 1,
|
160
|
+
'trade/account/trades': 1,
|
161
|
+
'trade/orders': 1,
|
162
|
+
},
|
163
|
+
'put': {
|
164
|
+
'trade/order': 1,
|
165
|
+
},
|
166
|
+
'delete': {
|
167
|
+
'trade/order': 1,
|
168
|
+
'trade/orders': 1,
|
169
|
+
},
|
170
|
+
'post': {
|
171
|
+
'trade/order': 1,
|
172
|
+
'trade/orders': 1,
|
173
|
+
'capital/withdraw': 1,
|
174
|
+
},
|
175
|
+
},
|
176
|
+
},
|
177
|
+
'requiredCredentials': {
|
178
|
+
'apiKey': True,
|
179
|
+
'secret': False,
|
180
|
+
'accountId': True,
|
181
|
+
'privateKey': True,
|
182
|
+
},
|
183
|
+
'fees': {
|
184
|
+
'trading': {
|
185
|
+
'tierBased': False,
|
186
|
+
'percentage': True,
|
187
|
+
'maker': self.parse_number('0.00015'),
|
188
|
+
'taker': self.parse_number('0.00045'),
|
189
|
+
},
|
190
|
+
},
|
191
|
+
'options': {
|
192
|
+
},
|
193
|
+
'features': {
|
194
|
+
'default': {
|
195
|
+
'sandbox': False,
|
196
|
+
'createOrder': {
|
197
|
+
'marginMode': False,
|
198
|
+
'triggerPrice': True,
|
199
|
+
'triggerPriceType': None,
|
200
|
+
'triggerDirection': None,
|
201
|
+
'stopLossPrice': False,
|
202
|
+
'takeProfitPrice': False,
|
203
|
+
'attachedStopLossTakeProfit': None,
|
204
|
+
'timeInForce': {
|
205
|
+
'IOC': True,
|
206
|
+
'FOK': False,
|
207
|
+
'PO': True,
|
208
|
+
'GTD': False,
|
209
|
+
},
|
210
|
+
'hedged': False,
|
211
|
+
'trailing': False,
|
212
|
+
'leverage': False,
|
213
|
+
'marketBuyByCost': False,
|
214
|
+
'marketBuyRequiresPrice': False,
|
215
|
+
'selfTradePrevention': False,
|
216
|
+
'iceberg': False,
|
217
|
+
},
|
218
|
+
'createOrders': None,
|
219
|
+
'fetchMyTrades': {
|
220
|
+
'marginMode': False,
|
221
|
+
'limit': None,
|
222
|
+
'daysBack': None,
|
223
|
+
'untilDays': None,
|
224
|
+
'symbolRequired': False,
|
225
|
+
},
|
226
|
+
'fetchOrder': {
|
227
|
+
'marginMode': False,
|
228
|
+
'trigger': False,
|
229
|
+
'trailing': False,
|
230
|
+
'symbolRequired': False,
|
231
|
+
},
|
232
|
+
'fetchOpenOrders': {
|
233
|
+
'marginMode': False,
|
234
|
+
'limit': None,
|
235
|
+
'trigger': False,
|
236
|
+
'trailing': False,
|
237
|
+
'symbolRequired': False,
|
238
|
+
},
|
239
|
+
'fetchOrders': None,
|
240
|
+
'fetchClosedOrders': None,
|
241
|
+
'fetchOHLCV': {
|
242
|
+
'limit': None,
|
243
|
+
},
|
244
|
+
},
|
245
|
+
'swap': {
|
246
|
+
'linear': {
|
247
|
+
'extends': 'default',
|
248
|
+
},
|
249
|
+
'inverse': None,
|
250
|
+
},
|
251
|
+
'future': {
|
252
|
+
'linear': {
|
253
|
+
'extends': 'default',
|
254
|
+
},
|
255
|
+
'inverse': None,
|
256
|
+
},
|
257
|
+
},
|
258
|
+
'commonCurrencies': {},
|
259
|
+
'exceptions': {
|
260
|
+
'exact': {
|
261
|
+
'2': BadRequest, # {"errorCode":2,"message":"Invalid signature: Failed to verify signature"}
|
262
|
+
'3': OrderNotFound, # {"errorCode":3,"message":"Not found: order ID 33","status":"failed"}
|
263
|
+
'4': BadRequest, # {"errorCode":4,"message":"Missing accountId","status":"failed"}
|
264
|
+
},
|
265
|
+
'broad': {
|
266
|
+
},
|
267
|
+
},
|
268
|
+
'precisionMode': TICK_SIZE,
|
269
|
+
})
|
270
|
+
|
271
|
+
def get_account_id(self):
|
272
|
+
self.check_required_credentials()
|
273
|
+
id = self.parse_to_int(self.accountId)
|
274
|
+
return id
|
275
|
+
|
276
|
+
def parse_market(self, market: dict) -> Market:
|
277
|
+
marketId = self.safe_string(market, 'symbol')
|
278
|
+
numericId = self.safe_number(market, 'id')
|
279
|
+
marketType = 'swap'
|
280
|
+
baseId = self.safe_string(market, 'underlyingSymbol')
|
281
|
+
quoteId = self.safe_string(market, 'settlementSymbol')
|
282
|
+
base = self.safe_currency_code(baseId)
|
283
|
+
quote = self.safe_currency_code(quoteId)
|
284
|
+
settleId: Str = self.safe_string(market, 'settlementSymbol')
|
285
|
+
settle: Str = self.safe_currency_code(settleId)
|
286
|
+
symbol = base + '/' + quote + ':' + settle
|
287
|
+
created = self.safe_integer_product(market, 'marketCreationTimestamp', 1000)
|
288
|
+
return {
|
289
|
+
'id': marketId,
|
290
|
+
'numericId': numericId,
|
291
|
+
'symbol': symbol,
|
292
|
+
'base': base,
|
293
|
+
'quote': quote,
|
294
|
+
'settle': settle,
|
295
|
+
'baseId': baseId,
|
296
|
+
'quoteId': quoteId,
|
297
|
+
'settleId': settleId,
|
298
|
+
'type': marketType,
|
299
|
+
'spot': False,
|
300
|
+
'margin': False,
|
301
|
+
'swap': True,
|
302
|
+
'future': False,
|
303
|
+
'option': False,
|
304
|
+
'active': self.safe_string(market, 'status') == 'LIVE',
|
305
|
+
'contract': True,
|
306
|
+
'linear': True,
|
307
|
+
'inverse': False,
|
308
|
+
'contractSize': self.parse_number('1'),
|
309
|
+
'expiry': None,
|
310
|
+
'expiryDatetime': None,
|
311
|
+
'strike': None,
|
312
|
+
'optionType': None,
|
313
|
+
'precision': {
|
314
|
+
'amount': self.parse_number(self.parse_precision(self.safe_string(market, 'underlyingDecimals'))),
|
315
|
+
'price': self.parse_number(self.safe_list(market, 'orderbookGranularities')[0]) / 10000.0,
|
316
|
+
},
|
317
|
+
'limits': {
|
318
|
+
'leverage': {
|
319
|
+
'min': None,
|
320
|
+
'max': None,
|
321
|
+
},
|
322
|
+
'amount': {
|
323
|
+
'min': None,
|
324
|
+
'max': None,
|
325
|
+
},
|
326
|
+
'price': {
|
327
|
+
'min': None,
|
328
|
+
'max': None,
|
329
|
+
},
|
330
|
+
'cost': {
|
331
|
+
'min': self.safe_number(market, 'minNotional'),
|
332
|
+
'max': None,
|
333
|
+
},
|
334
|
+
},
|
335
|
+
'created': created,
|
336
|
+
'info': market,
|
337
|
+
}
|
338
|
+
|
339
|
+
def fetch_markets(self, params={}) -> List[Market]:
|
340
|
+
"""
|
341
|
+
retrieves data on all markets for hibachi
|
342
|
+
|
343
|
+
https://api-doc.hibachi.xyz/#183981da-8df5-40a0-a155-da15015dd536
|
344
|
+
|
345
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
346
|
+
:returns dict[]: an array of objects representing market data
|
347
|
+
"""
|
348
|
+
response = self.publicGetMarketExchangeInfo(params)
|
349
|
+
# {
|
350
|
+
# "displayName": "ETH/USDT Perps",
|
351
|
+
# "id": 1,
|
352
|
+
# "maintenanceFactorForPositions": "0.030000",
|
353
|
+
# "marketCloseTimestamp": null,
|
354
|
+
# "marketOpenTimestamp": null,
|
355
|
+
# "minNotional": "1",
|
356
|
+
# "minOrderSize": "0.000000001",
|
357
|
+
# "orderbookGranularities": [
|
358
|
+
# "0.01",
|
359
|
+
# "0.1",
|
360
|
+
# "1",
|
361
|
+
# "10"
|
362
|
+
# ],
|
363
|
+
# "riskFactorForOrders": "0.066667",
|
364
|
+
# "riskFactorForPositions": "0.030000",
|
365
|
+
# "settlementDecimals": 6,
|
366
|
+
# "settlementSymbol": "USDT",
|
367
|
+
# "status": "LIVE",
|
368
|
+
# "stepSize": "0.000000001",
|
369
|
+
# "symbol": "ETH/USDT-P",
|
370
|
+
# "tickSize": "0.000001",
|
371
|
+
# "underlyingDecimals": 9,
|
372
|
+
# "underlyingSymbol": "ETH"
|
373
|
+
# },
|
374
|
+
rows = self.safe_list(response, 'futureContracts')
|
375
|
+
return self.parse_markets(rows)
|
376
|
+
|
377
|
+
def fetch_currencies(self, params={}) -> Currencies:
|
378
|
+
"""
|
379
|
+
fetches all available currencies on an exchange
|
380
|
+
|
381
|
+
https://api-doc.hibachi.xyz/#183981da-8df5-40a0-a155-da15015dd536
|
382
|
+
|
383
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
384
|
+
:returns dict: an associative dictionary of currencies
|
385
|
+
"""
|
386
|
+
# Hibachi only supports USDT on Arbitrum at self time
|
387
|
+
# We don't have an API endpoint to expose self information yet
|
388
|
+
result: dict = {}
|
389
|
+
networks: dict = {}
|
390
|
+
networkId = 'ARBITRUM'
|
391
|
+
networks[networkId] = {
|
392
|
+
'id': networkId,
|
393
|
+
'network': networkId,
|
394
|
+
'limits': {
|
395
|
+
'withdraw': {
|
396
|
+
'min': None,
|
397
|
+
'max': None,
|
398
|
+
},
|
399
|
+
'deposit': {
|
400
|
+
'min': None,
|
401
|
+
'max': None,
|
402
|
+
},
|
403
|
+
},
|
404
|
+
'active': None,
|
405
|
+
'deposit': None,
|
406
|
+
'withdraw': None,
|
407
|
+
'info': {},
|
408
|
+
}
|
409
|
+
code = self.safe_currency_code('USDT')
|
410
|
+
result[code] = self.safe_currency_structure({
|
411
|
+
'id': 'USDT',
|
412
|
+
'name': 'USDT',
|
413
|
+
'type': 'fiat',
|
414
|
+
'code': code,
|
415
|
+
'precision': self.parse_number('0.000001'),
|
416
|
+
'active': True,
|
417
|
+
'fee': None,
|
418
|
+
'networks': networks,
|
419
|
+
'deposit': True,
|
420
|
+
'withdraw': True,
|
421
|
+
'limits': {
|
422
|
+
'deposit': {
|
423
|
+
'min': None,
|
424
|
+
'max': None,
|
425
|
+
},
|
426
|
+
'withdraw': {
|
427
|
+
'min': None,
|
428
|
+
'max': None,
|
429
|
+
},
|
430
|
+
},
|
431
|
+
'info': {},
|
432
|
+
})
|
433
|
+
return result
|
434
|
+
|
435
|
+
def parse_balance(self, response) -> Balances:
|
436
|
+
result: dict = {
|
437
|
+
'info': response,
|
438
|
+
}
|
439
|
+
# Hibachi only supports USDT on Arbitrum at self time
|
440
|
+
code = self.safe_currency_code('USDT')
|
441
|
+
account = self.account()
|
442
|
+
account['total'] = self.safe_string(response, 'balance')
|
443
|
+
account['free'] = self.safe_string(response, 'maximalWithdraw')
|
444
|
+
result[code] = account
|
445
|
+
return self.safe_balance(result)
|
446
|
+
|
447
|
+
def fetch_balance(self, params={}) -> Balances:
|
448
|
+
"""
|
449
|
+
query for balance and get the amount of funds available for trading or funds locked in orders
|
450
|
+
|
451
|
+
https://api-doc.hibachi.xyz/#69aafedb-8274-4e21-bbaf-91dace8b8f31
|
452
|
+
|
453
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
454
|
+
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
|
455
|
+
"""
|
456
|
+
request: dict = {
|
457
|
+
'accountId': self.get_account_id(),
|
458
|
+
}
|
459
|
+
response = self.privateGetTradeAccountInfo(self.extend(request, params))
|
460
|
+
#
|
461
|
+
# {
|
462
|
+
# assets: [{quantity: '3.000000', symbol: 'USDT'}],
|
463
|
+
# balance: '3.000000',
|
464
|
+
# maximalWithdraw: '3.000000',
|
465
|
+
# numFreeTransfersRemaining: '100',
|
466
|
+
# positions: [],
|
467
|
+
# totalOrderNotional: '0.000000',
|
468
|
+
# totalPositionNotional: '0.000000',
|
469
|
+
# totalUnrealizedFundingPnl: '0.000000',
|
470
|
+
# totalUnrealizedPnl: '0.000000',
|
471
|
+
# totalUnrealizedTradingPnl: '0.000000',
|
472
|
+
# tradeMakerFeeRate: '0.00000000',
|
473
|
+
# tradeTakerFeeRate: '0.00020000'
|
474
|
+
# }
|
475
|
+
#
|
476
|
+
return self.parse_balance(response)
|
477
|
+
|
478
|
+
def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
|
479
|
+
prices = self.safe_dict(ticker, 'prices')
|
480
|
+
stats = self.safe_dict(ticker, 'stats')
|
481
|
+
bid = self.safe_number(prices, 'bidPrice')
|
482
|
+
ask = self.safe_number(prices, 'askPrice')
|
483
|
+
last = self.safe_number(prices, 'tradePrice')
|
484
|
+
high = self.safe_number(stats, 'high24h')
|
485
|
+
low = self.safe_number(stats, 'low24h')
|
486
|
+
volume = self.safe_number(stats, 'volume24h')
|
487
|
+
return self.safe_ticker({
|
488
|
+
'symbol': self.safe_symbol(None, market),
|
489
|
+
'timestamp': None,
|
490
|
+
'datetime': None,
|
491
|
+
'bid': bid,
|
492
|
+
'ask': ask,
|
493
|
+
'last': last,
|
494
|
+
'high': high,
|
495
|
+
'low': low,
|
496
|
+
'bidVolume': None,
|
497
|
+
'askVolume': None,
|
498
|
+
'vwap': None,
|
499
|
+
'open': None,
|
500
|
+
'close': last,
|
501
|
+
'previousClose': None,
|
502
|
+
'change': None,
|
503
|
+
'percentage': None,
|
504
|
+
'average': None,
|
505
|
+
'baseVolume': None,
|
506
|
+
'quoteVolume': volume,
|
507
|
+
'info': ticker,
|
508
|
+
}, market)
|
509
|
+
|
510
|
+
def parse_trade(self, trade: dict, market: Market = None) -> Trade:
|
511
|
+
# public fetchTrades:
|
512
|
+
# {
|
513
|
+
# "price": "3512.431902",
|
514
|
+
# "quantity": "1.414780098",
|
515
|
+
# "takerSide": "Buy",
|
516
|
+
# "timestamp": 1712692147
|
517
|
+
# }
|
518
|
+
#
|
519
|
+
# private fetchMyTrades:
|
520
|
+
# {
|
521
|
+
# "askAccountId": 221,
|
522
|
+
# "askOrderId": 589168494921909200,
|
523
|
+
# "bidAccountId": 132,
|
524
|
+
# "bidOrderId": 589168494829895700,
|
525
|
+
# "fee": "0.000477",
|
526
|
+
# "id": 199511136,
|
527
|
+
# "orderType": "MARKET",
|
528
|
+
# "price": "119257.90000",
|
529
|
+
# "quantity": "0.0000200000",
|
530
|
+
# "realizedPnl": "-0.000352",
|
531
|
+
# "side": "Sell",
|
532
|
+
# "symbol": "BTC/USDT-P",
|
533
|
+
# "timestamp": 1752543391
|
534
|
+
# }
|
535
|
+
marketId = self.safe_string(trade, 'symbol')
|
536
|
+
market = self.safe_market(marketId, market)
|
537
|
+
symbol = market['symbol']
|
538
|
+
id = self.safe_string(trade, 'id')
|
539
|
+
price = self.safe_string(trade, 'price')
|
540
|
+
amount = self.safe_string(trade, 'quantity')
|
541
|
+
timestamp = self.safe_integer_product(trade, 'timestamp', 1000)
|
542
|
+
cost = Precise.string_mul(price, amount)
|
543
|
+
side = None
|
544
|
+
fee = None
|
545
|
+
orderType = None
|
546
|
+
orderId = None
|
547
|
+
takerOrMaker = None
|
548
|
+
if id is None:
|
549
|
+
# public trades
|
550
|
+
side = self.safe_string_lower(trade, 'takerSide')
|
551
|
+
takerOrMaker = 'taker'
|
552
|
+
else:
|
553
|
+
# private trades
|
554
|
+
side = self.safe_string_lower(trade, 'side')
|
555
|
+
fee = {'cost': self.safe_string(trade, 'fee'), 'currency': 'USDT'}
|
556
|
+
orderType = self.safe_string_lower(trade, 'orderType')
|
557
|
+
if side == 'buy':
|
558
|
+
orderId = self.safe_string(trade, 'bidOrderId')
|
559
|
+
else:
|
560
|
+
orderId = self.safe_string(trade, 'askOrderId')
|
561
|
+
return self.safe_trade({
|
562
|
+
'id': id,
|
563
|
+
'timestamp': timestamp,
|
564
|
+
'datetime': self.iso8601(timestamp),
|
565
|
+
'symbol': symbol,
|
566
|
+
'side': side,
|
567
|
+
'price': price,
|
568
|
+
'amount': amount,
|
569
|
+
'cost': cost,
|
570
|
+
'order': orderId,
|
571
|
+
'takerOrMaker': takerOrMaker,
|
572
|
+
'type': orderType,
|
573
|
+
'fee': fee,
|
574
|
+
'info': trade,
|
575
|
+
}, market)
|
576
|
+
|
577
|
+
def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
|
578
|
+
"""
|
579
|
+
get the list of most recent trades for a particular symbol
|
580
|
+
|
581
|
+
https://api-doc.hibachi.xyz/#86a53bc1-d3bb-4b93-8a11-7034d4698caa
|
582
|
+
|
583
|
+
:param str symbol: unified market symbol
|
584
|
+
:param int [since]: timestamp in ms of the earliest trade to fetch
|
585
|
+
:param int [limit]: the maximum amount of trades to fetch(maximum value is 100)
|
586
|
+
:param dict [params]: extra parameters specific to the hibachi api endpoint
|
587
|
+
:returns dict[]: a list of recent [trade structures]
|
588
|
+
"""
|
589
|
+
self.load_markets()
|
590
|
+
market = self.market(symbol)
|
591
|
+
request = {
|
592
|
+
'symbol': market['id'],
|
593
|
+
}
|
594
|
+
response = self.publicGetMarketDataTrades(self.extend(request, params))
|
595
|
+
#
|
596
|
+
# {
|
597
|
+
# "trades": [
|
598
|
+
# {
|
599
|
+
# "price": "111091.38352",
|
600
|
+
# "quantity": "0.0090090093",
|
601
|
+
# "takerSide": "Buy",
|
602
|
+
# "timestamp": 1752095479
|
603
|
+
# },
|
604
|
+
# ]
|
605
|
+
# }
|
606
|
+
#
|
607
|
+
trades = self.safe_list(response, 'trades', [])
|
608
|
+
return self.parse_trades(trades, market)
|
609
|
+
|
610
|
+
def fetch_ticker(self, symbol: Str, params={}) -> Ticker:
|
611
|
+
"""
|
612
|
+
|
613
|
+
https://api-doc.hibachi.xyz/#4abb30c4-e5c7-4b0f-9ade-790111dbfa47
|
614
|
+
|
615
|
+
fetches a price ticker and the related information for the past 24h
|
616
|
+
:param str symbol: unified symbol of the market
|
617
|
+
:param dict [params]: extra parameters specific to the hibachi api endpoint
|
618
|
+
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
|
619
|
+
"""
|
620
|
+
self.load_markets()
|
621
|
+
market = self.market(symbol)
|
622
|
+
request: dict = {
|
623
|
+
'symbol': market['id'],
|
624
|
+
}
|
625
|
+
rawPromises = [
|
626
|
+
self.publicGetMarketDataPrices(self.extend(request, params)),
|
627
|
+
self.publicGetMarketDataStats(self.extend(request, params)),
|
628
|
+
]
|
629
|
+
promises = rawPromises
|
630
|
+
pricesResponse = promises[0]
|
631
|
+
# {
|
632
|
+
# "askPrice": "3514.650296",
|
633
|
+
# "bidPrice": "3513.596112",
|
634
|
+
# "fundingRateEstimation": {
|
635
|
+
# "estimatedFundingRate": "0.000001",
|
636
|
+
# "nextFundingTimestamp": 1712707200
|
637
|
+
# },
|
638
|
+
# "markPrice": "3514.288858",
|
639
|
+
# "spotPrice": "3514.715000",
|
640
|
+
# "symbol": "ETH/USDT-P",
|
641
|
+
# "tradePrice": "2372.746570"
|
642
|
+
# }
|
643
|
+
statsResponse = promises[1]
|
644
|
+
# {
|
645
|
+
# "high24h": "3819.507827",
|
646
|
+
# "low24h": "3754.474162",
|
647
|
+
# "symbol": "ETH/USDT-P",
|
648
|
+
# "volume24h": "23554.858590416"
|
649
|
+
# }
|
650
|
+
ticker = {
|
651
|
+
'prices': pricesResponse,
|
652
|
+
'stats': statsResponse,
|
653
|
+
}
|
654
|
+
return self.parse_ticker(ticker, market)
|
655
|
+
|
656
|
+
def parse_order_status(self, status: str) -> str:
|
657
|
+
statuses: dict = {
|
658
|
+
'PENDING': 'open',
|
659
|
+
'CHILD_PENDING': 'open',
|
660
|
+
'SCHEDULED_TWAP': 'open',
|
661
|
+
'PLACED': 'open',
|
662
|
+
'PARTIALLY_FILLED': 'open',
|
663
|
+
'FILLED': 'closed',
|
664
|
+
'CANCELLED': 'canceled',
|
665
|
+
'REJECTED': 'rejected',
|
666
|
+
}
|
667
|
+
return self.safe_string(statuses, status, status)
|
668
|
+
|
669
|
+
def parse_order(self, order: dict, market: Market = None) -> Order:
|
670
|
+
marketId = self.safe_string(order, 'symbol')
|
671
|
+
market = self.safe_market(marketId, market)
|
672
|
+
status = self.safe_string(order, 'status')
|
673
|
+
type = self.safe_string_lower(order, 'orderType')
|
674
|
+
price = self.safe_string(order, 'price')
|
675
|
+
rawSide = self.safe_string(order, 'side')
|
676
|
+
side = None
|
677
|
+
if rawSide == 'BID':
|
678
|
+
side = 'buy'
|
679
|
+
elif rawSide == 'ASK':
|
680
|
+
side = 'sell'
|
681
|
+
amount = self.safe_string(order, 'totalQuantity')
|
682
|
+
remaining = self.safe_string(order, 'availableQuantity')
|
683
|
+
totalQuantity = self.safe_string(order, 'totalQuantity')
|
684
|
+
availableQuantity = self.safe_string(order, 'availableQuantity')
|
685
|
+
filled = None
|
686
|
+
if totalQuantity is not None and availableQuantity is not None:
|
687
|
+
filled = Precise.string_sub(totalQuantity, availableQuantity)
|
688
|
+
timeInForce = 'GTC'
|
689
|
+
orderFlags = self.safe_value(order, 'orderFlags')
|
690
|
+
postOnly = False
|
691
|
+
reduceOnly = False
|
692
|
+
if orderFlags == 'POST_ONLY':
|
693
|
+
timeInForce = 'PO'
|
694
|
+
postOnly = True
|
695
|
+
elif orderFlags == 'IOC':
|
696
|
+
timeInForce = 'IOC'
|
697
|
+
elif orderFlags == 'REDUCE_ONLY':
|
698
|
+
reduceOnly = True
|
699
|
+
return self.safe_order({
|
700
|
+
'info': order,
|
701
|
+
'id': self.safe_string(order, 'orderId'),
|
702
|
+
'clientOrderId': None,
|
703
|
+
'datetime': None,
|
704
|
+
'timestamp': None,
|
705
|
+
'lastTradeTimestamp': None,
|
706
|
+
'lastUpdateTimestamp': None,
|
707
|
+
'status': self.parse_order_status(status),
|
708
|
+
'symbol': market['symbol'],
|
709
|
+
'type': type,
|
710
|
+
'timeInForce': timeInForce,
|
711
|
+
'side': side,
|
712
|
+
'price': price,
|
713
|
+
'average': None,
|
714
|
+
'amount': amount,
|
715
|
+
'filled': filled,
|
716
|
+
'remaining': remaining,
|
717
|
+
'cost': None,
|
718
|
+
'trades': None,
|
719
|
+
'fee': None,
|
720
|
+
'reduceOnly': reduceOnly,
|
721
|
+
'postOnly': postOnly,
|
722
|
+
'triggerPrice': self.safe_number(order, 'triggerPrice'),
|
723
|
+
}, market)
|
724
|
+
|
725
|
+
def fetch_order(self, id: str, symbol: Str = None, params={}) -> Order:
|
726
|
+
"""
|
727
|
+
fetches information on an order made by the user
|
728
|
+
|
729
|
+
https://api-doc.hibachi.xyz/#096a8854-b918-4de8-8731-b2a28d26b96d
|
730
|
+
|
731
|
+
:param str id: the order id
|
732
|
+
:param str symbol: unified symbol of the market the order was made in
|
733
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
734
|
+
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
735
|
+
"""
|
736
|
+
self.load_markets()
|
737
|
+
market = None
|
738
|
+
if symbol is not None:
|
739
|
+
market = self.market(symbol)
|
740
|
+
request: dict = {
|
741
|
+
'orderId': id,
|
742
|
+
'accountId': self.get_account_id(),
|
743
|
+
}
|
744
|
+
response = self.privateGetTradeOrder(self.extend(request, params))
|
745
|
+
return self.parse_order(response, market)
|
746
|
+
|
747
|
+
def fetch_trading_fees(self, params={}) -> TradingFees:
|
748
|
+
"""
|
749
|
+
fetch the trading fee
|
750
|
+
@param params extra parameters
|
751
|
+
:returns dict: a map of market symbols to `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
|
752
|
+
"""
|
753
|
+
self.load_markets()
|
754
|
+
request: dict = {
|
755
|
+
'accountId': self.get_account_id(),
|
756
|
+
}
|
757
|
+
response = self.privateGetTradeAccountInfo(self.extend(request, params))
|
758
|
+
# {
|
759
|
+
# "tradeMakerFeeRate": "0.00000000",
|
760
|
+
# "tradeTakerFeeRate": "0.00020000"
|
761
|
+
# },
|
762
|
+
makerFeeRate = self.safe_number(response, 'tradeMakerFeeRate')
|
763
|
+
takerFeeRate = self.safe_number(response, 'tradeTakerFeeRate')
|
764
|
+
result: dict = {}
|
765
|
+
for i in range(0, len(self.symbols)):
|
766
|
+
symbol = self.symbols[i]
|
767
|
+
result[symbol] = {
|
768
|
+
'info': response,
|
769
|
+
'symbol': symbol,
|
770
|
+
'maker': makerFeeRate,
|
771
|
+
'taker': takerFeeRate,
|
772
|
+
'percentage': True,
|
773
|
+
}
|
774
|
+
return result
|
775
|
+
|
776
|
+
def order_message(self, market, nonce: float, feeRate: float, type: OrderType, side: OrderSide, amount: float, price: Num = None):
|
777
|
+
sideInternal = 0
|
778
|
+
if side == 'sell':
|
779
|
+
sideInternal = 0
|
780
|
+
elif side == 'buy':
|
781
|
+
sideInternal = 1
|
782
|
+
# Converting them to internal representation:
|
783
|
+
# - Quantity: Internal = External * (10^underlyingDecimals)
|
784
|
+
# - Price: Internal = External * (2^32) * (10^(settlementDecimals-underlyingDecimals))
|
785
|
+
# - FeeRate: Internal = External * (10^8)
|
786
|
+
amountStr = self.amount_to_precision(self.safe_string(market, 'symbol'), amount)
|
787
|
+
feeRateStr = self.number_to_string(feeRate)
|
788
|
+
info = self.safe_dict(market, 'info')
|
789
|
+
underlying = '1e' + self.safe_string(info, 'underlyingDecimals')
|
790
|
+
settlement = '1e' + self.safe_string(info, 'settlementDecimals')
|
791
|
+
one = '1'
|
792
|
+
feeRateFactor = '100000000' # 10^8
|
793
|
+
priceFactor = '4294967296' # 2^32
|
794
|
+
quantityInternal = Precise.string_div(Precise.string_mul(amountStr, underlying), one, 0)
|
795
|
+
feeRateInternal = Precise.string_div(Precise.string_mul(feeRateStr, feeRateFactor), one, 0)
|
796
|
+
# Encoding
|
797
|
+
nonce16 = self.int_to_base16(nonce)
|
798
|
+
noncePadded = nonce16.rjust(16, '0')
|
799
|
+
encodedNonce = self.base16_to_binary(noncePadded)
|
800
|
+
numericId = self.int_to_base16(self.safe_integer(market, 'numericId'))
|
801
|
+
numericIdPadded = numericId.rjust(8, '0')
|
802
|
+
encodedMarketId = self.base16_to_binary(numericIdPadded)
|
803
|
+
quantity16 = self.int_to_base16(self.parse_to_int(quantityInternal))
|
804
|
+
quantityPadded = quantity16.rjust(16, '0')
|
805
|
+
encodedQuantity = self.base16_to_binary(quantityPadded)
|
806
|
+
sideInternal16 = self.int_to_base16(sideInternal)
|
807
|
+
sidePadded = sideInternal16.rjust(8, '0')
|
808
|
+
encodedSide = self.base16_to_binary(sidePadded)
|
809
|
+
feeRateInternal16 = self.int_to_base16(self.parse_to_int(feeRateInternal))
|
810
|
+
feeRatePadded = feeRateInternal16.rjust(16, '0')
|
811
|
+
encodedFeeRate = self.base16_to_binary(feeRatePadded)
|
812
|
+
encodedPrice = self.binary_concat()
|
813
|
+
if type == 'limit':
|
814
|
+
priceStr = self.price_to_precision(self.safe_string(market, 'symbol'), price)
|
815
|
+
priceInternal = Precise.string_div(Precise.string_div(Precise.string_mul(Precise.string_mul(priceStr, priceFactor), settlement), underlying), one, 0)
|
816
|
+
price16 = self.int_to_base16(self.parse_to_int(priceInternal))
|
817
|
+
pricePadded = price16.rjust(16, '0')
|
818
|
+
encodedPrice = self.base16_to_binary(pricePadded)
|
819
|
+
message = self.binary_concat(encodedNonce, encodedMarketId, encodedQuantity, encodedSide, encodedPrice, encodedFeeRate)
|
820
|
+
return message
|
821
|
+
|
822
|
+
def create_order_request(self, nonce: float, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
823
|
+
market = self.market(symbol)
|
824
|
+
feeRate = max(self.safe_number(market, 'taker'), self.safe_number(market, 'maker'))
|
825
|
+
sideInternal = ''
|
826
|
+
if side == 'sell':
|
827
|
+
sideInternal = 'ASK'
|
828
|
+
elif side == 'buy':
|
829
|
+
sideInternal = 'BID'
|
830
|
+
priceInternal = ''
|
831
|
+
if price:
|
832
|
+
priceInternal = self.price_to_precision(symbol, price)
|
833
|
+
message = self.order_message(market, nonce, feeRate, type, side, amount, price)
|
834
|
+
signature = self.sign_message(message, self.privateKey)
|
835
|
+
request = {
|
836
|
+
'symbol': self.safe_string(market, 'id'),
|
837
|
+
'nonce': nonce,
|
838
|
+
'side': sideInternal,
|
839
|
+
'orderType': type.upper(),
|
840
|
+
'quantity': self.amount_to_precision(symbol, amount),
|
841
|
+
'price': priceInternal,
|
842
|
+
'signature': signature,
|
843
|
+
'maxFeesPercent': self.number_to_string(feeRate),
|
844
|
+
}
|
845
|
+
postOnly = self.is_post_only(type.upper() == 'MARKET', None, params)
|
846
|
+
reduceOnly = self.safe_bool_2(params, 'reduceOnly', 'reduce_only')
|
847
|
+
timeInForce = self.safe_string_lower(params, 'timeInForce')
|
848
|
+
triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
|
849
|
+
if postOnly:
|
850
|
+
request['orderFlags'] = 'POST_ONLY'
|
851
|
+
elif timeInForce == 'ioc':
|
852
|
+
request['orderFlags'] = 'IOC'
|
853
|
+
elif reduceOnly:
|
854
|
+
request['orderFlags'] = 'REDUCE_ONLY'
|
855
|
+
if triggerPrice is not None:
|
856
|
+
request['triggerPrice'] = triggerPrice
|
857
|
+
params = self.omit(params, ['reduceOnly', 'reduce_only', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice'])
|
858
|
+
return self.extend(request, params)
|
859
|
+
|
860
|
+
def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
861
|
+
"""
|
862
|
+
create a trade order
|
863
|
+
|
864
|
+
https://api-doc.hibachi.xyz/#00f6d5ad-5275-41cb-a1a8-19ed5d142124
|
865
|
+
|
866
|
+
:param str symbol: unified symbol of the market to create an order in
|
867
|
+
:param str type: 'market' or 'limit'
|
868
|
+
:param str side: 'buy' or 'sell'
|
869
|
+
:param float amount: how much of currency you want to trade in units of base currency
|
870
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
871
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
872
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
873
|
+
"""
|
874
|
+
self.load_markets()
|
875
|
+
nonce = self.nonce()
|
876
|
+
request = self.create_order_request(nonce, symbol, type, side, amount, price, params)
|
877
|
+
request['accountId'] = self.get_account_id()
|
878
|
+
response = self.privatePostTradeOrder(request)
|
879
|
+
#
|
880
|
+
# {
|
881
|
+
# "orderId": "578721673790138368"
|
882
|
+
# }
|
883
|
+
#
|
884
|
+
return self.safe_order({
|
885
|
+
'id': self.safe_string(response, 'orderId'),
|
886
|
+
'status': 'pending',
|
887
|
+
})
|
888
|
+
|
889
|
+
def create_orders(self, orders: List[OrderRequest], params={}) -> List[Order]:
|
890
|
+
"""
|
891
|
+
*contract only* create a list of trade orders
|
892
|
+
|
893
|
+
https://api-doc.hibachi.xyz/#c2840b9b-f02c-44ed-937d-dc2819f135b4
|
894
|
+
|
895
|
+
:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
|
896
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
897
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
898
|
+
"""
|
899
|
+
self.load_markets()
|
900
|
+
nonce = self.nonce()
|
901
|
+
requestOrders = []
|
902
|
+
for i in range(0, len(orders)):
|
903
|
+
rawOrder = orders[i]
|
904
|
+
symbol = self.safe_string(rawOrder, 'symbol')
|
905
|
+
type = self.safe_string(rawOrder, 'type')
|
906
|
+
side = self.safe_string(rawOrder, 'side')
|
907
|
+
amount = self.safe_value(rawOrder, 'amount')
|
908
|
+
price = self.safe_value(rawOrder, 'price')
|
909
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
910
|
+
orderRequest = self.create_order_request(nonce + i, symbol, type, side, amount, price, orderParams)
|
911
|
+
orderRequest['action'] = 'place'
|
912
|
+
requestOrders.append(orderRequest)
|
913
|
+
request: dict = {
|
914
|
+
'accountId': self.get_account_id(),
|
915
|
+
'orders': requestOrders,
|
916
|
+
}
|
917
|
+
response = self.privatePostTradeOrders(self.extend(request, params))
|
918
|
+
#
|
919
|
+
# {"orders": [{nonce: '1754349993908', orderId: '589642085255349248'}]}
|
920
|
+
#
|
921
|
+
ret = []
|
922
|
+
responseOrders = self.safe_list(response, 'orders')
|
923
|
+
for i in range(0, len(responseOrders)):
|
924
|
+
responseOrder = responseOrders[i]
|
925
|
+
ret.append(self.safe_order({
|
926
|
+
'info': responseOrder,
|
927
|
+
'id': self.safe_string(responseOrder, 'orderId'),
|
928
|
+
'status': 'pending',
|
929
|
+
}))
|
930
|
+
return ret
|
931
|
+
|
932
|
+
def edit_order_request(self, nonce: float, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
|
933
|
+
market = self.market(symbol)
|
934
|
+
feeRate = max(self.safe_number(market, 'taker'), self.safe_number(market, 'maker'))
|
935
|
+
message = self.order_message(market, nonce, feeRate, type, side, amount, price)
|
936
|
+
signature = self.sign_message(message, self.privateKey)
|
937
|
+
request = {
|
938
|
+
'orderId': id,
|
939
|
+
'nonce': nonce,
|
940
|
+
'updatedQuantity': self.amount_to_precision(symbol, amount),
|
941
|
+
'updatedPrice': self.price_to_precision(symbol, price),
|
942
|
+
'maxFeesPercent': self.number_to_string(feeRate),
|
943
|
+
'signature': signature,
|
944
|
+
}
|
945
|
+
return self.extend(request, params)
|
946
|
+
|
947
|
+
def edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
|
948
|
+
"""
|
949
|
+
edit a limit order that is not matched
|
950
|
+
|
951
|
+
https://api-doc.hibachi.xyz/#94d2cdaf-1c71-440f-a981-da1112824810
|
952
|
+
|
953
|
+
:param str id: order id
|
954
|
+
:param str symbol: unified symbol of the market to create an order in
|
955
|
+
:param str type: must be 'limit'
|
956
|
+
:param str side: 'buy' or 'sell', should stay the same with original side
|
957
|
+
:param float amount: how much of currency you want to trade in units of base currency
|
958
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency
|
959
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
960
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
961
|
+
"""
|
962
|
+
self.load_markets()
|
963
|
+
nonce = self.nonce()
|
964
|
+
request = self.edit_order_request(nonce, id, symbol, type, side, amount, price, params)
|
965
|
+
request['accountId'] = self.get_account_id()
|
966
|
+
self.privatePutTradeOrder(request)
|
967
|
+
# At self time the response body is empty. A 200 response means the update request is accepted and sent to process
|
968
|
+
#
|
969
|
+
# {}
|
970
|
+
#
|
971
|
+
return self.safe_order({
|
972
|
+
'id': id,
|
973
|
+
'status': 'pending',
|
974
|
+
})
|
975
|
+
|
976
|
+
def edit_orders(self, orders: List[OrderRequest], params={}) -> List[Order]:
|
977
|
+
"""
|
978
|
+
edit a list of trade orders
|
979
|
+
|
980
|
+
https://api-doc.hibachi.xyz/#c2840b9b-f02c-44ed-937d-dc2819f135b4
|
981
|
+
|
982
|
+
:param Array orders: list of orders to edit, each object should contain the parameters required by editOrder, namely id, symbol, type, side, amount, price and params
|
983
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
984
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
985
|
+
"""
|
986
|
+
self.load_markets()
|
987
|
+
nonce = self.nonce()
|
988
|
+
requestOrders = []
|
989
|
+
for i in range(0, len(orders)):
|
990
|
+
rawOrder = orders[i]
|
991
|
+
id = self.safe_string(rawOrder, 'id')
|
992
|
+
symbol = self.safe_string(rawOrder, 'symbol')
|
993
|
+
type = self.safe_string(rawOrder, 'type')
|
994
|
+
side = self.safe_string(rawOrder, 'side')
|
995
|
+
amount = self.safe_value(rawOrder, 'amount')
|
996
|
+
price = self.safe_value(rawOrder, 'price')
|
997
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
998
|
+
orderRequest = self.edit_order_request(nonce + i, id, symbol, type, side, amount, price, orderParams)
|
999
|
+
orderRequest['action'] = 'modify'
|
1000
|
+
requestOrders.append(orderRequest)
|
1001
|
+
request: dict = {
|
1002
|
+
'accountId': self.get_account_id(),
|
1003
|
+
'orders': requestOrders,
|
1004
|
+
}
|
1005
|
+
response = self.privatePostTradeOrders(self.extend(request, params))
|
1006
|
+
#
|
1007
|
+
# {"orders": [{"orderId": "589636801329628160"}]}
|
1008
|
+
#
|
1009
|
+
ret = []
|
1010
|
+
responseOrders = self.safe_list(response, 'orders')
|
1011
|
+
for i in range(0, len(responseOrders)):
|
1012
|
+
responseOrder = responseOrders[i]
|
1013
|
+
ret.append(self.safe_order({
|
1014
|
+
'info': responseOrder,
|
1015
|
+
'id': self.safe_string(responseOrder, 'orderId'),
|
1016
|
+
'status': 'pending',
|
1017
|
+
}))
|
1018
|
+
return ret
|
1019
|
+
|
1020
|
+
def cancel_order_request(self, id: str):
|
1021
|
+
bigid = self.convert_to_big_int(id)
|
1022
|
+
idbase16 = self.int_to_base16(bigid)
|
1023
|
+
idPadded = idbase16.rjust(16, '0')
|
1024
|
+
message = self.base16_to_binary(idPadded)
|
1025
|
+
signature = self.sign_message(message, self.privateKey)
|
1026
|
+
return {
|
1027
|
+
'orderId': id,
|
1028
|
+
'signature': signature,
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
def cancel_order(self, id: str, symbol: Str = None, params={}):
|
1032
|
+
"""
|
1033
|
+
|
1034
|
+
https://api-doc.hibachi.xyz/#e99c4f48-e610-4b7c-b7f6-1b4bb7af0271
|
1035
|
+
|
1036
|
+
cancels an open order
|
1037
|
+
:param str id: order id
|
1038
|
+
:param str symbol: is unused
|
1039
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1040
|
+
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1041
|
+
"""
|
1042
|
+
request: dict = self.cancel_order_request(id)
|
1043
|
+
request['accountId'] = self.get_account_id()
|
1044
|
+
response = self.privateDeleteTradeOrder(self.extend(request, params))
|
1045
|
+
# At self time the response body is empty. A 200 response means the cancel request is accepted and sent to cancel
|
1046
|
+
#
|
1047
|
+
# {}
|
1048
|
+
#
|
1049
|
+
return self.safe_order({
|
1050
|
+
'info': response,
|
1051
|
+
'id': id,
|
1052
|
+
'status': 'canceled',
|
1053
|
+
})
|
1054
|
+
|
1055
|
+
def cancel_orders(self, ids: List[str], symbol: Str = None, params={}):
|
1056
|
+
"""
|
1057
|
+
cancel multiple orders
|
1058
|
+
|
1059
|
+
https://api-doc.hibachi.xyz/#c2840b9b-f02c-44ed-937d-dc2819f135b4
|
1060
|
+
|
1061
|
+
:param str[] ids: order ids
|
1062
|
+
:param str [symbol]: unified market symbol, unused
|
1063
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1064
|
+
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1065
|
+
"""
|
1066
|
+
orders = []
|
1067
|
+
for i in range(0, len(ids)):
|
1068
|
+
orderRequest = self.cancel_order_request(ids[i])
|
1069
|
+
orderRequest['action'] = 'cancel'
|
1070
|
+
orders.append(orderRequest)
|
1071
|
+
request: dict = {
|
1072
|
+
'accountId': self.get_account_id(),
|
1073
|
+
'orders': orders,
|
1074
|
+
}
|
1075
|
+
response = self.privatePostTradeOrders(self.extend(request, params))
|
1076
|
+
#
|
1077
|
+
# {"orders": [{"orderId": "589636801329628160"}]}
|
1078
|
+
#
|
1079
|
+
ret = []
|
1080
|
+
responseOrders = self.safe_list(response, 'orders')
|
1081
|
+
for i in range(0, len(responseOrders)):
|
1082
|
+
responseOrder = responseOrders[i]
|
1083
|
+
ret.append(self.safe_order({
|
1084
|
+
'info': responseOrder,
|
1085
|
+
'id': self.safe_string(responseOrder, 'orderId'),
|
1086
|
+
'status': 'canceled',
|
1087
|
+
}))
|
1088
|
+
return ret
|
1089
|
+
|
1090
|
+
def cancel_all_orders(self, symbol: Str = None, params={}):
|
1091
|
+
"""
|
1092
|
+
|
1093
|
+
https://api-doc.hibachi.xyz/#8ed24695-016e-49b2-a72d-7511ca921fee
|
1094
|
+
|
1095
|
+
cancel all open orders in a market
|
1096
|
+
:param str symbol: unified market symbol
|
1097
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1098
|
+
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1099
|
+
"""
|
1100
|
+
self.load_markets()
|
1101
|
+
nonce = self.nonce()
|
1102
|
+
nonce16 = self.int_to_base16(nonce)
|
1103
|
+
noncePadded = nonce16.rjust(16, '0')
|
1104
|
+
message = self.base16_to_binary(noncePadded)
|
1105
|
+
signature = self.sign_message(message, self.privateKey)
|
1106
|
+
request: dict = {
|
1107
|
+
'accountId': self.get_account_id(),
|
1108
|
+
'nonce': nonce,
|
1109
|
+
'signature': signature,
|
1110
|
+
}
|
1111
|
+
if symbol is not None:
|
1112
|
+
market = self.market(symbol)
|
1113
|
+
request['contractId'] = self.safe_integer(market, 'numericId')
|
1114
|
+
response = self.privateDeleteTradeOrders(self.extend(request, params))
|
1115
|
+
# At self time the response body is empty. A 200 response means the cancel request is accepted and sent to process
|
1116
|
+
#
|
1117
|
+
# {}
|
1118
|
+
#
|
1119
|
+
return [
|
1120
|
+
self.safe_order({
|
1121
|
+
'info': response,
|
1122
|
+
}),
|
1123
|
+
]
|
1124
|
+
|
1125
|
+
def encode_withdraw_message(self, amount: float, maxFees: float, address: str):
|
1126
|
+
# Converting them to internal representation:
|
1127
|
+
# - Quantity: Internal = External * (10^6)
|
1128
|
+
# - maxFees: Internal = External * (10^6)
|
1129
|
+
# We only have USDT currency time
|
1130
|
+
USDTAssetId = 1
|
1131
|
+
USDTFactor = '1000000'
|
1132
|
+
amountStr = self.number_to_string(amount)
|
1133
|
+
maxFeesStr = self.number_to_string(maxFees)
|
1134
|
+
one = '1'
|
1135
|
+
quantityInternal = Precise.string_div(Precise.string_mul(amountStr, USDTFactor), one, 0)
|
1136
|
+
maxFeesInternal = Precise.string_div(Precise.string_mul(maxFeesStr, USDTFactor), one, 0)
|
1137
|
+
# Encoding
|
1138
|
+
usdtAsset16 = self.int_to_base16(USDTAssetId)
|
1139
|
+
usdtAssetPadded = usdtAsset16.rjust(8, '0')
|
1140
|
+
encodedAssetId = self.base16_to_binary(usdtAssetPadded)
|
1141
|
+
quantity16 = self.int_to_base16(self.parse_to_int(quantityInternal))
|
1142
|
+
quantityPadded = quantity16.rjust(16, '0')
|
1143
|
+
encodedQuantity = self.base16_to_binary(quantityPadded)
|
1144
|
+
maxFees16 = self.int_to_base16(self.parse_to_int(maxFeesInternal))
|
1145
|
+
maxFeesPadded = maxFees16.rjust(16, '0')
|
1146
|
+
encodedMaxFees = self.base16_to_binary(maxFeesPadded)
|
1147
|
+
encodedAddress = self.base16_to_binary(address)
|
1148
|
+
message = self.binary_concat(encodedAssetId, encodedQuantity, encodedMaxFees, encodedAddress)
|
1149
|
+
return message
|
1150
|
+
|
1151
|
+
def withdraw(self, code: str, amount: float, address: str, tag=None, params={}) -> Transaction:
|
1152
|
+
"""
|
1153
|
+
make a withdrawal
|
1154
|
+
|
1155
|
+
https://api-doc.hibachi.xyz/#6421625d-3e45-45fa-be9b-d2a0e780c090
|
1156
|
+
|
1157
|
+
:param str code: unified currency code, only support USDT
|
1158
|
+
:param float amount: the amount to withdraw
|
1159
|
+
:param str address: the address to withdraw to
|
1160
|
+
:param str tag:
|
1161
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1162
|
+
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
|
1163
|
+
"""
|
1164
|
+
withdrawAddress = address[-40:]
|
1165
|
+
# Get the withdraw fees
|
1166
|
+
exchangeInfo = self.publicGetMarketExchangeInfo(params)
|
1167
|
+
# {
|
1168
|
+
# "feeConfig": {
|
1169
|
+
# "depositFees": "0.004518",
|
1170
|
+
# "tradeMakerFeeRate": "0.00000000",
|
1171
|
+
# "tradeTakerFeeRate": "0.00020000",
|
1172
|
+
# "transferFeeRate": "0.00010000",
|
1173
|
+
# "withdrawalFees": "0.012050"
|
1174
|
+
# },
|
1175
|
+
# }
|
1176
|
+
feeConfig = self.safe_dict(exchangeInfo, 'feeConfig')
|
1177
|
+
maxFees = self.safe_number(feeConfig, 'withdrawalFees')
|
1178
|
+
# Generate the signature
|
1179
|
+
message = self.encode_withdraw_message(amount, maxFees, withdrawAddress)
|
1180
|
+
signature = self.sign_message(message, self.privateKey)
|
1181
|
+
request = {
|
1182
|
+
'accountId': self.get_account_id(),
|
1183
|
+
'coin': 'USDT',
|
1184
|
+
'network': 'ARBITRUM',
|
1185
|
+
'withdrawAddress': withdrawAddress,
|
1186
|
+
'selfWithdrawal': False,
|
1187
|
+
'quantity': self.number_to_string(amount),
|
1188
|
+
'maxFees': self.number_to_string(maxFees),
|
1189
|
+
'signature': signature,
|
1190
|
+
}
|
1191
|
+
self.privatePostCapitalWithdraw(self.extend(request, params))
|
1192
|
+
# At self time the response body is empty. A 200 response means the withdraw request is accepted and sent to process
|
1193
|
+
#
|
1194
|
+
# {}
|
1195
|
+
#
|
1196
|
+
return {
|
1197
|
+
'info': None,
|
1198
|
+
'id': None,
|
1199
|
+
'txid': None,
|
1200
|
+
'timestamp': self.milliseconds(),
|
1201
|
+
'datetime': None,
|
1202
|
+
'address': None,
|
1203
|
+
'addressFrom': None,
|
1204
|
+
'addressTo': withdrawAddress,
|
1205
|
+
'tag': None,
|
1206
|
+
'tagFrom': None,
|
1207
|
+
'tagTo': None,
|
1208
|
+
'type': 'withdrawal',
|
1209
|
+
'amount': amount,
|
1210
|
+
'currency': code,
|
1211
|
+
'status': 'pending',
|
1212
|
+
'fee': {'currency': 'USDT', 'cost': maxFees},
|
1213
|
+
'network': 'ARBITRUM',
|
1214
|
+
'updated': None,
|
1215
|
+
'comment': None,
|
1216
|
+
'internal': None,
|
1217
|
+
}
|
1218
|
+
|
1219
|
+
def nonce(self):
|
1220
|
+
return self.milliseconds()
|
1221
|
+
|
1222
|
+
def sign_message(self, message, privateKey):
|
1223
|
+
if len(privateKey) == 44:
|
1224
|
+
# For Exchange Managed account, the key length is 44 and we use HMAC to sign the message
|
1225
|
+
return self.hmac(message, self.encode(privateKey), hashlib.sha256, 'hex')
|
1226
|
+
else:
|
1227
|
+
# For Trustless account, the key length is 66 including '0x' and we use ECDSA to sign the message
|
1228
|
+
hash = self.hash(self.encode(message), 'sha256', 'hex')
|
1229
|
+
signature = self.ecdsa(hash[-64:], privateKey[-64:], 'secp256k1', None)
|
1230
|
+
r = signature['r']
|
1231
|
+
s = signature['s']
|
1232
|
+
v = signature['v']
|
1233
|
+
return r.rjust(64, '0') + s.rjust(64, '0') + self.int_to_base16(v).rjust(2, '0')
|
1234
|
+
|
1235
|
+
def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
|
1236
|
+
"""
|
1237
|
+
fetches the state of the open orders on the orderbook
|
1238
|
+
|
1239
|
+
https://api-doc.hibachi.xyz/#4abb30c4-e5c7-4b0f-9ade-790111dbfa47
|
1240
|
+
|
1241
|
+
:param str symbol: unified symbol of the market
|
1242
|
+
:param int [limit]: currently unused
|
1243
|
+
:param dict [params]: extra parameters to be passed -- see documentation link above
|
1244
|
+
:returns dict: A dictionary containg `orderbook information <https://docs.ccxt.com/#/?id=order-book-structure>`
|
1245
|
+
"""
|
1246
|
+
self.load_markets()
|
1247
|
+
market: Market = self.market(symbol)
|
1248
|
+
request: dict = {
|
1249
|
+
'symbol': market['id'],
|
1250
|
+
}
|
1251
|
+
response = self.publicGetMarketDataOrderbook(self.extend(request, params))
|
1252
|
+
formattedResponse = {}
|
1253
|
+
formattedResponse['ask'] = self.safe_list(self.safe_dict(response, 'ask'), 'levels')
|
1254
|
+
formattedResponse['bid'] = self.safe_list(self.safe_dict(response, 'bid'), 'levels')
|
1255
|
+
# {
|
1256
|
+
# "ask": {
|
1257
|
+
# "endPrice": "3512.63",
|
1258
|
+
# "levels": [
|
1259
|
+
# {
|
1260
|
+
# "price": "3511.93",
|
1261
|
+
# "quantity": "0.284772482"
|
1262
|
+
# },
|
1263
|
+
# {
|
1264
|
+
# "price": "3512.28",
|
1265
|
+
# "quantity": "0.569544964"
|
1266
|
+
# },
|
1267
|
+
# {
|
1268
|
+
# "price": "3512.63",
|
1269
|
+
# "quantity": "0.854317446"
|
1270
|
+
# }
|
1271
|
+
# ],
|
1272
|
+
# "startPrice": "3511.93"
|
1273
|
+
# },
|
1274
|
+
# "bid": {
|
1275
|
+
# "endPrice": "3510.87",
|
1276
|
+
# "levels": [
|
1277
|
+
# {
|
1278
|
+
# "price": "3515.39",
|
1279
|
+
# "quantity": "2.345153070"
|
1280
|
+
# },
|
1281
|
+
# {
|
1282
|
+
# "price": "3511.22",
|
1283
|
+
# "quantity": "0.284772482"
|
1284
|
+
# },
|
1285
|
+
# {
|
1286
|
+
# "price": "3510.87",
|
1287
|
+
# "quantity": "0.569544964"
|
1288
|
+
# }
|
1289
|
+
# ],
|
1290
|
+
# "startPrice": "3515.39"
|
1291
|
+
# }
|
1292
|
+
# }
|
1293
|
+
return self.parse_order_book(formattedResponse, symbol, self.milliseconds(), 'bid', 'ask', 'price', 'quantity')
|
1294
|
+
|
1295
|
+
def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
1296
|
+
"""
|
1297
|
+
|
1298
|
+
https://api-doc.hibachi.xyz/#0adbf143-189f-40e0-afdc-88af4cba3c79
|
1299
|
+
|
1300
|
+
fetch all trades made by the user
|
1301
|
+
:param str symbol: unified market symbol
|
1302
|
+
:param int [since]: the earliest time in ms to fetch trades for
|
1303
|
+
:param int [limit]: the maximum number of trades structures to retrieve
|
1304
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1305
|
+
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
1306
|
+
"""
|
1307
|
+
self.load_markets()
|
1308
|
+
market: Market = None
|
1309
|
+
if symbol is not None:
|
1310
|
+
market = self.market(symbol)
|
1311
|
+
request = {'accountId': self.get_account_id()}
|
1312
|
+
response = self.privateGetTradeAccountTrades(self.extend(request, params))
|
1313
|
+
#
|
1314
|
+
# {
|
1315
|
+
# "trades": [
|
1316
|
+
# {
|
1317
|
+
# "askAccountId": 221,
|
1318
|
+
# "askOrderId": 589168494921909200,
|
1319
|
+
# "bidAccountId": 132,
|
1320
|
+
# "bidOrderId": 589168494829895700,
|
1321
|
+
# "fee": "0.000477",
|
1322
|
+
# "id": 199511136,
|
1323
|
+
# "orderType": "MARKET",
|
1324
|
+
# "price": "119257.90000",
|
1325
|
+
# "quantity": "0.0000200000",
|
1326
|
+
# "realizedPnl": "-0.000352",
|
1327
|
+
# "side": "Sell",
|
1328
|
+
# "symbol": "BTC/USDT-P",
|
1329
|
+
# "timestamp": 1752543391
|
1330
|
+
# }
|
1331
|
+
# ]
|
1332
|
+
# }
|
1333
|
+
#
|
1334
|
+
trades = self.safe_list(response, 'trades')
|
1335
|
+
return self.parse_trades(trades, market, since, limit, params)
|
1336
|
+
|
1337
|
+
def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
|
1338
|
+
#
|
1339
|
+
# [
|
1340
|
+
# {
|
1341
|
+
# "close": "3704.751036",
|
1342
|
+
# "high": "3716.530378",
|
1343
|
+
# "interval": "1h",
|
1344
|
+
# "low": "3699.627883",
|
1345
|
+
# "open": "3716.406894",
|
1346
|
+
# "timestamp": 1712628000,
|
1347
|
+
# "volumeNotional": "1637355.846362"
|
1348
|
+
# }
|
1349
|
+
# ]
|
1350
|
+
#
|
1351
|
+
return [
|
1352
|
+
self.safe_integer_product(ohlcv, 'timestamp', 1000),
|
1353
|
+
self.safe_number(ohlcv, 'open'),
|
1354
|
+
self.safe_number(ohlcv, 'high'),
|
1355
|
+
self.safe_number(ohlcv, 'low'),
|
1356
|
+
self.safe_number(ohlcv, 'close'),
|
1357
|
+
self.safe_number(ohlcv, 'volumeNotional'),
|
1358
|
+
]
|
1359
|
+
|
1360
|
+
def fetch_open_orders(self, symbol: str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
1361
|
+
"""
|
1362
|
+
fetches all current open orders
|
1363
|
+
|
1364
|
+
https://api-doc.hibachi.xyz/#3243f8a0-086c-44c5-ab8a-71bbb7bab403
|
1365
|
+
|
1366
|
+
:param str [symbol]: unified market symbol to filter by
|
1367
|
+
:param int [since]: milisecond timestamp of the earliest order
|
1368
|
+
:param int [limit]: the maximum number of open orders to return
|
1369
|
+
:param dict [params]: extra parameters
|
1370
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1371
|
+
"""
|
1372
|
+
self.load_markets()
|
1373
|
+
market = None
|
1374
|
+
if symbol is not None:
|
1375
|
+
market = self.market(symbol)
|
1376
|
+
request = {
|
1377
|
+
'accountId': self.get_account_id(),
|
1378
|
+
}
|
1379
|
+
response = self.privateGetTradeOrders(self.extend(request, params))
|
1380
|
+
# [
|
1381
|
+
# {
|
1382
|
+
# "accountId": 12452,
|
1383
|
+
# "availableQuantity": "0.0000230769",
|
1384
|
+
# "contractId": 2,
|
1385
|
+
# "creationTime": 1752684501,
|
1386
|
+
# "orderId": "589205486123876352",
|
1387
|
+
# "orderType": "LIMIT",
|
1388
|
+
# "price": "130000.00000",
|
1389
|
+
# "side": "ASK",
|
1390
|
+
# "status": "PLACED",
|
1391
|
+
# "symbol": "BTC/USDT-P",
|
1392
|
+
# "totalQuantity": "0.0000230769"
|
1393
|
+
# },
|
1394
|
+
# {
|
1395
|
+
# "accountId": 12452,
|
1396
|
+
# "availableQuantity": "1.234000000",
|
1397
|
+
# "contractId": 1,
|
1398
|
+
# "creationTime": 1752240682,
|
1399
|
+
# "orderId": "589089141754429441",
|
1400
|
+
# "orderType": "LIMIT",
|
1401
|
+
# "price": "1.234000",
|
1402
|
+
# "side": "BID",
|
1403
|
+
# "status": "PLACED",
|
1404
|
+
# "symbol": "ETH/USDT-P",
|
1405
|
+
# "totalQuantity": "1.234000000"
|
1406
|
+
# }
|
1407
|
+
# ]
|
1408
|
+
return self.parse_orders(response, market, since, limit)
|
1409
|
+
|
1410
|
+
def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
1411
|
+
"""
|
1412
|
+
|
1413
|
+
https://api-doc.hibachi.xyz/#4f0eacec-c61e-4d51-afb3-23c51c2c6bac
|
1414
|
+
|
1415
|
+
fetches historical candlestick data containing the close, high, low, open prices, interval and the volumeNotional
|
1416
|
+
:param str symbol: unified symbol of the market to fetch OHLCV data for
|
1417
|
+
:param str timeframe: the length of time each candle represents
|
1418
|
+
:param int [since]: timestamp in ms of the earliest candle to fetch
|
1419
|
+
:param int [limit]: the maximum amount of candles to fetch
|
1420
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1421
|
+
:param int [params.until]: timestamp in ms of the latest candle to fetch
|
1422
|
+
:returns int[][]: A list of candles ordered, open, high, low, close, volume
|
1423
|
+
"""
|
1424
|
+
self.load_markets()
|
1425
|
+
market = self.market(symbol)
|
1426
|
+
timeframe = self.safe_string(self.timeframes, timeframe, timeframe)
|
1427
|
+
request: dict = {
|
1428
|
+
'symbol': market['id'],
|
1429
|
+
'interval': timeframe,
|
1430
|
+
}
|
1431
|
+
if since is not None:
|
1432
|
+
request['fromMs'] = since
|
1433
|
+
until: Int = None
|
1434
|
+
until, params = self.handle_option_and_params(params, 'fetchOHLCV', 'until')
|
1435
|
+
if until is not None:
|
1436
|
+
request['toMs'] = until
|
1437
|
+
response = self.publicGetMarketDataKlines(self.extend(request, params))
|
1438
|
+
#
|
1439
|
+
# [
|
1440
|
+
# {
|
1441
|
+
# "close": "3704.751036",
|
1442
|
+
# "high": "3716.530378",
|
1443
|
+
# "interval": "1h",
|
1444
|
+
# "low": "3699.627883",
|
1445
|
+
# "open": "3716.406894",
|
1446
|
+
# "timestamp": 1712628000,
|
1447
|
+
# "volumeNotional": "1637355.846362"
|
1448
|
+
# }
|
1449
|
+
# ]
|
1450
|
+
#
|
1451
|
+
klines = self.safe_list(response, 'klines', [])
|
1452
|
+
return self.parse_ohlcvs(klines, market, timeframe, since, limit)
|
1453
|
+
|
1454
|
+
def fetch_positions(self, symbols: Strings = None, params={}) -> List[Position]:
|
1455
|
+
"""
|
1456
|
+
fetch all open positions
|
1457
|
+
|
1458
|
+
https://api-doc.hibachi.xyz/#69aafedb-8274-4e21-bbaf-91dace8b8f31
|
1459
|
+
|
1460
|
+
:param str[] [symbols]: list of unified market symbols
|
1461
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1462
|
+
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
1463
|
+
"""
|
1464
|
+
self.load_markets()
|
1465
|
+
symbols = self.market_symbols(symbols)
|
1466
|
+
request: dict = {
|
1467
|
+
'accountId': self.get_account_id(),
|
1468
|
+
}
|
1469
|
+
response = self.privateGetTradeAccountInfo(self.extend(request, params))
|
1470
|
+
#
|
1471
|
+
# {
|
1472
|
+
# "assets": [
|
1473
|
+
# {
|
1474
|
+
# "quantity": "14.130626",
|
1475
|
+
# "symbol": "USDT"
|
1476
|
+
# }
|
1477
|
+
# ],
|
1478
|
+
# "balance": "14.186087",
|
1479
|
+
# "maximalWithdraw": "4.152340",
|
1480
|
+
# "numFreeTransfersRemaining": 96,
|
1481
|
+
# "positions": [
|
1482
|
+
# {
|
1483
|
+
# "direction": "Short",
|
1484
|
+
# "entryNotional": "10.302213",
|
1485
|
+
# "notionalValue": "10.225008",
|
1486
|
+
# "quantity": "0.004310550",
|
1487
|
+
# "symbol": "ETH/USDT-P",
|
1488
|
+
# "unrealizedFundingPnl": "0.000000",
|
1489
|
+
# "unrealizedTradingPnl": "0.077204"
|
1490
|
+
# },
|
1491
|
+
# {
|
1492
|
+
# "direction": "Short",
|
1493
|
+
# "entryNotional": "2.000016",
|
1494
|
+
# "notionalValue": "1.999390",
|
1495
|
+
# "quantity": "0.0000328410",
|
1496
|
+
# "symbol": "BTC/USDT-P",
|
1497
|
+
# "unrealizedFundingPnl": "0.000000",
|
1498
|
+
# "unrealizedTradingPnl": "0.000625"
|
1499
|
+
# },
|
1500
|
+
# {
|
1501
|
+
# "direction": "Short",
|
1502
|
+
# "entryNotional": "2.000015",
|
1503
|
+
# "notionalValue": "2.022384",
|
1504
|
+
# "quantity": "0.01470600",
|
1505
|
+
# "symbol": "SOL/USDT-P",
|
1506
|
+
# "unrealizedFundingPnl": "0.000000",
|
1507
|
+
# "unrealizedTradingPnl": "-0.022369"
|
1508
|
+
# }
|
1509
|
+
# ],
|
1510
|
+
# }
|
1511
|
+
#
|
1512
|
+
data = self.safe_list(response, 'positions', [])
|
1513
|
+
return self.parse_positions(data, symbols)
|
1514
|
+
|
1515
|
+
def parse_position(self, position: dict, market: Market = None):
|
1516
|
+
#
|
1517
|
+
# {
|
1518
|
+
# "direction": "Short",
|
1519
|
+
# "entryNotional": "10.302213",
|
1520
|
+
# "notionalValue": "10.225008",
|
1521
|
+
# "quantity": "0.004310550",
|
1522
|
+
# "symbol": "ETH/USDT-P",
|
1523
|
+
# "unrealizedFundingPnl": "0.000000",
|
1524
|
+
# "unrealizedTradingPnl": "0.077204"
|
1525
|
+
# }
|
1526
|
+
#
|
1527
|
+
marketId = self.safe_string(position, 'symbol')
|
1528
|
+
market = self.safe_market(marketId, market)
|
1529
|
+
symbol = market['symbol']
|
1530
|
+
side = self.safe_string_lower(position, 'direction')
|
1531
|
+
quantity = self.safe_string(position, 'quantity')
|
1532
|
+
unrealizedFunding = self.safe_string(position, 'unrealizedFundingPnl', '0')
|
1533
|
+
unrealizedTrading = self.safe_string(position, 'unrealizedTradingPnl', '0')
|
1534
|
+
unrealizedPnl = Precise.string_add(unrealizedFunding, unrealizedTrading)
|
1535
|
+
return self.safe_position({
|
1536
|
+
'info': position,
|
1537
|
+
'id': None,
|
1538
|
+
'symbol': symbol,
|
1539
|
+
'entryPrice': self.safe_string(position, 'average_entry_price'),
|
1540
|
+
'markPrice': None,
|
1541
|
+
'notional': self.safe_string(position, 'notionalValue'),
|
1542
|
+
'collateral': None,
|
1543
|
+
'unrealizedPnl': unrealizedPnl,
|
1544
|
+
'side': side,
|
1545
|
+
'contracts': self.parse_number(quantity),
|
1546
|
+
'contractSize': None,
|
1547
|
+
'timestamp': None,
|
1548
|
+
'datetime': None,
|
1549
|
+
'hedged': None,
|
1550
|
+
'maintenanceMargin': None,
|
1551
|
+
'maintenanceMarginPercentage': None,
|
1552
|
+
'initialMargin': None,
|
1553
|
+
'initialMarginPercentage': None,
|
1554
|
+
'leverage': None,
|
1555
|
+
'liquidationPrice': None,
|
1556
|
+
'marginRatio': None,
|
1557
|
+
'marginMode': None,
|
1558
|
+
'percentage': None,
|
1559
|
+
})
|
1560
|
+
|
1561
|
+
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
1562
|
+
endpoint = '/' + self.implode_params(path, params)
|
1563
|
+
url = self.urls['api'][api] + endpoint
|
1564
|
+
headers = {}
|
1565
|
+
if method == 'GET':
|
1566
|
+
request = self.omit(params, self.extract_params(path))
|
1567
|
+
query = self.urlencode(request)
|
1568
|
+
if len(query) != 0:
|
1569
|
+
url += '?' + query
|
1570
|
+
if method == 'POST' or method == 'PUT' or method == 'DELETE':
|
1571
|
+
headers['Content-Type'] = 'application/json'
|
1572
|
+
body = self.json(params)
|
1573
|
+
if api == 'private':
|
1574
|
+
self.check_required_credentials()
|
1575
|
+
headers['Authorization'] = self.apiKey
|
1576
|
+
return {'url': url, 'method': method, 'body': body, 'headers': headers}
|
1577
|
+
|
1578
|
+
def handle_errors(self, httpCode: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
|
1579
|
+
if response is None:
|
1580
|
+
return None # fallback to default error handler
|
1581
|
+
if 'status' in response:
|
1582
|
+
#
|
1583
|
+
# {"errorCode":4,"message":"Invalid input: Invalid quantity: 0","status":"failed"}
|
1584
|
+
#
|
1585
|
+
status = self.safe_string(response, 'status')
|
1586
|
+
if status == 'failed':
|
1587
|
+
code = self.safe_string(response, 'errorCode')
|
1588
|
+
feedback = self.id + ' ' + body
|
1589
|
+
self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
|
1590
|
+
self.throw_exactly_matched_exception(self.exceptions['exact'], code, feedback)
|
1591
|
+
message = self.safe_string(response, 'message')
|
1592
|
+
self.throw_exactly_matched_exception(self.exceptions['exact'], message, feedback)
|
1593
|
+
raise ExchangeError(feedback)
|
1594
|
+
return None
|
1595
|
+
|
1596
|
+
def parse_transaction_type(self, type):
|
1597
|
+
types: dict = {
|
1598
|
+
'deposit': 'transaction',
|
1599
|
+
'withdrawal': 'transaction',
|
1600
|
+
'transfer-in': 'transfer',
|
1601
|
+
'transfer-out': 'transfer',
|
1602
|
+
}
|
1603
|
+
return self.safe_string(types, type, type)
|
1604
|
+
|
1605
|
+
def parse_transaction_status(self, status):
|
1606
|
+
statuses: dict = {
|
1607
|
+
'pending': 'pending',
|
1608
|
+
'claimable': 'pending',
|
1609
|
+
'completed': 'ok',
|
1610
|
+
'failed': 'canceled',
|
1611
|
+
}
|
1612
|
+
return self.safe_string(statuses, status, status)
|
1613
|
+
|
1614
|
+
def parse_ledger_entry(self, item: dict, currency: Currency = None) -> LedgerEntry:
|
1615
|
+
transactionType = self.safe_string(item, 'transactionType')
|
1616
|
+
timestamp = None
|
1617
|
+
type = None
|
1618
|
+
direction = None
|
1619
|
+
amount = None
|
1620
|
+
fee = None
|
1621
|
+
referenceId = None
|
1622
|
+
referenceAccount = None
|
1623
|
+
status = None
|
1624
|
+
if transactionType is None:
|
1625
|
+
# response from TradeAccountTradingHistory
|
1626
|
+
timestamp = self.safe_integer_product(item, 'timestamp', 1000)
|
1627
|
+
type = 'trade'
|
1628
|
+
amountStr = self.safe_string(item, 'realizedPnl')
|
1629
|
+
if Precise.string_lt(amountStr, '0'):
|
1630
|
+
direction = 'out'
|
1631
|
+
amountStr = Precise.string_neg(amountStr)
|
1632
|
+
else:
|
1633
|
+
direction = 'in'
|
1634
|
+
amount = self.parse_number(amountStr)
|
1635
|
+
fee = {'currency': 'USDT', 'cost': self.safe_number(item, 'fee')}
|
1636
|
+
status = 'ok'
|
1637
|
+
else:
|
1638
|
+
# response from CapitalHistory
|
1639
|
+
timestamp = self.safe_integer_product(item, 'timestampSec', 1000)
|
1640
|
+
amount = self.safe_number(item, 'quantity')
|
1641
|
+
direction = 'in' if (transactionType == 'deposit' or transactionType == 'transfer-in') else 'out'
|
1642
|
+
type = self.parse_transaction_type(transactionType)
|
1643
|
+
status = self.parse_transaction_status(self.safe_string(item, 'status'))
|
1644
|
+
if transactionType == 'transfer-in':
|
1645
|
+
referenceAccount = self.safe_string(item, 'srcAccountId')
|
1646
|
+
elif transactionType == 'transfer-out':
|
1647
|
+
referenceAccount = self.safe_string(item, 'receivingAccountId')
|
1648
|
+
referenceId = self.safe_string(item, 'transactionHash')
|
1649
|
+
return self.safe_ledger_entry({
|
1650
|
+
'id': self.safe_string(item, 'id'),
|
1651
|
+
'currency': self.currency('USDT'),
|
1652
|
+
'account': self.number_to_string(self.accountId),
|
1653
|
+
'referenceAccount': referenceAccount,
|
1654
|
+
'referenceId': referenceId,
|
1655
|
+
'status': status,
|
1656
|
+
'amount': amount,
|
1657
|
+
'before': None,
|
1658
|
+
'after': None,
|
1659
|
+
'fee': fee,
|
1660
|
+
'direction': direction,
|
1661
|
+
'timestamp': timestamp,
|
1662
|
+
'datetime': self.iso8601(timestamp),
|
1663
|
+
'type': type,
|
1664
|
+
'info': item,
|
1665
|
+
}, currency)
|
1666
|
+
|
1667
|
+
def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LedgerEntry]:
|
1668
|
+
"""
|
1669
|
+
fetch the history of changes, actions done by the user or operations that altered the balance of the user
|
1670
|
+
|
1671
|
+
https://api-doc.hibachi.xyz/#35125e3f-d154-4bfd-8276-a48bb1c62020
|
1672
|
+
|
1673
|
+
:param str [code]: unified currency code, default is None
|
1674
|
+
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
|
1675
|
+
:param int [limit]: max number of ledger entries to return, default is None
|
1676
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1677
|
+
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
|
1678
|
+
"""
|
1679
|
+
self.load_markets()
|
1680
|
+
currency = self.currency('USDT')
|
1681
|
+
request = {'accountId': self.get_account_id()}
|
1682
|
+
rawPromises = [
|
1683
|
+
self.privateGetCapitalHistory(self.extend(request, params)),
|
1684
|
+
self.privateGetTradeAccountTradingHistory(self.extend(request, params)),
|
1685
|
+
]
|
1686
|
+
promises = rawPromises
|
1687
|
+
responseCapitalHistory = promises[0]
|
1688
|
+
#
|
1689
|
+
# {
|
1690
|
+
# "transactions": [
|
1691
|
+
# {
|
1692
|
+
# "assetId": 1,
|
1693
|
+
# "blockNumber": 358396669,
|
1694
|
+
# "chain": "Arbitrum",
|
1695
|
+
# "etaTsSec": null,
|
1696
|
+
# "id": 358396669,
|
1697
|
+
# "quantity": "0.999500",
|
1698
|
+
# "status": "pending",
|
1699
|
+
# "timestampSec": 1752692872,
|
1700
|
+
# "token": "USDT",
|
1701
|
+
# "transactionHash": "0x408e48881e0ba77d8638e3fe57bc06bdec513ddaa8b672e0aefa7e22e2f18b5e",
|
1702
|
+
# "transactionType": "deposit"
|
1703
|
+
# },
|
1704
|
+
# {
|
1705
|
+
# "assetId": 1,
|
1706
|
+
# "etaTsSec": null,
|
1707
|
+
# "id": 13116,
|
1708
|
+
# "instantWithdrawalChain": null,
|
1709
|
+
# "instantWithdrawalToken": null,
|
1710
|
+
# "isInstantWithdrawal": False,
|
1711
|
+
# "quantity": "0.040000",
|
1712
|
+
# "status": "completed",
|
1713
|
+
# "timestampSec": 1752542708,
|
1714
|
+
# "transactionHash": "0xe89cf90b2408d1a273dc9427654145def102d9449e5e2cfc10690ccffc3d7e28",
|
1715
|
+
# "transactionType": "withdrawal",
|
1716
|
+
# "withdrawalAddress": "0x23625d5fc6a6e32638d908eb4c3a3415e5121f76"
|
1717
|
+
# },
|
1718
|
+
# {
|
1719
|
+
# "assetId": 1,
|
1720
|
+
# "id": 167,
|
1721
|
+
# "quantity": "10.000000",
|
1722
|
+
# "srcAccountId": 175,
|
1723
|
+
# "srcAddress": "0xc2f77ce029438a3fdfe68ddee25991a9fb985a86",
|
1724
|
+
# "status": "completed",
|
1725
|
+
# "timestampSec": 1732224729,
|
1726
|
+
# "transactionType": "transfer-in"
|
1727
|
+
# },
|
1728
|
+
# {
|
1729
|
+
# "assetId": 1,
|
1730
|
+
# "id": 170,
|
1731
|
+
# "quantity": "10.000000",
|
1732
|
+
# "receivingAccountId": 175,
|
1733
|
+
# "receivingAddress": "0xc2f77ce029438a3fdfe68ddee25991a9fb985a86",
|
1734
|
+
# "status": "completed",
|
1735
|
+
# "timestampSec": 1732225631,
|
1736
|
+
# "transactionType": "transfer-out"
|
1737
|
+
# },
|
1738
|
+
# ]
|
1739
|
+
# }
|
1740
|
+
#
|
1741
|
+
rowsCapitalHistory = self.safe_list(responseCapitalHistory, 'transactions')
|
1742
|
+
responseTradingHistory = promises[1]
|
1743
|
+
#
|
1744
|
+
# {
|
1745
|
+
# "tradingHistory": [
|
1746
|
+
# {
|
1747
|
+
# "eventType": "MARKET",
|
1748
|
+
# "fee": "0.000008",
|
1749
|
+
# "priceOrFundingRate": "119687.82481",
|
1750
|
+
# "quantity": "0.0000003727",
|
1751
|
+
# "realizedPnl": "0.004634",
|
1752
|
+
# "side": "Sell",
|
1753
|
+
# "symbol": "BTC/USDT-P",
|
1754
|
+
# "timestamp": 1752522571
|
1755
|
+
# },
|
1756
|
+
# {
|
1757
|
+
# "eventType": "FundingEvent",
|
1758
|
+
# "fee": "0",
|
1759
|
+
# "priceOrFundingRate": "0.000203",
|
1760
|
+
# "quantity": "0.0000003727",
|
1761
|
+
# "realizedPnl": "-0.000009067899008751979",
|
1762
|
+
# "side": "Long",
|
1763
|
+
# "symbol": "BTC/USDT-P",
|
1764
|
+
# "timestamp": 1752508800
|
1765
|
+
# },
|
1766
|
+
# ]
|
1767
|
+
# }
|
1768
|
+
#
|
1769
|
+
rowsTradingHistory = self.safe_list(responseTradingHistory, 'tradingHistory')
|
1770
|
+
rows = self.array_concat(rowsCapitalHistory, rowsTradingHistory)
|
1771
|
+
return self.parse_ledger(rows, currency, since, limit, params)
|
1772
|
+
|
1773
|
+
def fetch_deposit_address(self, code: str, params={}) -> DepositAddress:
|
1774
|
+
"""
|
1775
|
+
fetch deposit address for given currency and chain. currently, we have a single EVM address across multiple EVM chains. Note: This method is currently only supported for trustless accounts
|
1776
|
+
:param str code: unified currency code
|
1777
|
+
:param dict [params]: extra parameters for API
|
1778
|
+
:param str [params.publicKey]: your public key, you can get it from UI after creating API key
|
1779
|
+
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
|
1780
|
+
"""
|
1781
|
+
request = {
|
1782
|
+
'publicKey': self.safe_string(params, 'publicKey'),
|
1783
|
+
'accountId': self.get_account_id(),
|
1784
|
+
}
|
1785
|
+
response = self.privateGetCapitalDepositInfo(self.extend(request, params))
|
1786
|
+
# {
|
1787
|
+
# "depositAddressEvm": "0x0b95d90b9345dadf1460bd38b9f4bb0d2f4ed788"
|
1788
|
+
# }
|
1789
|
+
return {
|
1790
|
+
'info': response,
|
1791
|
+
'currency': 'USDT',
|
1792
|
+
'network': 'ARBITRUM',
|
1793
|
+
'address': self.safe_string(response, 'depositAddressEvm'),
|
1794
|
+
'tag': None,
|
1795
|
+
}
|
1796
|
+
|
1797
|
+
def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
|
1798
|
+
timestamp = self.safe_integer_product(transaction, 'timestampSec', 1000)
|
1799
|
+
address = self.safe_string(transaction, 'withdrawalAddress')
|
1800
|
+
transactionType = self.safe_string(transaction, 'transactionType')
|
1801
|
+
if transactionType != 'deposit' and transactionType != 'withdrawal':
|
1802
|
+
transactionType = self.parse_transaction_type(transactionType)
|
1803
|
+
return {
|
1804
|
+
'info': transaction,
|
1805
|
+
'id': self.safe_string(transaction, 'id'),
|
1806
|
+
'txid': self.safe_string(transaction, 'transactionHash'),
|
1807
|
+
'timestamp': timestamp,
|
1808
|
+
'datetime': self.iso8601(timestamp),
|
1809
|
+
'network': 'ARBITRUM', # Currently the exchange only exists on Arbitrum,
|
1810
|
+
'address': address,
|
1811
|
+
'addressTo': address,
|
1812
|
+
'addressFrom': None,
|
1813
|
+
'tag': None,
|
1814
|
+
'tagTo': None,
|
1815
|
+
'tagFrom': None,
|
1816
|
+
'type': transactionType,
|
1817
|
+
'amount': self.safe_number(transaction, 'quantity'),
|
1818
|
+
'currency': 'USDT',
|
1819
|
+
'status': self.parse_transaction_status(self.safe_string(transaction, 'status')),
|
1820
|
+
'updated': None,
|
1821
|
+
'internal': None,
|
1822
|
+
'comment': None,
|
1823
|
+
'fee': None,
|
1824
|
+
}
|
1825
|
+
|
1826
|
+
def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
1827
|
+
"""
|
1828
|
+
fetch deposits made to account
|
1829
|
+
|
1830
|
+
https://api-doc.hibachi.xyz/#35125e3f-d154-4bfd-8276-a48bb1c62020
|
1831
|
+
|
1832
|
+
:param str [code]: unified currency code
|
1833
|
+
:param int [since]: filter by earliest timestamp(ms)
|
1834
|
+
:param int [limit]: maximum number of deposits to be returned
|
1835
|
+
:param dict [params]: extra parameters to be passed to API
|
1836
|
+
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
|
1837
|
+
"""
|
1838
|
+
currency = self.safe_currency(code)
|
1839
|
+
request = {
|
1840
|
+
'accountId': self.get_account_id(),
|
1841
|
+
}
|
1842
|
+
response = self.privateGetCapitalHistory(self.extend(request, params))
|
1843
|
+
# {
|
1844
|
+
# "transactions": [
|
1845
|
+
# {
|
1846
|
+
# "assetId": 1,
|
1847
|
+
# "blockNumber": 0,
|
1848
|
+
# "chain": null,
|
1849
|
+
# "etaTsSec": 1752758789,
|
1850
|
+
# "id": 42688,
|
1851
|
+
# "quantity": "6.130000",
|
1852
|
+
# "status": "completed",
|
1853
|
+
# "timestampSec": 1752758788,
|
1854
|
+
# "token": null,
|
1855
|
+
# "transactionHash": "0x8dcd7bd1155b5624fb5e38a1365888f712ec633a57434340e05080c70b0e3bba",
|
1856
|
+
# "transactionType": "deposit"
|
1857
|
+
# },
|
1858
|
+
# {
|
1859
|
+
# "assetId": 1,
|
1860
|
+
# "etaTsSec": null,
|
1861
|
+
# "id": 12993,
|
1862
|
+
# "instantWithdrawalChain": null,
|
1863
|
+
# "instantWithdrawalToken": null,
|
1864
|
+
# "isInstantWithdrawal": False,
|
1865
|
+
# "quantity": "0.111930",
|
1866
|
+
# "status": "completed",
|
1867
|
+
# "timestampSec": 1752387891,
|
1868
|
+
# "transactionHash": "0x32ab5fe5b90f6d753bab83523ebc8465eb9daef54580e13cb9ff031d400c5620",
|
1869
|
+
# "transactionType": "withdrawal",
|
1870
|
+
# "withdrawalAddress": "0x43f15ef2ef2ab5e61e987ee3d652a5872aea8a6c"
|
1871
|
+
# },
|
1872
|
+
# ]
|
1873
|
+
# }
|
1874
|
+
transactions = self.safe_list(response, 'transactions')
|
1875
|
+
deposits = []
|
1876
|
+
for i in range(0, len(transactions)):
|
1877
|
+
transaction = transactions[i]
|
1878
|
+
if self.safe_string(transaction, 'transactionType') == 'deposit':
|
1879
|
+
deposits.append(transaction)
|
1880
|
+
return self.parse_transactions(deposits, currency, since, limit, params)
|
1881
|
+
|
1882
|
+
def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
1883
|
+
"""
|
1884
|
+
fetch withdrawals made from account
|
1885
|
+
|
1886
|
+
https://api-doc.hibachi.xyz/#35125e3f-d154-4bfd-8276-a48bb1c62020
|
1887
|
+
|
1888
|
+
:param str [code]: unified currency code
|
1889
|
+
:param int [since]: filter by earliest timestamp(ms)
|
1890
|
+
:param int [limit]: maximum number of deposits to be returned
|
1891
|
+
:param dict [params]: extra parameters to be passed to API
|
1892
|
+
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
|
1893
|
+
"""
|
1894
|
+
currency = self.safe_currency(code)
|
1895
|
+
request = {
|
1896
|
+
'accountId': self.get_account_id(),
|
1897
|
+
}
|
1898
|
+
response = self.privateGetCapitalHistory(self.extend(request, params))
|
1899
|
+
# {
|
1900
|
+
# "transactions": [
|
1901
|
+
# {
|
1902
|
+
# "assetId": 1,
|
1903
|
+
# "blockNumber": 0,
|
1904
|
+
# "chain": null,
|
1905
|
+
# "etaTsSec": 1752758789,
|
1906
|
+
# "id": 42688,
|
1907
|
+
# "quantity": "6.130000",
|
1908
|
+
# "status": "completed",
|
1909
|
+
# "timestampSec": 1752758788,
|
1910
|
+
# "token": null,
|
1911
|
+
# "transactionHash": "0x8dcd7bd1155b5624fb5e38a1365888f712ec633a57434340e05080c70b0e3bba",
|
1912
|
+
# "transactionType": "deposit"
|
1913
|
+
# },
|
1914
|
+
# {
|
1915
|
+
# "assetId": 1,
|
1916
|
+
# "etaTsSec": null,
|
1917
|
+
# "id": 12993,
|
1918
|
+
# "instantWithdrawalChain": null,
|
1919
|
+
# "instantWithdrawalToken": null,
|
1920
|
+
# "isInstantWithdrawal": False,
|
1921
|
+
# "quantity": "0.111930",
|
1922
|
+
# "status": "completed",
|
1923
|
+
# "timestampSec": 1752387891,
|
1924
|
+
# "transactionHash": "0x32ab5fe5b90f6d753bab83523ebc8465eb9daef54580e13cb9ff031d400c5620",
|
1925
|
+
# "transactionType": "withdrawal",
|
1926
|
+
# "withdrawalAddress": "0x43f15ef2ef2ab5e61e987ee3d652a5872aea8a6c"
|
1927
|
+
# },
|
1928
|
+
# ]
|
1929
|
+
# }
|
1930
|
+
transactions = self.safe_list(response, 'transactions')
|
1931
|
+
withdrawals = []
|
1932
|
+
for i in range(0, len(transactions)):
|
1933
|
+
transaction = transactions[i]
|
1934
|
+
if self.safe_string(transaction, 'transactionType') == 'withdrawal':
|
1935
|
+
withdrawals.append(transaction)
|
1936
|
+
return self.parse_transactions(withdrawals, currency, since, limit, params)
|
1937
|
+
|
1938
|
+
def fetch_time(self, params={}) -> Int:
|
1939
|
+
"""
|
1940
|
+
fetches the current integer timestamp in milliseconds from the exchange server
|
1941
|
+
|
1942
|
+
http://api-doc.hibachi.xyz/#b5c6a3bc-243d-4d35-b6d4-a74c92495434
|
1943
|
+
|
1944
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1945
|
+
:returns int: the current integer timestamp in milliseconds from the exchange server
|
1946
|
+
"""
|
1947
|
+
response = self.publicGetExchangeUtcTimestamp(params)
|
1948
|
+
#
|
1949
|
+
# {"timestampMs":1754077574040}
|
1950
|
+
#
|
1951
|
+
return self.safe_integer(response, 'timestampMs')
|
1952
|
+
|
1953
|
+
def fetch_open_interest(self, symbol: str, params={}):
|
1954
|
+
"""
|
1955
|
+
retrieves the open interest of a contract trading pair
|
1956
|
+
|
1957
|
+
https://api-doc.hibachi.xyz/#bc34e8ae-e094-4802-8d56-3efe3a7bad49
|
1958
|
+
|
1959
|
+
:param str symbol: unified CCXT market symbol
|
1960
|
+
:param dict [params]: exchange specific parameters
|
1961
|
+
:returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
|
1962
|
+
"""
|
1963
|
+
self.load_markets()
|
1964
|
+
market = self.market(symbol)
|
1965
|
+
request: dict = {
|
1966
|
+
'symbol': market['id'],
|
1967
|
+
}
|
1968
|
+
response = self.publicGetMarketDataOpenInterest(self.extend(request, params))
|
1969
|
+
#
|
1970
|
+
# {"totalQuantity" : "2.3299770166"}
|
1971
|
+
#
|
1972
|
+
timestamp = self.milliseconds()
|
1973
|
+
return self.safe_open_interest({
|
1974
|
+
'symbol': symbol,
|
1975
|
+
'openInterestAmount': self.safe_string(response, 'totalQuantity'),
|
1976
|
+
'openInterestValue': None,
|
1977
|
+
'timestamp': timestamp,
|
1978
|
+
'datetime': self.iso8601(timestamp),
|
1979
|
+
'info': response,
|
1980
|
+
}, market)
|
1981
|
+
|
1982
|
+
def fetch_funding_rate(self, symbol: str, params={}) -> FundingRate:
|
1983
|
+
"""
|
1984
|
+
fetch the current funding rate
|
1985
|
+
|
1986
|
+
https://api-doc.hibachi.xyz/#bca696ca-b9b2-4072-8864-5d6b8c09807e
|
1987
|
+
|
1988
|
+
:param str symbol: unified market symbol
|
1989
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1990
|
+
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
|
1991
|
+
"""
|
1992
|
+
self.load_markets()
|
1993
|
+
market = self.market(symbol)
|
1994
|
+
request: dict = {
|
1995
|
+
'symbol': market['id'],
|
1996
|
+
}
|
1997
|
+
response = self.publicGetMarketDataPrices(self.extend(request, params))
|
1998
|
+
#
|
1999
|
+
# {
|
2000
|
+
# "askPrice": "3514.650296",
|
2001
|
+
# "bidPrice": "3513.596112",
|
2002
|
+
# "fundingRateEstimation": {
|
2003
|
+
# "estimatedFundingRate": "0.000001",
|
2004
|
+
# "nextFundingTimestamp": 1712707200
|
2005
|
+
# },
|
2006
|
+
# "markPrice": "3514.288858",
|
2007
|
+
# "spotPrice": "3514.715000",
|
2008
|
+
# "symbol": "ETH/USDT-P",
|
2009
|
+
# "tradePrice": "2372.746570"
|
2010
|
+
# }
|
2011
|
+
#
|
2012
|
+
funding = self.safe_dict(response, 'fundingRateEstimation', {})
|
2013
|
+
timestamp = self.milliseconds()
|
2014
|
+
nextFundingTimestamp = self.safe_integer_product(funding, 'nextFundingTimestamp', 1000)
|
2015
|
+
return {
|
2016
|
+
'info': funding,
|
2017
|
+
'symbol': market['symbol'],
|
2018
|
+
'markPrice': None,
|
2019
|
+
'indexPrice': None,
|
2020
|
+
'interestRate': self.parse_number('0'),
|
2021
|
+
'estimatedSettlePrice': None,
|
2022
|
+
'timestamp': timestamp,
|
2023
|
+
'datetime': self.iso8601(timestamp),
|
2024
|
+
'fundingRate': self.safe_number(funding, 'estimatedFundingRate'),
|
2025
|
+
'fundingTimestamp': nextFundingTimestamp,
|
2026
|
+
'fundingDatetime': self.iso8601(nextFundingTimestamp),
|
2027
|
+
'nextFundingRate': None,
|
2028
|
+
'nextFundingTimestamp': None,
|
2029
|
+
'nextFundingDatetime': None,
|
2030
|
+
'previousFundingRate': None,
|
2031
|
+
'previousFundingTimestamp': None,
|
2032
|
+
'previousFundingDatetime': None,
|
2033
|
+
'interval': '8h',
|
2034
|
+
}
|
2035
|
+
|
2036
|
+
def fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
2037
|
+
"""
|
2038
|
+
fetches historical funding rate prices
|
2039
|
+
|
2040
|
+
https://api-doc.hibachi.xyz/#4abb30c4-e5c7-4b0f-9ade-790111dbfa47
|
2041
|
+
|
2042
|
+
:param str symbol: unified symbol of the market to fetch the funding rate history for
|
2043
|
+
:param int [since]: timestamp in ms of the earliest funding rate to fetch
|
2044
|
+
:param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
|
2045
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2046
|
+
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
|
2047
|
+
"""
|
2048
|
+
self.load_markets()
|
2049
|
+
market = self.market(symbol)
|
2050
|
+
request: dict = {
|
2051
|
+
'symbol': market['id'],
|
2052
|
+
}
|
2053
|
+
response = self.publicGetMarketDataFundingRates(self.extend(request, params))
|
2054
|
+
#
|
2055
|
+
# {
|
2056
|
+
# "data": [
|
2057
|
+
# {
|
2058
|
+
# "contractId": 2,
|
2059
|
+
# "fundingTimestamp": 1753488000,
|
2060
|
+
# "fundingRate": "0.000137",
|
2061
|
+
# "indexPrice": "117623.65010"
|
2062
|
+
# }
|
2063
|
+
# ]
|
2064
|
+
# }
|
2065
|
+
#
|
2066
|
+
data = self.safe_list(response, 'data')
|
2067
|
+
rates = []
|
2068
|
+
for i in range(0, len(data)):
|
2069
|
+
entry = data[i]
|
2070
|
+
timestamp = self.safe_integer_product(entry, 'fundingTimestamp', 1000)
|
2071
|
+
rates.append({
|
2072
|
+
'info': entry,
|
2073
|
+
'symbol': symbol,
|
2074
|
+
'fundingRate': self.safe_number(entry, 'fundingRate'),
|
2075
|
+
'timestamp': timestamp,
|
2076
|
+
'datetime': self.iso8601(timestamp),
|
2077
|
+
})
|
2078
|
+
sorted = self.sort_by(rates, 'timestamp')
|
2079
|
+
return self.filter_by_symbol_since_limit(sorted, symbol, since, limit)
|