bitfinexcom / bitfinex-api-go

BITFINEX Go trading API - Bitcoin, Litecoin, and Ether exchange
https://www.bitfinex.com/
MIT License
309 stars 220 forks source link

GetNonce() lead to an invalid auth #201

Open 0xAnarz opened 4 years ago

0xAnarz commented 4 years ago

GetNonce() for v2 REST can lead to an integer which exceed the MAX_SAFE_INTEGER constant, resulting in an authentication error from the API.

Temp fix : func (u *EpochNonceGenerator) GetNonce() string { return strconv.FormatUint(atomic.AddUint64(&u.nonce, 1) / 1000, 10) }

JacobPlaster commented 4 years ago

Oh not good, I guess we should use micro seconds instead of unix milli seconds. Thanks @0xAnarz for opening the issue.

I will work on a fix now.

JacobPlaster commented 4 years ago

Actually I've just looked into this. Right now the nonce is generated using the function uint64(time.Now().Unix() * 1000), which right now is 1573140173000.

MAX_SAFE_INTEGER is 9007199254740991 which means I am able to make 9005626114567991 requests before I exceed the integer limit.

Are you sure that the error you are seeing is due to an invalid nonce??

0xAnarz commented 4 years ago

func (u *EpochNonceGenerator) GetNonce() string { return strconv.FormatUint(atomic.AddUint64(&u.nonce, 1), 10) } actually give me 1573143819683568401

The temp fix (/1000) work, and without it I'm still getting :

2019/11/07 17:23:39 Error: POST https://api.bitfinex.com/v2/auth/r/positions: 500 apikey: invalid (10100)

Maybe an OS issue ? I'm doing it from win7

JacobPlaster commented 4 years ago

Thats strange, ill try this out on a windows machine.