ccxt 4.4.5__py2.py3-none-any.whl → 4.4.7__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.
@@ -268,6 +268,10 @@ class bitmart(Exchange, ImplicitAPI):
268
268
  'contract/private/submit-plan-order': 2.5,
269
269
  'contract/private/cancel-plan-order': 1.5,
270
270
  'contract/private/submit-leverage': 2.5,
271
+ 'contract/private/submit-tp-sl-order': 2.5,
272
+ 'contract/private/modify-plan-order': 2.5,
273
+ 'contract/private/modify-preset-plan-order': 2.5,
274
+ 'contract/private/modify-tp-sl-order': 2.5,
271
275
  },
272
276
  },
273
277
  },
@@ -881,43 +885,43 @@ class bitmart(Exchange, ImplicitAPI):
881
885
  async def fetch_contract_markets(self, params={}):
882
886
  response = await self.publicGetContractPublicDetails(params)
883
887
  #
884
- # {
885
- # "code": 1000,
886
- # "message": "Ok",
887
- # "trace": "9b92a999-9463-4c96-91a4-93ad1cad0d72",
888
- # "data": {
889
- # "symbols": [
890
- # {
891
- # "symbol": "BTCUSDT",
892
- # "product_type": 1,
893
- # "open_timestamp": 1594080000,
894
- # "expire_timestamp": 0,
895
- # "settle_timestamp": 0,
896
- # "base_currency": "BTC",
897
- # "quote_currency": "USDT",
898
- # "last_price": "23920",
899
- # "volume_24h": "18969368",
900
- # "turnover_24h": "458933659.7858",
901
- # "index_price": "23945.25191635",
902
- # "index_name": "BTCUSDT",
903
- # "contract_size": "0.001",
904
- # "min_leverage": "1",
905
- # "max_leverage": "100",
906
- # "price_precision": "0.1",
907
- # "vol_precision": "1",
908
- # "max_volume": "500000",
909
- # "min_volume": "1",
910
- # "funding_rate": "0.0001",
911
- # "expected_funding_rate": "0.00011",
912
- # "open_interest": "4134180870",
913
- # "open_interest_value": "94100888927.0433258",
914
- # "high_24h": "23900",
915
- # "low_24h": "23100",
916
- # "change_24h": "0.004"
917
- # },
918
- # ]
888
+ # {
889
+ # "code": 1000,
890
+ # "message": "Ok",
891
+ # "data": {
892
+ # "symbols": [
893
+ # {
894
+ # "symbol": "BTCUSDT",
895
+ # "product_type": 1,
896
+ # "open_timestamp": 1645977600000,
897
+ # "expire_timestamp": 0,
898
+ # "settle_timestamp": 0,
899
+ # "base_currency": "BTC",
900
+ # "quote_currency": "USDT",
901
+ # "last_price": "63547.4",
902
+ # "volume_24h": "110938430",
903
+ # "turnover_24h": "7004836342.6944",
904
+ # "index_price": "63587.85404255",
905
+ # "index_name": "BTCUSDT",
906
+ # "contract_size": "0.001",
907
+ # "min_leverage": "1",
908
+ # "max_leverage": "100",
909
+ # "price_precision": "0.1",
910
+ # "vol_precision": "1",
911
+ # "max_volume": "1000000",
912
+ # "min_volume": "1",
913
+ # "funding_rate": "0.0000801",
914
+ # "expected_funding_rate": "-0.0000035",
915
+ # "open_interest": "278214",
916
+ # "open_interest_value": "17555316.9355496",
917
+ # "high_24h": "64109.4",
918
+ # "low_24h": "61857.6",
919
+ # "change_24h": "0.0239264900886327",
920
+ # "funding_time": 1726819200000
921
+ # },
922
+ # ]
923
+ # }
919
924
  # }
920
- # }
921
925
  #
922
926
  data = self.safe_value(response, 'data', {})
