Skip to content

nonce too small fix #213

@JokerCatz

Description

@JokerCatz

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions