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