ohenrik / bitfinex

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

Can't create order because of library error #32

Closed Flowelfox closed 5 years ago

Flowelfox commented 5 years ago

When creating order getting error: File "...venv\lib\site-packages\bitfinex\websockets\client.py", line 648, in new_order set_cid=set_cid

File "...venv\lib\site-packages\bitfinex\websockets\client.py", line 562, in new_order_op client_order_id = utils.create_cid()

File "...venv\lib\site-packages\bitfinex\utils\__init__.py", line 16, in create_cid return int(float(now.strftime("%s.%f"))*10000)

ValueError: Invalid format string

I did some research, it works fine with upper 'S'.

I am using Python 3.7.0 Library version 1.1.4

dantimofte commented 5 years ago

what operating system are you running this on ?

dantimofte commented 5 years ago

I investigated a little and it would seem that %s (small s) is operating system dependent and that is why you might be getting an error if using something different than macos / ubuntu.

However %S (big S) even if it works is something enterily different and it would not generate the same numbers expected from that function.

A good solution that is not operating system dependant is suggested in this stackoverflow answer :

https://stackoverflow.com/questions/6999726/how-can-i-convert-a-datetime-object-to-milliseconds-since-epoch-unix-time-in-p

I have adapted the code so we get similar results as the old code :

`

from datetime import datetime now = datetime.utcnow() now.strftime("%s") '1551110468' now.strftime("%S") '08' epoch = datetime.utcfromtimestamp(0) int((now - epoch).total_seconds() 10000) 15511176686818 int(float(now.strftime("%s.%f"))10000) 15511104686818`

Flowelfox commented 5 years ago

what operating system are you running this on ?

I was getting this error on windows 10

dantimofte commented 5 years ago

You are welcome to submit a pull request for this issue that provides the same response but is platform agnostic.

Flowelfox commented 5 years ago

You are welcome to submit a pull request for this issue that provides the same response but is platform agnostic.

I'll submit pull request tomorrow with code that you provided