New to working with python and API's. Having difficulty creating a formula that involves numbers and variables. The variables were created using information (values, ex. available_balance = 4500, but 4500 is not a fixed number and is constantly changing) from trading website.

# Retrieving and printing values for available_balance and last_price
print('Available Balance: ')
print(session.get_wallet_balance(coin="USDT")['result']['USDT']['available_balance'])
print('Last Price: ')
print(session.latest_information_for_symbol(symbol="BTCUSDT")['result'][0]['last_price'])

# Assigning variables representing the value of available_balance and last_price
lastPrice = (session.latest_information_for_symbol(symbol="BTCUSDT")['result'][0]['last_price'])
availableBalance = (session.get_wallet_balance(coin="USDT")['result']['USDT']['available_balance'])

# Verifying values are properly assigned to variables
print()
print('Last Price and Available Balance:')
print(lastPrice, availableBalance, sep='\n')

# Order Size formula = last_price * available_balance * leverage * perc (ex. 100% = 1, 25% = 0.25) * (1-(0.00075) * 2)

orderSize = lastPrice * availableBalance * 15 * 100 * (1-(0.00075) * 2))
print(orderSize)

Error received was:

orderSize = lastPrice * availableBalance * 15 * 100 * (1-(0.00075) * 2)

TypeError: can't multiply sequence by non-int of type 'float'.

Any help would be great! I added the request example/response from Bybit's API:

enter image description here enter image description here


Solution 1:

The Type Error : [ can't multiply sequence by non-int of type 'float' ] indicates that there was a attempt that you are trying to multiply a floating datatype to a list ones....

You have to check What Was The Type Of lastPrice and availableBalance, One of them should return a seq which cant be multiplied with a float.

Hope It Helps Buddy ;)