Arbiter Bot Part 2 - Cancel Logic

in LeoFinance19 hours ago

First part https://ecency.com/hive-167922/@strangedad/arbiter-bot-for-all-hive is aribter_bot.py

This is the cancelling logic I've been working on for the arbiter systems.

I apologize I'm not putting a lot into writing of these individually but I will answer any questions.

I've been working on these bots for a long time, I just haven't had the time to upload all of these. So I definitely appreciate you folks hanging in there with me.

arbiter_cancel.py


import os
import json
import sys
import time

from place_order import cancel_oldest_order


def read_bot_info(path="bot_info.txt"):
    try:
        with open(path, "r", encoding="utf-8") as file:
            lines = [line.strip() for line in file if line.strip()]
            if len(lines) >= 2:
                return lines[0], lines[1]
    except Exception as exc:
        print(f"[ERROR] Failed to read credentials: {exc}")
    return None, None


def load_config(root):
    config_path = os.path.join(root, "bot_config.json")
    if os.path.exists(config_path):
        try:
            with open(config_path, "r", encoding="utf-8") as file:
                return json.load(file)
        except Exception as exc:
            print(f"[ERROR] Failed to read bot_config.json: {exc}")
            return None

    account, key = read_bot_info(os.path.join(root, "bot_info.txt"))
    if account and key:
        return {
            "account_name": account,
            "active_key": key,
            "token": "ARBITER",
            "hive_nodes": ["https://api.hive.blog", "https://anyx.io"],
        }

    return None


def cancel_one(account_name, active_key, token="ARBITER", nodes=None):
    return cancel_oldest_order(
        account_name,
        active_key=active_key,
        nodes=nodes or ["https://api.hive.blog", "https://anyx.io"],
        token=token,
    )


if __name__ == "__main__":
    root = os.path.dirname(__file__)
    config = load_config(root)

    if not config:
        print("[ERROR] Missing bot configuration. Run arbiter_bot.py first.")
        raise SystemExit(1)

    account = (config.get("account_name") or "").strip()
    key = (config.get("active_key") or "").strip()
    token = (config.get("token") or "ARBITER").strip()
    nodes = config.get("hive_nodes") or ["https://api.hive.blog", "https://anyx.io"]

    if not account or not key:
        print("[ERROR] bot_config.json must include account_name and active_key")
        raise SystemExit(1)

    run_once = len(sys.argv) > 1 and sys.argv[1] == "--once"
    if run_once:
        cancel_one(account, key, token=token, nodes=nodes)
    else:
        while True:
            cancel_one(account, key, token=token, nodes=nodes)
            time.sleep(300)


Arbiter Bot Part 1 - arbiter_bot.py


🤖 PeakeBot — Autonomous Trading System (RC-AWARE)

Independent multi-token trading bot featuring:
RC-aware execution, adaptive delay logic, and self-regulating trade cycles.

📊 Trading bot details:
👉 https://geocities.ws/p/e/peakecoin/trading-bot/peakebot_v0_01.html
💻 Open-source repositories:
👉 https://github.com/paulmoon410


🙏 Acknowledgements

Thanks to and please follow:
@enginewitty @ecoinstant @neoxian @txracer @thecrazygm @holdonia @aggroed

For their continued support, guidance, and help expanding the PeakeCoin ecosystem.