923
927
  symbols = self.safe_value(data, 'symbols', [])
@@ -1192,33 +1196,34 @@ class bitmart(Exchange, ImplicitAPI):
1192
1196
  # swap
1193
1197
  #
1194
1198
  # {
1195
- # "symbol": "BTCUSDT",
1196
- # "product_type": 1,
1197
- # "open_timestamp": 1594080000,
1198
- # "expire_timestamp": 0,
1199
- # "settle_timestamp": 0,
1200
- # "base_currency": "BTC",
1201
- # "quote_currency": "USDT",
1202
- # "last_price": "23920",
1203
- # "volume_24h": "18969368",
1204
- # "turnover_24h": "458933659.7858",
1205
- # "index_price": "23945.25191635",
1206
- # "index_name": "BTCUSDT",
1207
- # "contract_size": "0.001",
1208
- # "min_leverage": "1",
1209
- # "max_leverage": "100",
1210
- # "price_precision": "0.1",
1211
- # "vol_precision": "1",
1212
- # "max_volume": "500000",
1213
- # "min_volume": "1",
1214
- # "funding_rate": "0.0001",
1215
- # "expected_funding_rate": "0.00011",
1216
- # "open_interest": "4134180870",
1217
- # "open_interest_value": "94100888927.0433258",
1218
- # "high_24h": "23900",
1219
- # "low_24h": "23100",
1220
- # "change_24h": "0.004"
1221
- # }
1199
+ # "symbol": "BTCUSDT",
1200
+ # "product_type": 1,
1201
+ # "open_timestamp": 1645977600000,
1202
+ # "expire_timestamp": 0,
1203
+ # "settle_timestamp": 0,
1204
+ # "base_currency": "BTC",
1205
+ # "quote_currency": "USDT",
1206
+ # "last_price": "63547.4",
1207
+ # "volume_24h": "110938430",
1208
+ # "turnover_24h": "7004836342.6944",
1209
+ # "index_price": "63587.85404255",
1210
+ # "index_name": "BTCUSDT",
1211
+ # "contract_size": "0.001",
1212
+ # "min_leverage": "1",
1213
+ # "max_leverage": "100",
1214
+ # "price_precision": "0.1",
1215
+ # "vol_precision": "1",
1216
+ # "max_volume": "1000000",
1217
+ # "min_volume": "1",
1218
+ # "funding_rate": "0.0000801",
1219
+ # "expected_funding_rate": "-0.0000035",
1220
+ # "open_interest": "278214",
1221
+ # "open_interest_value": "17555316.9355496",
1222
+ # "high_24h": "64109.4",
1223
+ # "low_24h": "61857.6",
1224
+ # "change_24h": "0.0239264900886327",
1225
+ # "funding_time": 1726819200000
1226
+ # }
1222
1227
  #
1223
1228
  result = self.safe_list(ticker, 'result', [])
1224
1229
  average = self.safe_string_2(ticker, 'avg_price', 'index_price')
@@ -1307,27 +1312,43 @@ class bitmart(Exchange, ImplicitAPI):
1307
1312
  request['symbol'] = market['id']
1308
1313
  response = await self.publicGetContractPublicDetails(self.extend(request, params))
1309
1314
  #
