diff --git a/.appveyor.yml b/.appveyor.yml index 28c48959..945686b8 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,6 +1,6 @@ build: off -image: Visual Studio 2019 +image: Visual Studio 2022 # See https://www.appveyor.com/docs/build-environment/#build-worker-images clone_folder: c:\gopath\src\github.com\thrasher-corp\gocryptotrader @@ -36,7 +36,6 @@ services: init: - set PATH=%POSTGRES_PATH%\bin;%PATH% - - set PATH=C:\go119\bin;%PATH% install: - set Path=C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;%Path% diff --git a/backtester/btcli/commands.go b/backtester/btcli/commands.go index b908b466..8677006c 100644 --- a/backtester/btcli/commands.go +++ b/backtester/btcli/commands.go @@ -42,12 +42,12 @@ var executeStrategyFromFileCommand = &cli.Command{ &cli.StringFlag{ Name: "starttimeoverride", Aliases: []string{"s"}, - Usage: fmt.Sprintf("override the strategy file's start time using your local time. eg '%v'", time.Now().Truncate(time.Hour).AddDate(0, -1, 0).Format(common.SimpleTimeFormat)), + Usage: fmt.Sprintf("override the strategy file's start time using your local time. eg '%v'", time.Now().Truncate(time.Hour).AddDate(0, -1, 0).Format(time.DateTime)), }, &cli.StringFlag{ Name: "endtimeoverride", Aliases: []string{"e"}, - Usage: fmt.Sprintf("override the strategy file's end time using your local time. eg '%v'", time.Now().Truncate(time.Hour).Format(common.SimpleTimeFormat)), + Usage: fmt.Sprintf("override the strategy file's end time using your local time. eg '%v'", time.Now().Truncate(time.Hour).Format(time.DateTime)), }, &cli.Uint64Flag{ Name: "intervaloverride", @@ -100,13 +100,13 @@ func executeStrategyFromFile(c *cli.Context) error { var s, e time.Time if startTimeOverride != "" { - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTimeOverride, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTimeOverride, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } } if endTimeOverride != "" { - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTimeOverride, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTimeOverride, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } diff --git a/backtester/config/strategyconfig.go b/backtester/config/strategyconfig.go index fb1c6c99..25f1fffa 100644 --- a/backtester/config/strategyconfig.go +++ b/backtester/config/strategyconfig.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "strings" + "time" "github.com/shopspring/decimal" "github.com/thrasher-corp/gocryptotrader/backtester/common" @@ -316,8 +317,8 @@ func (c *Config) PrintSetting() { log.Infoln(common.Config, common.CMDColours.H2+"------------------API Settings-------------------------------"+common.CMDColours.Default) log.Infof(common.Config, "Data type: %v", c.DataSettings.DataType) log.Infof(common.Config, "Interval: %v", c.DataSettings.Interval) - log.Infof(common.Config, "Start date: %v", c.DataSettings.APIData.StartDate.Format(gctcommon.SimpleTimeFormat)) - log.Infof(common.Config, "End date: %v", c.DataSettings.APIData.EndDate.Format(gctcommon.SimpleTimeFormat)) + log.Infof(common.Config, "Start date: %v", c.DataSettings.APIData.StartDate.Format(time.DateTime)) + log.Infof(common.Config, "End date: %v", c.DataSettings.APIData.EndDate.Format(time.DateTime)) } if c.DataSettings.CSVData != nil { log.Infoln(common.Config, common.CMDColours.H2+"------------------CSV Settings-------------------------------"+common.CMDColours.Default) @@ -329,7 +330,7 @@ func (c *Config) PrintSetting() { log.Infoln(common.Config, common.CMDColours.H2+"------------------Database Settings--------------------------"+common.CMDColours.Default) log.Infof(common.Config, "Data type: %v", c.DataSettings.DataType) log.Infof(common.Config, "Interval: %v", c.DataSettings.Interval) - log.Infof(common.Config, "Start date: %v", c.DataSettings.DatabaseData.StartDate.Format(gctcommon.SimpleTimeFormat)) - log.Infof(common.Config, "End date: %v", c.DataSettings.DatabaseData.EndDate.Format(gctcommon.SimpleTimeFormat)) + log.Infof(common.Config, "Start date: %v", c.DataSettings.DatabaseData.StartDate.Format(time.DateTime)) + log.Infof(common.Config, "End date: %v", c.DataSettings.DatabaseData.EndDate.Format(time.DateTime)) } } diff --git a/backtester/config/strategyconfigbuilder/main.go b/backtester/config/strategyconfigbuilder/main.go index bef61f2c..15d82ba5 100644 --- a/backtester/config/strategyconfigbuilder/main.go +++ b/backtester/config/strategyconfigbuilder/main.go @@ -333,10 +333,10 @@ func parseAPI(reader *bufio.Reader, cfg *config.Config) error { var err error defaultStart := time.Now().Add(-time.Hour * 24 * 365) defaultEnd := time.Now() - fmt.Printf("What is the start date? Leave blank for \"%v\"\n", defaultStart.Format(gctcommon.SimpleTimeFormat)) + fmt.Printf("What is the start date? Leave blank for \"%v\"\n", defaultStart.Format(time.DateTime)) startDate = quickParse(reader) if startDate != "" { - cfg.DataSettings.APIData.StartDate, err = time.Parse(gctcommon.SimpleTimeFormat, startDate) + cfg.DataSettings.APIData.StartDate, err = time.Parse(time.DateTime, startDate) if err != nil { return err } @@ -344,10 +344,10 @@ func parseAPI(reader *bufio.Reader, cfg *config.Config) error { cfg.DataSettings.APIData.StartDate = defaultStart } - fmt.Printf("What is the end date? Leave blank for \"%v\"\n", defaultEnd.Format(gctcommon.SimpleTimeFormat)) + fmt.Printf("What is the end date? Leave blank for \"%v\"\n", defaultEnd.Format(time.DateTime)) endDate = quickParse(reader) if endDate != "" { - cfg.DataSettings.APIData.EndDate, err = time.Parse(gctcommon.SimpleTimeFormat, endDate) + cfg.DataSettings.APIData.EndDate, err = time.Parse(time.DateTime, endDate) if err != nil { return err } @@ -373,10 +373,10 @@ func parseDatabase(reader *bufio.Reader, cfg *config.Config) error { var err error defaultStart := time.Now().Add(-time.Hour * 24 * 365) defaultEnd := time.Now() - fmt.Printf("What is the start date? Leave blank for \"%v\"\n", defaultStart.Format(gctcommon.SimpleTimeFormat)) + fmt.Printf("What is the start date? Leave blank for \"%v\"\n", defaultStart.Format(time.DateTime)) startDate := quickParse(reader) if startDate != "" { - cfg.DataSettings.DatabaseData.StartDate, err = time.Parse(gctcommon.SimpleTimeFormat, startDate) + cfg.DataSettings.DatabaseData.StartDate, err = time.Parse(time.DateTime, startDate) if err != nil { return err } @@ -384,9 +384,9 @@ func parseDatabase(reader *bufio.Reader, cfg *config.Config) error { cfg.DataSettings.DatabaseData.StartDate = defaultStart } - fmt.Printf("What is the end date? Leave blank for \"%v\"\n", defaultEnd.Format(gctcommon.SimpleTimeFormat)) + fmt.Printf("What is the end date? Leave blank for \"%v\"\n", defaultEnd.Format(time.DateTime)) if endDate := quickParse(reader); endDate != "" { - cfg.DataSettings.DatabaseData.EndDate, err = time.Parse(gctcommon.SimpleTimeFormat, endDate) + cfg.DataSettings.DatabaseData.EndDate, err = time.Parse(time.DateTime, endDate) if err != nil { return err } diff --git a/backtester/eventhandlers/statistics/printresults.go b/backtester/eventhandlers/statistics/printresults.go index 04da3118..f34cbb8b 100644 --- a/backtester/eventhandlers/statistics/printresults.go +++ b/backtester/eventhandlers/statistics/printresults.go @@ -153,7 +153,7 @@ func (s *Statistic) CreateLog(data common.Event) (string, error) { } result = fmt.Sprintf(colour+ "%v %v%v%v| Price: %v\tDirection: %v", - ev.GetTime().Format(gctcommon.SimpleTimeFormat), + ev.GetTime().Format(time.DateTime), fSIL(ev.GetExchange(), limit12), fSIL(ev.GetAssetType().String(), limit10), fSIL(ev.Pair().String(), limit14), @@ -169,7 +169,7 @@ func (s *Statistic) CreateLog(data common.Event) (string, error) { } result = fmt.Sprintf(colour+ "%v %v%v%v| Price: %v\tDirection %v\tOrder placed: Amount: %v\tFee: %v\tTotal: %v", - ev.GetTime().Format(gctcommon.SimpleTimeFormat), + ev.GetTime().Format(time.DateTime), fSIL(ev.GetExchange(), limit12), fSIL(ev.GetAssetType().String(), limit10), fSIL(ev.Pair().String(), limit14), @@ -183,7 +183,7 @@ func (s *Statistic) CreateLog(data common.Event) (string, error) { } case signal.Event: result = fmt.Sprintf("%v %v%v%v| Price: $%v", - ev.GetTime().Format(gctcommon.SimpleTimeFormat), + ev.GetTime().Format(time.DateTime), fSIL(ev.GetExchange(), limit12), fSIL(ev.GetAssetType().String(), limit10), fSIL(ev.Pair().String(), limit14), @@ -192,7 +192,7 @@ func (s *Statistic) CreateLog(data common.Event) (string, error) { result += common.CMDColours.Default case data2.Event: result = fmt.Sprintf("%v %v%v%v| Price: $%v", - ev.GetTime().Format(gctcommon.SimpleTimeFormat), + ev.GetTime().Format(time.DateTime), fSIL(ev.GetExchange(), limit12), fSIL(ev.GetAssetType().String(), limit10), fSIL(ev.Pair().String(), limit14), diff --git a/backtester/eventhandlers/strategies/rsi/rsi.go b/backtester/eventhandlers/strategies/rsi/rsi.go index 64e12d5d..4afc15d3 100644 --- a/backtester/eventhandlers/strategies/rsi/rsi.go +++ b/backtester/eventhandlers/strategies/rsi/rsi.go @@ -188,7 +188,7 @@ func (s *Strategy) massageMissingData(data []decimal.Decimal, t time.Time) ([]fl if missingDataStreak >= s.rsiPeriod.IntPart() { return nil, fmt.Errorf("missing data exceeds RSI period length of %v at %s and will distort results. %w", s.rsiPeriod, - t.Format(gctcommon.SimpleTimeFormat), + t.Format(time.DateTime), base.ErrTooMuchBadData) } resp[i] = data[i].InexactFloat64() diff --git a/backtester/eventhandlers/strategies/top2bottom2/top2bottom2.go b/backtester/eventhandlers/strategies/top2bottom2/top2bottom2.go index adb49e40..99a15f22 100644 --- a/backtester/eventhandlers/strategies/top2bottom2/top2bottom2.go +++ b/backtester/eventhandlers/strategies/top2bottom2/top2bottom2.go @@ -14,7 +14,6 @@ import ( "github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/base" "github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/signal" "github.com/thrasher-corp/gocryptotrader/backtester/funding" - gctcommon "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/exchanges/order" ) @@ -265,7 +264,7 @@ func (s *Strategy) massageMissingData(data []decimal.Decimal, t time.Time) ([]fl if missingDataStreak >= s.mfiPeriod.IntPart() { return nil, fmt.Errorf("missing data exceeds mfi period length of %v at %s and will distort results. %w", s.mfiPeriod, - t.Format(gctcommon.SimpleTimeFormat), + t.Format(time.DateTime), base.ErrTooMuchBadData) } resp[i] = data[i].InexactFloat64() diff --git a/cmd/gctcli/commands.go b/cmd/gctcli/commands.go index 5e8f18cf..e6863899 100644 --- a/cmd/gctcli/commands.go +++ b/cmd/gctcli/commands.go @@ -1097,13 +1097,13 @@ var getOrdersCommand = &cli.Command{ &cli.StringFlag{ Name: "start", Usage: "start date, optional. Will filter any results before this date", - Value: time.Now().AddDate(0, -1, 0).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(0, -1, 0).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Usage: "end date, optional. Will filter any results after this date", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, }, @@ -1162,11 +1162,11 @@ func getOrders(c *cli.Context) error { } } var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -2820,13 +2820,13 @@ var withdrawalRequestCommand = &cli.Command{ &cli.StringFlag{ Name: "start", Usage: "the start date to get withdrawals from. Any withdrawal before this date will be filtered", - Value: time.Now().AddDate(0, -1, 0).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(0, -1, 0).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Usage: "the end date to get withdrawals from. Any withdrawal after this date will be filtered", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, &cli.Int64Flag{ @@ -2991,11 +2991,11 @@ func withdrawlRequestByDate(c *cli.Context) error { limit = limitStr } - s, err := time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err := time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err := time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err := time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -3327,14 +3327,14 @@ var getAuditEventCommand = &cli.Command{ Name: "start", Aliases: []string{"s"}, Usage: "start date to search", - Value: time.Now().Add(-time.Hour).Format(common.SimpleTimeFormat), + Value: time.Now().Add(-time.Hour).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Aliases: []string{"e"}, Usage: "end time to search", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, &cli.StringFlag{ @@ -3382,12 +3382,12 @@ func getAuditEvent(c *cli.Context) error { } } - s, err := time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err := time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err := time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err := time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -4018,13 +4018,13 @@ var getHistoricCandlesExtendedCommand = &cli.Command{ &cli.StringFlag{ Name: "start", Usage: "the date to begin retrieveing candles. Any candles before this date will be filtered", - Value: time.Now().AddDate(0, -1, 0).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(0, -1, 0).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Usage: "the date to end retrieveing candles. Any candles after this date will be filtered", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, &cli.BoolFlag{ @@ -4133,11 +4133,11 @@ func getHistoricCandlesExtended(c *cli.Context) error { candleInterval := time.Duration(candleGranularity) * time.Second var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -4210,13 +4210,13 @@ var findMissingSavedCandleIntervalsCommand = &cli.Command{ &cli.StringFlag{ Name: "start", Usage: " rounded down to the nearest hour", - Value: time.Now().AddDate(0, -1, 0).Truncate(time.Hour).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(0, -1, 0).Truncate(time.Hour).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Usage: " rounded down to the nearest hour", - Value: time.Now().Truncate(time.Hour).Format(common.SimpleTimeFormat), + Value: time.Now().Truncate(time.Hour).Format(time.DateTime), Destination: &endTime, }, }, @@ -4282,11 +4282,11 @@ func findMissingSavedCandleIntervals(c *cli.Context) error { candleInterval := time.Duration(candleGranularity) * time.Second var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -4371,14 +4371,14 @@ var getMarginRatesHistoryCommand = &cli.Command{ Name: "start", Aliases: []string{"sd"}, Usage: "", - Value: time.Now().AddDate(0, -1, 0).Truncate(time.Hour).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(0, -1, 0).Truncate(time.Hour).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Aliases: []string{"ed"}, Usage: "", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, &cli.BoolFlag{ @@ -4503,11 +4503,11 @@ func getMarginRatesHistory(c *cli.Context) error { } var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } diff --git a/cmd/gctcli/data_history.go b/cmd/gctcli/data_history.go index c237370e..42be78b9 100644 --- a/cmd/gctcli/data_history.go +++ b/cmd/gctcli/data_history.go @@ -29,11 +29,11 @@ var dataHistoryCommands = &cli.Command{ Flags: []cli.Flag{ &cli.StringFlag{ Name: "start_date", - Usage: "formatted as: 2006-01-02 15:04:05", + Usage: "formatted as: " + time.DateTime, }, &cli.StringFlag{ Name: "end_date", - Usage: "formatted as: 2006-01-02 15:04:05", + Usage: "formatted as: " + time.DateTime, }, }, Action: getDataHistoryJobsBetween, @@ -221,14 +221,14 @@ var ( }, &cli.StringFlag{ Name: "start_date", - Usage: "formatted as: 2006-01-02 15:04:05", - Value: time.Now().AddDate(-1, 0, 0).Format(common.SimpleTimeFormat), + Usage: "formatted as: " + time.DateTime, + Value: time.Now().AddDate(-1, 0, 0).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end_date", - Usage: "formatted as: 2006-01-02 15:04:05", - Value: time.Now().AddDate(0, -1, 0).Format(common.SimpleTimeFormat), + Usage: "formatted as: " + time.DateTime, + Value: time.Now().AddDate(0, -1, 0).Format(time.DateTime), Destination: &endTime, }, &cli.Uint64Flag{ @@ -399,11 +399,11 @@ func upsertDataHistoryJob(c *cli.Context) error { } var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -544,11 +544,11 @@ func getDataHistoryJobsBetween(c *cli.Context) error { } else { endTime = c.Args().Get(1) } - s, err := time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err := time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err := time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err := time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } diff --git a/cmd/gctcli/futures.go b/cmd/gctcli/futures.go index 31e9aa5b..11a18679 100644 --- a/cmd/gctcli/futures.go +++ b/cmd/gctcli/futures.go @@ -122,14 +122,14 @@ var futuresCommands = &cli.Command{ Name: "start", Aliases: []string{"sd"}, Usage: " rounded down to the nearest hour, ensure your starting position is within this window for accurate calculations", - Value: time.Now().AddDate(-1, 0, 0).Truncate(time.Hour).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(-1, 0, 0).Truncate(time.Hour).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Aliases: []string{"ed"}, Usage: " rounded down to the nearest hour, ensure your last position is within this window for accurate calculations", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, &cli.IntFlag{ @@ -237,14 +237,14 @@ var futuresCommands = &cli.Command{ Name: "start", Aliases: []string{"sd"}, Usage: " rounded down to the nearest hour, ensure your starting position is within this window for accurate calculations", - Value: time.Now().AddDate(-1, 0, 0).Truncate(time.Hour).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(-1, 0, 0).Truncate(time.Hour).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Aliases: []string{"ed"}, Usage: " rounded down to the nearest hour, ensure your last position is within this window for accurate calculations", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, &cli.BoolFlag{ @@ -583,11 +583,11 @@ func getFuturesPositions(c *cli.Context) error { return err } - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -774,11 +774,11 @@ func getFundingRates(c *cli.Context) error { return err } } - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } diff --git a/cmd/gctcli/technical_analysis.go b/cmd/gctcli/technical_analysis.go index 1d1b7753..2c765587 100644 --- a/cmd/gctcli/technical_analysis.go +++ b/cmd/gctcli/technical_analysis.go @@ -49,13 +49,13 @@ var commonFlag = []cli.Flag{ &cli.StringFlag{ Name: "start", Usage: "the start date", - Value: time.Now().AddDate(0, -1, 0).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(0, -1, 0).Format(time.DateTime), Destination: &taStartTime, }, &cli.StringFlag{ Name: "end", Usage: "the end date", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &taEndTime, }, } @@ -296,11 +296,11 @@ func getTecnicalAnalysis(c *cli.Context, algo string) error { taEndTime, _ = c.Value("end").(string) } - s, err := time.ParseInLocation(common.SimpleTimeFormat, taStartTime, time.Local) + s, err := time.ParseInLocation(time.DateTime, taStartTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err := time.ParseInLocation(common.SimpleTimeFormat, taEndTime, time.Local) + e, err := time.ParseInLocation(time.DateTime, taEndTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -411,11 +411,11 @@ func getBollingerBands(c *cli.Context) error { taEndTime, _ = c.Value("end").(string) } - s, err := time.ParseInLocation(common.SimpleTimeFormat, taStartTime, time.Local) + s, err := time.ParseInLocation(time.DateTime, taStartTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err := time.ParseInLocation(common.SimpleTimeFormat, taEndTime, time.Local) + e, err := time.ParseInLocation(time.DateTime, taEndTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -567,11 +567,11 @@ func getMACD(c *cli.Context) error { taEndTime, _ = c.Value("end").(string) } - s, err := time.ParseInLocation(common.SimpleTimeFormat, taStartTime, time.Local) + s, err := time.ParseInLocation(time.DateTime, taStartTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err := time.ParseInLocation(common.SimpleTimeFormat, taEndTime, time.Local) + e, err := time.ParseInLocation(time.DateTime, taEndTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -707,11 +707,11 @@ func getCoco(c *cli.Context) error { taEndTime, _ = c.Value("end").(string) } - s, err := time.ParseInLocation(common.SimpleTimeFormat, taStartTime, time.Local) + s, err := time.ParseInLocation(time.DateTime, taStartTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err := time.ParseInLocation(common.SimpleTimeFormat, taEndTime, time.Local) + e, err := time.ParseInLocation(time.DateTime, taEndTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } diff --git a/cmd/gctcli/trades.go b/cmd/gctcli/trades.go index 3d00b626..64f5f006 100644 --- a/cmd/gctcli/trades.go +++ b/cmd/gctcli/trades.go @@ -81,13 +81,13 @@ var tradeCommand = &cli.Command{ &cli.StringFlag{ Name: "start", Usage: "", - Value: time.Now().Add(-time.Hour * 6).Format(common.SimpleTimeFormat), + Value: time.Now().Add(-time.Hour * 6).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Usage: " WARNING: large date ranges may take considerable time", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, }, @@ -116,13 +116,13 @@ var tradeCommand = &cli.Command{ &cli.StringFlag{ Name: "start", Usage: "", - Value: time.Now().AddDate(0, -1, 0).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(0, -1, 0).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Usage: "", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, }, @@ -151,13 +151,13 @@ var tradeCommand = &cli.Command{ &cli.StringFlag{ Name: "start", Usage: " rounded down to the nearest hour", - Value: time.Now().Add(-time.Hour * 24).Truncate(time.Hour).Format(common.SimpleTimeFormat), + Value: time.Now().Add(-time.Hour * 24).Truncate(time.Hour).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Usage: " rounded down to the nearest hour", - Value: time.Now().Truncate(time.Hour).Format(common.SimpleTimeFormat), + Value: time.Now().Truncate(time.Hour).Format(time.DateTime), Destination: &endTime, }, }, @@ -193,13 +193,13 @@ var tradeCommand = &cli.Command{ &cli.StringFlag{ Name: "start", Usage: "", - Value: time.Now().AddDate(0, -1, 0).Format(common.SimpleTimeFormat), + Value: time.Now().AddDate(0, -1, 0).Format(time.DateTime), Destination: &startTime, }, &cli.StringFlag{ Name: "end", Usage: "", - Value: time.Now().Format(common.SimpleTimeFormat), + Value: time.Now().Format(time.DateTime), Destination: &endTime, }, &cli.BoolFlag{ @@ -267,11 +267,11 @@ func findMissingSavedTradeIntervals(c *cli.Context) error { } var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -396,11 +396,11 @@ func getSavedTrades(c *cli.Context) error { } var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -547,11 +547,11 @@ func getHistoricTrades(c *cli.Context) error { } } var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } @@ -685,11 +685,11 @@ func convertSavedTradesToCandles(c *cli.Context) error { candleInterval := time.Duration(candleGranularity) * time.Second var s, e time.Time - s, err = time.ParseInLocation(common.SimpleTimeFormat, startTime, time.Local) + s, err = time.ParseInLocation(time.DateTime, startTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for start: %v", err) } - e, err = time.ParseInLocation(common.SimpleTimeFormat, endTime, time.Local) + e, err = time.ParseInLocation(time.DateTime, endTime, time.Local) if err != nil { return fmt.Errorf("invalid time format for end: %v", err) } diff --git a/common/common.go b/common/common.go index 8014b5fc..bafc8dc2 100644 --- a/common/common.go +++ b/common/common.go @@ -26,10 +26,8 @@ import ( ) const ( - // SimpleTimeFormat a common, but non-implemented time format in golang - SimpleTimeFormat = "2006-01-02 15:04:05" // SimpleTimeFormatWithTimezone a common, but non-implemented time format in golang - SimpleTimeFormatWithTimezone = "2006-01-02 15:04:05 MST" + SimpleTimeFormatWithTimezone = time.DateTime + " MST" // GctExt is the extension for GCT Tengo script files GctExt = ".gct" defaultTimeout = time.Second * 15 diff --git a/engine/datahistory_manager.go b/engine/datahistory_manager.go index db7d87f4..0e5e8ca9 100644 --- a/engine/datahistory_manager.go +++ b/engine/datahistory_manager.go @@ -1015,7 +1015,7 @@ func (m *DataHistoryManager) validateCandles(job *DataHistoryJob, exch exchange. apiCandles.Candles[i] = can if len(candleIssues) > 0 { - candleIssues = append([]string{fmt.Sprintf("issues found at %v", can.Time.Format(common.SimpleTimeFormat))}, candleIssues...) + candleIssues = append([]string{fmt.Sprintf("issues found at %v", can.Time.Format(time.DateTime))}, candleIssues...) validationIssues = append(validationIssues, candleIssues...) r.Status = dataHistoryStatusFailed apiCandles.Candles[i].ValidationIssues = strings.Join(candleIssues, ", ") diff --git a/engine/rpcserver.go b/engine/rpcserver.go index 65103ffa..d1a25fdf 100644 --- a/engine/rpcserver.go +++ b/engine/rpcserver.go @@ -3921,11 +3921,11 @@ func (s *RPCServer) GetDataHistoryJobDetails(_ context.Context, r *gctrpc.GetDat for _, v := range result.Results { for i := range v { jobResults = append(jobResults, &gctrpc.DataHistoryJobResult{ - StartDate: v[i].IntervalStartDate.Format(common.SimpleTimeFormat), - EndDate: v[i].IntervalEndDate.Format(common.SimpleTimeFormat), + StartDate: v[i].IntervalStartDate.Format(time.DateTime), + EndDate: v[i].IntervalEndDate.Format(time.DateTime), HasData: v[i].Status == dataHistoryStatusComplete, Message: v[i].Result, - RunDate: v[i].Date.Format(common.SimpleTimeFormat), + RunDate: v[i].Date.Format(time.DateTime), }) } } @@ -3941,8 +3941,8 @@ func (s *RPCServer) GetDataHistoryJobDetails(_ context.Context, r *gctrpc.GetDat Base: result.Pair.Base.String(), Quote: result.Pair.Quote.String(), }, - StartDate: result.StartDate.Format(common.SimpleTimeFormat), - EndDate: result.EndDate.Format(common.SimpleTimeFormat), + StartDate: result.StartDate.Format(time.DateTime), + EndDate: result.EndDate.Format(time.DateTime), Interval: int64(result.Interval.Duration()), RequestSizeLimit: result.RequestSizeLimit, MaxRetryAttempts: result.MaxRetryAttempts, @@ -3979,8 +3979,8 @@ func (s *RPCServer) GetActiveDataHistoryJobs(_ context.Context, _ *gctrpc.GetInf Base: jobs[i].Pair.Base.String(), Quote: jobs[i].Pair.Quote.String(), }, - StartDate: jobs[i].StartDate.Format(common.SimpleTimeFormat), - EndDate: jobs[i].EndDate.Format(common.SimpleTimeFormat), + StartDate: jobs[i].StartDate.Format(time.DateTime), + EndDate: jobs[i].EndDate.Format(time.DateTime), Interval: int64(jobs[i].Interval.Duration()), RequestSizeLimit: jobs[i].RequestSizeLimit, MaxRetryAttempts: jobs[i].MaxRetryAttempts, @@ -4033,8 +4033,8 @@ func (s *RPCServer) GetDataHistoryJobsBetween(_ context.Context, r *gctrpc.GetDa Base: jobs[i].Pair.Base.String(), Quote: jobs[i].Pair.Quote.String(), }, - StartDate: jobs[i].StartDate.Format(common.SimpleTimeFormat), - EndDate: jobs[i].EndDate.Format(common.SimpleTimeFormat), + StartDate: jobs[i].StartDate.Format(time.DateTime), + EndDate: jobs[i].EndDate.Format(time.DateTime), Interval: int64(jobs[i].Interval.Duration()), RequestSizeLimit: jobs[i].RequestSizeLimit, MaxRetryAttempts: jobs[i].MaxRetryAttempts, @@ -4076,8 +4076,8 @@ func (s *RPCServer) GetDataHistoryJobSummary(_ context.Context, r *gctrpc.GetDat Base: job.Pair.Base.String(), Quote: job.Pair.Quote.String(), }, - StartDate: job.StartDate.Format(common.SimpleTimeFormat), - EndDate: job.EndDate.Format(common.SimpleTimeFormat), + StartDate: job.StartDate.Format(time.DateTime), + EndDate: job.EndDate.Format(time.DateTime), Interval: int64(job.Interval.Duration()), Status: job.Status.String(), DataType: job.DataType.String(), diff --git a/exchanges/binance/binance.go b/exchanges/binance/binance.go index 13d46e25..282e129b 100644 --- a/exchanges/binance/binance.go +++ b/exchanges/binance/binance.go @@ -73,8 +73,7 @@ const ( withdrawHistory = "/sapi/v1/capital/withdraw/history" depositAddress = "/sapi/v1/capital/deposit/address" - defaultRecvWindow = 5 * time.Second - binanceSAPITimeLayout = "2006-01-02 15:04:05" + defaultRecvWindow = 5 * time.Second ) // GetInterestHistory gets interest history for currency/currencies provided diff --git a/exchanges/binance/binance_test.go b/exchanges/binance/binance_test.go index 571e3f27..ba08ad97 100644 --- a/exchanges/binance/binance_test.go +++ b/exchanges/binance/binance_test.go @@ -115,23 +115,6 @@ func TestWrapperGetServerTime(t *testing.T) { } } -func TestParseSAPITime(t *testing.T) { - t.Parallel() - tm, err := time.Parse(binanceSAPITimeLayout, "2021-05-27 03:56:46") - if err != nil { - t.Fatal(tm) - } - tm = tm.UTC() - if tm.Year() != 2021 || - tm.Month() != 5 || - tm.Day() != 27 || - tm.Hour() != 3 || - tm.Minute() != 56 || - tm.Second() != 46 { - t.Fatal("incorrect values") - } -} - func TestUpdateTicker(t *testing.T) { t.Parallel() r, err := b.UpdateTicker(context.Background(), testPairMapping, asset.Spot) diff --git a/exchanges/binanceus/binanceus.go b/exchanges/binanceus/binanceus.go index 099e7342..88ca338d 100644 --- a/exchanges/binanceus/binanceus.go +++ b/exchanges/binanceus/binanceus.go @@ -107,8 +107,7 @@ const ( userAccountStream = "/api/v3/userDataStream" // Other Consts - defaultRecvWindow = 5 * time.Second - binanceUSAPITimeLayout = "2006-01-02 15:04:05" + defaultRecvWindow = 5 * time.Second // recvWindowSize5000 recvWindowSize5000 = 5000 diff --git a/exchanges/binanceus/binanceus_wrapper.go b/exchanges/binanceus/binanceus_wrapper.go index 36c87cca..db877765 100644 --- a/exchanges/binanceus/binanceus_wrapper.go +++ b/exchanges/binanceus/binanceus_wrapper.go @@ -502,7 +502,7 @@ func (bi *Binanceus) GetWithdrawalsHistory(ctx context.Context, c currency.Code, } resp := make([]exchange.WithdrawalHistory, len(withdrawals)) for i := range withdrawals { - tm, err := time.Parse(binanceUSAPITimeLayout, withdrawals[i].ApplyTime) + tm, err := time.Parse(time.DateTime, withdrawals[i].ApplyTime) if err != nil { return nil, err } diff --git a/exchanges/bithumb/bithumb.go b/exchanges/bithumb/bithumb.go index ec8d3654..b5cdd4f2 100644 --- a/exchanges/bithumb/bithumb.go +++ b/exchanges/bithumb/bithumb.go @@ -355,7 +355,7 @@ func (b *Bithumb) GetOrders(ctx context.Context, orderID, transactionType string } if !after.IsZero() { - params.Set("after", after.Format(common.SimpleTimeFormat)) + params.Set("after", after.Format(time.DateTime)) } return response, diff --git a/exchanges/bithumb/bithumb_websocket.go b/exchanges/bithumb/bithumb_websocket.go index 0d7b4406..2a1243cd 100644 --- a/exchanges/bithumb/bithumb_websocket.go +++ b/exchanges/bithumb/bithumb_websocket.go @@ -17,7 +17,7 @@ import ( const ( wsEndpoint = "wss://pubwss.bithumb.com/pub/ws" tickerTimeLayout = "20060102150405" - tradeTimeLayout = "2006-01-02 15:04:05.000000" + tradeTimeLayout = time.DateTime + ".000000" ) var ( diff --git a/exchanges/bithumb/bithumb_wrapper.go b/exchanges/bithumb/bithumb_wrapper.go index ed707e4d..83e160f2 100644 --- a/exchanges/bithumb/bithumb_wrapper.go +++ b/exchanges/bithumb/bithumb_wrapper.go @@ -478,7 +478,7 @@ func (b *Bithumb) GetRecentTrades(ctx context.Context, p currency.Pair, assetTyp return nil, err } var t time.Time - t, err = time.Parse(common.SimpleTimeFormat, tradeData.Data[i].TransactionDate) + t, err = time.Parse(time.DateTime, tradeData.Data[i].TransactionDate) if err != nil { return nil, err } diff --git a/exchanges/bitstamp/bitstamp_wrapper.go b/exchanges/bitstamp/bitstamp_wrapper.go index 298bb552..1e3f1a48 100644 --- a/exchanges/bitstamp/bitstamp_wrapper.go +++ b/exchanges/bitstamp/bitstamp_wrapper.go @@ -643,7 +643,7 @@ func (b *Bitstamp) GetOrderInfo(ctx context.Context, orderID string, _ currency. Amount: o.Transactions[i].BTC, } } - orderDate, err := time.Parse(common.SimpleTimeFormat, o.DateTime) + orderDate, err := time.Parse(time.DateTime, o.DateTime) if err != nil { return nil, err } diff --git a/exchanges/btse/btse.go b/exchanges/btse/btse.go index 61c8673d..3d06ec4b 100644 --- a/exchanges/btse/btse.go +++ b/exchanges/btse/btse.go @@ -613,5 +613,5 @@ func (b *BTSE) calculateTradingFee(ctx context.Context, feeBuilder *exchange.Fee } func parseOrderTime(timeStr string) (time.Time, error) { - return time.Parse(common.SimpleTimeFormat, timeStr) + return time.Parse(time.DateTime, timeStr) } diff --git a/exchanges/kline/kline.go b/exchanges/kline/kline.go index 60db39cc..5a816e7e 100644 --- a/exchanges/kline/kline.go +++ b/exchanges/kline/kline.go @@ -580,8 +580,8 @@ func (h *IntervalRangeHolder) createDateSummaryRange(start, end time.Time, hasDa return fmt.Sprintf("%s data between %s and %s", dataString, - start.Format(common.SimpleTimeFormat), - end.Format(common.SimpleTimeFormat)) + start.Format(time.DateTime), + end.Format(time.DateTime)) } // CreateIntervalTime is a simple helper function to set the time twice diff --git a/exchanges/poloniex/poloniex_websocket.go b/exchanges/poloniex/poloniex_websocket.go index 2063c1c9..7fb0660a 100644 --- a/exchanges/poloniex/poloniex_websocket.go +++ b/exchanges/poloniex/poloniex_websocket.go @@ -892,7 +892,7 @@ func (p *Poloniex) processAccountOrderLimit(notification []interface{}) error { } var timeParse time.Time - timeParse, err = time.Parse(common.SimpleTimeFormat, ts) + timeParse, err = time.Parse(time.DateTime, ts) if err != nil { return err } @@ -1030,7 +1030,7 @@ func (p *Poloniex) processAccountTrades(notification []interface{}) error { if !ok { return fmt.Errorf("%w time not string", errTypeAssertionFailure) } - timeParse, err := time.Parse(common.SimpleTimeFormat, t) + timeParse, err := time.Parse(time.DateTime, t) if err != nil { return err } diff --git a/exchanges/poloniex/poloniex_wrapper.go b/exchanges/poloniex/poloniex_wrapper.go index abf4e925..3dfcff4a 100644 --- a/exchanges/poloniex/poloniex_wrapper.go +++ b/exchanges/poloniex/poloniex_wrapper.go @@ -572,7 +572,7 @@ allTrades: } for i := range tradeData { var tt time.Time - tt, err = time.Parse(common.SimpleTimeFormat, tradeData[i].Date) + tt, err = time.Parse(time.DateTime, tradeData[i].Date) if err != nil { return nil, err } @@ -765,7 +765,7 @@ func (p *Poloniex) GetOrderInfo(ctx context.Context, orderID string, pair curren return nil, err } tradeHistory.TID = trades[i].GlobalTradeID - tradeHistory.Timestamp, err = time.Parse(common.SimpleTimeFormat, trades[i].Date) + tradeHistory.Timestamp, err = time.Parse(time.DateTime, trades[i].Date) if err != nil { return nil, err } @@ -801,7 +801,7 @@ func (p *Poloniex) GetOrderInfo(ctx context.Context, orderID string, pair curren return nil, err } - orderInfo.Date, err = time.Parse(common.SimpleTimeFormat, resp.Date) + orderInfo.Date, err = time.Parse(time.DateTime, resp.Date) if err != nil { return nil, err } @@ -953,7 +953,7 @@ func (p *Poloniex) GetActiveOrders(ctx context.Context, req *order.MultiOrderReq return nil, err } var orderDate time.Time - orderDate, err = time.Parse(common.SimpleTimeFormat, resp.Data[key][i].Date) + orderDate, err = time.Parse(time.DateTime, resp.Data[key][i].Date) if err != nil { log.Errorf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v", @@ -1011,7 +1011,7 @@ func (p *Poloniex) GetOrderHistory(ctx context.Context, req *order.MultiOrderReq if err != nil { return nil, err } - orderDate, err := time.Parse(common.SimpleTimeFormat, + orderDate, err := time.Parse(time.DateTime, resp.Data[key][i].Date) if err != nil { log.Errorf(log.ExchangeSys,