Python exclude Stocks and EFT from trading symbols

Dragos Drimbe  

I have the following code for getting all symbols

num_symbols = mt5.symbols_total()
    raw_symbols = mt5.symbols_get()
    if raw_symbols != None:
        for s in raw_symbols:
            selected = mt5.symbol_select(, True)
            test_symbol = mt5.symbol_info(str(
            t_now =
            sessiom_open = test_symbol.session_open
            sessiom_close = test_symbol.session_close
            if test_symbol == None:

I would like to exclude some symbols like stocks and EFT because of commission so in the symbol_info there is a entry category but is empty. The question is how I exclude this category of symbols?

Dominik Egert  
That's not as easy as it first seems.

Take a look at the Symbol definitions (CTRL-U)
You have multiple options, and they depend on the broker from which you receive the symbols.

The calculation type is one option.

The symbols path is another option.

The symbols country is a possible option.

The symbols industry is an option.

And most probably some more. You could go and analyze the description of the symbol, and filter by that as well.

The issue is, some brokers offer stocks and Forex as CFDs, other have forex symbols as Forex.

ETFs could be CFDs, or maybe even Futures.

Stocks can be indicated as stocks, and they might specifiy the exchange as well.

The challenge is, there is no definite way to separate these directly and reliable based on the symbols definitions across all brokers.

I guess, it is easier to define what you want, than to exclude what you don't want.

You could say, I want currencies, energies and Metalls. That could be done quite reliable by the symbols path.

I guess that would be the closest you can get to have a reliable selection.
Dragos Drimbe  
My broker have diferent accounts. one for trade where you trade only CFD's and one for invest with only stocks and EDT if I remember right. Trader have them all including stocks and EFT's. Yes it seems the symbol path is the only way and I also need it to calculate the leverage because is diferent for diferent types of instruments. Thank you for the idea.