i´m pretty new to python and even after searching the inet, i don´t understand what´s wrong here.
For using the Binance API, i need the Command like this: client.get_order_book(symbol = 'ETHBTC')
As the symbol is dynamic, i tried
x1 = 'symbol = '
x2 = symbols[0].get('symbol') #Output: ETHBTC
x = x1 + "'" + x2 + "'"
print(x) #Output: symbol = 'ETHBTC'
but when i call
client.get_order_book(x)
it draws the error:
TypeError: get_order_book() takes 1 positional argument but 2 were given
This is the rest of the Code:
client = Client(api_key, api_secret)
symbols = client.get_ticker()
print(symbols[0].get('symbol')) #Output ETHBTC
y = len(symbols)
for i in range(y):
x1 = 'symbol = '
x2 = symbols[i].get('symbol')
x = x1 + "'" + x2 + "'"
print(x) #Output: symbol = 'ETHBTC'
print(client.get_order_book(x))
i read a lot about self
, but i do not understand, where and how it has to be used here?!
x
is the literal string symbol='ETHBTC'
, not a "saved" keyword argument.
Your attempted call is equivalent to
client.get_order_book("symbol='ETHBTC'"),
but this method doesn't take any positional arguments (aside from self
). Here's the signature:
def get_order_book(self, **params):
To prepackage keyword arguments and simulate
client.get_order_book(symbol='ETHBTC')
you need a dict
to encapsulate the keyword argument.
x = {'symbol': 'ETHBTC'}
client.get_order_book(**x)