Add OHLC retrieval func (GetHistoricCandles) to all exchanges and expose it as a wrapper func (#414)

* initial wiring to providegethistoricalcandles

* initial wiring to providegethistoricalcandles

* initial wiring to providegethistoricalcandles

* gethistriccandles work from cli using hard coded inputs

* gethistoriccandles RPC service and CLI working fine for coinbasepro

* fixed unit test

* input check on grpc for gethistoriccandles

* updated deps

* fixed the return value when a method is not yet implemented

* code review: fixed CLI input check and int32->int64

* code review: handling wrong exchange name

* added check on granularity and allowing start and end being empty

* code review: removed currency2

* code review: dependency reverted

* improved func comment

* typo in func comment

* get historic values tests

* unit tests for get historical rates on coinbasepro

* using time format time.RFC3339

* names to camel case and improved comments

* test cleanup

* changed to camel case

* added InArray tests

* dropped not needed string time

* enforced use of int64

* fixed make check

* cleaned up code organisation to be consistent

* fixed Travis remarks

* more Travis remarks

* added comments

* regenerated proto files after merge

* linter fix
This commit is contained in:
Christian Achilli
2020-01-24 05:10:33 +00:00
committed by Adrian Gallagher
parent e5b64a5580
commit 5ac5ec8fc1
42 changed files with 1230 additions and 357 deletions

View File

@@ -12,6 +12,7 @@ import (
"os"
"os/user"
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
@@ -354,3 +355,24 @@ func SplitStringSliceByLimit(in []string, limit uint) [][]string {
}
return sliceSlice
}
// InArray checks if _val_ belongs to _array_
func InArray(val, array interface{}) (exists bool, index int) {
exists = false
index = -1
if array == nil {
return
}
switch reflect.TypeOf(array).Kind() {
case reflect.Array, reflect.Slice:
s := reflect.ValueOf(array)
for i := 0; i < s.Len(); i++ {
if reflect.DeepEqual(val, s.Index(i).Interface()) {
index = i
exists = true
return
}
}
}
return
}

View File

@@ -526,3 +526,41 @@ func TestSplitStringSliceByLimit(t *testing.T) {
t.Errorf("expected len() to be 20 instead received: %v", len(out[0]))
}
}
func TestInArray(t *testing.T) {
InArray(nil, nil)
array := [6]int{2, 3, 5, 7, 11, 13}
isIn, pos := InArray(5, array)
if !isIn {
t.Errorf("failed to find the value within the array")
}
if pos != 2 {
t.Errorf("failed return the correct position of the value in the array")
}
isIn, _ = InArray(1, array)
if isIn {
t.Errorf("found a non existent value in the array")
}
slice := make([]int, 0)
slice = append(append(slice, 5), 3)
isIn, pos = InArray(5, slice)
if !isIn {
t.Errorf("failed to find the value within the slice")
}
if pos != 0 {
t.Errorf("failed return the correct position of the value in the slice")
}
isIn, pos = InArray(3, slice)
if !isIn {
t.Errorf("failed to find the value within the slice")
}
if pos != 1 {
t.Errorf("failed return the correct position of the value in the slice")
}
isIn, _ = InArray(1, slice)
if isIn {
t.Errorf("found a non existent value in the slice")
}
}