Closed VuzzyM closed 2 years ago
It means the trading account does not have enough balance to place the order. You can use list_spot_accounts
with currency specified to check if the balance is enough.
It means the trading account does not have enough balance to place the order. You can use
list_spot_accounts
with currency specified to check if the balance is enough.
@revilwang Enough balance is, the problem is because the fees are not calculated correctly and that is why this happens. How can this be resolved?
WalletApi.get_trade_fee
(which is more recommended but requires wallet read-only access) or SpotApi.get_fee
?
- Are you using the fee rates retrieved from
WalletApi.get_trade_fee
(which is more recommended but requires wallet read-only access) orSpotApi.get_fee
?- How are the fee rates being used?
def place_order(base,quote, amount, side, last_price):
"""
Args:
'DOT', 'USDT', 50, 'buy', 400
"""
try:
order = Order(amount=str(float(amount)/float(last_price)), price=last_price, side=side, currency_pair=f'{base}_{quote}', time_in_force='ioc')
order = spot_api.create_order(order)
t = order
logger.info(f"PLACE ORDER: {t.side} | {t.id} | {t.account} | {t.type} | {t.currency_pair} | {t.status} | amount={t.amount} | price={t.price} | left={t.left} | filled_total={t.filled_total} | fill_price={t.fill_price}")
except Exception as e:
logger.error(e)
raise
else:
return order
if test_mode:
order_status = order[announcement_coin]['status']
else:
order_status = order[announcement_coin]['_status']
message = f'Order created on {announcement_coin} at a price of {price} each. {order_status=}'
logger.info(message)
if order_status == 'filled' or order_status == "closed":
if test_mode and float(order[announcement_coin]['_left']) > 0 and float(order[announcement_coin]['_amount']) > float(order[announcement_coin]['_left']):
# you can only sell what you have. Minus fees. Look for unfulfilled
newAmount = float(order[announcement_coin]['_amount']) - float(order[announcement_coin]['_left']) - float(order[announcement_coin]['_fee'])
order[announcement_coin]['volume'] = newAmount
else:
store_order('order_fulfilled.json', order)
# you can only sell what you have. Minus fees. Look for unfulfilled
newAmount = float(order[announcement_coin]['_amount']) - float(order[announcement_coin]['_left']) - float(order[announcement_coin]['_fee'])
order[announcement_coin]['_amount'] = newAmount
store_order('order.json', order)
if not test_mode and enable_sms:
try:
send_sms_message(message)
except Exception:
pass
elif order_status == 'open' or order_status == 'cancelled':
if not test_mode and order_status == 'open':
# cancel orders and try again in the next iteration
cancel_open_order(order[announcement_coin]['_id'], announcement_coin, pairing)
logger.info(f"Cancelled order {order[announcement_coin]['_id']} . Waiting for status of 'filled/closed' for {announcement_coin}")
order.clear() # reset for next iteration
@revilwang ?
I'm sorry but the code you provided contains other off-topic pieces. Can you provide the core snippet and make it clear what the problem is.
I'm sorry but the code you provided contains other off-topic pieces. Can you provide the core snippet and make it clear what the problem is.
I solved
Hello.
How to fix this error? "Not Enough balance" errors on sell on gate.io.
https://github.com/CyberPunkMetalHead/gateio-crypto-trading-bot-binance-announcements-new-coins/issues/54
2021-11-04 10:05:33,410 ERROR: (400) Reason: Bad Request HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 04 Nov 2021 07:05:33 GMT', 'Content-Type': 'application/json', 'Content-Length': '61', 'Connection': 'keep-alive', 'Server': 'openresty', 'X-Request-Id': '[6b48b60c-1567606542]'}) HTTP response body: {"label":"BALANCE_NOT_ENOUGH","message":"Not enough balance"}
Please help, thanks.