cli: rpc time parsing (#1107)

* fix rpc time parsing

* Update cmd/gctcli/helpers.go

Beautifully handled

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Fixes combined commit

* uses ParseInLocation, parse with timezone, remove helper functions

* lint

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
Scott
2022-12-28 12:23:59 +11:00
committed by GitHub
parent c20e308272
commit d92ffe6e9e
8 changed files with 170 additions and 193 deletions

View File

@@ -936,13 +936,13 @@ func (s *RPCServer) GetOrders(ctx context.Context, r *gctrpc.GetOrdersRequest) (
var start, end time.Time
if r.StartDate != "" {
start, err = time.Parse(common.SimpleTimeFormat, r.StartDate)
start, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.StartDate)
if err != nil {
return nil, err
}
}
if r.EndDate != "" {
end, err = time.Parse(common.SimpleTimeFormat, r.EndDate)
end, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.EndDate)
if err != nil {
return nil, err
}
@@ -1913,11 +1913,11 @@ func (s *RPCServer) WithdrawalEventsByExchange(ctx context.Context, r *gctrpc.Wi
// WithdrawalEventsByDate returns previous withdrawal request details by exchange
func (s *RPCServer) WithdrawalEventsByDate(_ context.Context, r *gctrpc.WithdrawalEventsByDateRequest) (*gctrpc.WithdrawalEventsByExchangeResponse, error) {
start, err := time.Parse(common.SimpleTimeFormat, r.Start)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.Start)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.End)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.End)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -2353,11 +2353,11 @@ func (s *RPCServer) GetExchangeTickerStream(r *gctrpc.GetExchangeTickerStreamReq
// GetAuditEvent returns matching audit events from database
func (s *RPCServer) GetAuditEvent(_ context.Context, r *gctrpc.GetAuditEventRequest) (*gctrpc.GetAuditEventResponse, error) {
start, err := time.Parse(common.SimpleTimeFormat, r.StartDate)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.StartDate)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.EndDate)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.EndDate)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -2401,11 +2401,11 @@ func (s *RPCServer) GetAuditEvent(_ context.Context, r *gctrpc.GetAuditEventRequ
// GetHistoricCandles returns historical candles for a given exchange
func (s *RPCServer) GetHistoricCandles(ctx context.Context, r *gctrpc.GetHistoricCandlesRequest) (*gctrpc.GetHistoricCandlesResponse, error) {
start, err := time.Parse(common.SimpleTimeFormat, r.Start)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.Start)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.End)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.End)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -2416,7 +2416,6 @@ func (s *RPCServer) GetHistoricCandles(ctx context.Context, r *gctrpc.GetHistori
if r.Pair == nil {
return nil, errCurrencyPairUnset
}
pair := currency.Pair{
Delimiter: r.Pair.Delimiter,
Base: currency.NewCode(r.Pair.Base),
@@ -3180,11 +3179,11 @@ func (s *RPCServer) GetSavedTrades(_ context.Context, r *gctrpc.GetSavedTradesRe
return nil, err
}
start, err := time.Parse(common.SimpleTimeFormat, r.Start)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.Start)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.End)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.End)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -3223,11 +3222,11 @@ func (s *RPCServer) ConvertTradesToCandles(_ context.Context, r *gctrpc.ConvertT
if r.End == "" || r.Start == "" || r.Exchange == "" || r.Pair == nil || r.AssetType == "" || r.Pair.String() == "" || r.TimeInterval == 0 {
return nil, errInvalidArguments
}
start, err := time.Parse(common.SimpleTimeFormat, r.Start)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.Start)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.End)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.End)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -3328,11 +3327,11 @@ func (s *RPCServer) FindMissingSavedCandleIntervals(_ context.Context, r *gctrpc
return nil, err
}
start, err := time.Parse(common.SimpleTimeFormat, r.Start)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.Start)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.End)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.End)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -3419,11 +3418,11 @@ func (s *RPCServer) FindMissingSavedTradeIntervals(_ context.Context, r *gctrpc.
if err != nil {
return nil, err
}
start, err := time.Parse(common.SimpleTimeFormat, r.Start)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.Start)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.End)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.End)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -3537,11 +3536,11 @@ func (s *RPCServer) GetHistoricTrades(r *gctrpc.GetSavedTradesRequest, stream gc
return err
}
var trades []trade.Data
start, err := time.Parse(common.SimpleTimeFormat, r.Start)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.Start)
if err != nil {
return fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.End)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.End)
if err != nil {
return fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -3845,11 +3844,11 @@ func (s *RPCServer) UpsertDataHistoryJob(_ context.Context, r *gctrpc.UpsertData
return nil, err
}
start, err := time.Parse(common.SimpleTimeFormat, r.StartDate)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.StartDate)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.EndDate)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.EndDate)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -4016,11 +4015,11 @@ func (s *RPCServer) GetDataHistoryJobsBetween(_ context.Context, r *gctrpc.GetDa
if r == nil {
return nil, errNilRequestData
}
start, err := time.Parse(common.SimpleTimeFormat, r.StartDate)
start, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.StartDate)
if err != nil {
return nil, fmt.Errorf("%w cannot parse start time %v", errInvalidTimes, err)
}
end, err := time.Parse(common.SimpleTimeFormat, r.EndDate)
end, err := time.Parse(common.SimpleTimeFormatWithTimezone, r.EndDate)
if err != nil {
return nil, fmt.Errorf("%w cannot parse end time %v", errInvalidTimes, err)
}
@@ -4410,13 +4409,13 @@ func (s *RPCServer) GetFuturesPositions(ctx context.Context, r *gctrpc.GetFuture
}
var start, end time.Time
if r.StartDate != "" {
start, err = time.Parse(common.SimpleTimeFormat, r.StartDate)
start, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.StartDate)
if err != nil {
return nil, err
}
}
if r.EndDate != "" {
end, err = time.Parse(common.SimpleTimeFormat, r.EndDate)
end, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.EndDate)
if err != nil {
return nil, err
}
@@ -4680,13 +4679,13 @@ func (s *RPCServer) GetFundingRates(ctx context.Context, r *gctrpc.GetFundingRat
start := time.Now().AddDate(-1, 0, 0)
end := time.Now()
if r.StartDate != "" {
start, err = time.Parse(common.SimpleTimeFormat, r.StartDate)
start, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.StartDate)
if err != nil {
return nil, err
}
}
if r.EndDate != "" {
end, err = time.Parse(common.SimpleTimeFormat, r.EndDate)
end, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.EndDate)
if err != nil {
return nil, err
}
@@ -5196,13 +5195,13 @@ func (s *RPCServer) GetMarginRatesHistory(ctx context.Context, r *gctrpc.GetMarg
start := time.Now().AddDate(0, -1, 0)
end := time.Now()
if r.StartDate != "" {
start, err = time.Parse(common.SimpleTimeFormat, r.StartDate)
start, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.StartDate)
if err != nil {
return nil, err
}
}
if r.EndDate != "" {
end, err = time.Parse(common.SimpleTimeFormat, r.EndDate)
end, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.EndDate)
if err != nil {
return nil, err
}
@@ -5242,7 +5241,7 @@ func (s *RPCServer) GetMarginRatesHistory(ctx context.Context, r *gctrpc.GetMarg
req.Rates = make([]margin.Rate, len(r.Rates))
for i := range r.Rates {
var offlineRate margin.Rate
offlineRate.Time, err = time.Parse(common.SimpleTimeFormat, r.Rates[i].Time)
offlineRate.Time, err = time.Parse(common.SimpleTimeFormatWithTimezone, r.Rates[i].Time)
if err != nil {
return nil, err
}

View File

@@ -478,8 +478,8 @@ func TestGetSavedTrades(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
})
if !errors.Is(err, ErrExchangeNotFound) {
t.Error(err)
@@ -492,14 +492,14 @@ func TestGetSavedTrades(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
})
if err == nil {
t.Error(unexpectedLackOfError)
return
}
if err.Error() != "request for Bitstamp spot trade data between 2019-11-30 00:00:00 and 2020-01-01 01:01:01 and returned no results" {
if err.Error() != "request for Bitstamp spot trade data between 2019-11-30 00:00:00 UTC and 2020-01-01 01:01:01 UTC and returned no results" {
t.Error(err)
}
err = sqltrade.Insert(sqltrade.Data{
@@ -524,8 +524,8 @@ func TestGetSavedTrades(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
})
if err != nil {
t.Error(err)
@@ -551,8 +551,8 @@ func TestConvertTradesToCandles(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
})
if !errors.Is(err, ErrExchangeNotFound) {
@@ -568,8 +568,8 @@ func TestConvertTradesToCandles(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
})
if !errors.Is(err, errNoTrades) {
@@ -601,8 +601,8 @@ func TestConvertTradesToCandles(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
})
if err != nil {
@@ -621,8 +621,8 @@ func TestConvertTradesToCandles(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
Sync: true,
})
@@ -639,8 +639,8 @@ func TestConvertTradesToCandles(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
Sync: true,
Force: true,
@@ -658,8 +658,8 @@ func TestConvertTradesToCandles(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
UseDb: true,
})
@@ -686,8 +686,8 @@ func TestGetHistoricCandles(t *testing.T) {
Base: cp.Base.String(),
Quote: cp.Quote.String(),
},
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
AssetType: asset.Spot.String(),
})
if !errors.Is(err, ErrExchangeNameIsEmpty) {
@@ -700,8 +700,8 @@ func TestGetHistoricCandles(t *testing.T) {
Base: cp.Base.String(),
Quote: cp.Quote.String(),
},
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
AssetType: asset.Spot.String(),
})
if !errors.Is(err, ErrExchangeNotFound) {
@@ -710,8 +710,8 @@ func TestGetHistoricCandles(t *testing.T) {
_, err = s.GetHistoricCandles(context.Background(), &gctrpc.GetHistoricCandlesRequest{
Exchange: testExchange,
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
Pair: nil,
AssetType: asset.Spot.String(),
})
@@ -724,8 +724,8 @@ func TestGetHistoricCandles(t *testing.T) {
Base: currency.BTC.String(),
Quote: currency.USD.String(),
},
Start: "2020-01-02 15:04:05",
End: "2020-01-02 15:04:05",
Start: "2020-01-02 15:04:05 UTC",
End: "2020-01-02 15:04:05 UTC",
})
if !errors.Is(err, common.ErrStartEqualsEnd) {
t.Errorf("received %v, expected %v", err, common.ErrStartEqualsEnd)
@@ -738,8 +738,8 @@ func TestGetHistoricCandles(t *testing.T) {
Base: cp.Base.String(),
Quote: cp.Quote.String(),
},
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
AssetType: asset.Spot.String(),
TimeInterval: int64(kline.OneHour.Duration()),
})
@@ -758,8 +758,8 @@ func TestGetHistoricCandles(t *testing.T) {
Quote: cp.Quote.String(),
},
AssetType: asset.Spot.String(),
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
Sync: true,
ExRequest: true,
@@ -779,8 +779,8 @@ func TestGetHistoricCandles(t *testing.T) {
Quote: cp.Quote.String(),
},
AssetType: asset.Spot.String(),
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
UseDb: true,
})
@@ -812,8 +812,8 @@ func TestGetHistoricCandles(t *testing.T) {
Quote: cp.Quote.String(),
},
AssetType: asset.Spot.String(),
Start: defaultStart.Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 3, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 3, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
TimeInterval: int64(kline.OneHour.Duration()),
UseDb: true,
FillMissingWithTrades: true,
@@ -852,8 +852,8 @@ func TestFindMissingSavedTradeIntervals(t *testing.T) {
Base: cp.Base.String(),
Quote: cp.Quote.String(),
},
Start: defaultStart.UTC().Format(common.SimpleTimeFormat),
End: defaultEnd.UTC().Format(common.SimpleTimeFormat),
Start: defaultStart.UTC().Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.UTC().Format(common.SimpleTimeFormatWithTimezone),
})
if err != nil {
t.Error(err)
@@ -884,8 +884,8 @@ func TestFindMissingSavedTradeIntervals(t *testing.T) {
Base: cp.Base.String(),
Quote: cp.Quote.String(),
},
Start: defaultStart.In(time.UTC).Format(common.SimpleTimeFormat),
End: defaultEnd.In(time.UTC).Format(common.SimpleTimeFormat),
Start: defaultStart.In(time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.In(time.UTC).Format(common.SimpleTimeFormatWithTimezone),
})
if err != nil {
t.Error(err)
@@ -917,8 +917,8 @@ func TestFindMissingSavedTradeIntervals(t *testing.T) {
Base: cp.Base.String(),
Quote: cp.Quote.String(),
},
Start: defaultStart.In(time.UTC).Format(common.SimpleTimeFormat),
End: defaultEnd.In(time.UTC).Format(common.SimpleTimeFormat),
Start: defaultStart.In(time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.In(time.UTC).Format(common.SimpleTimeFormatWithTimezone),
})
if err != nil {
t.Error(err)
@@ -955,8 +955,8 @@ func TestFindMissingSavedCandleIntervals(t *testing.T) {
Quote: cp.Quote.String(),
},
Interval: int64(time.Hour),
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
})
if err != nil && err.Error() != "no candle data found: Bitstamp BTC USD 3600 spot" {
t.Error(err)
@@ -993,8 +993,8 @@ func TestFindMissingSavedCandleIntervals(t *testing.T) {
Quote: cp.Quote.String(),
},
Interval: int64(time.Hour),
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
})
if err != nil {
t.Error(err)
@@ -1030,8 +1030,8 @@ func TestFindMissingSavedCandleIntervals(t *testing.T) {
Quote: cp.Quote.String(),
},
Interval: int64(time.Hour),
Start: defaultStart.Format(common.SimpleTimeFormat),
End: defaultEnd.Format(common.SimpleTimeFormat),
Start: defaultStart.Format(common.SimpleTimeFormatWithTimezone),
End: defaultEnd.Format(common.SimpleTimeFormatWithTimezone),
})
if err != nil {
t.Error(err)
@@ -1089,8 +1089,8 @@ func TestGetRecentTrades(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
})
if !errors.Is(err, ErrExchangeNotFound) {
t.Error(err)
@@ -1137,8 +1137,8 @@ func TestGetHistoricTrades(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
}, nil)
if !errors.Is(err, ErrExchangeNotFound) {
t.Error(err)
@@ -1151,8 +1151,8 @@ func TestGetHistoricTrades(t *testing.T) {
Quote: currency.USD.String(),
},
AssetType: asset.Spot.String(),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormatWithTimezone),
}, &dummyServer{})
if err != common.ErrFunctionNotSupported {
t.Error(err)
@@ -1299,8 +1299,8 @@ func TestGetOrders(t *testing.T) {
Exchange: exchName,
AssetType: asset.Spot.String(),
Pair: p,
StartDate: time.Now().UTC().Add(time.Second).Format(common.SimpleTimeFormat),
EndDate: time.Now().UTC().Add(-time.Hour).Format(common.SimpleTimeFormat),
StartDate: time.Now().UTC().Add(time.Second).Format(common.SimpleTimeFormatWithTimezone),
EndDate: time.Now().UTC().Add(-time.Hour).Format(common.SimpleTimeFormatWithTimezone),
})
if !errors.Is(err, common.ErrStartAfterTimeNow) {
t.Errorf("received %v, expected %v", err, common.ErrStartAfterTimeNow)
@@ -1310,8 +1310,8 @@ func TestGetOrders(t *testing.T) {
Exchange: exchName,
AssetType: asset.Spot.String(),
Pair: p,
StartDate: time.Now().UTC().Add(-time.Hour).Format(common.SimpleTimeFormat),
EndDate: time.Now().UTC().Add(time.Hour).Format(common.SimpleTimeFormat),
StartDate: time.Now().UTC().Add(-time.Hour).Format(common.SimpleTimeFormatWithTimezone),
EndDate: time.Now().UTC().Add(time.Hour).Format(common.SimpleTimeFormatWithTimezone),
})
if !errors.Is(err, exchange.ErrCredentialsAreEmpty) {
t.Errorf("received '%v', expected '%v'", err, exchange.ErrCredentialsAreEmpty)
@@ -1617,8 +1617,8 @@ func TestRPCServerUpsertDataHistoryJob(t *testing.T) {
Base: "BTC",
Quote: "USD",
},
StartDate: time.Now().Add(-time.Hour * 24).Format(common.SimpleTimeFormat),
EndDate: time.Now().Format(common.SimpleTimeFormat),
StartDate: time.Now().Add(-time.Hour * 24).Format(common.SimpleTimeFormatWithTimezone),
EndDate: time.Now().Format(common.SimpleTimeFormatWithTimezone),
Interval: int64(kline.OneHour.Duration()),
RequestSizeLimit: 10,
DataType: int64(dataHistoryCandleDataType),
@@ -1795,8 +1795,8 @@ func TestGetDataHistoryJobsBetween(t *testing.T) {
}
_, err = s.GetDataHistoryJobsBetween(context.Background(), &gctrpc.GetDataHistoryJobsBetweenRequest{
StartDate: time.Now().UTC().Add(time.Minute).Format(common.SimpleTimeFormat),
EndDate: time.Now().UTC().Format(common.SimpleTimeFormat),
StartDate: time.Now().UTC().Add(time.Minute).Format(common.SimpleTimeFormatWithTimezone),
EndDate: time.Now().UTC().Format(common.SimpleTimeFormatWithTimezone),
})
if !errors.Is(err, common.ErrStartAfterTimeNow) {
t.Fatalf("received %v, expected %v", err, common.ErrStartAfterTimeNow)
@@ -1808,8 +1808,8 @@ func TestGetDataHistoryJobsBetween(t *testing.T) {
}
r, err := s.GetDataHistoryJobsBetween(context.Background(), &gctrpc.GetDataHistoryJobsBetweenRequest{
StartDate: time.Now().Add(-time.Minute).UTC().Format(common.SimpleTimeFormat),
EndDate: time.Now().Add(time.Minute).UTC().Format(common.SimpleTimeFormat),
StartDate: time.Now().Add(-time.Minute).UTC().Format(common.SimpleTimeFormatWithTimezone),
EndDate: time.Now().Add(time.Minute).UTC().Format(common.SimpleTimeFormatWithTimezone),
})
if !errors.Is(err, nil) {
t.Errorf("received %v, expected %v", err, nil)
@@ -1993,6 +1993,7 @@ func TestRPCServer_unixTimestamp(t *testing.T) {
}
func TestRPCServer_GetTicker_LastUpdatedNanos(t *testing.T) {
t.Parallel()
// Make a dummy pair we'll be using for this test.
pair := currency.NewPairWithDelimiter("XXXXX", "YYYYY", "")
@@ -2844,7 +2845,7 @@ func TestGetMarginRatesHistory(t *testing.T) {
request.Rates = []*gctrpc.MarginRate{
{
Time: time.Now().Format(common.SimpleTimeFormat),
Time: time.Now().Format(common.SimpleTimeFormatWithTimezone),
HourlyRate: "1337",
},
}
@@ -2855,7 +2856,7 @@ func TestGetMarginRatesHistory(t *testing.T) {
request.Rates = []*gctrpc.MarginRate{
{
Time: time.Now().Format(common.SimpleTimeFormat),
Time: time.Now().Format(common.SimpleTimeFormatWithTimezone),
HourlyRate: "1337",
LendingPayment: &gctrpc.LendingPayment{Size: "1337"},
BorrowCost: &gctrpc.BorrowCost{Size: "1337"},