exchanges: Types and unmarshalling methods update (#1899)

* Added TimeInForce type and updated related files

* Linter issue fix and minor coinbasepro type update

* Bitrex consts update

* added unit test and minor changes in bittrex

* Unit tests update

* Fix minor linter issues

* Update TestStringToTimeInForce unit test

* fix conflict with gateio timeInForce

* Update order tests

* Complete updating the order unit tests

* update kucoin and deribit wrapper to match the time in force change

* fix time-in-force related test errors

* linter issue fix

* time in force constants, functions and unit tests update

* shift tif policies to TimeInForce

* Update time-in-force, related functions, and unit tests

* fix linter issue and time-in-force processing

* added a good till crossing tif value

* order type fix and fix related tim-in-force entries

* update time-in-force unmarshaling and unit test

* fix time-in-force error in gateio

* linter issue fix

* update based on review comments

* add unit test and fix missing issues

* minor fix and added benchmark unit test

* change GTT to GTC for limit

* fix linter issue

* added time-in-force value to place order param

* fix minor issues based on review comment and move tif code to separate files

* update on exchanges linked to time-in-force

* resolve missing review comments

* minor linter issues fix

* added time-in-force handler and update timeInForce parametered endpoint

* minor fixes based on review

* nits fix

* update based on review

* linter fix

* rm getTimeInForce func and minor change to time-in-force

* minor change

* update based on review comments

* wrappers and time-in-force calling approach

* update slice data processing

* fix linter issues

* remove unnecessary Unmarshal methods and replace type delatration and added unit tests

* minor change

* minor changes to types

* update gateio string to timeInForce conversion and unit test

* removed unused timeInForceString func from kraken

* removed redundant parentheses in slice unmarshaling

* array to slice conversion and other updates

* reverted slice target to array

* Binanceus unit test NotNil check to Len check

* change NotNil to Len check

* rename unmarshal unit test funcs name

* wrap json strings with []byte
This commit is contained in:
Samuael A.
2025-06-02 06:54:49 +03:00
committed by GitHub
parent 8fa6179f65
commit 0e9adcd1e1
28 changed files with 483 additions and 1095 deletions

View File

@@ -233,27 +233,11 @@ func (c *CoinbasePro) GetHistoricRates(ctx context.Context, currencyPair, start,
values.Set("granularity", strconv.FormatInt(granularity, 10))
}
var resp [][6]float64
var resp []History
path := common.EncodeURLValues(
fmt.Sprintf("%s/%s/%s", coinbaseproProducts, currencyPair, coinbaseproHistory),
values)
if err := c.SendHTTPRequest(ctx, exchange.RestSpot, path, &resp); err != nil {
return nil, err
}
history := make([]History, len(resp))
for x := range resp {
history[x] = History{
Time: time.Unix(int64(resp[x][0]), 0),
Low: resp[x][1],
High: resp[x][2],
Open: resp[x][3],
Close: resp[x][4],
Volume: resp[x][5],
}
}
return history, nil
return resp, c.SendHTTPRequest(ctx, exchange.RestSpot, path, &resp)
}
// GetStats returns a 24 hr stat for the product. Volume is in base currency

View File

@@ -13,6 +13,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
@@ -23,6 +24,7 @@ import (
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
"github.com/thrasher-corp/gocryptotrader/types"
)
var (
@@ -74,6 +76,30 @@ func TestGetTrades(t *testing.T) {
}
}
func TestHistoryUnmarshalJSON(t *testing.T) {
t.Parallel()
data := []byte(`[[1746649200,96269.22,96307.18,96275.58,96307.18,1.85952049],[1746649140,96256.39,96297.31,96296,96273.29,3.41045323],[1746649080,96256.01,96365.73,96365.73,96299.99,3.56073877]]`)
var resp []History
err := json.Unmarshal(data, &resp)
require.NoError(t, err)
require.Len(t, resp, 3)
assert.Equal(t, History{
Time: types.Time(time.Unix(1746649200, 0)),
Low: 96269.22,
High: 96307.18,
Open: 96275.58,
Close: 96307.18,
Volume: 1.85952049,
}, resp[0])
}
func TestGetHistoricRates(t *testing.T) {
t.Parallel()
result, err := c.GetHistoricRates(t.Context(), "BTC-USD", "", "", 0)
require.NoError(t, err)
assert.NotNil(t, result)
}
func TestGetHistoricRatesGranularityCheck(t *testing.T) {
end := time.Now()
start := end.Add(-time.Hour * 2)

View File

@@ -4,6 +4,8 @@ import (
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/types"
)
// Product holds product information
@@ -49,7 +51,7 @@ type Trade struct {
// History holds historic rate information
type History struct {
Time time.Time
Time types.Time
Low float64
High float64
Open float64
@@ -57,6 +59,11 @@ type History struct {
Volume float64
}
// UnmarshalJSON deserilizes kline data from a JSON array into History fields.
func (h *History) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &[6]any{&h.Time, &h.Low, &h.High, &h.Open, &h.Close, &h.Volume})
}
// Stats holds last 24 hr data for coinbasepro
type Stats struct {
Open float64 `json:"open,string"`

View File

@@ -788,7 +788,7 @@ func (c *CoinbasePro) GetHistoricCandles(ctx context.Context, pair currency.Pair
timeSeries := make([]kline.Candle, len(history))
for x := range history {
timeSeries[x] = kline.Candle{
Time: history[x].Time,
Time: history[x].Time.Time(),
Low: history[x].Low,
High: history[x].High,
Open: history[x].Open,
@@ -820,7 +820,7 @@ func (c *CoinbasePro) GetHistoricCandlesExtended(ctx context.Context, pair curre
for i := range history {
timeSeries = append(timeSeries, kline.Candle{
Time: history[i].Time,
Time: history[i].Time.Time(),
Low: history[i].Low,
High: history[i].High,
Open: history[i].Open,