1310
- # {
1311
- # "message":"OK",
1312
- # "code":1000,
1313
- # "trace":"4a0ebceb-d3f7-45a3-8feb-f61e230e24cd",
1314
- # "data":{
1315
- # "tickers":[
1316
- # {
1317
- # "contract_symbol":"DOGEUSDT",
1318
- # "last_price":"0.130180",
1319
- # "index_price":"0.13028635",
1320
- # "last_funding_rate":"0.00002025",
1321
- # "price_change_percent_24h":"-2.326",
1322
- # "volume_24h":"116789313.01797258",
1323
- # "url":"https://futures.bitmart.com/en?symbol=DOGEUSDT",
1324
- # "high_price":"0.134520",
1325
- # "low_price":"0.128570",
1326
- # "legal_coin_price":"0.13017401"
1327
- # }
1328
- # ]
1329
- # }
1330
- # }
1315
+ # {
1316
+ # "code": 1000,
1317
+ # "message": "Ok",
1318
+ # "data": {
1319
+ # "symbols": [
1320
+ # {
1321
+ # "symbol": "BTCUSDT",
1322
+ # "product_type": 1,
1323
+ # "open_timestamp": 1645977600000,
1324
+ # "expire_timestamp": 0,
1325
+ # "settle_timestamp": 0,
1326
+ # "base_currency": "BTC",
1327
+ # "quote_currency": "USDT",
1328
+ # "last_price": "63547.4",
1329
+ # "volume_24h": "110938430",
1330
+ # "turnover_24h": "7004836342.6944",
1331
+ # "index_price": "63587.85404255",
1332
+ # "index_name": "BTCUSDT",
1333
+ # "contract_size": "0.001",
1334
+ # "min_leverage": "1",
1335
+ # "max_leverage": "100",
1336
+ # "price_precision": "0.1",
1337
+ # "vol_precision": "1",
1338
+ # "max_volume": "1000000",
1339
+ # "min_volume": "1",
1340
+ # "funding_rate": "0.0000801",
1341
+ # "expected_funding_rate": "-0.0000035",
1342
+ # "open_interest": "278214",
1343
+ # "open_interest_value": "17555316.9355496",
1344
+ # "high_24h": "64109.4",
1345
+ # "low_24h": "61857.6",
1346
+ # "change_24h": "0.0239264900886327",
1347
+ # "funding_time": 1726819200000
1348
+ # },
1349
+ # ]
1350
+ # }
1351
+ # }
1331
1352
  #
1332
1353
  elif market['spot']:
1333
1354
  request['symbol'] = market['id']
@@ -1414,43 +1435,43 @@ class bitmart(Exchange, ImplicitAPI):
1414
1435
  elif type == 'swap':
1415
1436
  response = await self.publicGetContractPublicDetails(params)
1416
1437
  #
1417
- # {
1418
- # "code": 1000,
1419
- # "message": "Ok",
1420
- # "trace": "9b92a999-9463-4c96-91a4-93ad1cad0d72",
1421
- # "data": {
1422
- # "symbols": [
1423
- # {
1424
- # "symbol": "BTCUSDT",
1425
- # "product_type": 1,
1426
- # "open_timestamp": 1594080000,
1427
- # "expire_timestamp": 0,
1428
- # "settle_timestamp": 0,
1429
- # "base_currency": "BTC",
1430
- # "quote_currency": "USDT",
1431
- # "last_price": "23920",
1432
- # "volume_24h": "18969368",
1433
- # "turnover_24h": "458933659.7858",
1434
- # "index_price": "23945.25191635",
1435
- # "index_name": "BTCUSDT",
1436
- # "contract_size": "0.001",
1437
- # "min_leverage": "1",
1438
- # "max_leverage": "100",
1439
- # "price_precision": "0.1",
1440
- # "vol_precision": "1",
1441
- # "max_volume": "500000",
1442
- # "min_volume": "1",
1443
- # "funding_rate": "0.0001",
1444
- # "expected_funding_rate": "0.00011",
1445
- # "open_interest": "4134180870",
1446
- # "open_interest_value": "94100888927.0433258",
1447
- # "high_24h": "23900",
1448
- # "low_24h": "23100",
1449
- # "change_24h": "0.004"
1450
- # },
1451
- # ]
1452
- # }
1453
- # }
1438
+ # {
1439
+ # "code": 1000,
1440
+ # "message": "Ok",
1441
+ # "data": {
1442
+ # "symbols": [
1443
+ # {
1444
+ # "symbol": "BTCUSDT",
1445
+ # "product_type": 1,
1446
+ # "open_timestamp": 1645977600000,
1447
+ # "expire_timestamp": 0,
1448
+ # "settle_timestamp": 0,
1449
+ # "base_currency": "BTC",
1450
+ # "quote_currency": "USDT",
1451
+ # "last_price": "63547.4",
1452
+ # "volume_24h": "110938430",
1453
+ # "turnover_24h": "7004836342.6944",
1454
+ # "index_price": "63587.85404255",
1455
+ # "index_name": "BTCUSDT",
1456
+ # "contract_size": "0.001",
1457
+ # "min_leverage": "1",
1458
+ # "max_leverage": "100",
1459
+ # "price_precision": "0.1",
1460
+ # "vol_precision": "1",
1461
+ # "max_volume": "1000000",
1462
+ # "min_volume": "1",
1463
+ # "funding_rate": "0.0000801",
1464
+ # "expected_funding_rate": "-0.0000035",
1465
+ # "open_interest": "278214",
1466
+ # "open_interest_value": "17555316.9355496",
1467
+ # "high_24h": "64109.4",
1468
+ # "low_24h": "61857.6",
1469
+ # "change_24h": "0.0239264900886327",
1470
+ # "funding_time": 1726819200000
1471
+ # },
1472
+ # ]
1473
+ # }
1474
+ # }
1454
1475
  #
