🧪 PeakeCoin Bot Testing Suite

in Synergy Builders14 days ago

Maryland's Mascots

The PeakeCoin trading bot ecosystem is powerful—but like all serious automation tools, it needs proper stress testing before going live. To ensure smart trades execute as expected, I wrote a series of diagnostic scripts that target specific aspects of the bot’s lifecycle: from fetching market data to checking Hive Resource Credits.

This post documents what each script does, how to use it, and why it exists. These are essential for anyone testing or extending the bot infrastructure.


✅ 1. test_market.py: Validate Market Top Bid/Ask

Purpose: Confirms that the top-of-book market data is fetched accurately from Hive Engine for a given token.

🔗 View script

from fetch_market import get_orderbook_top

market = get_orderbook_top("SWAP.LTC")

Output: Spread % and mid-price based on top 1000 orders.
Why: Ensures you aren't placing orders based on stale or incomplete market info.
Reference: test_market.py :contentReference[oaicite:0]{index=0}


📄 2. test_order_finding.py: Inspect Open Orders

Purpose: Displays all open orders for an account, grouped by token.

🔗 View script

from place_order import get_open_orders

orders = get_open_orders("paulmoon410", "SWAP.LTC")
all_orders = get_open_orders("paulmoon410")

Output: Order count per token and a preview of open orders.
Why: Useful for debugging duplicate orders, stuck orders, or testing cancel logic.
Reference: test_order_finding.py :contentReference[oaicite:1]{index=1}


🌐 3. test_orders.py: API Endpoint Cross-Test

Purpose: Confirms that different Hive Engine RPC nodes return consistent open order data.

🔗 View script

"params": { "contract": "market", "table": "openOrders", "query": {"account": "paulmoon410"} }

Output: Lists open orders by symbol and counts them.
Why: Node reliability can affect bot decisions—this helps pick the best source.
Reference: test_orders.py :contentReference[oaicite:2]{index=2}


🔋 4. test_rc.py: Check RC Safety Before Trading

Purpose: Shows current Hive Resource Credits (RC), simulates operation costs, and determines if trading is safe.

🔗 View script

from fetch_market import get_resource_credits, check_rc_safety, estimate_rc_cost

Output: RC percentage, estimated number of trades possible, and safety level recommendations.
Why: Hive transactions require RC. Bots without enough RC can silently fail.
Reference: test_rc.py :contentReference[oaicite:3]{index=3}


🔁 5. trade_loop.py and hive_trading_bot.py: Live Trading Bots

These two are real bots meant to run continuously:

  • trade_loop.py: Basic loop that trades every 60 seconds with a fixed spread:contentReference[oaicite:4]{index=4}
  • hive_trading_bot.py: Full-featured bot with FTP logging and auto recovery:contentReference[oaicite:5]{index=5}

They both rely on:

from fetch_market import get_market_data
from place_order import place_order

🧠 Why I Built These

  • Debug with confidence — Every part of a live trading bot must be testable in isolation.
  • Rapid iteration — I can swap in new modules or pricing logic without flying blind.
  • Reliability — Market data, account orders, and RC are prone to API variation and failure. These scripts surface problems before money is at risk.

🛠️ Next Steps

  1. Run test_market.py and test_order_finding.py before each live session.
  2. Monitor test_rc.py output weekly or before high-frequency loops.
  3. Use test_orders.py when RPC errors or discrepancies arise.

Stay safe out there, and test before you trade.