I need to make the usage of an object variable to cut way down on lines of code and complexity. Here's the code I'm about to use:
exchange = ccxt.binance({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET',
'enableRateLimit': True,
})
I need to make the binance part dynamic since there's probably a few hundred different things that could be in this case. Is there an easy way to do that?
Thanks in advance.
asked Aug 1, 2018 at 15:40
xendi
2,5626 gold badges43 silver badges70 bronze badges
1 Answer 1
If you want to call each time a different method, you can use:
try:
# get a method and choose it's name runtime
yourMethod = getattr(ccxt, 'binance')
# call it
yourMethod({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET',
'enableRateLimit': True,
})
catch AttributeError:
print "method with that name doesn't exist"
answered Aug 1, 2018 at 15:57
nio
5,2992 gold badges26 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
ccxt?$method = 'mymethod'; $class->{$method}();