Peakecoin.bnb Trading Bot

in Learn to Code β€’ yesterday

πŸ“Š Fetching Hive Engine Market Data with Python

I'm barely understanding what to do for automated trading and crypto analytics. So as I'm learning Python script, fetch_market.py, is supposed to retrieve the latest SWAP.BNB market data from Hive Engine using its API I hope.πŸš€


πŸ› οΈ Why Fetch Market Data?

By querying the Hive Engine API, we can:
βœ… Get token prices
βœ… Use data for trading bots or analysis tools
βœ… Automate buys/sales


πŸ“ Python Code: fetch_market.py

import requests

HIVE_ENGINE_API = "https://api.hive-engine.com/rpc"

def get_market_data(token="SWAP.BNB"):
    """Fetch market data for a specific token."""
    payload = {
        "jsonrpc": "2.0",
        "method": "find",
        "params": {
            "contract": "market",
            "table": "metrics",
            "query": {"symbol": token},
            "limit": 1
        },
        "id": 1
    }
    response = requests.post(f"{HIVE_ENGINE_API}/contracts", json=payload)
    
    if response.status_code == 200:
        return response.json()
    else:
        print("Error fetching market data:", response.text)
        return None

# Example usage
if __name__ == "__main__":
    market_data = get_market_data("SWAP.BNB")
    print(market_data)