bitfinexcom / bitfinex-api-go

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

nonce to small error when using two libraries with same API Key #200

Open Jonah246 opened 4 years ago

Jonah246 commented 4 years ago

Issue type

Brief description

I used python-sdk and this Golang sdk with the same api-key. While it works smoothly in python, I got error 500 nonce: small (10114).

Additional Notes:

After reading the source code, I found that nonce generation rules differs between two libraries

utils/nonce.go

func NewEpochNonceGenerator() *EpochNonceGenerator {
    return &EpochNonceGenerator{
        nonce: uint64(time.Now().Unix() * 1000),
    }
}

utils/auth.py

def _gen_nonce():
  return int(round(time.time() * 1000000))

If users use the same ApiKey, Go-SDK will generate a nonce that's 1000 times smaller than the python's one and always yield a nonce to small error. It may not be a bug but would be nice to have consistent rules between libraries.

JacobPlaster commented 4 years ago

Hey @Jonah246 thanks for raising this as an issue and providing some good code examples. We are aware of this problem but havent changed it due to the fact that we like to encourage users to generate a new key for each strategy/implementation.

It may not be a bug but would be nice to have consistent rules between libraries.

I do agree with this so im going to leave this open and add a TODO for us to implement this. I guess we have two options, either we upgrade all of the libs to match the python lib (since the nonce is the largest there) or we break some peoples code and force them to re-generate new api keys.

For reference, the nodejs nonce generation function: https://github.com/bitfinexcom/bfx-api-node-util/blob/master/lib/nonce.js