1455
1476
  else:
1456
1477
  raise NotSupported(self.id + ' fetchTickers() does not support ' + type + ' markets, only spot and swap markets are accepted')
@@ -2185,7 +2206,7 @@ class bitmart(Exchange, ImplicitAPI):
2185
2206
 
2186
2207
  def parse_order(self, order: dict, market: Market = None) -> Order:
2187
2208
  #
2188
- # createOrder
2209
+ # createOrder, editOrder
2189
2210
  #
2190
2211
  # {
2191
2212
  # "order_id": 2707217580
@@ -2366,6 +2387,7 @@ class bitmart(Exchange, ImplicitAPI):
2366
2387
  :see: https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2367
2388
  :see: https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2368
2389
  :see: https://developer-pro.bitmart.com/en/futuresv2/#submit-plan-order-signed
2390
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#submit-tp-or-sl-order-signed
2369
2391
  :param str symbol: unified symbol of the market to create an order in
2370
2392
  :param str type: 'market', 'limit' or 'trailing' for swap markets only
2371
2393
  :param str side: 'buy' or 'sell'
@@ -2383,6 +2405,9 @@ class bitmart(Exchange, ImplicitAPI):
2383
2405
  :param int [params.activation_price_type]: *swap trailing order only* 1: last price, 2: fair price, default is 1
2384
2406
  :param str [params.trailingPercent]: *swap only* the percent to trail away from the current market price, min 0.1 max 5
2385
2407
  :param str [params.trailingTriggerPrice]: *swap only* the price to trigger a trailing order, default uses the price argument
