PeakeCoin Trading Bot Update - fetch_market.py fix

in LeoFinance6 hours ago

Generated pictures never let me down, lol

The words of @ecoinstant and @thecrazygm have been scrolling like a ticker on old news shows. In my semi-annoyed inner monologue voices, "Edge Cases, Edge Cases" like some evil chant. My trading bot wasn't getting the buy and sell orders correctly. So we, that's we as in me, had to creep in and figure out why I was placing orders going both directions off of the same collective information.

Needless to say, the past week has been exhausting, having to be an electrician and then come home to make millions on the internet, I don't have millions. I have millions, but its millions of things I need to get finished. None of that is important enough to dwell on for long.

So if you've been keeping up with what I've been piddling here's what I came up with. Notes if need in the code if you're a copy and paste specialist, I do not shame. We are here to stand on the shoulders of giants to reach the clouds do not be afraid to use what I've brought here for your own success. We can all be great, there's no capacity limit.

import requests

def get_orderbook_top(token="PEK"):
    # Pull top buy orders I'm hoping
    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, this is where it was killing me
    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



I have updated the GitHub https://github.com/PaulMoon410/peakecoin_bnb_bot if you wanted to scope it out there. I have to update the main file peakecoin_bot.py as well I'm only one man with so many fingers, thanks for being patient.

Sort:  

I love watching the progress!

It seems you are making pretty solid spread bot. How often do you think you would want to "refresh" your information?

When you say "refresh" my information, what does that mean?

I mean, when you get the lowest sale price, how long do you think that data will be true for?

Once you list your sale, you will have the lowest sale price. How long do you think that will last?

What is the probability, if you check again in 30 minutes, that your sell is still the lowest?

Right now the sale stays indefinitely. I haven't worked out the cancelling long waiting orders.

It also runs on smaller increments so whenever it's sleep time is cycled it runs again at .00000001 more or less than the last order placed

Do mean time between sales?