I'll be updating https://github.com/PaulMoon410/peakecoin_bnb_bot with these files shortly.
fetch_market.py
import requests
def get_orderbook_top(token="SWAP.BNB"):
payload = {
"jsonrpc": "2.0",
"method": "find",
"params": {
"contract": "market",
"table": "buyBook",
"query": {"symbol": token},
"limit": 1,
"indexes": [{"index": "priceDec", "descending": True}]
},
"id": 1
}
# Fetch the highest bid
buy_response = requests.post("https://api.hive-engine.com/rpc/contracts", json=payload)
# Modify the payload for the lowest ask
payload["table"] = "sellBook"
payload["indexes"] = [{"index": "price", "descending": False}]
sell_response = requests.post("https://api.hive-engine.com/rpc/contracts", json=payload)
# Optional: Print raw JSON response
print("📥 Buy:", buy_response.text)
print("📤 Sell:", sell_response.text)
# Parse responses
if buy_response.status_code == 200 and sell_response.status_code == 200:
buy_result = buy_response.json().get("result", [])
sell_result = sell_response.json().get("result", [])
highest_bid = float(buy_result[0]["price"]) if buy_result else 0
lowest_ask = float(sell_result[0]["price"]) if sell_result else 0
return {"highestBid": highest_bid, "lowestAsk": lowest_ask}
# In case of error
return None
In trying to make my PeakeCoin BNB trading bot more responsive to the market, I built and added a new script: fetch_market.py
.
This lightweight Python script connects directly to the Hive-Engine API and pulls the top buy and sell prices for any token. By using this data in the bot’s logic, it can place orders more intelligently, targeting the current spread instead of using static price points.
Here’s what it does:
- Gets the highest bid from the
buyBook
- Gets the lowest ask from the
sellBook
- Returns both so the trading script can place competitive orders
So far, the bot is broadcasting custom JSON transactions as expected, but I'm not seeing any movement in wallet contents yet. No gains, no losses — just static. That might mean:
- Orders are too far from market price and not filling
- Orders are being placed but immediately canceled/overwritten
- Or something subtle isn’t firing correctly in the execution logic
For now, it’s a waiting game. I’ll monitor activity and adjust as needed. But the foundation is getting stronger with each update.
There is absolutely no input I am against. @txracer @millhouze @apsagu @crrdlx
@thecrazygm I did code in both the active and posting keys to get it to function as well.
@enginewitty I think I may have it packaged up in a few days if you wanted to play around with the code. I don't have it all uploaded yet.
@techcoderx I wrote up a ReadMe thank you for that one.