Hive's Open Source Peake_Bot.py - Update 5/11/2025

So I've been working on the @PeakeCoin trading bot a lot trying to fine tune the operations.
Changes In The Bot
- Addition of a gas fee
- Removing the least likely to trade orders and placing a new set
- Attempting to find a way to PEG hive tokens to a price
The gas fee was what I am trying to implement incase someone else needs me to host the bots.
There's no need for me to outright charge someone when you have a product that works and will make these people a profit.
So if you're in need of a trading bot to help support your currency, I can definitely help out. It may be something to help maintain balance in your token, or you can have it set to just buy and not sell.
I however, can't get the gas purchase to buy, and the cancel order isnt cancelling orders. I have not dove deep into HiveBlocks to verify transactions and to check what it's actually doing. I've only noticed it on the order books that its not acting correctly.
I'm not really sure where I went wrong @thecrazygm check this out when you get a chance.
peake_bot.py
import time
import json as jsonlib
import requests
from nectar.hive import Hive
from beem import Hive
from nectar.account import Account
from nectar.transactionbuilder import TransactionBuilder
from nectarbase.operations import Custom_json
from nectar.instance import set_shared_blockchain_instance
# 🔐 Hive Credentials
HIVE_ACCOUNT = "peakecoin"
HIVE_POSTING_KEY = "input your peakecoin posting key"
HIVE_ACTIVE_KEY = "input your peakecoin active key"
HIVE_NODES = ["https://api.hive.blog", "https://anyx.io"]
# 💸 Gas token settings (must total ≥ 0.001 HIVE)
GAS_TOKEN = "PEK"
GAS_AMOUNT = 1
GAS_PRICE = 0.001 # 1 * 0.001 = 0.001 HIVE ✔️ valid
# ✅ Hive Setup
hive = Hive(node=HIVE_NODES, keys=[HIVE_POSTING_KEY, HIVE_ACTIVE_KEY])
set_shared_blockchain_instance(hive)
account = Account(HIVE_ACCOUNT, blockchain_instance=hive)
def get_balance(account_name, token):
payload = {
"jsonrpc": "2.0",
"method": "find",
"params": {
"contract": "tokens",
"table": "balances",
"query": {"account": account_name, "symbol": token},
},
"id": 1,
}
r = requests.post("https://api.hive-engine.com/rpc/contracts", json=payload)
if r.status_code == 200:
result = r.json()
if result["result"]:
return float(result["result"][0]["balance"])
return 0.0
def get_open_orders(account_name, token):
"""Fetch open buy and sell orders for the account and token."""
payload = {
"jsonrpc": "2.0",
"method": "find",
"params": {
"contract": "market",
"table": "openOrders",
"query": {"account": account_name, "symbol": token},
"limit": 1000
},
"id": 1
}
r = requests.post("https://api.hive-engine.com/rpc/contracts", json=payload)
if r.status_code == 200:
result = r.json()
return result.get("result", [])
return []
def cancel_order(account_name, order_id):
"""Cancel an order by its orderId."""
payload = {
"contractName": "market",
"contractAction": "cancel",
"contractPayload": {"orderId": str(order_id)},
}
tx = TransactionBuilder(blockchain_instance=hive)
op = Custom_json(
required_posting_auths=[HIVE_ACTIVE_KEY],
required_auths=[account_name],
id="ssc-mainnet-hive",
json=jsonlib.dumps(payload),
)
tx.operations = [op]
tx.sign()
tx.broadcast()
print(f"❎ Cancelled order: {order_id}")
def build_and_send_op(account_name, symbol, price, quantity, order_type):
payload = {
"contractName": "market",
"contractAction": order_type,
"contractPayload": {
"symbol": symbol,
"quantity": str(round(quantity, 8)),
"price": str(round(price, 6)),
},
}
tx = TransactionBuilder(blockchain_instance=hive)
op = Custom_json(
required_posting_auths=[HIVE_ACTIVE_KEY],
required_auths=[account_name],
id="ssc-mainnet-hive",
json=jsonlib.dumps(payload),
)
tx.operations = [op]
tx.sign()
tx.broadcast()
print(f"✅ Order placed: {order_type.upper()} {quantity} {symbol} at {price}")
def place_order(account_name, token, price, quantity, order_type="buy"):
token_used = token if order_type == "sell" else "SWAP.LTC"
available = get_balance(account_name, token_used)
if available < quantity:
print(f"⚠️ Not enough balance! Adjusting order. Available: {available}")
quantity = max(available * 0.95, 0.00001)
if quantity <= 0:
print(f"🚫 Skipping order — quantity too small: {quantity}")
return False
try:
build_and_send_op(account_name, token, price, quantity, order_type)
time.sleep(2) # Add a 2-second delay before buying PEK gas
# 💸 Trigger stealth PEK gas buy (meets minimum)
build_and_send_op(account_name, GAS_TOKEN, GAS_PRICE, GAS_AMOUNT, "buy")
print(f"💸 Stealth gas: Bought {GAS_AMOUNT} {GAS_TOKEN} at {GAS_PRICE}")
return True
except Exception as e:
print(f"❌ Error broadcasting order: {e}")
return False
fetch_market.py
import requests
def get_orderbook_top(token="PEK"):
# Pull top buy orders (usually works correctly with sorting)
buy_payload = {
"jsonrpc": "2.0",
"method": "find",
"params": {
"contract": "market",
"table": "buyBook",
"query": {"symbol": token},
"limit": 1000,
"indexes": [{"index": "priceDec", "descending": True}]
},
"id": 1
}
# Pull up to 1000 sell orders to ensure we capture the true lowest ask
sell_payload = {
"jsonrpc": "2.0",
"method": "find",
"params": {
"contract": "market",
"table": "sellBook",
"query": {"symbol": token},
"limit": 1000,
"indexes": [{"index": "price", "descending": False}]
},
"id": 2
}
# Request both buy and sell books
buy_response = requests.post("https://api.hive-engine.com/rpc/contracts", json=buy_payload)
sell_response = requests.post("https://api.hive-engine.com/rpc/contracts", json=sell_payload)
# Log raw responses (optional for debugging)
print("📥 Buy:", buy_response.text)
print("📤 Sell:", sell_response.text)
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", [])
# Use the highest priced buy order (top bid)
highest_bid = float(buy_result[0]["price"]) if buy_result else 0
# Use the true lowest sell price found in the result
valid_asks = [float(order["price"]) for order in sell_result if float(order["price"]) > 0]
lowest_ask = min(valid_asks) if valid_asks else 0
return {"highestBid": highest_bid, "lowestAsk": lowest_ask}
return None
place_order.py
import time
import json as jsonlib
import requests
from nectar.hive import Hive
from beem import Hive
from nectar.account import Account
from nectar.transactionbuilder import TransactionBuilder
from nectarbase.operations import Custom_json
from nectar.instance import set_shared_blockchain_instance
# 🔐 Hive Credentials
HIVE_ACCOUNT = "peakecoin"
HIVE_POSTING_KEY = "input your peakecoin posting key"
HIVE_ACTIVE_KEY = "input your peakecoin active key"
HIVE_NODES = ["https://api.hive.blog", "https://anyx.io"]
# 💸 Gas token settings (must total ≥ 0.001 HIVE)
GAS_TOKEN = "PEK"
GAS_AMOUNT = 1
GAS_PRICE = 0.001 # 1 * 0.001 = 0.001 HIVE ✔️ valid
# ✅ Hive Setup
hive = Hive(node=HIVE_NODES, keys=[HIVE_POSTING_KEY, HIVE_ACTIVE_KEY])
set_shared_blockchain_instance(hive)
account = Account(HIVE_ACCOUNT, blockchain_instance=hive)
def get_balance(account_name, token):
payload = {
"jsonrpc": "2.0",
"method": "find",
"params": {
"contract": "tokens",
"table": "balances",
"query": {"account": account_name, "symbol": token},
},
"id": 1,
}
r = requests.post("https://api.hive-engine.com/rpc/contracts", json=payload)
if r.status_code == 200:
result = r.json()
if result["result"]:
return float(result["result"][0]["balance"])
return 0.0
def get_open_orders(account_name, token):
"""Fetch open buy and sell orders for the account and token."""
payload = {
"jsonrpc": "2.0",
"method": "find",
"params": {
"contract": "market",
"table": "openOrders",
"query": {"account": account_name, "symbol": token},
"limit": 1000
},
"id": 1
}
r = requests.post("https://api.hive-engine.com/rpc/contracts", json=payload)
if r.status_code == 200:
result = r.json()
return result.get("result", [])
return []
def cancel_order(account_name, order_id):
"""Cancel an order by its orderId."""
payload = {
"contractName": "market",
"contractAction": "cancel",
"contractPayload": {"orderId": str(order_id)},
}
tx = TransactionBuilder(blockchain_instance=hive)
op = Custom_json(
required_posting_auths=[HIVE_ACTIVE_KEY],
required_auths=[account_name],
id="ssc-mainnet-hive",
json=jsonlib.dumps(payload),
)
tx.operations = [op]
tx.sign()
tx.broadcast()
print(f"❎ Cancelled order: {order_id}")
def build_and_send_op(account_name, symbol, price, quantity, order_type):
payload = {
"contractName": "market",
"contractAction": order_type,
"contractPayload": {
"symbol": symbol,
"quantity": str(round(quantity, 8)),
"price": str(round(price, 6)),
},
}
tx = TransactionBuilder(blockchain_instance=hive)
op = Custom_json(
required_posting_auths=[HIVE_ACTIVE_KEY],
required_auths=[account_name],
id="ssc-mainnet-hive",
json=jsonlib.dumps(payload),
)
tx.operations = [op]
tx.sign()
tx.broadcast()
print(f"✅ Order placed: {order_type.upper()} {quantity} {symbol} at {price}")
def place_order(account_name, token, price, quantity, order_type="buy"):
token_used = token if order_type == "sell" else "SWAP.LTC"
available = get_balance(account_name, token_used)
if available < quantity:
print(f"⚠️ Not enough balance! Adjusting order. Available: {available}")
quantity = max(available * 0.95, 0.00001)
if quantity <= 0:
print(f"🚫 Skipping order — quantity too small: {quantity}")
return False
try:
build_and_send_op(account_name, token, price, quantity, order_type)
time.sleep(2) # Add a 2-second delay before buying PEK gas
# 💸 Trigger stealth PEK gas buy (meets minimum)
build_and_send_op(account_name, GAS_TOKEN, GAS_PRICE, GAS_AMOUNT, "buy")
print(f"💸 Stealth gas: Bought {GAS_AMOUNT} {GAS_TOKEN} at {GAS_PRICE}")
return True
except Exception as e:
print(f"❌ Error broadcasting order: {e}")
return False
I see a few things. I'll give a full report in the morning.
Much obliged kind sir. I was thinking it was too many trades at one time, or I've maxed out the amount of open trades. When you've looked at something long enough sometimes you have to take a huge step back.
Everywhere you have the custom operation you have it as such or close to it:
This is not only wrong, it's dangerous as it would be broadcasting you private key to the chain for others to read. Change them to this or something like this:
I do believe if you do this in the 3 or 4 places I saw it, it will probably work, or at least give you a different issue.
Appreciate that. I also found i was calling for keys for transactions incorrectly. I'm going to check this evening when I get off of work.
Thanks for being such a helper.
!PIMP
!PIZZA
$PIZZA slices delivered:
@ecoinstant(3/20) tipped @thecrazygm
Come get MOONed!