I'm not sure how to find open order numbers to match the sell book order numbers to have them canceled.
@thecrazygm @enginewitty @powerpaul
If anyone has any insight I've been sick for days and trying to work on this... thanks.

import time
from place_order import cancel_order, get_open_orders
from fetch_market import get_orderbook_top
def cancel_one_order(account_name, active_key, nodes=None):
"""
Cancel one open order for the given account.
"""
try:
sell_orders = get_open_orders(account_name)
if sell_orders:
order_id = sell_orders[0].get('_id') # Get the first order in the list
if order_id:
print(f"[INFO] Cancelling order ID: {order_id}")
cancel_order(account_name, order_id, active_key=active_key, nodes=nodes)
print(f"[INFO] Order {order_id} cancelled successfully.")
else:
print("[INFO] No valid order ID found to cancel.")
else:
print("[INFO] No open orders to cancel.")
except Exception as e:
print(f"[ERROR] Failed to cancel order: {e}")
def read_bot_info(file_path):
"""
Reads the bot credentials (account name and active key) from a file.
The file should have two lines:
- First line: Hive account name
- Second line: Hive active key
"""
try:
with open(file_path, "r") as file:
lines = file.read().splitlines()
if len(lines) >= 2:
return lines[0], lines[1] # Return account name and active key
else:
print(f"[ERROR] Invalid bot_info.txt format. Expected 2 lines, got {len(lines)}.")
except FileNotFoundError:
print(f"[ERROR] File not found: {file_path}")
except Exception as e:
print(f"[ERROR] Failed to read bot info: {e}")
return None, None
if __name__ == "__main__":
# Read credentials from bot_info.txt
HIVE_ACCOUNT, HIVE_ACTIVE_KEY = read_bot_info("bot_info.txt")
HIVE_NODES = ["https://api.hive.blog", "https://anyx.io"]
if not HIVE_ACCOUNT or not HIVE_ACTIVE_KEY:
print("[ERROR] Missing Hive account credentials. Please check bot_info.txt.")
else:
while True:
print(f"[INFO] Checking for open orders to cancel for account: {HIVE_ACCOUNT}")
cancel_one_order(HIVE_ACCOUNT, HIVE_ACTIVE_KEY, nodes=HIVE_NODES)
print("[INFO] Waiting for 5 minutes before the next cycle.")
time.sleep(300) # Wait for 5 minutes
If you print:
order_id = sell_orders[0].get('_id') # Get the first order in the list
print(sell_orders[0])
does it actually belong to the account that is trying to cancel it.The rest looks okay, but I think maybe your query to get the list of open orders is returning everyone's and not just yours, so you may be trying to cancel the first order in the list, even if it's not the one you want.
So it's the entire sellbook?
I'll have to read it over. I was getting null returns when I was using orders and open orders...
The issue I was having was it wants the order id... but is the sellbook ID different? They appear different.
Can you cancel orders with a TX ID or would I need to find the correlatting order for that TX ID?
I may not be asking correctly, because you know I'm learning on my own. Not trying to be difficult.
Yes, if you look a the docs: https://github.com/hive-engine/hivesmartcontracts-wiki/blob/main/Market-Smart-Contract.md
{ "contractName": "market", "contractAction": "cancel", "contractPayload": { "type": "sell", "id": "1b7e32719b76f07e144d15c8d3045545b896e90b" } }
'll check it out. If I have any other questions I'll be back.