2408
+ :param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
2409
+ :param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
2410
+ :param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
2386
2411
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2387
2412
  """
2388
2413
  await self.load_markets()
@@ -2390,6 +2415,10 @@ class bitmart(Exchange, ImplicitAPI):
2390
2415
  result = self.handle_margin_mode_and_params('createOrder', params)
2391
2416
  marginMode = self.safe_string(result, 0)
2392
2417
  triggerPrice = self.safe_string_n(params, ['triggerPrice', 'stopPrice', 'trigger_price'])
2418
+ stopLossPrice = self.safe_string(params, 'stopLossPrice')
2419
+ takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
2420
+ isStopLoss = stopLossPrice is not None
2421
+ isTakeProfit = takeProfitPrice is not None
2393
2422
  isTriggerOrder = triggerPrice is not None
2394
2423
  response = None
2395
2424
  if market['spot']:
@@ -2402,6 +2431,8 @@ class bitmart(Exchange, ImplicitAPI):
2402
2431
  swapRequest = self.create_swap_order_request(symbol, type, side, amount, price, params)
2403
2432
  if isTriggerOrder:
2404
2433
  response = await self.privatePostContractPrivateSubmitPlanOrder(swapRequest)
2434
+ elif isStopLoss or isTakeProfit:
2435
+ response = await self.privatePostContractPrivateSubmitTpSlOrder(swapRequest)
2405
2436
  else:
2406
2437
  response = await self.privatePostContractPrivateSubmitOrder(swapRequest)
2407
2438
  #
@@ -2496,8 +2527,9 @@ class bitmart(Exchange, ImplicitAPI):
2496
2527
  :see: https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2497
2528
  :see: https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2498
2529
  :see: https://developer-pro.bitmart.com/en/futuresv2/#submit-plan-order-signed
2530
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#submit-tp-or-sl-order-signed
2499
2531
  :param str symbol: unified symbol of the market to create an order in
2500
- :param str type: 'market', 'limit' or 'trailing'
2532
+ :param str type: 'market', 'limit', 'trailing', 'stop_loss', or 'take_profit'
2501
2533
  :param str side: 'buy' or 'sell'
2502
2534
  :param float amount: how much of currency you want to trade in units of base currency
2503
2535
  :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
@@ -2512,9 +2544,20 @@ class bitmart(Exchange, ImplicitAPI):
2512
2544
  :param int [params.activation_price_type]: *swap trailing order only* 1: last price, 2: fair price, default is 1
2513
2545
  :param str [params.trailingPercent]: *swap only* the percent to trail away from the current market price, min 0.1 max 5
2514
2546
  :param str [params.trailingTriggerPrice]: *swap only* the price to trigger a trailing order, default uses the price argument
2547
+ :param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
2548
+ :param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
2549
+ :param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
2515
2550
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2516
2551
  """
2517
2552
  market = self.market(symbol)
2553
+ stopLossPrice = self.safe_string(params, 'stopLossPrice')
2554
+ takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
2555
+ isStopLoss = stopLossPrice is not None
2556
+ isTakeProfit = takeProfitPrice is not None
2557
+ if isStopLoss:
2558
+ type = 'stop_loss'
2559
+ elif isTakeProfit:
2560
+ type = 'take_profit'
2518
2561
  request: dict = {
2519
2562
  'symbol': market['id'],
2520
2563
  'type': type,
@@ -2524,7 +2567,7 @@ class bitmart(Exchange, ImplicitAPI):
2524
2567
  mode = self.safe_integer(params, 'mode') # only for swap
2525
2568
  isMarketOrder = type == 'market'
2526
2569
  postOnly = None
2527
- reduceOnly = self.safe_value(params, 'reduceOnly')
2570
+ reduceOnly = self.safe_bool(params, 'reduceOnly')
2528
2571
  isExchangeSpecificPo = (mode == 4)
2529
2572
  postOnly, params = self.handle_post_only(isMarketOrder, isExchangeSpecificPo, params)
2530
2573
  ioc = ((timeInForce == 'IOC') or (mode == 3))
@@ -2563,6 +2606,18 @@ class bitmart(Exchange, ImplicitAPI):
2563
2606
  request['price_way'] = 1
2564
2607
  else:
2565
2608
  request['price_way'] = 2
2609
+ marginMode = None
2610
+ marginMode, params = self.handle_margin_mode_and_params('createOrder', params, 'cross')
2611
+ if isStopLoss or isTakeProfit:
2612
+ reduceOnly = True
2613
+ request['price_type'] = self.safe_integer(params, 'price_type', 1)
2614
+ request['executive_price'] = self.price_to_precision(symbol, price)
2615
+ if isStopLoss:
2616
+ request['trigger_price'] = self.price_to_precision(symbol, stopLossPrice)
2617
+ else:
2618
+ request['trigger_price'] = self.price_to_precision(symbol, takeProfitPrice)
2619
+ else:
2620
+ request['open_type'] = marginMode
2566
2621
  if side == 'buy':
2567
2622
  if reduceOnly:
2568
2623
  request['side'] = 2 # buy close short
@@ -2573,15 +2628,12 @@ class bitmart(Exchange, ImplicitAPI):
2573
2628
  request['side'] = 3 # sell close long
2574
2629
  else:
2575
2630
  request['side'] = 4 # sell open short
2576
- marginMode = None
2577
- marginMode, params = self.handle_margin_mode_and_params('createOrder', params, 'cross')
2578
- request['open_type'] = marginMode
2579
2631
  clientOrderId = self.safe_string(params, 'clientOrderId')
2580
2632
  if clientOrderId is not None:
2581
2633
  params = self.omit(params, 'clientOrderId')
2582
2634
  request['client_order_id'] = clientOrderId
2583
2635
  leverage = self.safe_integer(params, 'leverage')
2584
- params = self.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice'])
2636
+ params = self.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice'])
2585
2637
  if leverage is not None:
2586
2638
  request['leverage'] = self.number_to_string(leverage)
2587
2639
  elif isTriggerOrder:
@@ -4414,6 +4466,114 @@ class bitmart(Exchange, ImplicitAPI):
4414
4466
  'datetime': self.iso8601(timestamp),
4415
4467
  })
