PeakeCoin  avatar

PeakeCoin - uni_bot.py

peakecoin

Published: 23 Jul 2025 โ€บ Updated: 23 Jul 2025PeakeCoin - uni_bot.py

PeakeCoin - uni_bot.py

alt

What we're using to make the plug and play trading bots for all platforms.

uni_blank.py


from profit_strategies import get_profit_percent
import time
from fetch_market import get_orderbook_top
from place_order import place_order, get_open_orders, get_balance

# Hive account details (fill in before use)
HIVE_ACCOUNT = ""  # <-- Fill in your Hive username
HIVE_ACTIVE_KEY = ""  # <-- Fill in your Hive active key
HIVE_NODES = ["https://api.hive.blog", "https://anyx.io"]
TOKEN = "SWAP.TOKEN"  # <-- Fill in your token symbol, e.g., SWAP.BTC
DELAY = 1500

def get_resource_credits(account_name):
    try:
        import requests
        url = "https://api.hive.blog"
        payload = {
            "jsonrpc": "2.0",
            "method": "rc_api.find_rc_accounts",
            "params": {"accounts": [account_name]},
            "id": 1
        }
        resp = requests.post(url, json=payload, timeout=10)
        if resp.status_code == 200:
            data = resp.json()
            rc = data.get('result', {}).get('rc_accounts', [{}])[0]
            if rc and 'rc_manabar' in rc and 'max_rc' in rc:
                current = int(rc['rc_manabar']['current_mana'])
                max_rc = int(rc['max_rc'])
                percent = round(current / max_rc * 100, 2) if max_rc > 0 else 0.0
                return percent
    except Exception:
        pass
    return None

def smart_trade(account_name, token):
    try:
        print("\n==============================")
        print(f"[TOKEN BOT] Starting Smart Trade for {token}")
        rc_percent = get_resource_credits(account_name)
        if rc_percent is not None:
            print(f"[TOKEN BOT] Resource Credits: {rc_percent}%")
            if rc_percent < 10.0:
                print(f"[TOKEN BOT] WARNING: Resource Credits too low ({rc_percent}%). Skipping trade cycle.")
                print("==============================\n")
                return
        else:
            print(f"[TOKEN BOT] Resource Credits: Unable to fetch.")
        market = get_orderbook_top(token)
        if not market:
            print(f"[TOKEN BOT] Market fetch failed for {token}. Skipping this cycle.")
            print("==============================\n")
            return
        print(f"[TOKEN BOT] Market fetch success for {token}.")
        bid = float(market.get("highestBid", 0))
        ask = float(market.get("lowestAsk", 0))
        buy_price = round(bid, 8) if bid > 0 else 0  # Buy at highest bid
        sell_price = round(ask, 8) if ask > 0 else 0  # Sell at lowest ask
        if buy_price >= sell_price and buy_price > 0:
            sell_price = round(buy_price * 1.01, 8)  # Add 1% to sell price as fallback
        hive_balance = get_balance(account_name, "SWAP.HIVE")
        token_balance = get_balance(account_name, token)
        buy_qty = round(hive_balance * 0.20 / buy_price, 8) if buy_price > 0 else 0
        sell_qty = round(token_balance * 0.20, 8)
        print(f"[TOKEN BOT] Preparing BUY: {buy_qty} {token} at {buy_price}")
        print(f"[TOKEN BOT] Preparing SELL: {sell_qty} {token} at {sell_price}")
        open_orders = get_open_orders(account_name, token)
        duplicate_buy = any(o.get('type') == 'buy' and float(o.get('price', 0)) == buy_price for o in open_orders)
        if buy_qty <= 0:
            print(f"[TOKEN BOT] Skipping BUY: buy_qty is zero or negative. Check HIVE balance and buy price.")
        elif duplicate_buy:
            print(f"[TOKEN BOT] Skipping BUY: Duplicate buy order at {buy_price} detected.")
        else:
            try:
                place_order(account_name, token, buy_price, buy_qty, order_type="buy", active_key=HIVE_ACTIVE_KEY, nodes=HIVE_NODES)
                print(f"[TOKEN BOT] BUY order submitted: {buy_qty} {token} at {buy_price}")
                time.sleep(5)
                open_orders = get_open_orders(account_name, token)
                if open_orders:
                    print(f"[TOKEN BOT] Open orders after BUY: {len(open_orders)} found.")
                else:
                    print(f"[TOKEN BOT] No open orders found after BUY (may be node delay).")
                time.sleep(1)
            except Exception as e:
                print(f"[TOKEN BOT] BUY order exception: {e}")
        min_profit_percent = 0.01
        min_sell_price = round(buy_price * (1 + min_profit_percent), 8)
        force_sell_price = min_sell_price  # Always enforce profit, ignore market ask
        if force_sell_price > buy_price and sell_qty > 0:
            open_orders = get_open_orders(account_name, token)
            duplicate_sell = any(o.get('type') == 'sell' and float(o.get('price', 0)) == force_sell_price for o in open_orders)
            if duplicate_sell:
                print(f"[TOKEN BOT] Skipping SELL: Duplicate sell order at {force_sell_price} detected.")
            else:
                try:
                    place_order(account_name, token, force_sell_price, sell_qty, order_type="sell", active_key=HIVE_ACTIVE_KEY, nodes=HIVE_NODES)
                    print(f"[TOKEN BOT] SELL order submitted: {sell_qty} {token} at {force_sell_price}")
                    print(f"[TOKEN BOT] Profit percent: {get_profit_percent(buy_price, force_sell_price)}%")
                    time.sleep(5)
                    open_orders = get_open_orders(account_name, token)
                    if open_orders:
                        print(f"[TOKEN BOT] Open orders after SELL: {len(open_orders)} found.")
                    else:
                        print(f"[TOKEN BOT] No open orders found after SELL (may be node delay).")
                    time.sleep(1)
                except Exception as e:
                    print(f"[TOKEN BOT] SELL order exception: {e}")
        else:
            print(f"[TOKEN BOT] SELL order skipped: Not profitable or sell_qty is zero.")
        print(f"[TOKEN BOT] Trade cycle for {token} complete.")
        print("==============================\n")
        time.sleep(DELAY)
    except Exception:
        print(f"[TOKEN BOT] Unexpected error in smart_trade.")

if __name__ == "__main__":
    while True:
        try:
            print(f"[TOKEN BOT] Starting new trade cycle for {TOKEN}.")
            smart_trade(HIVE_ACCOUNT, TOKEN)
            print(f"[TOKEN BOT] Waiting 10 seconds before next cycle...")
            time.sleep(10)
        except Exception:
            print(f"[TOKEN BOT] Unexpected error in main loop.")
        remaining = max(0, DELAY - 10)
        if remaining > 0:
            print(f"[TOKEN BOT] Waiting {remaining} seconds to complete delay interval...")
            time.sleep(remaining)



Leave PeakeCoin - uni_bot.py to:

Written by

Maryland's Official...Un-official Crypto

Read more #hive-186392 posts


Best Posts From PeakeCoin

We have not curated any of peakecoin's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From PeakeCoin