diff --git a/httpc/client.go b/httpc/client.go index a02e5d2..42ae992 100644 --- a/httpc/client.go +++ b/httpc/client.go @@ -11,7 +11,7 @@ import ( "github.com/goccy/go-json" "github.com/larscom/go-bitvavo/v2/crypto" - "github.com/larscom/go-bitvavo/v2/jsond" + "github.com/larscom/go-bitvavo/v2/types" "github.com/larscom/go-bitvavo/v2/util" ) @@ -102,7 +102,7 @@ func unwrapErr(response *http.Response) error { return err } - var bitvavoErr *jsond.BitvavoErr + var bitvavoErr *types.BitvavoErr if err := json.Unmarshal(bytes, &bitvavoErr); err != nil { return fmt.Errorf("did not get OK response, code=%d, body=%s", response.StatusCode, string(bytes)) } diff --git a/httpc/httpclient.go b/httpc/httpclient.go index f3492d6..8dffdcc 100644 --- a/httpc/httpclient.go +++ b/httpc/httpclient.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/larscom/go-bitvavo/v2/jsond" "github.com/larscom/go-bitvavo/v2/log" + "github.com/larscom/go-bitvavo/v2/types" "github.com/larscom/go-bitvavo/v2/util" ) @@ -47,24 +47,24 @@ type HttpClient interface { // GetMarkets returns the available markets with their status (trading,halted,auction) and // available order types. - GetMarkets() ([]jsond.Market, error) + GetMarkets() ([]types.Market, error) // GetMarkets returns the available markets with their status (trading,halted,auction) and // available order types for a single market (e.g: ETH-EUR) - GetMarket(market string) (jsond.Market, error) + GetMarket(market string) (types.Market, error) // GetAssets returns information on the supported assets - GetAssets() ([]jsond.Asset, error) + GetAssets() ([]types.Asset, error) // GetAsset returns information on the supported asset by symbol (e.g: ETH). - GetAsset(symbol string) (jsond.Asset, error) + GetAsset(symbol string) (types.Asset, error) // GetOrderBook returns a book with bids and asks for market. // That is, the buy and sell orders made by all Bitvavo users in a specific market (e.g: ETH-EUR). // The orders in the return parameters are sorted by price // // Optionally provide the depth to return the top depth orders only. - GetOrderBook(market string, depth ...uint64) (jsond.Book, error) + GetOrderBook(market string, depth ...uint64) (types.Book, error) } type Option func(*httpClient) @@ -146,8 +146,8 @@ func (c *httpClient) GetTime() (int64, error) { return int64(resp["time"]), nil } -func (c *httpClient) GetMarkets() ([]jsond.Market, error) { - return httpGet[[]jsond.Market]( +func (c *httpClient) GetMarkets() ([]types.Market, error) { + return httpGet[[]types.Market]( fmt.Sprintf("%s/markets", httpUrl), emptyParams, c.updateRateLimit, @@ -157,11 +157,11 @@ func (c *httpClient) GetMarkets() ([]jsond.Market, error) { ) } -func (c *httpClient) GetMarket(market string) (jsond.Market, error) { +func (c *httpClient) GetMarket(market string) (types.Market, error) { params := make(url.Values) params.Add("market", market) - return httpGet[jsond.Market]( + return httpGet[types.Market]( fmt.Sprintf("%s/markets", httpUrl), params, c.updateRateLimit, @@ -171,8 +171,8 @@ func (c *httpClient) GetMarket(market string) (jsond.Market, error) { ) } -func (c *httpClient) GetAssets() ([]jsond.Asset, error) { - return httpGet[[]jsond.Asset]( +func (c *httpClient) GetAssets() ([]types.Asset, error) { + return httpGet[[]types.Asset]( fmt.Sprintf("%s/assets", httpUrl), emptyParams, c.updateRateLimit, @@ -182,11 +182,11 @@ func (c *httpClient) GetAssets() ([]jsond.Asset, error) { ) } -func (c *httpClient) GetAsset(symbol string) (jsond.Asset, error) { +func (c *httpClient) GetAsset(symbol string) (types.Asset, error) { params := make(url.Values) params.Add("symbol", symbol) - return httpGet[jsond.Asset]( + return httpGet[types.Asset]( fmt.Sprintf("%s/assets", httpUrl), params, c.updateRateLimit, @@ -196,13 +196,13 @@ func (c *httpClient) GetAsset(symbol string) (jsond.Asset, error) { ) } -func (c *httpClient) GetOrderBook(market string, depth ...uint64) (jsond.Book, error) { +func (c *httpClient) GetOrderBook(market string, depth ...uint64) (types.Book, error) { params := make(url.Values) if len(depth) > 0 { params.Add("depth", fmt.Sprint(depth[0])) } - return httpGet[jsond.Book]( + return httpGet[types.Book]( fmt.Sprintf("%s/%s/book", httpUrl, market), params, c.updateRateLimit, diff --git a/httpc/httpclientauth.go b/httpc/httpclientauth.go index e589f3d..cb3fcc5 100644 --- a/httpc/httpclientauth.go +++ b/httpc/httpclientauth.go @@ -6,16 +6,16 @@ import ( "net/url" - "github.com/larscom/go-bitvavo/v2/jsond" + "github.com/larscom/go-bitvavo/v2/types" ) type HttpClientAuth interface { // GetBalance returns the balance on the account. // Optionally provide the symbol to filter for in uppercase (e.g: ETH) - GetBalance(symbol ...string) ([]jsond.Balance, error) + GetBalance(symbol ...string) ([]types.Balance, error) // GetAccount returns trading volume and fees for account. - GetAccount() (jsond.Account, error) + GetAccount() (types.Account, error) } type httpClientAuth struct { @@ -45,13 +45,13 @@ func newHttpClientAuth( } } -func (c *httpClientAuth) GetBalance(symbol ...string) ([]jsond.Balance, error) { +func (c *httpClientAuth) GetBalance(symbol ...string) ([]types.Balance, error) { params := make(url.Values) if len(symbol) > 0 { params.Add("symbol", symbol[0]) } - return httpGet[[]jsond.Balance]( + return httpGet[[]types.Balance]( fmt.Sprintf("%s/balance", httpUrl), params, c.updateRateLimit, @@ -61,8 +61,8 @@ func (c *httpClientAuth) GetBalance(symbol ...string) ([]jsond.Balance, error) { ) } -func (c *httpClientAuth) GetAccount() (jsond.Account, error) { - return httpGet[jsond.Account]( +func (c *httpClientAuth) GetAccount() (types.Account, error) { + return httpGet[types.Account]( fmt.Sprintf("%s/account", httpUrl), emptyParams, c.updateRateLimit, diff --git a/jsond/account.go b/types/account.go similarity index 98% rename from jsond/account.go rename to types/account.go index 670fa83..c47eec3 100644 --- a/jsond/account.go +++ b/types/account.go @@ -1,4 +1,4 @@ -package jsond +package types import ( "github.com/goccy/go-json" diff --git a/jsond/asset.go b/types/asset.go similarity index 99% rename from jsond/asset.go rename to types/asset.go index 7948634..4ed18ff 100644 --- a/jsond/asset.go +++ b/types/asset.go @@ -1,4 +1,4 @@ -package jsond +package types import ( "github.com/goccy/go-json" diff --git a/jsond/balance.go b/types/balance.go similarity index 98% rename from jsond/balance.go rename to types/balance.go index 8c224fa..39d9475 100644 --- a/jsond/balance.go +++ b/types/balance.go @@ -1,4 +1,4 @@ -package jsond +package types import ( "github.com/goccy/go-json" diff --git a/jsond/book.go b/types/book.go similarity index 99% rename from jsond/book.go rename to types/book.go index d309200..2b8cceb 100644 --- a/jsond/book.go +++ b/types/book.go @@ -1,4 +1,4 @@ -package jsond +package types import ( "github.com/goccy/go-json" diff --git a/jsond/candle.go b/types/candle.go similarity index 98% rename from jsond/candle.go rename to types/candle.go index 392735a..54c15d0 100644 --- a/jsond/candle.go +++ b/types/candle.go @@ -1,4 +1,4 @@ -package jsond +package types import ( "fmt" diff --git a/jsond/error.go b/types/error.go similarity index 96% rename from jsond/error.go rename to types/error.go index 859a138..d9d8d43 100644 --- a/jsond/error.go +++ b/types/error.go @@ -1,4 +1,4 @@ -package jsond +package types import ( "fmt" diff --git a/jsond/fill.go b/types/fill.go similarity index 98% rename from jsond/fill.go rename to types/fill.go index 089d760..e9a0c3c 100644 --- a/jsond/fill.go +++ b/types/fill.go @@ -1,4 +1,4 @@ -package jsond +package types type Fill struct { // The id of the order on which has been filled diff --git a/jsond/market.go b/types/market.go similarity index 99% rename from jsond/market.go rename to types/market.go index 447a861..6e71032 100644 --- a/jsond/market.go +++ b/types/market.go @@ -1,4 +1,4 @@ -package jsond +package types import ( "github.com/goccy/go-json" diff --git a/jsond/order.go b/types/order.go similarity index 99% rename from jsond/order.go rename to types/order.go index 8144fd5..96f33fb 100644 --- a/jsond/order.go +++ b/types/order.go @@ -1,4 +1,4 @@ -package jsond +package types type Order struct { Guid string `json:"guid"` diff --git a/jsond/ticker.go b/types/ticker.go similarity index 98% rename from jsond/ticker.go rename to types/ticker.go index d561819..fe1da46 100644 --- a/jsond/ticker.go +++ b/types/ticker.go @@ -1,4 +1,4 @@ -package jsond +package types type Ticker struct { // The price of the best (highest) bid offer available, only sent when either bestBid or bestBidSize has changed. diff --git a/jsond/ticker24h.go b/types/ticker24h.go similarity index 98% rename from jsond/ticker24h.go rename to types/ticker24h.go index a7b101b..7440b25 100644 --- a/jsond/ticker24h.go +++ b/types/ticker24h.go @@ -1,4 +1,4 @@ -package jsond +package types type Ticker24h struct { // The open price of the 24 hour period. diff --git a/jsond/trade.go b/types/trade.go similarity index 96% rename from jsond/trade.go rename to types/trade.go index 8bb8e21..8f3238a 100644 --- a/jsond/trade.go +++ b/types/trade.go @@ -1,4 +1,4 @@ -package jsond +package types type Trade struct { // The trade ID of the returned trade (UUID). diff --git a/wsc/account.go b/wsc/account.go index 859c0af..bdbd901 100644 --- a/wsc/account.go +++ b/wsc/account.go @@ -6,8 +6,8 @@ import ( "github.com/goccy/go-json" "github.com/larscom/go-bitvavo/v2/crypto" - "github.com/larscom/go-bitvavo/v2/jsond" "github.com/larscom/go-bitvavo/v2/log" + "github.com/larscom/go-bitvavo/v2/types" "github.com/larscom/go-bitvavo/v2/util" "github.com/smallnest/safemap" ) @@ -20,7 +20,7 @@ type OrderEvent struct { Market string `json:"market"` // The order itself. - Order jsond.Order `json:"order"` + Order types.Order `json:"order"` } func (o *OrderEvent) UnmarshalJSON(bytes []byte) error { @@ -59,7 +59,7 @@ func (o *OrderEvent) UnmarshalJSON(bytes []byte) error { o.Market = market o.Event = event - o.Order = jsond.Order{ + o.Order = types.Order{ Guid: guid, OrderId: orderId, Created: int64(created), @@ -91,7 +91,7 @@ type FillEvent struct { // The market which was requested in the subscription Market string `json:"market"` // The fill itself - Fill jsond.Fill `json:"fill"` + Fill types.Fill `json:"fill"` } func (f *FillEvent) UnmarshalJSON(bytes []byte) error { @@ -119,7 +119,7 @@ func (f *FillEvent) UnmarshalJSON(bytes []byte) error { f.Market = market f.Event = event - f.Fill = jsond.Fill{ + f.Fill = types.Fill{ OrderId: orderId, FillId: fillId, Timestamp: int64(timestamp), diff --git a/wsc/book.go b/wsc/book.go index dfe814a..a0300b0 100644 --- a/wsc/book.go +++ b/wsc/book.go @@ -3,8 +3,8 @@ package wsc import ( "fmt" - "github.com/larscom/go-bitvavo/v2/jsond" "github.com/larscom/go-bitvavo/v2/log" + "github.com/larscom/go-bitvavo/v2/types" "github.com/goccy/go-json" "github.com/larscom/go-bitvavo/v2/util" @@ -19,7 +19,7 @@ type BookEvent struct { Market string `json:"market"` // The book containing the bids and asks. - Book jsond.Book `json:"book"` + Book types.Book `json:"book"` } func (b *BookEvent) UnmarshalJSON(bytes []byte) error { diff --git a/wsc/candles.go b/wsc/candles.go index ca0ee7b..98c897d 100644 --- a/wsc/candles.go +++ b/wsc/candles.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/larscom/go-bitvavo/v2/jsond" "github.com/larscom/go-bitvavo/v2/log" + "github.com/larscom/go-bitvavo/v2/types" "github.com/larscom/go-bitvavo/v2/util" "github.com/goccy/go-json" @@ -23,7 +23,7 @@ type CandlesEvent struct { Interval string `json:"interval"` // The candle in the defined time period. - Candle jsond.Candle `json:"candle"` + Candle types.Candle `json:"candle"` } type CandlesEventHandler interface { diff --git a/wsc/ticker.go b/wsc/ticker.go index 3bda3c5..e862dc3 100644 --- a/wsc/ticker.go +++ b/wsc/ticker.go @@ -3,8 +3,8 @@ package wsc import ( "fmt" - "github.com/larscom/go-bitvavo/v2/jsond" "github.com/larscom/go-bitvavo/v2/log" + "github.com/larscom/go-bitvavo/v2/types" "github.com/goccy/go-json" "github.com/larscom/go-bitvavo/v2/util" @@ -19,7 +19,7 @@ type TickerEvent struct { Market string `json:"market"` // The ticker containing the prices. - Ticker jsond.Ticker `json:"ticker"` + Ticker types.Ticker `json:"ticker"` } func (t *TickerEvent) UnmarshalJSON(bytes []byte) error { @@ -40,7 +40,7 @@ func (t *TickerEvent) UnmarshalJSON(bytes []byte) error { ) t.Market = market - t.Ticker = jsond.Ticker{ + t.Ticker = types.Ticker{ BestBid: util.IfOrElse(len(bestBid) > 0, func() float64 { return util.MustFloat64(bestBid) }, 0), BestBidSize: util.IfOrElse(len(bestBidSize) > 0, func() float64 { return util.MustFloat64(bestBidSize) }, 0), BestAsk: util.IfOrElse(len(bestAsk) > 0, func() float64 { return util.MustFloat64(bestAsk) }, 0), diff --git a/wsc/ticker24h.go b/wsc/ticker24h.go index 4497e72..ab86b7b 100644 --- a/wsc/ticker24h.go +++ b/wsc/ticker24h.go @@ -3,8 +3,8 @@ package wsc import ( "fmt" - "github.com/larscom/go-bitvavo/v2/jsond" "github.com/larscom/go-bitvavo/v2/log" + "github.com/larscom/go-bitvavo/v2/types" "github.com/goccy/go-json" "github.com/larscom/go-bitvavo/v2/util" @@ -19,7 +19,7 @@ type Ticker24hEvent struct { Market string `json:"market"` // The ticker24h containing the prices etc. - Ticker24h jsond.Ticker24h `json:"ticker24h"` + Ticker24h types.Ticker24h `json:"ticker24h"` } func (t *Ticker24hEvent) UnmarshalJSON(bytes []byte) error { @@ -58,7 +58,7 @@ func (t *Ticker24hEvent) UnmarshalJSON(bytes []byte) error { t.Event = event t.Market = market - t.Ticker24h = jsond.Ticker24h{ + t.Ticker24h = types.Ticker24h{ Open: util.IfOrElse(len(open) > 0, func() float64 { return util.MustFloat64(open) }, 0), High: util.IfOrElse(len(high) > 0, func() float64 { return util.MustFloat64(high) }, 0), Low: util.IfOrElse(len(low) > 0, func() float64 { return util.MustFloat64(low) }, 0), diff --git a/wsc/trades.go b/wsc/trades.go index c6e43ad..7aa679f 100644 --- a/wsc/trades.go +++ b/wsc/trades.go @@ -3,8 +3,8 @@ package wsc import ( "fmt" - "github.com/larscom/go-bitvavo/v2/jsond" "github.com/larscom/go-bitvavo/v2/log" + "github.com/larscom/go-bitvavo/v2/types" "github.com/goccy/go-json" "github.com/larscom/go-bitvavo/v2/util" @@ -19,7 +19,7 @@ type TradesEvent struct { Market string `json:"market"` // The trade containing the price, side etc. - Trade jsond.Trade `json:"trade"` + Trade types.Trade `json:"trade"` } func (t *TradesEvent) UnmarshalJSON(bytes []byte) error { @@ -42,7 +42,7 @@ func (t *TradesEvent) UnmarshalJSON(bytes []byte) error { t.Event = event t.Market = market - t.Trade = jsond.Trade{ + t.Trade = types.Trade{ Id: id, Amount: util.IfOrElse(len(amount) > 0, func() float64 { return util.MustFloat64(amount) }, 0), Price: util.IfOrElse(len(price) > 0, func() float64 { return util.MustFloat64(price) }, 0), diff --git a/wsc/wsclient.go b/wsc/wsclient.go index 3de5106..76aa05c 100644 --- a/wsc/wsclient.go +++ b/wsc/wsclient.go @@ -4,8 +4,8 @@ import ( "net/http" "time" - "github.com/larscom/go-bitvavo/v2/jsond" "github.com/larscom/go-bitvavo/v2/log" + "github.com/larscom/go-bitvavo/v2/types" "github.com/goccy/go-json" "github.com/gorilla/websocket" @@ -280,7 +280,7 @@ func (ws *wsClient) handleMessage(bytes []byte) { var baseEvent *BaseEvent if err := json.Unmarshal(bytes, &baseEvent); err != nil { - var wsError *jsond.BitvavoErr + var wsError *types.BitvavoErr if err := json.Unmarshal(bytes, &wsError); err != nil { log.Logger().Error("Don't know how to handle this message", "message", string(bytes)) } else { @@ -291,7 +291,7 @@ func (ws *wsClient) handleMessage(bytes []byte) { } } -func (ws *wsClient) handlError(err *jsond.BitvavoErr) { +func (ws *wsClient) handlError(err *types.BitvavoErr) { ws.logDebug("Handling incoming error", "err", err) switch err.Action {