Skip to content

Commit 8babd1b

Browse files
authored
libxc: Coinbase API fixes (#3570)
1 parent 448ad36 commit 8babd1b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

client/mm/libxc/coinbase.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,11 +1513,11 @@ var max = big.NewInt(math.MaxInt64)
15131513
type nonceSource struct{}
15141514

15151515
func (n nonceSource) Nonce() (string, error) {
1516-
r, err := rand.Int(rand.Reader, max)
1517-
if err != nil {
1516+
b := make([]byte, 16)
1517+
if _, err := rand.Read(b); err != nil {
15181518
return "", err
15191519
}
1520-
return r.String(), nil
1520+
return hex.EncodeToString(b), nil
15211521
}
15221522

15231523
type APIKeyClaims struct {
@@ -1537,7 +1537,7 @@ func buildJWT(apiName, uri string, privKey *ecdsa.PrivateKey) (string, error) {
15371537
cl := &APIKeyClaims{
15381538
Claims: &jwt.Claims{
15391539
Subject: apiName,
1540-
Issuer: "coinbase-cloud",
1540+
Issuer: "cdp",
15411541
NotBefore: jwt.NewNumericDate(time.Now()),
15421542
Expiry: jwt.NewNumericDate(time.Now().Add(time.Minute * 2)),
15431543
},

client/mm/libxc/coinbase_live_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,13 @@ func TestPlaceTrade(t *testing.T) {
571571
}
572572

573573
msgRate := calc.MessageRate(rate, bui, qui)
574-
qty := uint64(math.Round(amount * float64(bui.Conventional.ConversionFactor)))
574+
575+
var qty, quoteQty uint64
576+
if !sell && orderType == OrderTypeMarket {
577+
quoteQty = uint64(math.Round(amount * float64(qui.Conventional.ConversionFactor)))
578+
} else {
579+
qty = uint64(math.Round(amount * float64(bui.Conventional.ConversionFactor)))
580+
}
575581

576582
wg := sync.WaitGroup{}
577583
wg.Add(1)
@@ -597,7 +603,7 @@ func TestPlaceTrade(t *testing.T) {
597603
}
598604
}()
599605

600-
trade, err := c.Trade(ctx, uint32(baseID), uint32(quoteID), sell, msgRate, qty, orderType, updaterID)
606+
trade, err := c.Trade(ctx, uint32(baseID), uint32(quoteID), sell, msgRate, qty, quoteQty, orderType, updaterID)
601607
if err != nil {
602608
t.Fatalf("Trade error: %v", err)
603609
}

0 commit comments

Comments
 (0)