Trading in the world of Hive Engine is profitable, but automation is going to be crucial to staying ahead. I'm trying to create a Python-based trading bot designed for SWAP.BNB trading on Hive Engine, complete with order execution and FTP log uploads.
This trading bot automatically:
✅ Fetches the latest market data for SWAP.BNB
✅ Places buy and sell orders based on a configurable spread
✅ Uploads trade logs to an FTP server (optional)
✅ Runs continuously with a time delay between trades
✅Anything I've missed?
Below is the full Python script for the bot. 👇I'm working on each piece currently. Feel free to use this if you would like, but if there's anything wrong with what I've done. Please educate me; I do not know everything. I'm frankensteining things together at this point.
import time
import logging
from fetch_market import get_market_data
from place_order import place_order
from ftp_upload import upload_to_ftp
# Updated Bot Settings
TOKEN = "SWAP.BNB" # Trading Token
ACCOUNT = "peakecoin.bnb" # Hive Engine Account
TRADE_AMOUNT = 5 # Number of tokens per trade (modify as needed)
SPREAD_PERCENT = 1.5 # Spread percentage (1.5% above/below market price)
SLEEP_TIME = 60 # Delay between trades (in seconds)
# Logging setup
logging.basicConfig(filename="bnb_trade_log.txt", level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s")
def trading_bot():
"""Main trading loop for executing orders on Hive Engine."""
while True:
try:
market_data = get_market_data(TOKEN)
if market_data:
last_price = float(market_data['result'][0]['lastPrice'])
buy_price = round(last_price * (1 - SPREAD_PERCENT / 100), 4)
sell_price = round(last_price * (1 + SPREAD_PERCENT / 100), 4)
logging.info(f"Market Price: {last_price} | Buy: {buy_price} | Sell: {sell_price}")
# Place buy and sell orders
buy_order = place_order(ACCOUNT, TOKEN, buy_price, TRADE_AMOUNT, "buy")
sell_order = place_order(ACCOUNT, TOKEN, sell_price, TRADE_AMOUNT, "sell")
logging.info(f"Buy Order Response: {buy_order}")
logging.info(f"Sell Order Response: {sell_order}")
# Upload log to FTP (Optional)
upload_to_ftp("bnb_trade_log.txt", "bnb_trade_log.txt")
else:
logging.warning("No market data received.")
except Exception as e:
logging.error(f"Error in trading loop: {str(e)}")
time.sleep(SLEEP_TIME)
if __name__ == "__main__":
logging.info("Starting PeakeCoin Trading Bot for SWAP.BNB...")
trading_bot()