order: slight optimizations (#917)

* order: slight optimizations

* orders: add benchmarks, small optimize and change order side to uin8 for comparitive optimizations.

* orders: continue to convert string type -> uint

* orders/backtester: interim move type to orders package, later can expand or deprecate.

* orders: handle errors

* orders: optimize filters and remove error returns when its clearly not needed

* orders: remove log call

* backtester: zero value check

* orders/futures: zero value -> flag

* linter: fix

* linter: more fixes

* linters: rides again

* glorious: nits

* common: Add zero value unix check for time values; also addresses glorious nits

* glorious scott: nits

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2022-05-06 12:27:21 +10:00
committed by GitHub
parent d735effc8e
commit cdcc9630de
60 changed files with 1375 additions and 802 deletions

View File

@@ -57,6 +57,7 @@ var (
errUserAgentInvalid = errors.New("cannot set invalid user agent")
errHTTPClientInvalid = errors.New("custom http client cannot be nil")
zeroValueUnix = time.Unix(0, 0)
// ErrTypeAssertFailure defines an error when type assertion fails
ErrTypeAssertFailure = errors.New("type assert failure")
)
@@ -429,10 +430,10 @@ func (e Errors) Unwrap() error {
// StartEndTimeCheck provides some basic checks which occur
// frequently in the codebase
func StartEndTimeCheck(start, end time.Time) error {
if start.IsZero() {
if start.IsZero() || start.Equal(zeroValueUnix) {
return fmt.Errorf("start %w", ErrDateUnset)
}
if end.IsZero() {
if end.IsZero() || end.Equal(zeroValueUnix) {
return fmt.Errorf("end %w", ErrDateUnset)
}
if start.After(time.Now()) {

View File

@@ -655,6 +655,16 @@ func TestParseStartEndDate(t *testing.T) {
t.Errorf("received %v, expected %v", err, ErrDateUnset)
}
err = StartEndTimeCheck(et, zeroValueUnix)
if !errors.Is(err, ErrDateUnset) {
t.Errorf("received %v, expected %v", err, ErrDateUnset)
}
err = StartEndTimeCheck(zeroValueUnix, et)
if !errors.Is(err, ErrDateUnset) {
t.Errorf("received %v, expected %v", err, ErrDateUnset)
}
err = StartEndTimeCheck(et, et)
if !errors.Is(err, ErrStartEqualsEnd) {
t.Errorf("received %v, expected %v", err, ErrStartEqualsEnd)