mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-19 15:10:05 +00:00
Fix bugs with unmarshaling on ZB and OKGroup (#290)
* Replace nonce increment with mutex to atomic incrementation * Fix ZB order unmarshaling * Fix CancelSpotOrderResponse unmarshaling on OKGroup
This commit is contained in:
committed by
Adrian Gallagher
parent
f19cf37752
commit
1967507d40
@@ -3,14 +3,14 @@ package nonce
|
||||
import (
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Nonce struct holds the nonce value
|
||||
type Nonce struct {
|
||||
// Standard nonce
|
||||
n int64
|
||||
mtx sync.Mutex
|
||||
n int64
|
||||
// Hash table exclusive exchange specific nonce values
|
||||
boundedCall map[string]int64
|
||||
boundedMtx sync.Mutex
|
||||
@@ -18,39 +18,28 @@ type Nonce struct {
|
||||
|
||||
// Inc increments the nonce value
|
||||
func (n *Nonce) Inc() {
|
||||
n.mtx.Lock()
|
||||
n.n++
|
||||
n.mtx.Unlock()
|
||||
atomic.AddInt64(&n.n, 1)
|
||||
}
|
||||
|
||||
// Get retrives the nonce value
|
||||
func (n *Nonce) Get() int64 {
|
||||
n.mtx.Lock()
|
||||
defer n.mtx.Unlock()
|
||||
return n.n
|
||||
return atomic.LoadInt64(&n.n)
|
||||
}
|
||||
|
||||
// GetInc increments and returns the value of the nonce
|
||||
func (n *Nonce) GetInc() int64 {
|
||||
n.mtx.Lock()
|
||||
defer n.mtx.Unlock()
|
||||
n.n++
|
||||
return n.n
|
||||
n.Inc()
|
||||
return n.Get()
|
||||
}
|
||||
|
||||
// Set sets the nonce value
|
||||
func (n *Nonce) Set(val int64) {
|
||||
n.mtx.Lock()
|
||||
n.n = val
|
||||
n.mtx.Unlock()
|
||||
atomic.StoreInt64(&n.n, val)
|
||||
}
|
||||
|
||||
// String returns a string version of the nonce
|
||||
func (n *Nonce) String() string {
|
||||
n.mtx.Lock()
|
||||
result := strconv.FormatInt(n.n, 10)
|
||||
n.mtx.Unlock()
|
||||
return result
|
||||
return strconv.FormatInt(n.Get(), 10)
|
||||
}
|
||||
|
||||
// Value is a return type for GetValue
|
||||
|
||||
@@ -183,7 +183,7 @@ type CancelSpotOrderRequest struct {
|
||||
// CancelSpotOrderResponse response data for CancelSpotOrder
|
||||
type CancelSpotOrderResponse struct {
|
||||
ClientOID string `json:"client_oid"`
|
||||
OrderID int64 `json:"order_id"`
|
||||
OrderID int64 `json:"order_id,string"`
|
||||
Result bool `json:"result"`
|
||||
}
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ type AccountsBaseResponse struct {
|
||||
// Order is the order details for retrieving all orders
|
||||
type Order struct {
|
||||
Currency string `json:"currency"`
|
||||
ID int64 `json:"id"`
|
||||
Price int `json:"price"`
|
||||
ID int64 `json:"id,string"`
|
||||
Price float64 `json:"price"`
|
||||
Status int `json:"status"`
|
||||
TotalAmount float64 `json:"total_amount"`
|
||||
TradeAmount int `json:"trade_amount"`
|
||||
TradeDate int `json:"trade_date"`
|
||||
TradeMoney int `json:"trade_money"`
|
||||
TradeMoney float64 `json:"trade_money"`
|
||||
Type int64 `json:"type"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user