Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nonce too small fix #213

Open
JokerCatz opened this issue Jun 11, 2020 · 1 comment
Open

nonce too small fix #213

JokerCatz opened this issue Jun 11, 2020 · 1 comment

Comments

@JokerCatz
Copy link

JokerCatz commented Jun 11, 2020

https://github.com/bitfinexcom/bitfinex-api-go/blame/4d37e8d4be18f16ab50082b0c2c080542225f4a0/utils/nonce.go#L30

nonce: uint64(time.Now().Unix()) * 1000,
// time.now.second x 1000 != millisecond
// I think it mean
nonce: uint64(time.Now().UnixNano()) / 10e5,

if I new the client obj every time , the nonce will be same of same "second" , the conn obj init nonce will be same ...

so I think just use nano second be nonce will fix this

type CustomNonceGenerator struct {
}
func (u *CustomNonceGenerator) GetNonce() string {
    return strconv.FormatUint(uint64(time.Now().UnixNano()), 10)
   // or same code : millisecond
   // return strconv.FormatUint(uint64(time.Now().UnixNano()) / 10e5, 10)
}
// ...
func{
    conn := bitfinexRest.NewClientWithURLNonce("https://api.bitfinex.com/v2/", &CustomNonceGenerator{}).Credentials(...)
}

or just fix source code , init conn nonce be nano second

nonce: uint64(time.Now().UnixNano()),

but multi conn obj will be nonce collision ...

or use a global var + lock to increase it?

@calj
Copy link
Contributor

calj commented Jul 15, 2020

We had this problem while doing parallel requests to the rest API. It appears when requests arrive in different orders to the server.

We quick fixed by introducing a lock in our code to prevent parallel rest calls.

Eventually we could introduce this lock in the library.
An other approach would be to change the API to async, the lib would push requests in order using a channel, a single go routine would make all rest calls, on response the library would trigger a callback specified by the caller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@JokerCatz @calj and others