Skip to content

Commit

Permalink
Fix bugs with unmarshaling on ZB and OKGroup (thrasher-corp#290)
Browse files Browse the repository at this point in the history
* Replace nonce increment with mutex to atomic incrementation
* Fix ZB order unmarshaling
* Fix CancelSpotOrderResponse unmarshaling on OKGroup
  • Loading branch information
vadimzhukck authored and thrasher- committed May 3, 2019
1 parent f19cf37 commit 1967507
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
27 changes: 8 additions & 19 deletions exchanges/nonce/nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,43 @@ 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
}

// 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
Expand Down
2 changes: 1 addition & 1 deletion exchanges/okgroup/okgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
6 changes: 3 additions & 3 deletions exchanges/zb/zb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down

0 comments on commit 1967507

Please sign in to comment.