Skip to content

Commit

Permalink
🔧 fix(coinbase): fix bugs and revise request structs
Browse files Browse the repository at this point in the history
  • Loading branch information
dboyliao committed Feb 26, 2025
1 parent bd8c472 commit 15d968d
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"go.testEnvFile": "${workspaceFolder}/.env.local",
}
20 changes: 18 additions & 2 deletions pkg/exchange/coinbase/api/v1/get_candles_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/c9s/requestgen"
)

// an array of [ time, low, high, open, close, volume ]
// `time` is the timestamp of the start time of the bucket, which is the seconds since epoch.
type RawCandle []fixedpoint.Value

type Candle struct {
Time types.Time `json:"time"`
Low fixedpoint.Value `json:"low"`
Expand All @@ -17,15 +21,27 @@ type Candle struct {
Volume fixedpoint.Value `json:"volume"`
}

type GetCandlesResponse []Candle
type GetCandlesResponse []RawCandle

func (rc *RawCandle) Candle() *Candle {
values := *rc
return &Candle{
Time: types.Time(time.Unix(values[0].Int64(), 0)),
Low: values[1],
High: values[2],
Open: values[3],
Close: values[4],
Volume: values[5],
}
}

// https://docs.cdp.coinbase.com/exchange/reference/exchangerestapi_getproductcandles
//
//go:generate requestgen -method GET -url /products/:product_id/candles -type GetCandlesRequest -responseType .GetCandlesResponse
type GetCandlesRequest struct {
client requestgen.AuthenticatedAPIClient

productID string `param:"product_id,required"`
productID string `param:"product_id,slug,required"`
granularity *string `param:"granularity" validValues:"60,300,900,3600,21600,86400"`
start *time.Time `param:"start,seconds"`
end *time.Time `param:"end,seconds"`
Expand Down
38 changes: 22 additions & 16 deletions pkg/exchange/coinbase/api/v1/get_candles_request_requestgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pkg/exchange/coinbase/api/v1/get_order_trades_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ type Trade struct {

type TradeSnapshot []Trade

//go:generate requestgen -method GET -url "/orders/fills" -type GetOrderTradesRequest -responseType .TradeSnapshot
//go:generate requestgen -method GET -url "/fills" -type GetOrderTradesRequest -responseType .TradeSnapshot
type GetOrderTradesRequest struct {
client requestgen.AuthenticatedAPIClient

orderID string `param:"order_id,required"`
orderID string `param:"order_id"`
productID string `param:"product_id"` // one of order_id or product_id is required
limit int `param:"limit"`
before *string `param:"before"`
after *string `param:"after"`
before *int `param:"before"` // pagination id, which is the trade_id (exclusive)
after *int `param:"after"` // pagination id, which is the trade_id (exclusive)
marketType *MarketType `param:"market_type"`
startDate *string `param:"start_date"`
endDate *string `param:"end_date"`
Expand Down
24 changes: 14 additions & 10 deletions pkg/exchange/coinbase/api/v1/get_order_trades_request_requestgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/exchange/coinbase/api/v1/get_orders_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ type GetOrdersRequest struct {
sorting *string `param:"sorting" validValues:"asc,desc"`
startDate *time.Time `param:"start_date" timeFormat:"RFC3339"`
endDate *time.Time `param:"end_date" timeFormat:"RFC3339"`
before *time.Time `param:"before" timeFormat:"RFC3339"`
after *time.Time `param:"after" timeFormat:"RFC3339"`
before *time.Time `param:"before" timeFormat:"RFC3339"` // pagination id, which is the date of the order (exclusive)
after *time.Time `param:"after" timeFormat:"RFC3339"` // pagination id, which is the date of the order (exclusive)
limit int `param:"limit,required"`
status []string `param:"status,required"`
}
Expand All @@ -73,7 +73,7 @@ type GetOrdersRequest struct {
type GetSingleOrderRequest struct {
client requestgen.AuthenticatedAPIClient

orderID string `param:"order_id,required"`
orderID string `param:"order_id,slug,required"`
}

func (client *RestAPIClient) NewGetOrdersRequest() *GetOrdersRequest {
Expand Down
35 changes: 19 additions & 16 deletions pkg/exchange/coinbase/api/v1/get_single_order_request_requestgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/exchange/coinbase/api/v1/get_ticker_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Ticker struct {
type GetTickerRequest struct {
client requestgen.AuthenticatedAPIClient

productID string `param:"product_id,required"`
productID string `param:"product_id,slug,required"`
}

func (client *RestAPIClient) NewGetTickerRequest() *GetTickerRequest {
Expand Down
35 changes: 19 additions & 16 deletions pkg/exchange/coinbase/api/v1/get_ticker_request_requestgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15d968d

Please sign in to comment.