4416
4468
 
4469
+ async def edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}) -> Order:
4470
+ """
4471
+ edits an open order
4472
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#modify-plan-order-signed
4473
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#modify-tp-sl-order-signed
4474
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#modify-preset-plan-order-signed
4475
+ :param str id: order id
4476
+ :param str symbol: unified symbol of the market to edit an order in
4477
+ :param str type: 'market' or 'limit'
4478
+ :param str side: 'buy' or 'sell'
4479
+ :param float [amount]: how much you want to trade in units of the base currency
4480
+ :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
4481
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4482
+ :param str [params.triggerPrice]: *swap only* the price to trigger a stop order
4483
+ :param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
4484
+ :param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
4485
+ :param str [params.stopLoss.triggerPrice]: *swap only* the price to trigger a preset stop-loss order
4486
+ :param str [params.takeProfit.triggerPrice]: *swap only* the price to trigger a preset take-profit order
4487
+ :param str [params.clientOrderId]: client order id of the order
4488
+ :param int [params.price_type]: *swap only* 1: last price, 2: fair price, default is 1
4489
+ :param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
4490
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4491
+ """
4492
+ await self.load_markets()
4493
+ market = self.market(symbol)
4494
+ if not market['swap']:
4495
+ raise NotSupported(self.id + ' editOrder() does not support ' + market['type'] + ' markets, only swap markets are supported')
4496
+ stopLossPrice = self.safe_string(params, 'stopLossPrice')
4497
+ takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
4498
+ triggerPrice = self.safe_string_n(params, ['triggerPrice', 'stopPrice', 'trigger_price'])
4499
+ stopLoss = self.safe_dict(params, 'stopLoss', {})
4500
+ takeProfit = self.safe_dict(params, 'takeProfit', {})
4501
+ presetStopLoss = self.safe_string(stopLoss, 'triggerPrice')
4502
+ presetTakeProfit = self.safe_string(takeProfit, 'triggerPrice')
4503
+ isTriggerOrder = triggerPrice is not None
4504
+ isStopLoss = stopLossPrice is not None
4505
+ isTakeProfit = takeProfitPrice is not None
4506
+ isPresetStopLoss = presetStopLoss is not None
4507
+ isPresetTakeProfit = presetTakeProfit is not None
4508
+ request: dict = {
4509
+ 'symbol': market['id'],
4510
+ }
4511
+ clientOrderId = self.safe_string(params, 'clientOrderId')
4512
+ if clientOrderId is not None:
4513
+ params = self.omit(params, 'clientOrderId')
4514
+ request['client_order_id'] = clientOrderId
4515
+ if id is not None:
4516
+ request['order_id'] = id
4517
+ params = self.omit(params, ['triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit'])
4518
+ response = None
4519
+ if isTriggerOrder or isStopLoss or isTakeProfit:
4520
+ request['price_type'] = self.safe_integer(params, 'price_type', 1)
4521
+ if price is not None:
4522
+ request['executive_price'] = self.price_to_precision(symbol, price)
4523
+ if isTriggerOrder:
4524
+ request['type'] = type
4525
+ request['trigger_price'] = self.price_to_precision(symbol, triggerPrice)
4526
+ response = await self.privatePostContractPrivateModifyPlanOrder(self.extend(request, params))
4527
+ #
4528
+ # {
4529
+ # "code": 1000,
4530
+ # "message": "Ok",
4531
+ # "data": {
4532
+ # "order_id": "3000023150003503"
4533
+ # },
4534
+ # "trace": "324523453245.108.1734567125596324575"
4535
+ # }
4536
+ #
4537
+ elif isStopLoss or isTakeProfit:
4538
+ request['category'] = type
4539
+ if isStopLoss:
4540
+ request['trigger_price'] = self.price_to_precision(symbol, stopLossPrice)
4541
+ else:
4542
+ request['trigger_price'] = self.price_to_precision(symbol, takeProfitPrice)
4543
+ response = await self.privatePostContractPrivateModifyTpSlOrder(self.extend(request, params))
4544
+ #
4545
+ # {
4546
+ # "code": 1000,
4547
+ # "message": "Ok",
4548
+ # "data": {
4549
+ # "order_id": "3000023150003480"
4550
+ # },
4551
+ # "trace": "23452345.104.1724536582682345459"
4552
+ # }
4553
+ #
4554
+ elif isPresetStopLoss or isPresetTakeProfit:
4555
+ if isPresetStopLoss:
4556
+ request['preset_stop_loss_price_type'] = self.safe_integer(params, 'price_type', 1)
4557
+ request['preset_stop_loss_price'] = self.price_to_precision(symbol, presetStopLoss)
4558
+ else:
4559
+ request['preset_take_profit_price_type'] = self.safe_integer(params, 'price_type', 1)
4560
+ request['preset_take_profit_price'] = self.price_to_precision(symbol, presetTakeProfit)
4561
+ response = await self.privatePostContractPrivateModifyPresetPlanOrder(self.extend(request, params))
4562
+ #
4563
+ # {
4564
+ # "code": 1000,
4565
+ # "message": "Ok",
4566
+ # "data": {
4567
+ # "order_id": "3000023150003496"
4568
+ # },
4569
+ # "trace": "a5c3234534534a836bc476a203.123452.172716624359200197"
4570
+ # }
4571
+ #
4572
+ else:
4573
+ raise NotSupported(self.id + ' editOrder() only supports trigger, stop loss and take profit orders')
4574
+ data = self.safe_dict(response, 'data', {})
4575
+ return self.parse_order(data, market)
4576
+
4417
4577
  def nonce(self):
