Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecated base_max_size, base_min_size, and max_market_funds #111

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Client will respect environment variables: COINBASE_PRO_BASEURL, COINBASE_PRO_PA

```go
import (
coinbasepro "github.com/preichenberger/go-coinbasepro/v2"
coinbasepro "github.com/preichenberger/go-coinbasepro"
)

client := coinbasepro.NewClient()
Expand Down Expand Up @@ -187,7 +187,7 @@ Results return coinbase time type which handles different types of time parsing
```go
import(
"time"
coinbasepro "github.com/preichenberger/go-coinbasepro/v2"
coinbasepro "github.com/preichenberger/go-coinbasepro"
)

coinbaseTime := coinbasepro.Time{}
Expand Down
21 changes: 7 additions & 14 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"math"
"net/http"
"os"
"strconv"
Expand All @@ -17,7 +16,6 @@ type Client struct {
Key string
Passphrase string
HTTPClient *http.Client
RetryCount int
}

type ClientConfig struct {
Expand All @@ -41,7 +39,6 @@ func NewClient() *Client {
HTTPClient: &http.Client{
Timeout: 15 * time.Second,
},
RetryCount: 0,
}

if os.Getenv("COINBASE_PRO_SANDBOX") == "1" {
Expand Down Expand Up @@ -75,19 +72,15 @@ func (c *Client) UpdateConfig(config *ClientConfig) {

func (c *Client) Request(method string, url string,
params, result interface{}) (res *http.Response, err error) {
for i := 0; i < c.RetryCount+1; i++ {
retryDuration := time.Duration((math.Pow(2, float64(i))-1)/2*1000) * time.Millisecond
time.Sleep(retryDuration)

res, err = c.request(method, url, params, result)
if res != nil && res.StatusCode == 429 {
continue
} else {
break
}

if err = BeforeRequest(c, method, fmt.Sprintf("%s%s", c.BaseURL, url)); err != nil {
return nil, err
}
defer func() {
AfterRequest()
}()

return res, err
return c.request(method, url, params, result)
}

func (c *Client) request(method string, url string,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/preichenberger/go-coinbasepro/v2
module github.com/svanas/go-coinbasepro

require github.com/gorilla/websocket v1.4.0
58 changes: 29 additions & 29 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ import (
type Message struct {
Type string `json:"type"`
ProductID string `json:"product_id"`
ProductIds []string `json:"product_ids"`
Products []Product `json:"products"`
Currencies []Currency `json:"currencies"`
TradeID int `json:"trade_id,number"`
OrderID string `json:"order_id"`
ClientOID string `json:"client_oid"`
Sequence int64 `json:"sequence,number"`
MakerOrderID string `json:"maker_order_id"`
TakerOrderID string `json:"taker_order_id"`
Time Time `json:"time,string"`
RemainingSize string `json:"remaining_size"`
NewSize string `json:"new_size"`
OldSize string `json:"old_size"`
Size string `json:"size"`
Price string `json:"price"`
Side string `json:"side"`
Reason string `json:"reason"`
OrderType string `json:"order_type"`
Funds string `json:"funds"`
NewFunds string `json:"new_funds"`
OldFunds string `json:"old_funds"`
Message string `json:"message"`
ProductIds []string `json:"product_ids,omitempty"`
Products []Product `json:"products,omitempty"`
Currencies []Currency `json:"currencies,omitempty"`
TradeID int `json:"trade_id,number,omitempty"`
OrderID string `json:"order_id,omitempty"`
ClientOID string `json:"client_oid,omitempty"`
Sequence int64 `json:"sequence,number,omitempty"`
MakerOrderID string `json:"maker_order_id,omitempty"`
TakerOrderID string `json:"taker_order_id,omitempty"`
Time Time `json:"time,string,omitempty"`
RemainingSize string `json:"remaining_size,omitempty"`
NewSize string `json:"new_size,omitempty"`
OldSize string `json:"old_size,omitempty"`
Size string `json:"size,omitempty"`
Price string `json:"price,omitempty"`
Side string `json:"side,omitempty"`
Reason string `json:"reason,omitempty"`
OrderType string `json:"order_type,omitempty"`
Funds string `json:"funds,omitempty"`
NewFunds string `json:"new_funds,omitempty"`
OldFunds string `json:"old_funds,omitempty"`
Message string `json:"message,omitempty"`
Bids []SnapshotEntry `json:"bids,omitempty"`
Asks []SnapshotEntry `json:"asks,omitempty"`
Changes []SnapshotChange `json:"changes,omitempty"`
LastSize string `json:"last_size"`
BestBid string `json:"best_bid"`
BestAsk string `json:"best_ask"`
Channels []MessageChannel `json:"channels"`
UserID string `json:"user_id"`
ProfileID string `json:"profile_id"`
LastTradeID int `json:"last_trade_id"`
LastSize string `json:"last_size,omitempty"`
BestBid string `json:"best_bid,omitempty"`
BestAsk string `json:"best_ask,omitempty"`
Channels []MessageChannel `json:"channels,omitempty"`
UserID string `json:"user_id,omitempty"`
ProfileID string `json:"profile_id,omitempty"`
LastTradeID int `json:"last_trade_id,omitempty"`
}

type MessageChannel struct {
Expand Down
2 changes: 1 addition & 1 deletion order.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Order struct {
Funds string `json:"funds,omitempty"`
SpecifiedFunds string `json:"specified_funds,omitempty"`
// Response Fields
ID string `json:"id"`
ID string `json:"id,omitempty"`
Status string `json:"status,omitempty"`
Settled bool `json:"settled,omitempty"`
DoneReason string `json:"done_reason,omitempty"`
Expand Down
20 changes: 10 additions & 10 deletions product.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
)

type Product struct {
ID string `json:"id"`
BaseCurrency string `json:"base_currency"`
QuoteCurrency string `json:"quote_currency"`
BaseMinSize string `json:"base_min_size"`
BaseMaxSize string `json:"base_max_size"`
QuoteIncrement string `json:"quote_increment"`
BaseIncrement string `json:"base_increment"`
DisplayName string `json:"display_name"`
MinMarketFunds string `json:"min_market_funds"`
MaxMarketFunds string `json:"max_market_funds"`
ID string `json:"id"`
BaseCurrency string `json:"base_currency"`
QuoteCurrency string `json:"quote_currency"`
// BaseMinSize string `json:"base_min_size"` deprecated on 2022-06-30, see https://docs.cloud.coinbase.com/exchange/docs/changelog#2022-jun-02
// BaseMaxSize string `json:"base_max_size"` deprecated on 2022-06-30, see https://docs.cloud.coinbase.com/exchange/docs/changelog#2022-jun-02
QuoteIncrement string `json:"quote_increment"`
BaseIncrement string `json:"base_increment"`
DisplayName string `json:"display_name"`
MinMarketFunds string `json:"min_market_funds"`
// MaxMarketFunds string `json:"max_market_funds"` deprecated on 2022-06-30, see https://docs.cloud.coinbase.com/exchange/docs/changelog#2022-jun-02
MarginEnabled bool `json:"margin_enabled"`
PostOnly bool `json:"post_only"`
LimitOnly bool `json:"limit_only"`
Expand Down
1 change: 0 additions & 1 deletion test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func NewTestClient() *Client {
client.UpdateConfig(&ClientConfig{
BaseURL: "https://api-public.sandbox.pro.coinbase.com",
})
client.RetryCount = 2

return client
}
Expand Down
25 changes: 25 additions & 0 deletions throttler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package coinbasepro

import (
"time"
)

var (
lastRequest time.Time
RequestsPerSecond float64 = 10
BeforeRequest func(client *Client, method, endpoint string) error = nil
AfterRequest func() = nil
)

func init() {
BeforeRequest = func(client *Client, method, endpoint string) error {
elapsed := time.Since(lastRequest)
if elapsed.Seconds() < (float64(1) / RequestsPerSecond) {
time.Sleep(time.Duration((float64(time.Second) / RequestsPerSecond)) - elapsed)
}
return nil
}
AfterRequest = func() {
lastRequest = time.Now()
}
}