mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 15:10:40 +00:00
golangci-lint/CI: Bump versions and introduce new linters (#798)
* golangci-lint/CI: Bump versions
Fix remaining linter issues
* Specifically set AppVeyor version
* Fix the infamous typos 👀
* Add go env cmd to AppVeyor
* Add go version cmd to AppVeyor
* Specify AppVeyor image, adjust linters
* Update go get to go install due to deprecation
* Bump golangci-lint timeout time for AppVeyor
* Change NW contract to NQ
* Address nitters
* GetRandomPair -> Pair{}
* Address nits
* Address time nitterinos plus additional tweaks
* More time inception upgrades!
* Bending time and space
This commit is contained in:
@@ -374,51 +374,59 @@ func (b *Binance) GetSpotKline(ctx context.Context, arg *KlinesRequestParams) ([
|
||||
|
||||
path := candleStick + "?" + params.Encode()
|
||||
|
||||
if err := b.SendHTTPRequest(ctx,
|
||||
err = b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
path,
|
||||
spotDefaultRate,
|
||||
&resp); err != nil {
|
||||
return klineData, err
|
||||
&resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, responseData := range resp.([]interface{}) {
|
||||
responseData, ok := resp.([]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("unable to type assert responseData")
|
||||
}
|
||||
for x := range responseData {
|
||||
individualData, ok := responseData[x].([]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("unable to type assert individualData")
|
||||
}
|
||||
if len(individualData) != 12 {
|
||||
return nil, errors.New("unexpected kline data length")
|
||||
}
|
||||
var candle CandleStick
|
||||
for i, individualData := range responseData.([]interface{}) {
|
||||
switch i {
|
||||
case 0:
|
||||
tempTime := individualData.(float64)
|
||||
var err error
|
||||
candle.OpenTime, err = convert.TimeFromUnixTimestampFloat(tempTime)
|
||||
if err != nil {
|
||||
return klineData, err
|
||||
}
|
||||
case 1:
|
||||
candle.Open, _ = strconv.ParseFloat(individualData.(string), 64)
|
||||
case 2:
|
||||
candle.High, _ = strconv.ParseFloat(individualData.(string), 64)
|
||||
case 3:
|
||||
candle.Low, _ = strconv.ParseFloat(individualData.(string), 64)
|
||||
case 4:
|
||||
candle.Close, _ = strconv.ParseFloat(individualData.(string), 64)
|
||||
case 5:
|
||||
candle.Volume, _ = strconv.ParseFloat(individualData.(string), 64)
|
||||
case 6:
|
||||
tempTime := individualData.(float64)
|
||||
var err error
|
||||
candle.CloseTime, err = convert.TimeFromUnixTimestampFloat(tempTime)
|
||||
if err != nil {
|
||||
return klineData, err
|
||||
}
|
||||
case 7:
|
||||
candle.QuoteAssetVolume, _ = strconv.ParseFloat(individualData.(string), 64)
|
||||
case 8:
|
||||
candle.TradeCount = individualData.(float64)
|
||||
case 9:
|
||||
candle.TakerBuyAssetVolume, _ = strconv.ParseFloat(individualData.(string), 64)
|
||||
case 10:
|
||||
candle.TakerBuyQuoteAssetVolume, _ = strconv.ParseFloat(individualData.(string), 64)
|
||||
}
|
||||
if candle.OpenTime, err = convert.TimeFromUnixTimestampFloat(individualData[0]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.Open, err = convert.FloatFromString(individualData[1]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.High, err = convert.FloatFromString(individualData[2]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.Low, err = convert.FloatFromString(individualData[3]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.Close, err = convert.FloatFromString(individualData[4]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.Volume, err = convert.FloatFromString(individualData[5]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.CloseTime, err = convert.TimeFromUnixTimestampFloat(individualData[6]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.QuoteAssetVolume, err = convert.FloatFromString(individualData[7]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.TradeCount, ok = individualData[8].(float64); !ok {
|
||||
return nil, errors.New("unable to type assert trade count")
|
||||
}
|
||||
if candle.TakerBuyAssetVolume, err = convert.FloatFromString(individualData[9]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if candle.TakerBuyQuoteAssetVolume, err = convert.FloatFromString(individualData[10]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
klineData = append(klineData, candle)
|
||||
}
|
||||
@@ -784,7 +792,7 @@ func (b *Binance) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, m
|
||||
}
|
||||
|
||||
if params.Get("recvWindow") == "" {
|
||||
params.Set("recvWindow", strconv.FormatInt(convert.RecvWindow(defaultRecvWindow), 10))
|
||||
params.Set("recvWindow", strconv.FormatInt(defaultRecvWindow.Milliseconds(), 10))
|
||||
}
|
||||
|
||||
interim := json.RawMessage{}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//+build !mock_test_off
|
||||
//go:build !mock_test_off
|
||||
// +build !mock_test_off
|
||||
|
||||
// This will build if build tag mock_test_off is not parsed and will try to mock
|
||||
// all tests in _test.go
|
||||
|
||||
@@ -1622,6 +1622,7 @@ func TestGetAggregatedTradesBatched(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if tt.mock != mockTests {
|
||||
t.Skip()
|
||||
}
|
||||
@@ -1677,6 +1678,7 @@ func TestGetAggregatedTradesErrors(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetAggregatedTrades(context.Background(), tt.args)
|
||||
if err == nil {
|
||||
t.Errorf("Binance.GetAggregatedTrades() error = %v, wantErr true", err)
|
||||
@@ -2550,8 +2552,8 @@ func TestWsOrderExecutionReport(t *testing.T) {
|
||||
Side: order.Buy,
|
||||
Status: order.New,
|
||||
AssetType: asset.Spot,
|
||||
Date: time.Unix(0, 1616627567900*int64(time.Millisecond)),
|
||||
LastUpdated: time.Unix(0, 1616627567900*int64(time.Millisecond)),
|
||||
Date: time.UnixMilli(1616627567900),
|
||||
LastUpdated: time.UnixMilli(1616627567900),
|
||||
Pair: currency.NewPair(currency.BTC, currency.USDT),
|
||||
}
|
||||
// empty the channel. otherwise mock_test will fail
|
||||
@@ -2583,8 +2585,7 @@ func TestWsOrderExecutionReport(t *testing.T) {
|
||||
func TestWsOutboundAccountPosition(t *testing.T) {
|
||||
t.Parallel()
|
||||
payload := []byte(`{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e":"outboundAccountPosition","E":1616628815745,"u":1616628815745,"B":[{"a":"BTC","f":"0.00225109","l":"0.00123000"},{"a":"BNB","f":"0.00000000","l":"0.00000000"},{"a":"USDT","f":"54.43390661","l":"0.00000000"}]}}`)
|
||||
err := b.wsHandleData(payload)
|
||||
if err != nil {
|
||||
if err := b.wsHandleData(payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ func (b *Binance) FetchTradablePairs(ctx context.Context, a asset.Item) ([]strin
|
||||
case asset.CoinMarginedFutures:
|
||||
cInfo, err := b.FuturesExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return pairs, nil
|
||||
return pairs, err
|
||||
}
|
||||
for z := range cInfo.Symbols {
|
||||
if cInfo.Symbols[z].ContractStatus == "TRADING" {
|
||||
@@ -385,7 +385,7 @@ func (b *Binance) FetchTradablePairs(ctx context.Context, a asset.Item) ([]strin
|
||||
case asset.USDTMarginedFutures:
|
||||
uInfo, err := b.UExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return pairs, nil
|
||||
return pairs, err
|
||||
}
|
||||
for u := range uInfo.Symbols {
|
||||
if uInfo.Symbols[u].Status == "TRADING" {
|
||||
@@ -751,8 +751,7 @@ func (b *Binance) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (
|
||||
}
|
||||
acc.AssetType = assetType
|
||||
info.Accounts = append(info.Accounts, acc)
|
||||
err := account.Process(&info)
|
||||
if err != nil {
|
||||
if err := account.Process(&info); err != nil {
|
||||
return account.Holdings{}, err
|
||||
}
|
||||
return info, nil
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRateLimit_Limit(t *testing.T) {
|
||||
t.Parallel()
|
||||
symbol := "BTC-USDT"
|
||||
|
||||
testTable := map[string]struct {
|
||||
@@ -56,6 +57,7 @@ func TestRateLimit_Limit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateLimit_LimitStatic(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTable := map[string]request.EndpointLimit{
|
||||
"Default": spotDefaultRate,
|
||||
"Historical Trades": spotHistoricalTradesRate,
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
)
|
||||
|
||||
// binanceTime provides an internal conversion helper
|
||||
@@ -16,7 +14,7 @@ func (t *binanceTime) UnmarshalJSON(data []byte) error {
|
||||
if err := json.Unmarshal(data, ×tamp); err != nil {
|
||||
return err
|
||||
}
|
||||
*t = binanceTime(time.Unix(0, timestamp*int64(time.Millisecond)))
|
||||
*t = binanceTime(time.UnixMilli(timestamp))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -27,7 +25,7 @@ func (t binanceTime) Time() time.Time {
|
||||
|
||||
// timeString gets the time as Binance timestamp
|
||||
func timeString(t time.Time) string {
|
||||
return strconv.FormatInt(convert.UnixMillis(t), 10)
|
||||
return strconv.FormatInt(t.UnixMilli(), 10)
|
||||
}
|
||||
|
||||
// UnmarshalJSON deserialises the JSON info, including the timestamp
|
||||
@@ -74,11 +72,8 @@ func (a *NewOrderResponse) UnmarshalJSON(data []byte) error {
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
// there can be an empty response, then `a` is set to nil
|
||||
if aux != nil {
|
||||
a.TransactionTime = aux.TransactionTime.Time()
|
||||
} else {
|
||||
a = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user