4418
4578
  return self.milliseconds()
4419
4579
 
@@ -1614,12 +1614,19 @@ class bybit(Exchange, ImplicitAPI):
1614
1614
  async def fetch_future_markets(self, params):
1615
1615
  params = self.extend(params)
1616
1616
  params['limit'] = 1000 # minimize number of requests
1617
+ preLaunchMarkets = []
1617
1618
  usePrivateInstrumentsInfo = self.safe_bool(self.options, 'usePrivateInstrumentsInfo', False)
1618
1619
  response: dict = None
1619
1620
  if usePrivateInstrumentsInfo:
1620
1621
  response = await self.privateGetV5MarketInstrumentsInfo(params)
1621
1622
  else:
1622
- response = await self.publicGetV5MarketInstrumentsInfo(params)
1623
+ linearPromises = [
1624
+ self.publicGetV5MarketInstrumentsInfo(params),
1625
+ self.publicGetV5MarketInstrumentsInfo(self.extend(params, {'status': 'PreLaunch'})),
1626
+ ]
1627
+ promises = await asyncio.gather(*linearPromises)
1628
+ response = self.safe_dict(promises, 0, {})
1629
+ preLaunchMarkets = self.safe_dict(promises, 1, {})
1623
1630
  data = self.safe_dict(response, 'result', {})
