mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Split common package more and QA
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
@@ -42,7 +43,7 @@ func main() {
|
||||
key = string(result)
|
||||
}
|
||||
|
||||
file, err := common.ReadFile(inFile)
|
||||
file, err := ioutil.ReadFile(inFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to read input file %s. Error: %s.", inFile, err)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
@@ -59,7 +60,7 @@ func writeFile(file string, data []byte) error {
|
||||
|
||||
func main() {
|
||||
genKeys := false
|
||||
privKeyData, err := common.ReadFile("privatekey.pem")
|
||||
privKeyData, err := ioutil.ReadFile("privatekey.pem")
|
||||
if err != nil {
|
||||
genKeys = true
|
||||
}
|
||||
@@ -100,7 +101,7 @@ func main() {
|
||||
|
||||
} else {
|
||||
var pubKeyData []byte
|
||||
pubKeyData, err = common.ReadFile("publickey.pem")
|
||||
pubKeyData, err = ioutil.ReadFile("publickey.pem")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ const (
|
||||
)
|
||||
|
||||
// GetV4UUID returns a RFC 4122 UUID based on random numbers
|
||||
func GetV4UUID() uuid.UUID {
|
||||
func GetV4UUID() (uuid.UUID, error) {
|
||||
return uuid.NewV4()
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ func ExtractPort(host string) int {
|
||||
|
||||
// OutputCSV dumps data into a file as comma-separated values
|
||||
func OutputCSV(filePath string, data [][]string) error {
|
||||
_, err := ReadFile(filePath)
|
||||
_, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
errTwo := WriteFile(filePath, nil)
|
||||
if errTwo != nil {
|
||||
@@ -289,37 +289,10 @@ func OutputCSV(filePath string, data [][]string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
writer := csv.NewWriter(file)
|
||||
|
||||
err = writer.WriteAll(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
writer.Flush()
|
||||
file.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnixTimestampToTime returns time.time
|
||||
func UnixTimestampToTime(timeint64 int64) time.Time {
|
||||
return time.Unix(timeint64, 0)
|
||||
}
|
||||
|
||||
// UnixTimestampStrToTime returns a time.time and an error
|
||||
func UnixTimestampStrToTime(timeStr string) (time.Time, error) {
|
||||
i, err := strconv.ParseInt(timeStr, 10, 64)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
|
||||
return time.Unix(i, 0), nil
|
||||
}
|
||||
|
||||
// ReadFile reads a file and returns read data as byte array.
|
||||
func ReadFile(file string) ([]byte, error) {
|
||||
return ioutil.ReadFile(file)
|
||||
return writer.WriteAll(data)
|
||||
}
|
||||
|
||||
// WriteFile writes selected data to a file and returns an error
|
||||
@@ -327,11 +300,6 @@ func WriteFile(file string, data []byte) error {
|
||||
return ioutil.WriteFile(file, data, 0644)
|
||||
}
|
||||
|
||||
// RemoveFile removes a file
|
||||
func RemoveFile(file string) error {
|
||||
return os.Remove(file)
|
||||
}
|
||||
|
||||
// GetURIPath returns the path of a URL given a URI
|
||||
func GetURIPath(uri string) string {
|
||||
urip, err := url.Parse(uri)
|
||||
@@ -353,16 +321,6 @@ func GetExecutablePath() (string, error) {
|
||||
return filepath.Dir(ex), nil
|
||||
}
|
||||
|
||||
// UnixMillis converts a UnixNano timestamp to milliseconds
|
||||
func UnixMillis(t time.Time) int64 {
|
||||
return t.UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
// RecvWindow converts a supplied time.Duration to milliseconds
|
||||
func RecvWindow(d time.Duration) int64 {
|
||||
return int64(d) / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
// GetDefaultDataDir returns the default data directory
|
||||
// Windows - C:\Users\%USER%\AppData\Roaming\GoCryptoTrader
|
||||
// Linux/Unix or OSX - $HOME/.gocryptotrader
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIsEnabled(t *testing.T) {
|
||||
@@ -29,7 +28,6 @@ func TestIsEnabled(t *testing.T) {
|
||||
|
||||
func TestIsValidCryptoAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
b, err := IsValidCryptoAddress("1Mz7153HMuxXTuR2R1t78mGSdzaAtNbBWX", "bTC")
|
||||
if err != nil && !b {
|
||||
t.Errorf("Test Failed - Common IsValidCryptoAddress error: %s", err)
|
||||
@@ -229,6 +227,7 @@ func TestSendHTTPRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSendHTTPGetRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
type test struct {
|
||||
Address string `json:"address"`
|
||||
ETH struct {
|
||||
@@ -265,6 +264,7 @@ func TestSendHTTPGetRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJSONEncode(t *testing.T) {
|
||||
t.Parallel()
|
||||
type test struct {
|
||||
Status int `json:"status"`
|
||||
Data []struct {
|
||||
@@ -320,6 +320,7 @@ func TestJSONDecode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEncodeURLValues(t *testing.T) {
|
||||
t.Parallel()
|
||||
urlstring := "https://www.test.com"
|
||||
expectedOutput := `https://www.test.com?env=TEST%2FDATABASE&format=json`
|
||||
values := url.Values{}
|
||||
@@ -385,84 +386,6 @@ func TestOutputCSV(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnixTimestampToTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTime := int64(1489439831)
|
||||
tm := time.Unix(testTime, 0)
|
||||
expectedOutput := "2017-03-13 21:17:11 +0000 UTC"
|
||||
actualResult := UnixTimestampToTime(testTime)
|
||||
if tm.String() != actualResult.String() {
|
||||
t.Errorf(
|
||||
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnixTimestampStrToTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTime := "1489439831"
|
||||
incorrectTime := "DINGDONG"
|
||||
expectedOutput := "2017-03-13 21:17:11 +0000 UTC"
|
||||
actualResult, err := UnixTimestampStrToTime(testTime)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if actualResult.UTC().String() != expectedOutput {
|
||||
t.Errorf(
|
||||
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
|
||||
}
|
||||
actualResult, err = UnixTimestampStrToTime(incorrectTime)
|
||||
if err == nil {
|
||||
t.Error("Test failed. Common UnixTimestampStrToTime error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadFile(t *testing.T) {
|
||||
pathCorrect := "../testdata/dump"
|
||||
pathIncorrect := "testdata/dump"
|
||||
|
||||
_, err := ReadFile(pathCorrect)
|
||||
if err != nil {
|
||||
t.Errorf("Test failed - Common ReadFile error: %s", err)
|
||||
}
|
||||
_, err = ReadFile(pathIncorrect)
|
||||
if err == nil {
|
||||
t.Errorf("Test failed - Common ReadFile error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteFile(t *testing.T) {
|
||||
path := "../testdata/writefiletest"
|
||||
err := WriteFile(path, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. Common WriteFile error: %s", err)
|
||||
}
|
||||
_, err = ReadFile(path)
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. Common WriteFile error: %s", err)
|
||||
}
|
||||
|
||||
err = WriteFile("", nil)
|
||||
if err == nil {
|
||||
t.Error("Test failed. Common WriteFile allowed bad path")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveFile(t *testing.T) {
|
||||
TestWriteFile(t)
|
||||
path := "../testdata/writefiletest"
|
||||
err := RemoveFile(path)
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. Common RemoveFile error: %s", err)
|
||||
}
|
||||
|
||||
TestOutputCSV(t)
|
||||
path = "../testdata/dump"
|
||||
err = RemoveFile(path)
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. Common RemoveFile error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetURIPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
// mapping of input vs expected result
|
||||
@@ -488,30 +411,6 @@ func TestGetExecutablePath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnixMillis(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTime := time.Date(2014, time.October, 28, 0, 32, 0, 0, time.UTC)
|
||||
expectedOutput := int64(1414456320000)
|
||||
|
||||
actualOutput := UnixMillis(testTime)
|
||||
if actualOutput != expectedOutput {
|
||||
t.Errorf("Test failed. Common UnixMillis. Expected '%d'. Actual '%d'.",
|
||||
expectedOutput, actualOutput)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecvWindow(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTime := time.Duration(24760000)
|
||||
expectedOutput := int64(24)
|
||||
|
||||
actualOutput := RecvWindow(testTime)
|
||||
if actualOutput != expectedOutput {
|
||||
t.Errorf("Test failed. Common RecvWindow. Expected '%d'. Actual '%d'",
|
||||
expectedOutput, actualOutput)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDefaultDataDir(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
@@ -625,9 +524,9 @@ func TestChangePerm(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("os.Stat failed. Err: %v", err)
|
||||
}
|
||||
err = RemoveFile(testDir)
|
||||
err = os.Remove(testDir)
|
||||
if err != nil {
|
||||
t.Fatalf("RemoveFile failed. Err: %v", err)
|
||||
t.Fatalf("os.Remove failed. Err: %v", err)
|
||||
}
|
||||
default:
|
||||
err := ChangePerm("")
|
||||
@@ -650,9 +549,9 @@ func TestChangePerm(t *testing.T) {
|
||||
if a.Mode().Perm() != 0770 {
|
||||
t.Fatalf("expected file permissions differ. expecting 0770 got %#o", a.Mode().Perm())
|
||||
}
|
||||
err = RemoveFile(testDir)
|
||||
err = os.Remove(testDir)
|
||||
if err != nil {
|
||||
t.Fatalf("RemoveFile failed. Err: %v", err)
|
||||
t.Fatalf("os.Remove failed. Err: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,3 +53,27 @@ func TimeFromUnixTimestampFloat(raw interface{}) (time.Time, error) {
|
||||
}
|
||||
return time.Unix(0, int64(ts)*int64(time.Millisecond)), nil
|
||||
}
|
||||
|
||||
// UnixTimestampToTime returns time.time
|
||||
func UnixTimestampToTime(timeint64 int64) time.Time {
|
||||
return time.Unix(timeint64, 0)
|
||||
}
|
||||
|
||||
// UnixTimestampStrToTime returns a time.time and an error
|
||||
func UnixTimestampStrToTime(timeStr string) (time.Time, error) {
|
||||
i, err := strconv.ParseInt(timeStr, 10, 64)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return time.Unix(i, 0), nil
|
||||
}
|
||||
|
||||
// UnixMillis converts a UnixNano timestamp to milliseconds
|
||||
func UnixMillis(t time.Time) int64 {
|
||||
return t.UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
// RecvWindow converts a supplied time.Duration to milliseconds
|
||||
func RecvWindow(d time.Duration) int64 {
|
||||
return int64(d) / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
@@ -94,3 +94,58 @@ func TestTimeFromUnixTimestampFloat(t *testing.T) {
|
||||
t.Error("Test failed. Common TimeFromUnixTimestampFloat. Converted invalid syntax.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnixTimestampToTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTime := int64(1489439831)
|
||||
tm := time.Unix(testTime, 0)
|
||||
expectedOutput := "2017-03-13 21:17:11 +0000 UTC"
|
||||
actualResult := UnixTimestampToTime(testTime)
|
||||
if tm.String() != actualResult.String() {
|
||||
t.Errorf(
|
||||
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnixTimestampStrToTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTime := "1489439831"
|
||||
incorrectTime := "DINGDONG"
|
||||
expectedOutput := "2017-03-13 21:17:11 +0000 UTC"
|
||||
actualResult, err := UnixTimestampStrToTime(testTime)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if actualResult.UTC().String() != expectedOutput {
|
||||
t.Errorf(
|
||||
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
|
||||
}
|
||||
actualResult, err = UnixTimestampStrToTime(incorrectTime)
|
||||
if err == nil {
|
||||
t.Error("Test failed. Common UnixTimestampStrToTime error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnixMillis(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTime := time.Date(2014, time.October, 28, 0, 32, 0, 0, time.UTC)
|
||||
expectedOutput := int64(1414456320000)
|
||||
|
||||
actualOutput := UnixMillis(testTime)
|
||||
if actualOutput != expectedOutput {
|
||||
t.Errorf("Test failed. Common UnixMillis. Expected '%d'. Actual '%d'.",
|
||||
expectedOutput, actualOutput)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecvWindow(t *testing.T) {
|
||||
t.Parallel()
|
||||
testTime := time.Duration(24760000)
|
||||
expectedOutput := int64(24)
|
||||
|
||||
actualOutput := RecvWindow(testTime)
|
||||
if actualOutput != expectedOutput {
|
||||
t.Errorf("Test failed. Common RecvWindow. Expected '%d'. Actual '%d'",
|
||||
expectedOutput, actualOutput)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/common/convert"
|
||||
"github.com/thrasher-/gocryptotrader/connchecker"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
|
||||
@@ -947,7 +949,7 @@ func (c *Config) CheckExchangeConfigValues() error {
|
||||
}
|
||||
}
|
||||
if !c.Exchanges[i].Features.Supports.RESTCapabilities.AutoPairUpdates && !c.Exchanges[i].Features.Supports.WebsocketCapabilities.AutoPairUpdates {
|
||||
lastUpdated := common.UnixTimestampToTime(c.Exchanges[i].CurrencyPairs.LastUpdated)
|
||||
lastUpdated := convert.UnixTimestampToTime(c.Exchanges[i].CurrencyPairs.LastUpdated)
|
||||
lastUpdated = lastUpdated.AddDate(0, 0, configPairsLastUpdatedWarningThreshold)
|
||||
if lastUpdated.Unix() <= time.Now().Unix() {
|
||||
log.Warnf(WarningPairsLastUpdatedThresholdExceeded, c.Exchanges[i].Name, configPairsLastUpdatedWarningThreshold)
|
||||
@@ -1125,8 +1127,8 @@ func (c *Config) CheckCurrencyConfigValues() error {
|
||||
}
|
||||
|
||||
if c.Currency.Cryptocurrencies.Join() == "" {
|
||||
if c.Cryptocurrencies.Join() != "" {
|
||||
c.Currency.Cryptocurrencies = c.Cryptocurrencies
|
||||
if c.Cryptocurrencies != nil {
|
||||
c.Currency.Cryptocurrencies = *c.Cryptocurrencies
|
||||
c.Cryptocurrencies = nil
|
||||
} else {
|
||||
c.Currency.Cryptocurrencies = currency.GetDefaultCryptocurrencies()
|
||||
@@ -1146,13 +1148,19 @@ func (c *Config) CheckCurrencyConfigValues() error {
|
||||
}
|
||||
|
||||
if c.Currency.FiatDisplayCurrency.IsEmpty() {
|
||||
if c.FiatDisplayCurrency.IsEmpty() {
|
||||
c.Currency.FiatDisplayCurrency = c.FiatDisplayCurrency
|
||||
c.FiatDisplayCurrency = currency.NewCode("")
|
||||
if c.FiatDisplayCurrency != nil {
|
||||
c.Currency.FiatDisplayCurrency = *c.FiatDisplayCurrency
|
||||
c.FiatDisplayCurrency = nil
|
||||
} else {
|
||||
c.Currency.FiatDisplayCurrency = currency.USD
|
||||
}
|
||||
}
|
||||
|
||||
// Flush old setting which still exists
|
||||
if c.FiatDisplayCurrency != nil {
|
||||
c.FiatDisplayCurrency = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1376,7 +1384,7 @@ func GetFilePath(file string) (string, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
data, err := common.ReadFile(newDirs[x])
|
||||
data, err := ioutil.ReadFile(newDirs[x])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -1416,7 +1424,7 @@ func (c *Config) ReadConfig(configPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := common.ReadFile(defaultPath)
|
||||
file, err := ioutil.ReadFile(defaultPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
)
|
||||
|
||||
func TestPromptForConfigEncryption(t *testing.T) {
|
||||
@@ -87,7 +86,7 @@ func TestDecryptConfigFile(t *testing.T) {
|
||||
|
||||
func TestConfirmConfigJSON(t *testing.T) {
|
||||
var result interface{}
|
||||
testConfirmJSON, err := common.ReadFile(ConfigTestFile)
|
||||
testConfirmJSON, err := ioutil.ReadFile(ConfigTestFile)
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. testConfirmJSON: %s", err)
|
||||
}
|
||||
|
||||
@@ -682,7 +682,8 @@ func TestCheckExchangeConfigValues(t *testing.T) {
|
||||
}
|
||||
|
||||
checkExchangeConfigValues.Exchanges = checkExchangeConfigValues.Exchanges[:0]
|
||||
checkExchangeConfigValues.Cryptocurrencies = currency.NewCurrenciesFromStringArray([]string{"TESTYTEST"})
|
||||
cryptos := currency.NewCurrenciesFromStringArray([]string{"TESTYTEST"})
|
||||
checkExchangeConfigValues.Cryptocurrencies = &cryptos
|
||||
err = checkExchangeConfigValues.CheckExchangeConfigValues()
|
||||
if err == nil {
|
||||
t.Errorf(
|
||||
|
||||
@@ -30,8 +30,8 @@ type Config struct {
|
||||
// Deprecated config settings, will be removed at a future date
|
||||
Webserver *WebserverConfig `json:"webserver,omitempty"`
|
||||
CurrencyPairFormat *CurrencyPairFormatConfig `json:"currencyPairFormat,omitempty"`
|
||||
FiatDisplayCurrency currency.Code `json:"fiatDispayCurrency,omitempty"`
|
||||
Cryptocurrencies currency.Currencies `json:"cryptocurrencies,omitempty"`
|
||||
FiatDisplayCurrency *currency.Code `json:"fiatDispayCurrency,omitempty"`
|
||||
Cryptocurrencies *currency.Currencies `json:"cryptocurrencies,omitempty"`
|
||||
SMS *SMSGlobalConfig `json:"smsGlobal,omitempty"`
|
||||
}
|
||||
|
||||
@@ -328,9 +328,9 @@ type APIConfig struct {
|
||||
AuthenticatedSupport bool `json:"authenticatedSupport"`
|
||||
PEMKeySupport bool `json:"pemKeySupport,omitempty"`
|
||||
|
||||
Endpoints APIEndpointsConfig `json:"endpoints"`
|
||||
Credentials APICredentialsConfig `json:"credentials"`
|
||||
CredentialsValidator APICredentialsValidatorConfig `json:"credentialsValidator"`
|
||||
Endpoints APIEndpointsConfig `json:"endpoints"`
|
||||
Credentials APICredentialsConfig `json:"credentials"`
|
||||
CredentialsValidator *APICredentialsValidatorConfig `json:"credentialsValidator,omitempty"`
|
||||
}
|
||||
|
||||
// HTTPRateConfig stores the exchanges HTTP rate limiter config
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -304,7 +305,7 @@ func (s *Storage) ForeignExchangeUpdater() {
|
||||
|
||||
// SeedCurrencyAnalysisData sets a new instance of a coinmarketcap data.
|
||||
func (s *Storage) SeedCurrencyAnalysisData() error {
|
||||
b, err := common.ReadFile(s.path)
|
||||
b, err := ioutil.ReadFile(s.path)
|
||||
if err != nil {
|
||||
err = s.FetchCurrencyAnalysisData()
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/common/convert"
|
||||
"github.com/thrasher-/gocryptotrader/common/crypto"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
@@ -487,7 +488,7 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re
|
||||
if params == nil {
|
||||
params = url.Values{}
|
||||
}
|
||||
params.Set("recvWindow", strconv.FormatInt(common.RecvWindow(5*time.Second), 10))
|
||||
params.Set("recvWindow", strconv.FormatInt(convert.RecvWindow(5*time.Second), 10))
|
||||
params.Set("timestamp", strconv.FormatInt(time.Now().Unix()*1000, 10))
|
||||
|
||||
signature := params.Encode()
|
||||
|
||||
@@ -144,6 +144,9 @@ func (e *Base) SetFeatureDefaults() {
|
||||
// SetAPICredentialDefaults sets the API Credential validator defaults
|
||||
func (e *Base) SetAPICredentialDefaults() {
|
||||
// Exchange hardcoded settings take precedence and overwrite the config settings
|
||||
if e.Config.API.CredentialsValidator == nil {
|
||||
e.Config.API.CredentialsValidator = new(config.APICredentialsValidatorConfig)
|
||||
}
|
||||
if e.Config.API.CredentialsValidator.RequiresKey != e.API.CredentialsValidator.RequiresKey {
|
||||
e.Config.API.CredentialsValidator.RequiresKey = e.API.CredentialsValidator.RequiresKey
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ func (z *ZB) SendAuthenticatedHTTPRequest(httpMethod string, params url.Values,
|
||||
[]byte(params.Encode()),
|
||||
[]byte(crypto.Sha1ToHex(z.API.Credentials.Secret)))
|
||||
|
||||
params.Set("reqTime", fmt.Sprintf("%d", common.UnixMillis(time.Now())))
|
||||
params.Set("reqTime", fmt.Sprintf("%d", convert.UnixMillis(time.Now())))
|
||||
params.Set("sign", fmt.Sprintf("%x", hmac))
|
||||
|
||||
urlPath := fmt.Sprintf("%s/%s?%s",
|
||||
|
||||
3
go.mod
3
go.mod
@@ -3,6 +3,7 @@ module github.com/thrasher-/gocryptotrader
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.2.1 // indirect
|
||||
github.com/golang/protobuf v1.3.1
|
||||
github.com/google/go-querystring v1.0.0
|
||||
github.com/gorilla/mux v1.7.2
|
||||
@@ -10,7 +11,7 @@ require (
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0
|
||||
github.com/pquerna/otp v1.2.0
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
|
||||
github.com/urfave/cli v1.20.0
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5
|
||||
golang.org/x/net v0.0.0-20190606173856-1492cefac77f
|
||||
|
||||
20
go.sum
20
go.sum
@@ -1,10 +1,15 @@
|
||||
cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
@@ -21,16 +26,22 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmo
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0 h1:bM6ZAFZmc/wPFaRDi0d5L7hGEZEx/2u+Tmr2evNHDiI=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pquerna/otp v1.2.0 h1:/A3+Jn+cagqayeR3iHs/L62m5ue7710D35zl1zJ1kok=
|
||||
github.com/pquerna/otp v1.2.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
@@ -49,19 +60,23 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190606173856-1492cefac77f h1:IWHgpgFqnL5AhBUBZSgBdjl2vkQUEzcY+JNKWfcgAU0=
|
||||
golang.org/x/net v0.0.0-20190606173856-1492cefac77f/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190605220351-eb0b1bdb6ae6 h1:XRqWpmQ5ACYxWuYX495S0sHawhPGOVrh62WzgXsQnWs=
|
||||
@@ -69,6 +84,7 @@ google.golang.org/genproto v0.0.0-20190605220351-eb0b1bdb6ae6/go.mod h1:z3L6/3dT
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||
|
||||
Reference in New Issue
Block a user