ohenrik / bitfinex

A Python client for the Bitfinex API
MIT License
58 stars 32 forks source link

Error in new order #39

Closed andrebrener closed 5 years ago

andrebrener commented 5 years ago

I'm using python 3.7.4 in OSX

Now I'm getting this error:

 File "/Users/andre/git-repos/work/crypto_trader/python/test.py", line 22, in <module>
    trade_client.multi_order(operations=[order_operation])
  File "/usr/local/lib/python3.7/site-packages/bitfinex/websockets/client.py", line 719, in multi_order
    return [order[1].get("cid", None) for order in operations]
  File "/usr/local/lib/python3.7/site-packages/bitfinex/websockets/client.py", line 719, in <listcomp>
    return [order[1].get("cid", None) for order in operations]
KeyError: 1
[0, 'hb']
[0, 'n', [1566490238285, 'ox_multi-req', None, None, None, None, 'ERROR', 'input: invalid']]

My code is the following:


trade_client = WssClient(BFX_KEY, BFX_SECRET)
trade_client.authenticate(callback=handle_account_messages)

trade_client.start()
time.sleep(5)

order_operation = trade_client.new_order_op(
    order_type='FOK',
    symbol='BTCUSD',
    amount=0.004,
    price=1000.0
)

trade_client.multi_order(
    operations=[order_operation]
)```
dantimofte commented 5 years ago

i found the problem in the method new_order_op which does not format the order info as requested by bitfinex : https://docs.bitfinex.com/v2/reference#ws-input-order-multi-op

to make it work until the issue is resolved you can do this :

trade_client = WssClient(BFX_KEY, BFX_SECRET)
trade_client.authenticate(callback=handle_account_messages)

trade_client.start()
time.sleep(5)

order_operation = trade_client.new_order_op(
    order_type='FOK',
    symbol='BTCUSD',
    amount=0.004,
    price=1000.0
)

order_operation = ["on", order_operation]

trade_client.multi_order(
    operations=[order_operation]
)
andrebrener commented 5 years ago

It seems it's not accepting float values for amount & price params. It gives me amount: invalid and price: invalid, but when changing them to strings it worked fine