1624
1631
  markets = self.safe_list(data, 'list', [])
1625
1632
  paginationCursor = self.safe_string(data, 'nextPageCursor')
@@ -1682,6 +1689,9 @@ class bybit(Exchange, ImplicitAPI):
1682
1689
  # "time": 1672712495660
1683
1690
  # }
1684
1691
  #
1692
+ preLaunchData = self.safe_dict(preLaunchMarkets, 'result', {})
1693
+ preLaunchMarketsList = self.safe_list(preLaunchData, 'list', [])
1694
+ markets = self.array_concat(markets, preLaunchMarketsList)
1685
1695
  result = []
1686
1696
  category = self.safe_string(data, 'category')
1687
1697
  for i in range(0, len(markets)):
@@ -5776,13 +5786,17 @@ class bybit(Exchange, ImplicitAPI):
5776
5786
  currencyId = self.safe_string_2(item, 'coin', 'currency')
5777
5787
  code = self.safe_currency_code(currencyId, currency)
5778
5788
  currency = self.safe_currency(currencyId, currency)
5779
- amount = self.safe_string_2(item, 'amount', 'change')
5780
- after = self.safe_string_2(item, 'wallet_balance', 'cashBalance')
5781
- direction = 'out' if Precise.string_lt(amount, '0') else 'in'
5789
+ amountString = self.safe_string_2(item, 'amount', 'change')
5790
+ afterString = self.safe_string_2(item, 'wallet_balance', 'cashBalance')
5791
+ direction = 'out' if Precise.string_lt(amountString, '0') else 'in'
5782
5792
  before = None
5783
- if after is not None and amount is not None:
5784
- difference = amount if (direction == 'out') else Precise.string_neg(amount)
5785
- before = Precise.string_add(after, difference)
5793
+ after = None
5794
+ amount = None
5795
+ if afterString is not None and amountString is not None:
5796
+ difference = amountString if (direction == 'out') else Precise.string_neg(amountString)
5797
+ before = self.parse_to_numeric(Precise.string_add(afterString, difference))
5798
+ after = self.parse_to_numeric(afterString)
5799
+ amount = self.parse_to_numeric(Precise.string_abs(amountString))
5786
5800
  timestamp = self.parse8601(self.safe_string(item, 'exec_time'))
5787
5801
  if timestamp is None:
5788
5802
  timestamp = self.safe_integer(item, 'transactionTime')
@@ -5795,15 +5809,15 @@ class bybit(Exchange, ImplicitAPI):
5795
5809
  'referenceAccount': None,
5796
5810
  'type': self.parse_ledger_entry_type(self.safe_string(item, 'type')),
5797
5811
  'currency': code,
5798
- 'amount': self.parse_to_numeric(Precise.string_abs(amount)),
5812
+ 'amount': amount,
5799
5813
  'timestamp': timestamp,
5800
5814
  'datetime': self.iso8601(timestamp),
5801
- 'before': self.parse_to_numeric(before),
5802
- 'after': self.parse_to_numeric(after),
5815
+ 'before': before,
5816
+ 'after': after,
5803
5817
  'status': 'ok',
5804
5818
  'fee': {
5805
5819
  'currency': code,
5806
- 'cost': self.parse_to_numeric(self.safe_string(item, 'fee')),
5820
+ 'cost': self.safe_number(item, 'fee'),
5807
5821
  },
5808
5822
  }, currency)
5809
5823