From c66e9dac99c1a6d34f1e9d563d42f32814bb669c Mon Sep 17 00:00:00 2001 From: griffnb Date: Thu, 26 Apr 2018 14:21:25 -0500 Subject: [PATCH 1/4] Update nonce.go --- utils/nonce.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/nonce.go b/utils/nonce.go index 13af9bde8..fc16baafa 100644 --- a/utils/nonce.go +++ b/utils/nonce.go @@ -27,7 +27,7 @@ func (u *EpochNonceGenerator) GetNonce() string { func NewEpochNonceGenerator() *EpochNonceGenerator { return &EpochNonceGenerator{ - nonce: uint64(time.Now().Unix()) * 1000, + nonce: uint64(time.Now().UnixNano() / 1000), } } @@ -36,7 +36,7 @@ func NewEpochNonceGenerator() *EpochNonceGenerator { var nonce uint64 func init() { - nonce = uint64(time.Now().Unix()) * 1000 + nonce = uint64(time.Now().UnixNano() / 1000) } // GetNonce is a naive nonce producer that takes the current Unix nano epoch From 28f02e4dd46512bbfbad63da698fd679a321d25a Mon Sep 17 00:00:00 2001 From: griffnb Date: Thu, 26 Apr 2018 14:46:28 -0500 Subject: [PATCH 2/4] make nonce unix nano --- utils/nonce.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/utils/nonce.go b/utils/nonce.go index fc16baafa..ee48b71db 100644 --- a/utils/nonce.go +++ b/utils/nonce.go @@ -2,7 +2,6 @@ package utils import ( "strconv" - "sync/atomic" "time" ) @@ -22,12 +21,12 @@ type EpochNonceGenerator struct { // key and as such needs to be synchronised with other instances using the same // key in order to avoid race conditions. func (u *EpochNonceGenerator) GetNonce() string { - return strconv.FormatUint(atomic.AddUint64(&u.nonce, 1), 10) + return strconv.FormatUint(time.Now().UnixNano(), 10) } func NewEpochNonceGenerator() *EpochNonceGenerator { return &EpochNonceGenerator{ - nonce: uint64(time.Now().UnixNano() / 1000), + nonce: uint64(time.Now().UnixNano()), } } @@ -36,7 +35,7 @@ func NewEpochNonceGenerator() *EpochNonceGenerator { var nonce uint64 func init() { - nonce = uint64(time.Now().UnixNano() / 1000) + nonce = uint64(time.Now().UnixNano()) } // GetNonce is a naive nonce producer that takes the current Unix nano epoch @@ -45,5 +44,5 @@ func init() { // key and as such needs to be synchronised with other instances using the same // key in order to avoid race conditions. func GetNonce() string { - return strconv.FormatUint(atomic.AddUint64(&nonce, 1), 10) + return strconv.FormatUint(time.Now().UnixNano(), 10) } From 862b5482ea069f98808697ae7a39dd11174550a7 Mon Sep 17 00:00:00 2001 From: griffnb Date: Thu, 26 Apr 2018 14:52:01 -0500 Subject: [PATCH 3/4] nonce change --- utils/nonce.go | 4 ++-- v1/client.go | 2 +- v1/websocket.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/nonce.go b/utils/nonce.go index ee48b71db..a9d0501f4 100644 --- a/utils/nonce.go +++ b/utils/nonce.go @@ -21,7 +21,7 @@ type EpochNonceGenerator struct { // key and as such needs to be synchronised with other instances using the same // key in order to avoid race conditions. func (u *EpochNonceGenerator) GetNonce() string { - return strconv.FormatUint(time.Now().UnixNano(), 10) + return strconv.FormatInt(time.Now().UnixNano(), 10) } func NewEpochNonceGenerator() *EpochNonceGenerator { @@ -44,5 +44,5 @@ func init() { // key and as such needs to be synchronised with other instances using the same // key in order to avoid race conditions. func GetNonce() string { - return strconv.FormatUint(time.Now().UnixNano(), 10) + return strconv.FormatInt(time.Now().UnixNano(), 10) } diff --git a/v1/client.go b/v1/client.go index 375193eba..3c2581dfb 100644 --- a/v1/client.go +++ b/v1/client.go @@ -12,7 +12,7 @@ import ( "net/http" "net/url" - "github.com/bitfinexcom/bitfinex-api-go/utils" + "github.com/blockcapital/bitfinex-api-go/utils" ) const ( diff --git a/v1/websocket.go b/v1/websocket.go index 4b418d447..aa46d1d79 100644 --- a/v1/websocket.go +++ b/v1/websocket.go @@ -8,7 +8,7 @@ import ( "net/http" "reflect" - "github.com/bitfinexcom/bitfinex-api-go/utils" + "github.com/blockcapital/bitfinex-api-go/utils" "github.com/gorilla/websocket" ) From 860c247bc38abe6e864342cf80592f5f8df42f82 Mon Sep 17 00:00:00 2001 From: griffnb Date: Thu, 26 Apr 2018 14:52:35 -0500 Subject: [PATCH 4/4] point to right nonce --- v2/rest/client.go | 3 ++- v2/websocket/client.go | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/v2/rest/client.go b/v2/rest/client.go index 640691198..94014756e 100644 --- a/v2/rest/client.go +++ b/v2/rest/client.go @@ -6,11 +6,12 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/bitfinexcom/bitfinex-api-go/utils" "io" "io/ioutil" "net/http" "net/url" + + "github.com/blockcapital/bitfinex-api-go/utils" ) var productionBaseURL = "https://api.bitfinex.com/v2/" diff --git a/v2/websocket/client.go b/v2/websocket/client.go index f79c7f848..25efddda4 100644 --- a/v2/websocket/client.go +++ b/v2/websocket/client.go @@ -10,13 +10,12 @@ import ( "time" "unicode" - "github.com/bitfinexcom/bitfinex-api-go/utils" + "github.com/blockcapital/bitfinex-api-go/utils" + bitfinex "github.com/blockcapital/bitfinex-api-go/v2" "crypto/hmac" "crypto/sha512" "encoding/hex" - - "github.com/bitfinexcom/bitfinex-api-go/v2" ) var productionBaseURL = "wss://api.bitfinex.com/ws/2"