Hemanth Girimath
Hemanth Girimath

Reputation: 74

python-binance: Get all orders, without specifying symbol

Trying to fetch my Binance accounts order history with the python-binance module. There is an option to get all orders within one symbol (see documentation):

orders = client.get_all_orders(symbol='BNBBTC', limit=10)

Bu the problem is I can't pass more than 1coin in the symbol parameter How can I pass a list for the symbol parameter, I want to fetch more than 1 coins order history in a single function as I'm trying to build a portfolio for my Binance account. Or is there another method to do so?

Upvotes: 1

Views: 8510

Answers (2)

WolftrotDev
WolftrotDev

Reputation: 26

I was asking myself the same thing. Well, a work around would be to iterate over all the tickers available in Binance looking for the ones we did traded in the past.

If you are working the free plan of the API, the best would be to setup a storage file or database and store all the result. Then you have to care about keeping with the changes from there.

Yeah, it is exactly how I am going to deal with this.

(edit) : Sleep function will be needed to avoid more than 1200 queries per minute.

(example) :

def getAllTickers(self):

        # Get all available exchange tickers
        exchangeInfo = self.client.get_exchange_info()

        # Extract the tickers general info
        exchangeSymbols = []

        for i in exchangeInfo['symbols']:
            exchangeSymbols.append(i)

        return exchangeSymbols

            
    def getMyTrades(self, strSymbol):
        return self.client.get_my_trades(symbol=strSymbol)

    def getMyTradedTickers(self):

        tickers = self.getAllTickers()
        # Extract every ticker where trade happened
        traded = []
        for i in tickers:
            tickerTransactions = self.getMyTrades(i["symbol"])
            if tickerTransactions :
                traded.append(tickerTransactions)
                print(i["symbol"], " transactions available")
            else :
                print(i["symbol"], " has no transactions")
            self.time.sleep(0.1)
        
        return traded

**Srry for the code quality. Python is not my main coding language and im getting use to it.

Upvotes: 0

fbardos
fbardos

Reputation: 540

Currently it is not possible to get all historical orders or trades without specifying the symbol in one call, even without the module python-binance.

There is an ongoing discussion on the Binance forum, requesting this feature.


As a workaround:

  • If you know your ordered symbols: Use the function get_all_orders() multiple times for each symbol in a loop.
  • If you don't know your ordered symbols: you could send a GET request for each symbol available at Binance (as mentioned in the discussion linked above). But be careful with the rateLimits.

Upvotes: 3

Related Questions