Cheery22487 / hive_arbitrage

This is a small arbitrage bot working on the hive blockchain.
2 stars 0 forks source link

issuse with batch fetching order books #3

Open johnxn opened 1 week ago

johnxn commented 1 week ago

hi, in stead of geting buy/sell orders one token at a time, we could retrieve order books for all tokens in a single request, like this

url = HE_NODE + "/contracts"
            json_params = {
                "jsonrpc": "2.0",
                "id": 42069,
                "method": "find",
                "params": {
                    "contract": "market",
                    "query": {
                        "symbol": {"$in": tokens}
                    },
                    "indexes": [{"index": "priceDec", "descending": False}], 
                    "limit": 1000,
                    "offset": 0,
                    "table": "sellBook"
                }
            }

This will save us a little more time, could it make our bot a little more profitable? Thanks again for sharing with your work, l learnt a lot from it.

Cheery22487 commented 5 days ago

Yes, this is an excellent idea. I wasn’t aware it was possible to make this general API request.

Reducing the number of API calls would significantly increase the scan frequency. Additionally, decreasing the lag between retrieving the first sell orders and the last buy orders—which is present now—will reduce vulnerability to market movements.

I’m not certain how substantial the practical upside will be, but significantly reducing the number of API calls is certainly a big advantage on its own.

I’ll update it when I get around to it.

Thank you very much for the feedback!