title: Python, bybit - order not exists or too late to cancel
body: <p>I am trying to make a crypto bot on bybit platform which does have an API: <a href="https://bybit-exchange.github.io/docs/inverse/?python--pybit#t-cancelactive" rel="nofollow noreferrer">https://bybit-exchange.github.io/docs/inverse/?python--pybit#t-cancelactive</a>, but when trying to close the position I get this error: order not exists or too late to cancel</p>
  <p>This is how the program runs:</p>
  <p><em>logged in</em></p>
  <p><em>62338.5</em></p>
  <p><em>({'ret_code': 0, 'ret_msg': 'OK', 'ext_code': '', 'ext_info': '', 'result': {'user_id': 3477310, 'order_id': 'c22d6d15-1616-4f82-84b1-672967072886', 'symbol': 'BTCUSD', 'side': 'Buy', 'order_type': 'Market', 'price': 64208.5, 'qty': 1, 'time_in_force': 'ImmediateOrCancel', 'order_status': 'Created', 'last_exec_time': 0, 'last_exec_price': 0, 'leaves_qty': 1, 'cum_exec_qty': 0, 'cum_exec_value': 0, 'cum_exec_fee': 0, 'reject_reason': 'EC_NoError', 'order_link_id': '', 'created_at': '2021-11-01T08:02:13.586Z', 'updated_at': '2021-11-01T08:02:13.586Z', 'take_profit': '0.00', 'stop_loss': '0.00', 'tp_trigger_by': 'UNKNOWN', 'sl_trigger_by': 'UNKNOWN'}, 'time_now': '1635753733.586516', 'rate_limit_status': 199, 'rate_limit_reset_ms': 1635753733583, 'rate_limit': 200}, &lt;bravado.requests_client.RequestsResponseAdapter object at 0x000002802DF44C10&gt;)</em></p>
  <p>c22d6d15-1616-4f82-84b1-672967072886</p>
  <p>And here I get the error:</p>
  <p><strong>({'ret_code': 20001, 'ret_msg': 'order not exists or too late to cancel', 'ext_code': '', 'ext_info': '', 'result': None, 'time_now': '1635869643.350265', 'rate_limit_status': 198, 'rate_limit_reset_ms': 1635869643348, 'rate_limit': 200}, &lt;bravado.requests_client.RequestsResponseAdapter object at 0x000001912BDCAE50&gt;)</strong></p>
  <p><strong>order has been closed</strong></p>
  <p>As you can see it did not close the position</p>
  <p>And this is my code:</p>
  <pre><code>import bybit
  import time
  
  
  client = bybit.bybit(test=False, api_key='key', api_secret='secret_key')
  print('logged in')
  
  info = client.Market.Market_symbolInfo(symbol='BTCUSD').result()
  
  keys = info[0]['result']
  btc_original = keys[0]['last_price']
  BTC_original = float(btc_original)
  print(BTC_original)
  
  #open new position
  open_pos = client.Order.Order_new(side=&quot;Buy&quot;,symbol=&quot;BTCUSD&quot;,order_type=&quot;Market&quot;,qty=1, time_in_force='GoodTillCencel').result()
  print(open_pos)
  print(type(open_pos))
  
  time.sleep(5)
  #get order info 
  order_ID = open_pos[0]['result']['order_id']
  print(order_ID)
  print(type(order_ID))
  
  time.sleep(5)
  #close order
  close_it = client.Order.Order_cancel(symbol=&quot;BTCUSD&quot;, order_id=order_ID).result()
  print(close_it)
  print('order has been closed')
  </code></pre>