mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-27 15:10:30 +00:00
Merge branch 'test'
Merge current test branch progress
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
//"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
"crypto/sha1"
|
||||
@@ -122,6 +123,11 @@ func StringContains(input, substring string) bool {
|
||||
return strings.Contains(input, substring)
|
||||
}
|
||||
|
||||
func DataContains(haystack []string, needle string) bool {
|
||||
data := strings.Join(haystack, ",")
|
||||
return strings.Contains(data, needle)
|
||||
}
|
||||
|
||||
func JoinStrings(input []string, seperator string) string {
|
||||
return strings.Join(input, seperator)
|
||||
}
|
||||
@@ -253,8 +259,8 @@ func SendHTTPGetRequest(url string, jsonDecode bool, result interface{}) (err er
|
||||
|
||||
if jsonDecode {
|
||||
err := JSONDecode(contents, &result)
|
||||
|
||||
if err != nil {
|
||||
log.Println(string(contents[:]))
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -129,6 +129,23 @@ func TestStringContains(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataContains(t *testing.T) {
|
||||
t.Parallel()
|
||||
originalHaystack := []string{"hello", "world", "data", "Contains", "string"}
|
||||
originalNeedle := "world"
|
||||
anotherNeedle := "thing"
|
||||
expectedOutput := true
|
||||
expectedOutputTwo := false
|
||||
actualResult := DataContains(originalHaystack, originalNeedle)
|
||||
if actualResult != expectedOutput {
|
||||
t.Error(fmt.Sprintf("Test failed. Expected '%t'. Actual '%t'", expectedOutput, actualResult))
|
||||
}
|
||||
actualResult = DataContains(originalHaystack, anotherNeedle)
|
||||
if actualResult != expectedOutputTwo {
|
||||
t.Error(fmt.Sprintf("Test failed. Expected '%t'. Actual '%t'", expectedOutputTwo, actualResult))
|
||||
}
|
||||
}
|
||||
|
||||
func TestJoinStrings(t *testing.T) {
|
||||
t.Parallel()
|
||||
originalInputOne := []string{"hello", "moto"}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
const (
|
||||
CONFIG_FILE = "config.dat"
|
||||
OLD_CONFIG_FILE = "config.json"
|
||||
CONFIG_TEST = "../testdata/configtest.dat"
|
||||
|
||||
CONFIG_FILE_ENCRYPTION_PROMPT = 0
|
||||
CONFIG_FILE_ENCRYPTION_ENABLED = 1
|
||||
@@ -205,10 +206,19 @@ func (c *Config) CheckWebserverConfigValues() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) RetrieveConfigCurrencyPairs() {
|
||||
func (c *Config) RetrieveConfigCurrencyPairs() error {
|
||||
cryptoCurrencies := common.SplitStrings(c.Cryptocurrencies, ",")
|
||||
fiatCurrencies := common.SplitStrings(currency.DEFAULT_CURRENCIES, ",")
|
||||
|
||||
for _, s := range cryptoCurrencies {
|
||||
_, err := strconv.Atoi(s)
|
||||
if err != nil && common.StringContains(c.Cryptocurrencies, s) {
|
||||
continue
|
||||
} else {
|
||||
return errors.New("RetrieveConfigCurrencyPairs: Incorrect Crypto-Currency")
|
||||
}
|
||||
}
|
||||
|
||||
for _, exchange := range c.Exchanges {
|
||||
if exchange.Enabled {
|
||||
baseCurrencies := common.SplitStrings(exchange.BaseCurrencies, ",")
|
||||
@@ -252,9 +262,11 @@ func (c *Config) RetrieveConfigCurrencyPairs() {
|
||||
}
|
||||
c.Cryptocurrencies = common.JoinStrings(cryptoCurrencies, ",")
|
||||
currency.CryptoCurrencies = c.Cryptocurrencies
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) ReadConfig() error {
|
||||
func CheckConfig() error {
|
||||
_, err := common.ReadFile(OLD_CONFIG_FILE)
|
||||
if err == nil {
|
||||
err = os.Rename(OLD_CONFIG_FILE, CONFIG_FILE)
|
||||
@@ -263,8 +275,23 @@ func (c *Config) ReadConfig() error {
|
||||
}
|
||||
log.Printf(RenamingConfigFile+"\n", OLD_CONFIG_FILE, CONFIG_FILE)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
file, err := common.ReadFile(CONFIG_FILE)
|
||||
func (c *Config) ReadConfig(configPath string) error {
|
||||
defaultPath := ""
|
||||
if configPath == "" {
|
||||
defaultPath = CONFIG_FILE
|
||||
} else {
|
||||
defaultPath = configPath
|
||||
}
|
||||
|
||||
err := CheckConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := common.ReadFile(defaultPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -282,7 +309,7 @@ func (c *Config) ReadConfig() error {
|
||||
if c.EncryptConfig == CONFIG_FILE_ENCRYPTION_PROMPT {
|
||||
if c.PromptForConfigEncryption() {
|
||||
c.EncryptConfig = CONFIG_FILE_ENCRYPTION_ENABLED
|
||||
return c.SaveConfig()
|
||||
return c.SaveConfig("")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -304,7 +331,14 @@ func (c *Config) ReadConfig() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) SaveConfig() error {
|
||||
func (c *Config) SaveConfig(configPath string) error {
|
||||
defaultPath := ""
|
||||
if configPath == "" {
|
||||
defaultPath = CONFIG_FILE
|
||||
} else {
|
||||
defaultPath = configPath
|
||||
}
|
||||
|
||||
payload, err := json.MarshalIndent(c, "", " ")
|
||||
|
||||
if c.EncryptConfig == CONFIG_FILE_ENCRYPTION_ENABLED {
|
||||
@@ -319,15 +353,15 @@ func (c *Config) SaveConfig() error {
|
||||
}
|
||||
}
|
||||
|
||||
err = common.WriteFile(CONFIG_FILE, payload)
|
||||
err = common.WriteFile(defaultPath, payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) LoadConfig() error {
|
||||
err := c.ReadConfig()
|
||||
func (c *Config) LoadConfig(configPath string) error {
|
||||
err := c.ReadConfig(configPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf(ErrFailureOpeningConfig, CONFIG_FILE, err)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
)
|
||||
@@ -30,7 +31,7 @@ func (c *Config) PromptForConfigEncryption() bool {
|
||||
|
||||
if !common.YesOrNo(input) {
|
||||
c.EncryptConfig = CONFIG_FILE_ENCRYPTION_DISABLED
|
||||
c.SaveConfig()
|
||||
c.SaveConfig("")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -40,7 +41,7 @@ func PromptForConfigKey() ([]byte, error) {
|
||||
var cryptoKey []byte
|
||||
|
||||
for len(cryptoKey) != 32 {
|
||||
log.Println("Enter password (32 characters):")
|
||||
fmt.Println("Enter password (32 characters):")
|
||||
|
||||
_, err := fmt.Scanln(&cryptoKey)
|
||||
if err != nil {
|
||||
@@ -51,7 +52,6 @@ func PromptForConfigKey() ([]byte, error) {
|
||||
fmt.Println("Please re-enter password (32 characters):")
|
||||
}
|
||||
}
|
||||
|
||||
nonce := make([]byte, 12)
|
||||
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
|
||||
return nil, err
|
||||
@@ -101,6 +101,9 @@ func DecryptConfigFile(configData, key []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func ConfirmConfigJSON(file []byte, result interface{}) error {
|
||||
if !common.StringContains(reflect.TypeOf(result).String(), "*") {
|
||||
return errors.New("ConfirmConfigJSON Error: Parameter interface is not a pointer.")
|
||||
}
|
||||
return common.JSONDecode(file, &result)
|
||||
}
|
||||
|
||||
|
||||
89
config/config_encryption_test.go
Normal file
89
config/config_encryption_test.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
)
|
||||
|
||||
func TestPromptForConfigEncryption(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if Cfg.PromptForConfigEncryption() {
|
||||
t.Error("Test failed. PromptForConfigEncryption return incorrect bool")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptForConfigKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
byteyBite, err := PromptForConfigKey()
|
||||
if err == nil && len(byteyBite) > 1 {
|
||||
t.Errorf("Test failed. PromptForConfigKey: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryptDecryptConfigFile(t *testing.T) { //Dual function Test
|
||||
testKey := []byte("12345678901234567890123456789012")
|
||||
testConfigData, err := common.ReadFile("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. EncryptConfigFile: %s", err)
|
||||
}
|
||||
encryptedFile, err2 := EncryptConfigFile(testConfigData, testKey)
|
||||
if err2 != nil {
|
||||
t.Errorf("Test failed. EncryptConfigFile: %s", err2)
|
||||
}
|
||||
if reflect.TypeOf(encryptedFile).String() != "[]uint8" {
|
||||
t.Errorf("Test failed. EncryptConfigFile: Incorrect Type")
|
||||
}
|
||||
|
||||
decryptedFile, err3 := DecryptConfigFile(encryptedFile, testKey)
|
||||
if err3 != nil {
|
||||
t.Errorf("Test failed. DecryptConfigFile: %s", err3)
|
||||
}
|
||||
if reflect.TypeOf(decryptedFile).String() != "[]uint8" {
|
||||
t.Errorf("Test failed. DecryptConfigFile: Incorrect Type")
|
||||
}
|
||||
unmarshalled := Config{}
|
||||
err4 := json.Unmarshal(decryptedFile, &unmarshalled)
|
||||
if err4 != nil {
|
||||
t.Errorf("Test failed. DecryptConfigFile: %s", err3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfirmJson(t *testing.T) {
|
||||
var result interface{}
|
||||
testConfirmJson, err := common.ReadFile("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. TestConfirmJson: %s", err)
|
||||
}
|
||||
err2 := ConfirmConfigJSON(testConfirmJson, &result)
|
||||
if err2 != nil {
|
||||
t.Errorf("Test failed. TestConfirmJson: %s", err2)
|
||||
}
|
||||
if result == nil {
|
||||
t.Errorf("Test failed. TestConfirmJson: Error Unmarshalling JSON")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfirmECS(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ECStest := []byte("THORS-HAMMER")
|
||||
if !ConfirmECS(ECStest) {
|
||||
t.Errorf("Test failed. TestConfirmECS: Error finding ECS.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveECS(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ECStest := []byte("THORS-HAMMER")
|
||||
isremoved := RemoveECS(ECStest)
|
||||
|
||||
if string(isremoved) != "" {
|
||||
t.Errorf("Test failed. TestConfirmECS: Error ECS not deleted.")
|
||||
}
|
||||
}
|
||||
142
config/config_test.go
Normal file
142
config/config_test.go
Normal file
@@ -0,0 +1,142 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetConfigEnabledExchanges(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defaultEnabledExchanges := 17
|
||||
GetConfigEnabledExchanges := GetConfig()
|
||||
err := GetConfigEnabledExchanges.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Error("Test failed. GetConfigEnabledExchanges load config error: " + err.Error())
|
||||
}
|
||||
enabledExch := GetConfigEnabledExchanges.GetConfigEnabledExchanges()
|
||||
if enabledExch != defaultEnabledExchanges {
|
||||
t.Error("Test failed. GetConfigEnabledExchanges is wrong")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetExchangeConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
GetExchangeConfig := GetConfig()
|
||||
err := GetExchangeConfig.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. GetExchangeConfig.LoadConfig Error: %s", err.Error())
|
||||
}
|
||||
r, err := GetExchangeConfig.GetExchangeConfig("ANX")
|
||||
if err != nil && (ExchangeConfig{}) == r {
|
||||
t.Errorf("Test failed. GetExchangeConfig.GetExchangeConfig Error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateExchangeConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
UpdateExchangeConfig := GetConfig()
|
||||
err := UpdateExchangeConfig.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. UpdateExchangeConfig.LoadConfig Error: %s", err.Error())
|
||||
}
|
||||
e, err2 := UpdateExchangeConfig.GetExchangeConfig("ANX")
|
||||
if err2 != nil {
|
||||
t.Errorf("Test failed. UpdateExchangeConfig.GetExchangeConfig: %s", err.Error())
|
||||
}
|
||||
e.APIKey = "test1234"
|
||||
err3 := UpdateExchangeConfig.UpdateExchangeConfig(e)
|
||||
if err3 != nil {
|
||||
t.Errorf("Test failed. UpdateExchangeConfig.UpdateExchangeConfig: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckSMSGlobalConfigValues(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkSMSGlobalConfigValues := GetConfig()
|
||||
err := checkSMSGlobalConfigValues.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. checkSMSGlobalConfigValues.LoadConfig: %s", err)
|
||||
}
|
||||
err2 := checkSMSGlobalConfigValues.CheckSMSGlobalConfigValues()
|
||||
if err2 == nil {
|
||||
t.Error("Test failed. checkSMSGlobalConfigValues.CheckSMSGlobalConfigValues: Incorrect Return Value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckExchangeConfigValues(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkExchangeConfigValues := Config{}
|
||||
err := checkExchangeConfigValues.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. checkExchangeConfigValues.LoadConfig: %s", err.Error())
|
||||
}
|
||||
|
||||
err3 := checkExchangeConfigValues.CheckExchangeConfigValues()
|
||||
if err3 != nil {
|
||||
t.Errorf("Test failed. checkExchangeConfigValues.CheckExchangeConfigValues: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckWebserverConfigValues(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkWebserverConfigValues := GetConfig()
|
||||
err := checkWebserverConfigValues.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. checkWebserverConfigValues.LoadConfig: %s", err.Error())
|
||||
}
|
||||
err2 := checkWebserverConfigValues.CheckWebserverConfigValues()
|
||||
if err2 != nil {
|
||||
t.Errorf("Test failed. checkWebserverConfigValues.CheckWebserverConfigValues: %s", err2.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetrieveConfigCurrencyPairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
retrieveConfigCurrencyPairs := GetConfig()
|
||||
err := retrieveConfigCurrencyPairs.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. checkWebserverConfigValues.LoadConfig: %s", err.Error())
|
||||
}
|
||||
err2 := retrieveConfigCurrencyPairs.RetrieveConfigCurrencyPairs()
|
||||
if err2 != nil {
|
||||
t.Errorf("Test failed. checkWebserverConfigValues.RetrieveConfigCurrencyPairs: %s", err2.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
readConfig := GetConfig()
|
||||
err := readConfig.ReadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Error("Test failed. TestReadConfig " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
loadConfig := GetConfig()
|
||||
err := loadConfig.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Error("Test failed. TestLoadConfig " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveConfig(t *testing.T) {
|
||||
saveConfig := GetConfig()
|
||||
err := saveConfig.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test failed. TestSaveConfig.LoadConfig: %s", err.Error())
|
||||
}
|
||||
err2 := saveConfig.SaveConfig("../testdata/configtest.dat")
|
||||
if err2 != nil {
|
||||
t.Errorf("Test failed. TestSaveConfig.SaveConfig, %s", err2.Error())
|
||||
}
|
||||
}
|
||||
@@ -35,11 +35,11 @@ func SaveAllSettings(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
//Reload the configuration
|
||||
err := bot.config.SaveConfig()
|
||||
err := bot.config.SaveConfig("")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = bot.config.LoadConfig()
|
||||
err = bot.config.LoadConfig("")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -63,21 +63,33 @@ func IsDefaultCryptocurrency(currency string) bool {
|
||||
}
|
||||
|
||||
func IsFiatCurrency(currency string) bool {
|
||||
if BaseCurrencies == "" {
|
||||
log.Println("IsFiatCurrency: BaseCurrencies string variable not populated")
|
||||
}
|
||||
return common.StringContains(BaseCurrencies, common.StringToUpper(currency))
|
||||
}
|
||||
|
||||
func IsCryptocurrency(currency string) bool {
|
||||
if CryptoCurrencies == "" {
|
||||
log.Println("IsCryptocurrency: CryptoCurrencies string variable not populated")
|
||||
}
|
||||
return common.StringContains(CryptoCurrencies, common.StringToUpper(currency))
|
||||
}
|
||||
|
||||
func ContainsSeparator(input string) (bool, string) {
|
||||
separators := []string{"-", "_"}
|
||||
var separatorsContainer []string
|
||||
|
||||
for _, x := range separators {
|
||||
if common.StringContains(input, x) {
|
||||
return true, x
|
||||
separatorsContainer = append(separatorsContainer, x)
|
||||
}
|
||||
}
|
||||
return false, ""
|
||||
if len(separatorsContainer) == 0 {
|
||||
return false, ""
|
||||
} else {
|
||||
return true, strings.Join(separatorsContainer, ",")
|
||||
}
|
||||
}
|
||||
|
||||
func ContainsBaseCurrencyIndex(baseCurrencies []string, currency string) (bool, string) {
|
||||
@@ -100,13 +112,28 @@ func ContainsBaseCurrency(baseCurrencies []string, currency string) bool {
|
||||
|
||||
func CheckAndAddCurrency(input []string, check string) []string {
|
||||
for _, x := range input {
|
||||
if check == x {
|
||||
if IsDefaultCurrency(x) {
|
||||
if IsDefaultCurrency(check) {
|
||||
if check == x {
|
||||
return input
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
} else if IsDefaultCryptocurrency(x) {
|
||||
if IsDefaultCryptocurrency(check) {
|
||||
if check == x {
|
||||
return input
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
}
|
||||
if IsCryptocurrency(check) && IsFiatCurrency(check) {
|
||||
return input
|
||||
}
|
||||
|
||||
input = append(input, check)
|
||||
return input
|
||||
@@ -118,7 +145,6 @@ func SeedCurrencyData(fiatCurrencies string) error {
|
||||
}
|
||||
|
||||
err := QueryYahooCurrencyValues(fiatCurrencies)
|
||||
|
||||
if err != nil {
|
||||
return ErrQueryingYahoo
|
||||
}
|
||||
@@ -142,16 +168,15 @@ func MakecurrencyPairs(supportedCurrencies string) string {
|
||||
}
|
||||
|
||||
func ConvertCurrency(amount float64, from, to string) (float64, error) {
|
||||
if len(CurrencyStore) == 0 {
|
||||
err := SeedCurrencyData(common.StringToUpper(from) + "," + common.StringToUpper(to))
|
||||
currency := common.StringToUpper(from + to)
|
||||
|
||||
if CurrencyStore[currency].Name != currency {
|
||||
err := SeedCurrencyData(currency[:len(from)] + "," + currency[len(to):])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
currency := common.StringToUpper(from + to)
|
||||
if common.StringContains(currency, "RUB") {
|
||||
currency = strings.Replace(currency, "RUB", "RUR", -1)
|
||||
}
|
||||
|
||||
for x, y := range CurrencyStore {
|
||||
if x == currency {
|
||||
return amount * y.Rate, nil
|
||||
|
||||
268
currency/currency_test.go
Normal file
268
currency/currency_test.go
Normal file
@@ -0,0 +1,268 @@
|
||||
package currency
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
)
|
||||
|
||||
func TestIsDefaultCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var str1, str2, str3 string = "USD", "usd", "cats123"
|
||||
|
||||
if !IsDefaultCurrency(str1) {
|
||||
t.Errorf("Test Failed. TestIsDefaultCurrency: \nCannot match currency, %s.", str1)
|
||||
}
|
||||
if !IsDefaultCurrency(str2) {
|
||||
t.Errorf("Test Failed. TestIsDefaultCurrency: \nCannot match currency, %s.", str2)
|
||||
}
|
||||
if IsDefaultCurrency(str3) {
|
||||
t.Errorf("Test Failed. TestIsDefaultCurrency: \nFunction return is incorrect with, %s.", str3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsDefaultCryptocurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var str1, str2, str3 string = "BTC", "btc", "dogs123"
|
||||
|
||||
if !IsDefaultCryptocurrency(str1) {
|
||||
t.Errorf("Test Failed. TestIsDefaultCryptocurrency: \nCannot match currency, %s.", str1)
|
||||
}
|
||||
if !IsDefaultCryptocurrency(str2) {
|
||||
t.Errorf("Test Failed. TestIsDefaultCryptocurrency: \nCannot match currency, %s.", str2)
|
||||
}
|
||||
if IsDefaultCryptocurrency(str3) {
|
||||
t.Errorf("Test Failed. TestIsDefaultCryptocurrency: \nFunction return is incorrect with, %s.", str3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsFiatCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
BaseCurrencies = "USD,AUD"
|
||||
var str1, str2, str3 string = "BTC", "USD", "birds123"
|
||||
|
||||
if IsFiatCurrency(str1) {
|
||||
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str1)
|
||||
}
|
||||
if !IsFiatCurrency(str2) {
|
||||
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str2)
|
||||
}
|
||||
if IsFiatCurrency(str3) {
|
||||
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsCryptocurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
CryptoCurrencies = "BTC,LTC,DASH"
|
||||
var str1, str2, str3 string = "USD", "BTC", "pterodactyl123"
|
||||
|
||||
if IsCryptocurrency(str1) {
|
||||
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str1)
|
||||
}
|
||||
if !IsCryptocurrency(str2) {
|
||||
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str2)
|
||||
}
|
||||
if IsCryptocurrency(str3) {
|
||||
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainsSeparator(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var str1, str2, str3, str4 string = "ding-dong", "ding_dong", "dong_ding-dang", "ding"
|
||||
|
||||
doesIt, whatIsIt := ContainsSeparator(str1)
|
||||
if doesIt != true || whatIsIt != "-" {
|
||||
t.Errorf("Test Failed. ContainsSeparator: \nCannot find separator, %s.", str1)
|
||||
}
|
||||
doesIt2, whatIsIt2 := ContainsSeparator(str2)
|
||||
if doesIt2 != true || whatIsIt2 != "_" {
|
||||
t.Errorf("Test Failed. ContainsSeparator: \nCannot find separator, %s.", str2)
|
||||
}
|
||||
doesIt3, whatIsIt3 := ContainsSeparator(str3)
|
||||
if doesIt3 != true || len(whatIsIt3) != 3 {
|
||||
t.Errorf("Test Failed. ContainsSeparator: \nCannot find or incorrect separator, %s.", str3)
|
||||
}
|
||||
doesIt4, whatIsIt4 := ContainsSeparator(str4)
|
||||
if doesIt4 != false || whatIsIt4 != "" {
|
||||
t.Errorf("Test Failed. ContainsSeparator: \nReturn Issues with string, %s.", str3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainsBaseCurrencyIndex(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
baseCurrencies := []string{"USD", "AUD", "EUR", "CNY"}
|
||||
currency1, currency2 := "USD", "DINGDONG"
|
||||
|
||||
isIt, whatIsIt := ContainsBaseCurrencyIndex(baseCurrencies, currency1)
|
||||
if !isIt && whatIsIt != "USD" {
|
||||
t.Errorf("Test Failed. ContainsBaseCurrencyIndex: \nReturned: %t & %s, with Currency as %s.", isIt, whatIsIt, currency1)
|
||||
}
|
||||
isIt2, whatIsIt2 := ContainsBaseCurrencyIndex(baseCurrencies, currency2)
|
||||
if isIt2 && whatIsIt2 != "DINGDONG" {
|
||||
t.Errorf("Test Failed. ContainsBaseCurrencyIndex: \nReturned: %t & %s, with Currency as %s.", isIt2, whatIsIt2, currency2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainsBaseCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
baseCurrencies := []string{"USD", "AUD", "EUR", "CNY"}
|
||||
currency1, currency2 := "USD", "DINGDONG"
|
||||
|
||||
isIt := ContainsBaseCurrency(baseCurrencies, currency1)
|
||||
if !isIt {
|
||||
t.Errorf("Test Failed. ContainsBaseCurrency: \nReturned: %t, with Currency as %s.", isIt, currency1)
|
||||
}
|
||||
isIt2 := ContainsBaseCurrency(baseCurrencies, currency2)
|
||||
if isIt2 {
|
||||
t.Errorf("Test Failed. ContainsBaseCurrency: \nReturned: %t, with Currency as %s.", isIt2, currency2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckAndAddCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
inputFiat := []string{"USD", "AUD", "EUR"}
|
||||
inputCrypto := []string{"BTC", "LTC", "ETH", "DOGE", "DASH", "XRP"}
|
||||
fiat := "USD"
|
||||
fiatIncrease := "CNY"
|
||||
crypto := "LTC"
|
||||
cryptoIncrease := "XMR"
|
||||
obtuse := "CATSANDDOGS"
|
||||
|
||||
appendedString := CheckAndAddCurrency(inputFiat, fiat)
|
||||
if len(appendedString) > len(inputFiat) {
|
||||
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputFiat, currency as %s.", fiat)
|
||||
}
|
||||
appendedString = CheckAndAddCurrency(inputFiat, fiatIncrease)
|
||||
if len(appendedString) <= len(inputFiat) {
|
||||
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputFiat, currency as %s.", fiatIncrease)
|
||||
}
|
||||
appendedString = CheckAndAddCurrency(inputFiat, crypto)
|
||||
if len(appendedString) > len(inputFiat) {
|
||||
t.Log(appendedString)
|
||||
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputFiat, currency as %s.", crypto)
|
||||
}
|
||||
appendedString = CheckAndAddCurrency(inputFiat, obtuse)
|
||||
if len(appendedString) > len(inputFiat) {
|
||||
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputFiat, currency as %s.", obtuse)
|
||||
}
|
||||
|
||||
appendedString = CheckAndAddCurrency(inputCrypto, crypto)
|
||||
if len(appendedString) > len(inputCrypto) {
|
||||
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputCrytpo, currency as %s.", crypto)
|
||||
}
|
||||
appendedString = CheckAndAddCurrency(inputCrypto, cryptoIncrease)
|
||||
if len(appendedString) <= len(inputCrypto) {
|
||||
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputCrytpo, currency as %s.", cryptoIncrease)
|
||||
}
|
||||
appendedString = CheckAndAddCurrency(inputCrypto, fiat)
|
||||
if len(appendedString) > len(inputCrypto) {
|
||||
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputCrytpo, currency as %s.", fiat)
|
||||
}
|
||||
appendedString = CheckAndAddCurrency(inputCrypto, obtuse)
|
||||
if len(appendedString) > len(inputCrypto) {
|
||||
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputCrytpo, currency as %s.", obtuse)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeedCurrencyData(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
currencyRequestDefault := ""
|
||||
currencyRequestUSDAUD := "USD,AUD"
|
||||
currencyRequestObtuse := "WigWham"
|
||||
|
||||
err := SeedCurrencyData(currencyRequestDefault)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. SeedCurrencyData: Error %s with currency as %s.", err, currencyRequestDefault)
|
||||
}
|
||||
err2 := SeedCurrencyData(currencyRequestUSDAUD)
|
||||
if err2 != nil {
|
||||
t.Errorf("Test Failed. SeedCurrencyData: Error %s with currency as %s.", err2, currencyRequestUSDAUD)
|
||||
}
|
||||
err3 := SeedCurrencyData(currencyRequestObtuse)
|
||||
if err3 == nil {
|
||||
t.Errorf("Test Failed. SeedCurrencyData: Error %s with currency as %s.", err3, currencyRequestObtuse)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakecurrencyPairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
lengthDefault := len(common.SplitStrings(DEFAULT_CURRENCIES, ","))
|
||||
fiatPairsLength := len(common.SplitStrings(MakecurrencyPairs(DEFAULT_CURRENCIES), ","))
|
||||
|
||||
if lengthDefault*(lengthDefault-1) > fiatPairsLength {
|
||||
t.Error("Test Failed. MakecurrencyPairs: Error, mismatched length")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fiatCurrencies := DEFAULT_CURRENCIES
|
||||
for _, currencyFrom := range common.SplitStrings(fiatCurrencies, ",") {
|
||||
for _, currencyTo := range common.SplitStrings(fiatCurrencies, ",") {
|
||||
if currencyFrom == currencyTo {
|
||||
continue
|
||||
} else {
|
||||
floatyMcfloat, err := ConvertCurrency(1000, currencyFrom, currencyTo)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. ConvertCurrency: Error %s with return: %.2f Currency 1: %s Currency 2: %s",
|
||||
err, floatyMcfloat, currencyFrom, currencyTo)
|
||||
}
|
||||
if reflect.TypeOf(floatyMcfloat).String() != "float64" {
|
||||
t.Error("Test Failed. ConvertCurrency: Error, incorrect return type")
|
||||
}
|
||||
if floatyMcfloat <= 0 {
|
||||
t.Error("Test Failed. ConvertCurrency: Error, negative return or a serious issue with current fiat")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchYahooCurrencyData(t *testing.T) {
|
||||
t.Parallel()
|
||||
var fetchData []string
|
||||
fiatCurrencies := DEFAULT_CURRENCIES
|
||||
|
||||
for _, currencyOne := range common.SplitStrings(fiatCurrencies, ",") {
|
||||
for _, currencyTwo := range common.SplitStrings(fiatCurrencies, ",") {
|
||||
if currencyOne == currencyTwo {
|
||||
continue
|
||||
} else {
|
||||
fetchData = append(fetchData, currencyOne+currencyTwo)
|
||||
}
|
||||
}
|
||||
}
|
||||
err := FetchYahooCurrencyData(fetchData)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. FetchYahooCurrencyData: Error %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryYahooCurrencyValues(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := QueryYahooCurrencyValues(DEFAULT_CURRENCIES)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. QueryYahooCurrencyValues: Error, %s", err)
|
||||
}
|
||||
|
||||
err2 := QueryYahooCurrencyValues(DEFAULT_CRYPTOCURRENCIES)
|
||||
if err2 == nil {
|
||||
t.Errorf("Test Failed. QueryYahooCurrencyValues: Error, %s", err2)
|
||||
}
|
||||
|
||||
}
|
||||
216
events/event_test.go
Normal file
216
events/event_test.go
Normal file
@@ -0,0 +1,216 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAddEvent(t *testing.T) {
|
||||
eventID, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err != nil && eventID != 0 {
|
||||
t.Errorf("Test Failed. AddEvent: Error, %s", err)
|
||||
}
|
||||
eventID, err = AddEvent("ANXX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err == nil && eventID == 0 {
|
||||
t.Error("Test Failed. AddEvent: Error, error not captured in Exchange")
|
||||
}
|
||||
eventID, err = AddEvent("ANX", "prices", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err == nil && eventID == 0 {
|
||||
t.Error("Test Failed. AddEvent: Error, error not captured in Item")
|
||||
}
|
||||
eventID, err = AddEvent("ANX", "price", "3===D", "BTC", "LTC", ACTION_TEST)
|
||||
if err == nil && eventID == 0 {
|
||||
t.Error("Test Failed. AddEvent: Error, error not captured in Condition")
|
||||
}
|
||||
eventID, err = AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_prints")
|
||||
if err == nil && eventID == 0 {
|
||||
t.Error("Test Failed. AddEvent: Error, error not captured in Action")
|
||||
}
|
||||
eventID, err = AddEvent("ANX", "price", ">,==", "BATMAN", "ROBIN", ACTION_TEST)
|
||||
if err == nil && eventID == 0 {
|
||||
t.Error("Test Failed. AddEvent: Error, error not captured in Action")
|
||||
}
|
||||
if !RemoveEvent(eventID) {
|
||||
t.Error("Test Failed. RemoveEvent: Error, error removing event")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveEvent(t *testing.T) {
|
||||
eventID, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err != nil && eventID != 0 {
|
||||
t.Errorf("Test Failed. RemoveEvent: Error, %s", err)
|
||||
}
|
||||
if !RemoveEvent(eventID) {
|
||||
t.Error("Test Failed. RemoveEvent: Error, error removing event")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEventCounter(t *testing.T) {
|
||||
one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. GetEventCounter: Error, %s", err)
|
||||
}
|
||||
two, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. GetEventCounter: Error, %s", err)
|
||||
}
|
||||
three, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. GetEventCounter: Error, %s", err)
|
||||
}
|
||||
|
||||
total, _ := GetEventCounter()
|
||||
if total <= 0 {
|
||||
t.Errorf("Test Failed. GetEventCounter: Total = %d", total)
|
||||
}
|
||||
|
||||
if !RemoveEvent(one) {
|
||||
t.Error("Test Failed. GetEventCounter: Error, error removing event")
|
||||
}
|
||||
if !RemoveEvent(two) {
|
||||
t.Error("Test Failed. GetEventCounter: Error, error removing event")
|
||||
}
|
||||
if !RemoveEvent(three) {
|
||||
t.Error("Test Failed. GetEventCounter: Error, error removing event")
|
||||
}
|
||||
|
||||
total2, _ := GetEventCounter()
|
||||
if total2 != 0 {
|
||||
t.Errorf("Test Failed. GetEventCounter: Total = %d", total2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecuteAction(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. ExecuteAction: Error, %s", err)
|
||||
}
|
||||
isExecuted := Events[one].ExecuteAction()
|
||||
if !isExecuted {
|
||||
t.Error("Test Failed. ExecuteAction: Error, error removing event")
|
||||
}
|
||||
|
||||
if !RemoveEvent(one) {
|
||||
t.Error("Test Failed. ExecuteAction: Error, error removing event")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventToString(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. EventToString: Error, %s", err)
|
||||
}
|
||||
|
||||
eventString := Events[one].EventToString()
|
||||
if eventString != "If the BTCLTC price on ANX is > == then ACTION_TEST." {
|
||||
t.Error("Test Failed. EventToString: Error, incorrect return string")
|
||||
}
|
||||
|
||||
if !RemoveEvent(one) {
|
||||
t.Error("Test Failed. EventToString: Error, error removing event")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCheckCondition(t *testing.T) { //error handling needs to be implemented
|
||||
t.Parallel()
|
||||
|
||||
one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. EventToString: Error, %s", err)
|
||||
}
|
||||
|
||||
conditionBool := Events[one].CheckCondition()
|
||||
if conditionBool { //check once error handling is implemented
|
||||
t.Error("Test Failed. EventToString: Error, wrong conditional.")
|
||||
}
|
||||
|
||||
if !RemoveEvent(one) {
|
||||
t.Error("Test Failed. EventToString: Error, error removing event")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestIsValidEvent(t *testing.T) {
|
||||
err := IsValidEvent("ANX", "price", ">,==", ACTION_TEST)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. IsValidExchange: Error %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckEvents(t *testing.T) { //Add error handling
|
||||
//CheckEvents() //check once error handling is implemented
|
||||
}
|
||||
|
||||
func TestIsValidExchange(t *testing.T) {
|
||||
boolean := IsValidExchange("ANX", CONFIG_PATH_TEST)
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidExchange: Error, incorrect Exchange")
|
||||
}
|
||||
boolean = IsValidExchange("OBTUSE", CONFIG_PATH_TEST)
|
||||
if boolean {
|
||||
t.Error("Test Failed. IsValidExchange: Error, incorrect return")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsValidCondition(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
boolean := IsValidCondition(">")
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
|
||||
}
|
||||
boolean = IsValidCondition(">=")
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
|
||||
}
|
||||
boolean = IsValidCondition("<")
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
|
||||
}
|
||||
boolean = IsValidCondition("<=")
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
|
||||
}
|
||||
boolean = IsValidCondition("==")
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
|
||||
}
|
||||
boolean = IsValidCondition("**********")
|
||||
if boolean {
|
||||
t.Error("Test Failed. IsValidCondition: Error, incorrect return")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsValidAction(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
boolean := IsValidAction("sms")
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidAction: Error, incorrect Action")
|
||||
}
|
||||
boolean = IsValidAction(ACTION_TEST)
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidAction: Error, incorrect Action")
|
||||
}
|
||||
boolean = IsValidAction("randomstring")
|
||||
if boolean {
|
||||
t.Error("Test Failed. IsValidAction: Error, incorrect return")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsValidItem(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
boolean := IsValidItem("price")
|
||||
if !boolean {
|
||||
t.Error("Test Failed. IsValidItem: Error, incorrect Item")
|
||||
}
|
||||
boolean = IsValidItem("obtuse")
|
||||
if boolean {
|
||||
t.Error("Test Failed. IsValidItem: Error, incorrect return")
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-/gocryptotrader/smsglobal"
|
||||
@@ -22,14 +23,16 @@ const (
|
||||
IS_EQUAL = "=="
|
||||
ACTION_SMS_NOTIFY = "SMS"
|
||||
ACTION_CONSOLE_PRINT = "CONSOLE_PRINT"
|
||||
ACTION_TEST = "ACTION_TEST"
|
||||
CONFIG_PATH_TEST = "../testdata/configtest.dat"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidItem = errors.New("Invalid item.")
|
||||
ErrInvalidCondition = errors.New("Invalid conditional option.")
|
||||
ErrInvalidAction = errors.New("Invalid action.")
|
||||
ErrExchangeDisabled = errors.New("Desired exchange is disabled.")
|
||||
ErrFiatCurrencyInvalid = errors.New("Invalid fiat currency.")
|
||||
ErrInvalidItem = errors.New("Invalid item.")
|
||||
ErrInvalidCondition = errors.New("Invalid conditional option.")
|
||||
ErrInvalidAction = errors.New("Invalid action.")
|
||||
ErrExchangeDisabled = errors.New("Desired exchange is disabled.")
|
||||
ErrCurrencyInvalid = errors.New("Invalid currency.")
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
@@ -47,11 +50,14 @@ var Events []*Event
|
||||
|
||||
func AddEvent(Exchange, Item, Condition, FirstCurrency, SecondCurrency, Action string) (int, error) {
|
||||
err := IsValidEvent(Exchange, Item, Condition, Action)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if !IsValidCurrency(FirstCurrency, SecondCurrency) {
|
||||
return 0, ErrCurrencyInvalid
|
||||
}
|
||||
|
||||
Event := &Event{}
|
||||
|
||||
if len(Events) == 0 {
|
||||
@@ -115,7 +121,7 @@ func (e *Event) EventToString() string {
|
||||
return fmt.Sprintf("If the %s%s %s on %s is %s then %s.", e.FirstCurrency, e.SecondCurrency, e.Item, e.Exchange, condition[0]+" "+condition[1], e.Action)
|
||||
}
|
||||
|
||||
func (e *Event) CheckCondition() bool {
|
||||
func (e *Event) CheckCondition() bool { //Add error handling
|
||||
lastPrice := 0.00
|
||||
condition := common.SplitStrings(e.Condition, ",")
|
||||
targetPrice, _ := strconv.ParseFloat(condition[1], 64)
|
||||
@@ -167,7 +173,16 @@ func (e *Event) CheckCondition() bool {
|
||||
}
|
||||
|
||||
func IsValidEvent(Exchange, Item, Condition, Action string) error {
|
||||
if !IsValidExchange(Exchange) {
|
||||
Exchange = common.StringToUpper(Exchange)
|
||||
Item = common.StringToUpper(Item)
|
||||
Action = common.StringToUpper(Action)
|
||||
|
||||
configPath := ""
|
||||
if Action == ACTION_TEST {
|
||||
configPath = CONFIG_PATH_TEST
|
||||
}
|
||||
|
||||
if !IsValidExchange(Exchange, configPath) {
|
||||
return ErrExchangeDisabled
|
||||
}
|
||||
|
||||
@@ -196,7 +211,7 @@ func IsValidEvent(Exchange, Item, Condition, Action string) error {
|
||||
return ErrInvalidAction
|
||||
}
|
||||
} else {
|
||||
if Action != ACTION_CONSOLE_PRINT {
|
||||
if Action != ACTION_CONSOLE_PRINT && Action != ACTION_TEST {
|
||||
return ErrInvalidAction
|
||||
}
|
||||
}
|
||||
@@ -220,8 +235,27 @@ func CheckEvents() {
|
||||
}
|
||||
}
|
||||
|
||||
func IsValidExchange(Exchange string) bool {
|
||||
func IsValidCurrency(currencies ...string) bool {
|
||||
for _, whatIsIt := range currencies {
|
||||
whatIsIt = common.StringToUpper(whatIsIt)
|
||||
if currency.IsDefaultCryptocurrency(whatIsIt) {
|
||||
return true
|
||||
}
|
||||
if currency.IsDefaultCurrency(whatIsIt) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsValidExchange(Exchange, configPath string) bool {
|
||||
Exchange = common.StringToUpper(Exchange)
|
||||
|
||||
cfg := config.GetConfig()
|
||||
if len(cfg.Exchanges) == 0 {
|
||||
cfg.LoadConfig(configPath)
|
||||
}
|
||||
|
||||
for _, x := range cfg.Exchanges {
|
||||
if x.Name == Exchange && x.Enabled {
|
||||
return true
|
||||
@@ -239,14 +273,16 @@ func IsValidCondition(Condition string) bool {
|
||||
}
|
||||
|
||||
func IsValidAction(Action string) bool {
|
||||
Action = common.StringToUpper(Action)
|
||||
switch Action {
|
||||
case ACTION_SMS_NOTIFY, ACTION_CONSOLE_PRINT:
|
||||
case ACTION_SMS_NOTIFY, ACTION_CONSOLE_PRINT, ACTION_TEST:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsValidItem(Item string) bool {
|
||||
Item = common.StringToUpper(Item)
|
||||
switch Item {
|
||||
case ITEM_PRICE:
|
||||
return true
|
||||
|
||||
@@ -137,6 +137,10 @@ func (a *Alphapoint) GetProducts() (AlphapointProducts, error) {
|
||||
}
|
||||
|
||||
func (a *Alphapoint) CreateAccount(firstName, lastName, email, phone, password string) error {
|
||||
if len(password) < 8 {
|
||||
return errors.New("Alphapoint Error - Create account - Password must be 8 characters or more.")
|
||||
}
|
||||
|
||||
request := make(map[string]interface{})
|
||||
request["firstname"] = firstName
|
||||
request["lastname"] = lastName
|
||||
@@ -390,7 +394,6 @@ func (a *Alphapoint) SendRequest(method, path string, data map[string]interface{
|
||||
if err != nil {
|
||||
return errors.New("SendAuthenticatedHTTPRequest: Unable to JSON request")
|
||||
}
|
||||
|
||||
resp, err := common.SendHTTPRequest(method, path, headers, bytes.NewBuffer(PayloadJson))
|
||||
|
||||
if err != nil {
|
||||
|
||||
413
exchanges/alphapoint/alphapoint_test.go
Normal file
413
exchanges/alphapoint/alphapoint_test.go
Normal file
@@ -0,0 +1,413 @@
|
||||
package alphapoint
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSetDefaults(t *testing.T) {
|
||||
t.Parallel()
|
||||
SetDefaults := Alphapoint{}
|
||||
|
||||
SetDefaults.SetDefaults()
|
||||
if SetDefaults.APIUrl != "https://sim3.alphapoint.com:8400" {
|
||||
t.Error("Test Failed - SetDefaults: String Incorrect -", SetDefaults.APIUrl)
|
||||
}
|
||||
if SetDefaults.WebsocketURL != "wss://sim3.alphapoint.com:8401/v1/GetTicker/" {
|
||||
t.Error("Test Failed - SetDefaults: String Incorrect -", SetDefaults.WebsocketURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
GetTicker := Alphapoint{}
|
||||
GetTicker.SetDefaults()
|
||||
|
||||
response, err := GetTicker.GetTicker("BTCUSD")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Alphapoint GetTicker init error: ", err)
|
||||
}
|
||||
if reflect.ValueOf(response).NumField() != 13 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker struct change/or updated")
|
||||
}
|
||||
if reflect.TypeOf(response.Ask).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Ask value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.Bid).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Bid value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.BuyOrderCount).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.BuyOrderCount value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.High).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.High value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.IsAccepted).String() != "bool" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.IsAccepted value is not a bool")
|
||||
}
|
||||
if reflect.TypeOf(response.Last).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Last value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.Low).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Low value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.NumOfCreateOrders).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.NumOfCreateOrders value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.RejectReason).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.RejectReason value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(response.SellOrderCount).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.SellOrderCount value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.Total24HrNumTrades).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Total24HrNumTrades value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.Total24HrQtyTraded).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Total24HrQtyTraded value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(response.Volume).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Volume value is not a float64")
|
||||
}
|
||||
|
||||
if response.Ask < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Ask value is negative")
|
||||
}
|
||||
if response.Bid < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Bid value is negative")
|
||||
}
|
||||
if response.BuyOrderCount < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.High value is negative")
|
||||
}
|
||||
if response.High < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Last value is negative")
|
||||
}
|
||||
if response.Last < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Low value is negative")
|
||||
}
|
||||
if response.Low < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.Mid value is negative")
|
||||
}
|
||||
if response.NumOfCreateOrders < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
|
||||
}
|
||||
if response.SellOrderCount < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
|
||||
}
|
||||
if response.Total24HrNumTrades < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
|
||||
}
|
||||
if response.Total24HrQtyTraded < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
|
||||
}
|
||||
if response.Volume < 0 {
|
||||
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTrades(t *testing.T) {
|
||||
GetTrades := Alphapoint{}
|
||||
GetTrades.SetDefaults()
|
||||
|
||||
trades, err := GetTrades.GetTrades("BTCUSD", 0, 10)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Init error: %s", err)
|
||||
}
|
||||
if reflect.ValueOf(trades).NumField() != 7 {
|
||||
t.Error("Test Failed - Alphapoint AlphapointTrades struct updated/changed")
|
||||
}
|
||||
if len(trades.Trades) == 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades: Incorrect length")
|
||||
}
|
||||
if reflect.ValueOf(trades.Trades[0]).NumField() != 8 {
|
||||
t.Error("Test Failed - Alphapoint AlphapointTrades.Trades struct updated/changed")
|
||||
}
|
||||
if reflect.TypeOf(trades.Trades[0].BookServerOrderID).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is not a int")
|
||||
}
|
||||
if reflect.TypeOf(trades.Trades[0].IncomingOrderSide).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.IncomingOrderSide value is not a int")
|
||||
}
|
||||
if reflect.TypeOf(trades.Trades[0].IncomingServerOrderID).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.IncomingServerOrderID value is not a int")
|
||||
}
|
||||
if reflect.TypeOf(trades.Trades[0].Price).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.Price value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(trades.Trades[0].Quantity).String() != "float64" {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.Quantity value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(trades.Trades[0].TID).String() != "int64" {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.TID value is not a int64")
|
||||
}
|
||||
if reflect.TypeOf(trades.Trades[0].UTCTicks).String() != "int64" {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.UTCTicks value is not a int64")
|
||||
}
|
||||
if reflect.TypeOf(trades.Trades[0].Unixtime).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.Unixtime value is not a int")
|
||||
}
|
||||
if reflect.TypeOf(trades.Count).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint trades.Count value is not a int")
|
||||
}
|
||||
if reflect.TypeOf(trades.DateTimeUTC).String() != "int64" {
|
||||
t.Error("Test Failed - Alphapoint trades.DateTimeUTC value is not a int64")
|
||||
}
|
||||
if reflect.TypeOf(trades.Instrument).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint trades.Instrument value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(trades.IsAccepted).String() != "bool" {
|
||||
t.Error("Test Failed - Alphapoint trades.IsAccepted value is not a bool")
|
||||
}
|
||||
if reflect.TypeOf(trades.RejectReason).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint trades.string value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(trades.StartIndex).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint trades.Count value is not a int")
|
||||
}
|
||||
|
||||
if trades.Count < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Count value is negative")
|
||||
}
|
||||
if trades.DateTimeUTC <= 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.DateTimeUTC value is negative or 0")
|
||||
}
|
||||
if trades.Instrument != "BTCUSD" {
|
||||
t.Error("Test Failed - Alphapoint trades.Instrument value is incorrect")
|
||||
}
|
||||
if trades.IsAccepted != true {
|
||||
t.Error("Test Failed - Alphapoint trades.IsAccepted value is true")
|
||||
}
|
||||
if len(trades.RejectReason) > 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.IsAccepted value has been returned")
|
||||
}
|
||||
if trades.StartIndex != 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.StartIndex value is incorrect")
|
||||
}
|
||||
if trades.Trades[0].BookServerOrderID < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
|
||||
}
|
||||
if trades.Trades[0].IncomingOrderSide < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
|
||||
}
|
||||
if trades.Trades[0].IncomingServerOrderID < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
|
||||
}
|
||||
if trades.Trades[0].Price < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
|
||||
}
|
||||
if trades.Trades[0].Quantity < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
|
||||
}
|
||||
if trades.Trades[0].TID != 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
|
||||
}
|
||||
if trades.Trades[0].UTCTicks < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
|
||||
}
|
||||
if trades.Trades[0].Unixtime < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTradesByDate(t *testing.T) {
|
||||
GetTradesByDate := Alphapoint{}
|
||||
GetTradesByDate.SetDefaults()
|
||||
|
||||
trades, err := GetTradesByDate.GetTradesByDate("BTCUSD", 1414799400, 1414800000)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Init error: %s", err)
|
||||
}
|
||||
if reflect.ValueOf(trades).NumField() != 7 {
|
||||
t.Error("Test Failed - Alphapoint AlphapointTrades struct updated/changed")
|
||||
}
|
||||
if len(trades.Trades) != 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Trades: Incorrect length")
|
||||
}
|
||||
if reflect.TypeOf(trades.DateTimeUTC).String() != "int64" {
|
||||
t.Error("Test Failed - Alphapoint trades.Count value is not a int64")
|
||||
}
|
||||
if reflect.TypeOf(trades.EndDate).String() != "int64" {
|
||||
t.Error("Test Failed - Alphapoint trades.DateTimeUTC value is not a int64")
|
||||
}
|
||||
if reflect.TypeOf(trades.Instrument).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint trades.Instrument value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(trades.IsAccepted).String() != "bool" {
|
||||
t.Error("Test Failed - Alphapoint trades.IsAccepted value is not a bool")
|
||||
}
|
||||
if reflect.TypeOf(trades.RejectReason).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint trades.string value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(trades.StartDate).String() != "int64" {
|
||||
t.Error("Test Failed - Alphapoint trades.StartDate value is not a int64")
|
||||
}
|
||||
|
||||
if trades.DateTimeUTC < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.Count value is negative")
|
||||
}
|
||||
if trades.EndDate < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.DateTimeUTC value is negative")
|
||||
}
|
||||
if trades.Instrument != "BTCUSD" {
|
||||
t.Error("Test Failed - Alphapoint trades.Instrument value is incorrect")
|
||||
}
|
||||
if trades.IsAccepted != true {
|
||||
t.Error("Test Failed - Alphapoint trades.IsAccepted value is true")
|
||||
}
|
||||
if len(trades.RejectReason) > 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.IsAccepted value has been returned")
|
||||
}
|
||||
if trades.StartDate < 0 {
|
||||
t.Error("Test Failed - Alphapoint trades.StartIndex value is negative")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
GetOrderbook := Alphapoint{}
|
||||
GetOrderbook.SetDefaults()
|
||||
|
||||
orderBook, err := GetOrderbook.GetOrderbook("BTCUSD")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Init error: %s", err)
|
||||
}
|
||||
if reflect.ValueOf(orderBook).NumField() != 4 {
|
||||
t.Error("Test Failed - Alphapoint AlphapointOrderbook struct updated/changed")
|
||||
}
|
||||
if reflect.TypeOf(orderBook.IsAccepted).String() != "bool" {
|
||||
t.Error("Test Failed - Alphapoint orderBook.IsAccepted value is not a bool")
|
||||
}
|
||||
if reflect.TypeOf(orderBook.RejectReason).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint orderBook.RejectReason value is not a string")
|
||||
}
|
||||
if len(orderBook.Asks) < 1 {
|
||||
t.Error("Test Failed - Alphapoint orderBook.Asks does not contain anything.")
|
||||
}
|
||||
if len(orderBook.Bids) < 1 {
|
||||
t.Error("Test Failed - Alphapoint orderBook.Asks does not contain anything.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetProductPairs(t *testing.T) {
|
||||
GetProductPairs := Alphapoint{}
|
||||
GetProductPairs.SetDefaults()
|
||||
|
||||
productPairs, err := GetProductPairs.GetProductPairs()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Init error: %s", err)
|
||||
}
|
||||
if reflect.ValueOf(productPairs).NumField() != 3 {
|
||||
t.Error("Test Failed - Alphapoint GetProductPairs struct updated/changed")
|
||||
}
|
||||
if reflect.TypeOf(productPairs.IsAccepted).String() != "bool" {
|
||||
t.Error("Test Failed - Alphapoint productPairs.IsAccepted value is not a bool")
|
||||
}
|
||||
if reflect.TypeOf(productPairs.RejectReason).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint productPairs.RejectReason value is not a string")
|
||||
}
|
||||
|
||||
if len(productPairs.ProductPairs) >= 1 {
|
||||
if reflect.ValueOf(productPairs.ProductPairs[0]).NumField() != 6 {
|
||||
t.Error("Test Failed - Alphapoint GetProductPairs.ProductPairs[] struct updated/changed")
|
||||
}
|
||||
if reflect.TypeOf(productPairs.ProductPairs[0].Name).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Name value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(productPairs.ProductPairs[0].Product1Decimalplaces).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product1Decimalplaces value is not a int")
|
||||
}
|
||||
if reflect.TypeOf(productPairs.ProductPairs[0].Product1Label).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product1Label value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(productPairs.ProductPairs[0].Product2Decimalplaces).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product2Decimalplaces value is not a int")
|
||||
}
|
||||
if reflect.TypeOf(productPairs.ProductPairs[0].Product2Label).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product2Label value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(productPairs.ProductPairs[0].Productpaircode).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Productpaircode value is not a int")
|
||||
}
|
||||
|
||||
if productPairs.ProductPairs[0].Product1Decimalplaces < 0 {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product1Decimalplaces value is negative")
|
||||
}
|
||||
if productPairs.ProductPairs[0].Product2Decimalplaces < 0 {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product2Decimalplaces value is negative")
|
||||
}
|
||||
if productPairs.ProductPairs[0].Productpaircode < 0 {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Productpaircode value is negative")
|
||||
}
|
||||
} else {
|
||||
t.Error("Test Failed - Alphapoint productPairs.ProductPairs no product pairs.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetProducts(t *testing.T) {
|
||||
GetProducts := Alphapoint{}
|
||||
GetProducts.SetDefaults()
|
||||
|
||||
products, err := GetProducts.GetProducts()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Init error: %s", err)
|
||||
}
|
||||
if reflect.ValueOf(products).NumField() != 3 {
|
||||
t.Error("Test Failed - Alphapoint GetProductPairs struct updated/changed")
|
||||
}
|
||||
if reflect.TypeOf(products.IsAccepted).String() != "bool" {
|
||||
t.Error("Test Failed - Alphapoint products.IsAccepted value is not a bool")
|
||||
}
|
||||
if reflect.TypeOf(products.RejectReason).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint products.RejectReason value is not a string")
|
||||
}
|
||||
|
||||
if len(products.Products) >= 1 {
|
||||
if reflect.ValueOf(products.Products[0]).NumField() != 5 {
|
||||
t.Error("Test Failed - Alphapoint Getproducts.Products[] struct updated/changed")
|
||||
}
|
||||
if reflect.TypeOf(products.Products[0].DecimalPlaces).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint products.Products.DecimalPlaces value is not a int")
|
||||
}
|
||||
if reflect.TypeOf(products.Products[0].FullName).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint products.Products.FullName value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(products.Products[0].IsDigital).String() != "bool" {
|
||||
t.Error("Test Failed - Alphapoint products.Products.IsDigital value is not a bool")
|
||||
}
|
||||
if reflect.TypeOf(products.Products[0].Name).String() != "string" {
|
||||
t.Error("Test Failed - Alphapoint products.Products.Name value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(products.Products[0].ProductCode).String() != "int" {
|
||||
t.Error("Test Failed - Alphapoint products.Products.ProductCode value is not a int")
|
||||
}
|
||||
|
||||
if products.Products[0].DecimalPlaces < 0 {
|
||||
t.Error("Test Failed - Alphapoint products.Products.DecimalPlaces value is negative")
|
||||
}
|
||||
if products.Products[0].ProductCode < 0 {
|
||||
t.Log(products.Products[0].ProductCode)
|
||||
t.Error("Test Failed - Alphapoint products.Products.ProductCode value is negative")
|
||||
}
|
||||
} else {
|
||||
t.Error("Test Failed - Alphapoint products.Products no product pairs.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateAccount(t *testing.T) {
|
||||
CreateAccount := Alphapoint{}
|
||||
CreateAccount.SetDefaults()
|
||||
|
||||
err := CreateAccount.CreateAccount("test", "account", "something@something.com", "0292383745", "lolcat123")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Init error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUserInfo(t *testing.T) {
|
||||
GetUserInfo := Alphapoint{}
|
||||
GetUserInfo.SetDefaults()
|
||||
|
||||
userInfo, err := GetUserInfo.GetUserInfo()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Init error: %s", err)
|
||||
}
|
||||
t.Log(userInfo)
|
||||
}
|
||||
@@ -61,9 +61,8 @@ func (a *ANX) Setup(exch config.ExchangeConfig) {
|
||||
func (a *ANX) GetFee(maker bool) float64 {
|
||||
if maker {
|
||||
return a.MakerFee
|
||||
} else {
|
||||
return a.TakerFee
|
||||
}
|
||||
return a.TakerFee
|
||||
}
|
||||
|
||||
func (a *ANX) GetTicker(currency string) (ANXTicker, error) {
|
||||
@@ -75,7 +74,7 @@ func (a *ANX) GetTicker(currency string) (ANXTicker, error) {
|
||||
return ticker, nil
|
||||
}
|
||||
|
||||
func (a *ANX) GetAPIKey(username, password, otp, deviceID string) (string, string) {
|
||||
func (a *ANX) GetAPIKey(username, password, otp, deviceID string) (string, string, error) {
|
||||
request := make(map[string]interface{})
|
||||
request["nonce"] = strconv.FormatInt(time.Now().UnixNano(), 10)[0:13]
|
||||
request["username"] = username
|
||||
@@ -96,21 +95,18 @@ func (a *ANX) GetAPIKey(username, password, otp, deviceID string) (string, strin
|
||||
var response APIKeyResponse
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(ANX_APIKEY, request, &response)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return "", ""
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
||||
return "", ""
|
||||
return "", "", errors.New("Response code is not OK: " + response.ResultCode)
|
||||
}
|
||||
|
||||
return response.APIKey, response.APISecret
|
||||
return response.APIKey, response.APISecret, nil
|
||||
}
|
||||
|
||||
func (a *ANX) GetDataToken() string {
|
||||
func (a *ANX) GetDataToken() (string, error) {
|
||||
request := make(map[string]interface{})
|
||||
|
||||
type DataTokenResponse struct {
|
||||
@@ -122,22 +118,18 @@ func (a *ANX) GetDataToken() string {
|
||||
var response DataTokenResponse
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(ANX_DATA_TOKEN, request, &response)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return ""
|
||||
return "", err
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
||||
return ""
|
||||
return "", errors.New("Response code is not OK: %s" + response.ResultCode)
|
||||
}
|
||||
|
||||
return response.Token
|
||||
return response.Token, nil
|
||||
}
|
||||
|
||||
func (a *ANX) NewOrder(orderType string, buy bool, tradedCurrency, tradedCurrencyAmount, settlementCurrency, settlementCurrencyAmount, limitPriceSettlement string,
|
||||
replace bool, replaceUUID string, replaceIfActive bool) {
|
||||
replace bool, replaceUUID string, replaceIfActive bool) error {
|
||||
request := make(map[string]interface{})
|
||||
|
||||
var order ANXOrder
|
||||
@@ -169,16 +161,14 @@ func (a *ANX) NewOrder(orderType string, buy bool, tradedCurrency, tradedCurrenc
|
||||
var response OrderResponse
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(ANX_ORDER_NEW, request, &response)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
||||
return
|
||||
return errors.New("Response code is not OK: %s" + response.ResultCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *ANX) OrderInfo(orderID string) (ANXOrderResponse, error) {
|
||||
@@ -295,7 +285,7 @@ func (a *ANX) GetDepositAddress(currency, name string, new bool) (string, error)
|
||||
return response.Address, nil
|
||||
}
|
||||
|
||||
func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interface{}, result interface{}) (err error) {
|
||||
func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interface{}, result interface{}) error {
|
||||
request := make(map[string]interface{})
|
||||
request["nonce"] = strconv.FormatInt(time.Now().UnixNano(), 10)[0:13]
|
||||
path = fmt.Sprintf("api/%s/%s", ANX_API_VERSION, path)
|
||||
|
||||
146
exchanges/anx/anx_test.go
Normal file
146
exchanges/anx/anx_test.go
Normal file
@@ -0,0 +1,146 @@
|
||||
package anx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
)
|
||||
|
||||
func TestSetDefaults(t *testing.T) {
|
||||
setDefaults := ANX{}
|
||||
setDefaults.SetDefaults()
|
||||
|
||||
if setDefaults.Name != "ANX" {
|
||||
t.Error("Test Failed - ANX SetDefaults() incorrect values set")
|
||||
}
|
||||
if setDefaults.Enabled != false {
|
||||
t.Error("Test Failed - ANX SetDefaults() incorrect values set")
|
||||
}
|
||||
if setDefaults.TakerFee != 0.6 {
|
||||
t.Error("Test Failed - ANX SetDefaults() incorrect values set")
|
||||
}
|
||||
if setDefaults.MakerFee != 0.3 {
|
||||
t.Error("Test Failed - ANX SetDefaults() incorrect values set")
|
||||
}
|
||||
if setDefaults.Verbose != false {
|
||||
t.Error("Test Failed - ANX SetDefaults() incorrect values set")
|
||||
}
|
||||
if setDefaults.Websocket != false {
|
||||
t.Error("Test Failed - ANX SetDefaults() incorrect values set")
|
||||
}
|
||||
if setDefaults.RESTPollingDelay != 10 {
|
||||
t.Error("Test Failed - ANX SetDefaults() incorrect values set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
setup := ANX{}
|
||||
anxSetupConfig := config.GetConfig()
|
||||
anxSetupConfig.LoadConfig("../../testdata/configtest.dat")
|
||||
anxConfig, err := anxSetupConfig.GetExchangeConfig("ANX")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - ANX Setup() init error")
|
||||
}
|
||||
setup.Setup(anxConfig)
|
||||
|
||||
if setup.Enabled != true {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if setup.AuthenticatedAPISupport != false {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if len(setup.APIKey) <= 0 {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if len(setup.APISecret) != 0 {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if setup.RESTPollingDelay != 10 {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if setup.Verbose != false {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if setup.Websocket != false {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if len(setup.BaseCurrencies) <= 0 {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if len(setup.AvailablePairs) <= 0 {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
if len(setup.EnabledPairs) <= 0 {
|
||||
t.Error("Test Failed - ANX Setup() incorrect values set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
getFee := ANX{}
|
||||
makerFeeExpected, takerFeeExpected := 0.3, 0.6
|
||||
|
||||
getFee.SetDefaults()
|
||||
if getFee.GetFee(true) != makerFeeExpected {
|
||||
t.Error("Test Failed - ANX GetFee() incorrect return value")
|
||||
}
|
||||
if getFee.GetFee(false) != takerFeeExpected {
|
||||
t.Error("Test Failed - ANX GetFee() incorrect return value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
getTicker := ANX{}
|
||||
ticker, err := getTicker.GetTicker("BTCUSD")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - ANX GetTicker() error: %s", err)
|
||||
}
|
||||
if ticker.Result != "success" {
|
||||
t.Error("Test Failed - ANX GetTicker() unsuccessful")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAPIKey(t *testing.T) {
|
||||
getAPIKey := ANX{}
|
||||
apiKey, apiSecret, err := getAPIKey.GetAPIKey("userName", "passWord", "", "1337")
|
||||
if err == nil {
|
||||
t.Error("Test Failed - ANX GetAPIKey() Incorrect")
|
||||
}
|
||||
if apiKey != "" {
|
||||
t.Error("Test Failed - ANX GetAPIKey() Incorrect")
|
||||
}
|
||||
if apiSecret != "" {
|
||||
t.Error("Test Failed - ANX GetAPIKey() Incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDataToken(t *testing.T) {
|
||||
getDataToken := ANX{}
|
||||
_, err := getDataToken.GetDataToken()
|
||||
if err != nil {
|
||||
t.Error("Test Failed - ANX GetDataToken() Incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewOrder(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestOrderInfo(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestSend(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestCreateNewSubAccount(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestSendAuthenticatedHTTPRequest(t *testing.T) {
|
||||
|
||||
}
|
||||
25
exchanges/anx/anx_wrapper_test.go
Normal file
25
exchanges/anx/anx_wrapper_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package anx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestRun(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestGetTickerPrice(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestGetOrderbookEx(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestGetExchangeAccountInfo(t *testing.T) {
|
||||
|
||||
}
|
||||
@@ -95,8 +95,8 @@ func (b *Bitfinex) GetTicker(symbol string, values url.Values) (BitfinexTicker,
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (b *Bitfinex) GetStats(symbol string) (BitfinexStats, error) {
|
||||
response := BitfinexStats{}
|
||||
func (b *Bitfinex) GetStats(symbol string) ([]BitfinexStats, error) {
|
||||
response := []BitfinexStats{}
|
||||
err := common.SendHTTPGetRequest(BITFINEX_API_URL+BITFINEX_STATS+symbol, true, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
@@ -105,6 +105,9 @@ func (b *Bitfinex) GetStats(symbol string) (BitfinexStats, error) {
|
||||
}
|
||||
|
||||
func (b *Bitfinex) GetLendbook(symbol string, values url.Values) (BitfinexLendbook, error) {
|
||||
if len(symbol) == 6 {
|
||||
symbol = symbol[:3]
|
||||
}
|
||||
path := common.EncodeURLValues(BITFINEX_API_URL+BITFINEX_LENDBOOK+symbol, values)
|
||||
response := BitfinexLendbook{}
|
||||
err := common.SendHTTPGetRequest(path, true, &response)
|
||||
@@ -167,7 +170,7 @@ func (b *Bitfinex) GetAccountInfo() ([]BitfinexAccountInfo, error) {
|
||||
err := b.SendAuthenticatedHTTPRequest("POST", BITFINEX_ACCOUNT_INFO, nil, &response)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return response, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
@@ -243,7 +246,7 @@ func (b *Bitfinex) CancelOrder(OrderID int64) (BitfinexOrder, error) {
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (b *Bitfinex) CancelMultiplateOrders(OrderIDs []int64) (string, error) {
|
||||
func (b *Bitfinex) CancelMultipleOrders(OrderIDs []int64) (string, error) {
|
||||
request := make(map[string]interface{})
|
||||
request["order_ids"] = OrderIDs
|
||||
response := BitfinexGenericResponse{}
|
||||
@@ -534,7 +537,6 @@ func (b *Bitfinex) CloseMarginFunding(SwapID int64) (BitfinexOffer, error) {
|
||||
func (b *Bitfinex) GetAccountBalance() ([]BitfinexBalance, error) {
|
||||
response := []BitfinexBalance{}
|
||||
err := b.SendAuthenticatedHTTPRequest("POST", BITFINEX_BALANCES, nil, &response)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -586,7 +588,11 @@ func (b *Bitfinex) Withdrawal(withdrawType, wallet, address string, amount float
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[string]interface{}, result interface{}) (err error) {
|
||||
func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[string]interface{}, result interface{}) error {
|
||||
if len(b.APIKey) == 0 {
|
||||
return errors.New("SendAuthenticatedHTTPRequest: Invalid API key")
|
||||
}
|
||||
|
||||
request := make(map[string]interface{})
|
||||
request["request"] = fmt.Sprintf("/v%s/%s", BITFINEX_API_VERSION, path)
|
||||
request["nonce"] = strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||
@@ -598,7 +604,6 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[
|
||||
}
|
||||
|
||||
PayloadJson, err := common.JSONEncode(request)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("SendAuthenticatedHTTPRequest: Unable to JSON request")
|
||||
}
|
||||
@@ -615,15 +620,21 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[
|
||||
headers["X-BFX-SIGNATURE"] = common.HexEncodeToString(hmac)
|
||||
|
||||
resp, err := common.SendHTTPRequest(method, BITFINEX_API_URL+path, headers, strings.NewReader(""))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.Contains(resp, "message") {
|
||||
return errors.New("SendAuthenticatedHTTPRequest: " + resp[11:])
|
||||
}
|
||||
|
||||
if b.Verbose {
|
||||
log.Printf("Recieved raw: \n%s\n", resp)
|
||||
}
|
||||
|
||||
err = common.JSONDecode([]byte(resp), &result)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("Unable to JSON Unmarshal response.")
|
||||
return errors.New("SendAuthenticatedHTTPRequest: Unable to JSON Unmarshal response.")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
1565
exchanges/bitfinex/bitfinex_test.go
Normal file
1565
exchanges/bitfinex/bitfinex_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -83,7 +83,7 @@ type BitfinexOffer struct {
|
||||
IsCancelled bool `json:"is_cancelled"`
|
||||
OriginalAmount float64 `json:"original_amount,string"`
|
||||
RemainingAmount float64 `json:"remaining_amount,string"`
|
||||
ExecutedAmount float64 `json:"remaining_amount,string"`
|
||||
ExecutedAmount float64 `json:"executed_amount,string"`
|
||||
}
|
||||
|
||||
type BitfinexBookStructure struct {
|
||||
|
||||
@@ -12,20 +12,28 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
BITFINEX_WEBSOCKET = "wss://api2.bitfinex.com:3000/ws"
|
||||
BITFINEX_WEBSOCKET_VERSION = "1.1"
|
||||
BITFINEX_WEBSOCKET_POSITION_SNAPSHOT = "ps"
|
||||
BITFINEX_WEBSOCKET_POSITION_NEW = "pn"
|
||||
BITFINEX_WEBSOCKET_POSITION_UPDATE = "pu"
|
||||
BITFINEX_WEBSOCKET_POSITION_CLOSE = "pc"
|
||||
BITFINEX_WEBSOCKET_WALLET_SNAPSHOT = "ws"
|
||||
BITFINEX_WEBSOCKET_WALLET_UPDATE = "wu"
|
||||
BITFINEX_WEBSOCKET_ORDER_SNAPSHOT = "os"
|
||||
BITFINEX_WEBSOCKET_ORDER_NEW = "on"
|
||||
BITFINEX_WEBSOCKET_ORDER_UPDATE = "ou"
|
||||
BITFINEX_WEBSOCKET_ORDER_CANCEL = "oc"
|
||||
BITFINEX_WEBSOCKET_TRADE_EXECUTED = "te"
|
||||
BITFINEX_WEBSOCKET_HEARTBEAT = "hb"
|
||||
BITFINEX_WEBSOCKET = "wss://api.bitfinex.com/ws"
|
||||
BITFINEX_WEBSOCKET_VERSION = "1.1"
|
||||
BITFINEX_WEBSOCKET_POSITION_SNAPSHOT = "ps"
|
||||
BITFINEX_WEBSOCKET_POSITION_NEW = "pn"
|
||||
BITFINEX_WEBSOCKET_POSITION_UPDATE = "pu"
|
||||
BITFINEX_WEBSOCKET_POSITION_CLOSE = "pc"
|
||||
BITFINEX_WEBSOCKET_WALLET_SNAPSHOT = "ws"
|
||||
BITFINEX_WEBSOCKET_WALLET_UPDATE = "wu"
|
||||
BITFINEX_WEBSOCKET_ORDER_SNAPSHOT = "os"
|
||||
BITFINEX_WEBSOCKET_ORDER_NEW = "on"
|
||||
BITFINEX_WEBSOCKET_ORDER_UPDATE = "ou"
|
||||
BITFINEX_WEBSOCKET_ORDER_CANCEL = "oc"
|
||||
BITFINEX_WEBSOCKET_TRADE_EXECUTED = "te"
|
||||
BITFINEX_WEBSOCKET_HEARTBEAT = "hb"
|
||||
BITFINEX_WEBSOCKET_ALERT_RESTARTING = "20051"
|
||||
BITFINEX_WEBSOCKET_ALERT_REFRESHING = "20060"
|
||||
BITFINEX_WEBSOCKET_ALERT_RESUME = "20061"
|
||||
BITFINEX_WEBSOCKET_UNKNOWN_EVENT = "10000"
|
||||
BITFINEX_WEBSOCKET_UNKNOWN_PAIR = "10001"
|
||||
BITFINEX_WEBSOCKET_SUBSCRIPTION_FAILED = "10300"
|
||||
BITFINEX_WEBSOCKET_ALREADY_SUBSCRIBED = "10301"
|
||||
BITFINEX_WEBSOCKET_UNKNOWN_CHANNEL = "10302"
|
||||
)
|
||||
|
||||
func (b *Bitfinex) WebsocketPingHandler() error {
|
||||
@@ -48,7 +56,7 @@ func (b *Bitfinex) WebsocketSend(data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Bitfinex) WebsocketSubscribe(channel string, params map[string]string) {
|
||||
func (b *Bitfinex) WebsocketSubscribe(channel string, params map[string]string) error {
|
||||
request := make(map[string]string)
|
||||
request["event"] = "subscribe"
|
||||
request["channel"] = channel
|
||||
@@ -58,8 +66,7 @@ func (b *Bitfinex) WebsocketSubscribe(channel string, params map[string]string)
|
||||
request[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
b.WebsocketSend(request)
|
||||
return b.WebsocketSend(request)
|
||||
}
|
||||
|
||||
func (b *Bitfinex) WebsocketSendAuth() error {
|
||||
|
||||
232
exchanges/bitfinex/bitfinex_websocket_test.go
Normal file
232
exchanges/bitfinex/bitfinex_websocket_test.go
Normal file
@@ -0,0 +1,232 @@
|
||||
package bitfinex
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
)
|
||||
|
||||
func TestWebsocketPingHandler(t *testing.T) {
|
||||
wsPingHandler := Bitfinex{}
|
||||
var Dialer websocket.Dialer
|
||||
var err error
|
||||
|
||||
wsPingHandler.WebsocketConn, _, err = Dialer.Dial(BITFINEX_WEBSOCKET, http.Header{})
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex dialer error: %s", err)
|
||||
}
|
||||
err = wsPingHandler.WebsocketPingHandler()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex WebsocketPingHandler() error: %s", err)
|
||||
}
|
||||
err = wsPingHandler.WebsocketConn.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocketConn.Close() error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebsocketSend(t *testing.T) {
|
||||
wsSend := Bitfinex{}
|
||||
var Dialer websocket.Dialer
|
||||
var err error
|
||||
|
||||
type WebsocketHandshake struct {
|
||||
Event string `json:"event"`
|
||||
Code int64 `json:"code"`
|
||||
Version float64 `json:"version"`
|
||||
}
|
||||
|
||||
request, dodgyrequest := make(map[string]string), make(map[string]string)
|
||||
request["event"] = "ping"
|
||||
dodgyrequest["dodgyEvent"] = "didgereedodge"
|
||||
|
||||
hs := WebsocketHandshake{}
|
||||
|
||||
for {
|
||||
wsSend.WebsocketConn, _, err = Dialer.Dial(BITFINEX_WEBSOCKET, http.Header{})
|
||||
if err != nil {
|
||||
if err.Error() == "websocket: close 1006 (abnormal closure): unexpected EOF" {
|
||||
err = wsSend.WebsocketConn.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocketConn.Close() error: %s", err)
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
t.Errorf("Test Failed - Bitfinex websocket connection error: %s", err)
|
||||
}
|
||||
}
|
||||
mType, resp, err := wsSend.WebsocketConn.ReadMessage()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocketconn.ReadMessage() error: %s", err)
|
||||
}
|
||||
if mType != websocket.TextMessage {
|
||||
t.Errorf("Test Failed - Bitfinex websocketconn.ReadMessage() mType error: %d", mType)
|
||||
}
|
||||
err = common.JSONDecode(resp, &hs)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex JSONDecode error: %s", err)
|
||||
}
|
||||
if hs.Code != 0 {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Code incorrect: %d", hs.Code)
|
||||
}
|
||||
if hs.Event != "info" {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Event incorrect: %s", hs.Event)
|
||||
}
|
||||
if hs.Version != 1.1 {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Version incorrect: %f", hs.Version)
|
||||
}
|
||||
|
||||
err = wsSend.WebsocketSend(request)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocket send error: %s", err)
|
||||
}
|
||||
mType, resp, err = wsSend.WebsocketConn.ReadMessage()
|
||||
if err != nil {
|
||||
if err.Error() == "websocket: close 1006 (abnormal closure): unexpected EOF" {
|
||||
err = wsSend.WebsocketConn.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocketConn.Close() error: %s", err)
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
t.Errorf("Test Failed - Bitfinex websocketConn.ReadMessage() error: %s", err)
|
||||
}
|
||||
}
|
||||
if mType != websocket.TextMessage {
|
||||
t.Errorf("Test Failed - Bitfinex websocketconn.ReadMessage() mType error: %d", mType)
|
||||
}
|
||||
err = common.JSONDecode(resp, &hs)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex JSONDecode error: %s", err)
|
||||
}
|
||||
if hs.Code != 0 {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Code incorrect: %d", hs.Code)
|
||||
}
|
||||
if hs.Event != "pong" {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Event incorrect: %s", hs.Event)
|
||||
}
|
||||
if hs.Version != 1.1 {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Version incorrect: %f", hs.Version)
|
||||
}
|
||||
|
||||
err = wsSend.WebsocketSend(dodgyrequest)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocket send error: %s", err)
|
||||
}
|
||||
mType, resp, err = wsSend.WebsocketConn.ReadMessage()
|
||||
if err != nil {
|
||||
if err.Error() == "websocket: close 1006 (abnormal closure): unexpected EOF" {
|
||||
err = wsSend.WebsocketConn.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocketConn.Close() error: %s", err)
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
t.Errorf("Test Failed - Bitfinex websocketConn.ReadMessage() error: %s", err)
|
||||
}
|
||||
}
|
||||
if mType != websocket.TextMessage {
|
||||
t.Errorf("Test Failed - Bitfinex websocketconn.ReadMessage() mType error: %d", mType)
|
||||
}
|
||||
err = common.JSONDecode(resp, &hs)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex JSONDecode error: %s", err)
|
||||
}
|
||||
if hs.Code != 10000 {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Code incorrect: %d", hs.Code)
|
||||
}
|
||||
if hs.Event != "error" {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Event incorrect: %s", hs.Event)
|
||||
}
|
||||
if hs.Version != 1.1 {
|
||||
t.Errorf("Test Failed - Bitfinex hs.Version incorrect: %f", hs.Version)
|
||||
}
|
||||
|
||||
err = wsSend.WebsocketConn.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocketConn.Close() error: %s", err)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebsocketSubscribe(t *testing.T) {
|
||||
websocketSubcribe := Bitfinex{}
|
||||
var Dialer websocket.Dialer
|
||||
var err error
|
||||
params := make(map[string]string)
|
||||
params["pair"] = "BTCUSD"
|
||||
|
||||
websocketSubcribe.WebsocketConn, _, err = Dialer.Dial(BITFINEX_WEBSOCKET, http.Header{})
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex Dialer error: %s", err)
|
||||
}
|
||||
err = websocketSubcribe.WebsocketSubscribe("ticker", params)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex WebsocketSubscribe() error: %s", err)
|
||||
}
|
||||
|
||||
err = websocketSubcribe.WebsocketConn.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex websocketConn.Close() error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebsocketSendAuth(t *testing.T) {
|
||||
wsSendAuth := Bitfinex{}
|
||||
var Dialer websocket.Dialer
|
||||
var err error
|
||||
|
||||
wsSendAuth.WebsocketConn, _, err = Dialer.Dial(BITFINEX_WEBSOCKET, http.Header{})
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex Dialer error: %s", err)
|
||||
}
|
||||
err = wsSendAuth.WebsocketSendAuth()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex WebsocketSendAuth() error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebsocketSendUnauth(t *testing.T) {
|
||||
wsSendUnauth := Bitfinex{}
|
||||
var Dialer websocket.Dialer
|
||||
var err error
|
||||
|
||||
wsSendUnauth.WebsocketConn, _, err = Dialer.Dial(BITFINEX_WEBSOCKET, http.Header{})
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex Dialer error: %s", err)
|
||||
}
|
||||
err = wsSendUnauth.WebsocketSendUnauth()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex WebsocketSendAuth() error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebsocketAddSubscriptionChannel(t *testing.T) {
|
||||
wsAddSubscriptionChannel := Bitfinex{}
|
||||
wsAddSubscriptionChannel.SetDefaults()
|
||||
var Dialer websocket.Dialer
|
||||
var err error
|
||||
|
||||
wsAddSubscriptionChannel.WebsocketConn, _, err = Dialer.Dial(BITFINEX_WEBSOCKET, http.Header{})
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex Dialer error: %s", err)
|
||||
}
|
||||
|
||||
wsAddSubscriptionChannel.WebsocketAddSubscriptionChannel(1337, "ticker", "BTCUSD")
|
||||
if len(wsAddSubscriptionChannel.WebsocketSubdChannels) == 0 {
|
||||
t.Errorf("Test Failed - Bitfinex WebsocketAddSubscriptionChannel() error: %s", err)
|
||||
}
|
||||
if wsAddSubscriptionChannel.WebsocketSubdChannels[1337].Channel != "ticker" {
|
||||
t.Errorf("Test Failed - Bitfinex WebsocketAddSubscriptionChannel() error: %s", err)
|
||||
}
|
||||
if wsAddSubscriptionChannel.WebsocketSubdChannels[1337].Pair != "BTCUSD" {
|
||||
t.Errorf("Test Failed - Bitfinex WebsocketAddSubscriptionChannel() error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// func TestWebsocketClient(t *testing.T) {
|
||||
//
|
||||
// }
|
||||
48
exchanges/bitfinex/bitfinex_wrapper_test.go
Normal file
48
exchanges/bitfinex/bitfinex_wrapper_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package bitfinex
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
)
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
start := Bitfinex{}
|
||||
start.Start()
|
||||
}
|
||||
|
||||
func TestRun(t *testing.T) {
|
||||
run := Bitfinex{}
|
||||
run.Run()
|
||||
}
|
||||
|
||||
func TestGetTickerPrice(t *testing.T) {
|
||||
getTickerPrice := Bitfinex{}
|
||||
_, err := getTickerPrice.GetTickerPrice("BTCUSD")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex GetTickerPrice() error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderbookEx(t *testing.T) {
|
||||
getOrderBookEx := Bitfinex{}
|
||||
_, err := getOrderBookEx.GetOrderbookEx("BTCUSD")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex GetOrderbookEx() error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetExchangeAccountInfo(t *testing.T) {
|
||||
getExchangeAccountInfo := Bitfinex{}
|
||||
newConfig := config.GetConfig()
|
||||
newConfig.LoadConfig("../../testdata/configtest.dat")
|
||||
exchConf, err := newConfig.GetExchangeConfig("Bitfinex")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex getExchangeConfig(): %s", err)
|
||||
}
|
||||
getExchangeAccountInfo.Setup(exchConf)
|
||||
_, err = getExchangeAccountInfo.GetExchangeAccountInfo()
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex GetExchangeAccountInfo() error: %s", err)
|
||||
}
|
||||
}
|
||||
86
exchanges/exchange_test.go
Normal file
86
exchanges/exchange_test.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
)
|
||||
|
||||
func TestGetName(t *testing.T) {
|
||||
GetName := ExchangeBase{
|
||||
Name: "TESTNAME",
|
||||
}
|
||||
|
||||
name := GetName.GetName()
|
||||
if name != "TESTNAME" {
|
||||
t.Error("Test Failed - Exchange getName() returned incorrect name")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEnabledCurrencies(t *testing.T) {
|
||||
enabledPairs := []string{"BTCUSD", "BTCAUD", "LTCUSD", "LTCAUD"}
|
||||
GetEnabledCurrencies := ExchangeBase{
|
||||
Name: "TESTNAME",
|
||||
EnabledPairs: enabledPairs,
|
||||
}
|
||||
|
||||
enCurr := GetEnabledCurrencies.GetEnabledCurrencies()
|
||||
if enCurr[0] != "BTCUSD" {
|
||||
t.Error("Test Failed - Exchange GetEnabledCurrencies() incorrect string")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetEnabled(t *testing.T) {
|
||||
SetEnabled := ExchangeBase{
|
||||
Name: "TESTNAME",
|
||||
Enabled: false,
|
||||
}
|
||||
|
||||
SetEnabled.SetEnabled(true)
|
||||
if !SetEnabled.Enabled {
|
||||
t.Error("Test Failed - Exchange SetEnabled(true) did not set boolean")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsEnabled(t *testing.T) {
|
||||
IsEnabled := ExchangeBase{
|
||||
Name: "TESTNAME",
|
||||
Enabled: false,
|
||||
}
|
||||
|
||||
if IsEnabled.IsEnabled() {
|
||||
t.Error("Test Failed - Exchange IsEnabled() did not return correct boolean")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetAPIKeys(t *testing.T) {
|
||||
SetAPIKeys := ExchangeBase{
|
||||
Name: "TESTNAME",
|
||||
Enabled: false,
|
||||
}
|
||||
|
||||
SetAPIKeys.SetAPIKeys("RocketMan", "Digereedoo", "007", false)
|
||||
|
||||
if SetAPIKeys.APIKey != "RocketMan" && SetAPIKeys.APISecret != "Digereedoo" && SetAPIKeys.ClientID != "007" {
|
||||
t.Error("Test Failed - Exchange SetAPIKeys() did not set correct values")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestUpdateAvailableCurrencies(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Log("SOMETHING DONE HAPPENED!")
|
||||
}
|
||||
|
||||
UAC := ExchangeBase{
|
||||
Name: "ANX",
|
||||
}
|
||||
exchangeProducts := []string{"ltc", "btc", "usd", "aud"}
|
||||
|
||||
err2 := UAC.UpdateAvailableCurrencies(exchangeProducts)
|
||||
if err2 != nil {
|
||||
t.Errorf("Test Failed - Exchange UpdateAvailableCurrencies() error: %s", err2)
|
||||
}
|
||||
}
|
||||
@@ -45,21 +45,22 @@ func (this ByVolume) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func AddExchangeInfo(exchange, crypto, fiat string, price, volume float64) {
|
||||
if currency.BaseCurrencies == "" {
|
||||
currency.BaseCurrencies = currency.DEFAULT_CURRENCIES
|
||||
}
|
||||
|
||||
if !currency.IsFiatCurrency(fiat) {
|
||||
return
|
||||
}
|
||||
if len(ExchInfo) == 0 {
|
||||
AppendExchangeInfo(exchange, crypto, fiat, price, volume)
|
||||
} else {
|
||||
if ExchangeInfoAlreadyExists(exchange, crypto, fiat, price, volume) {
|
||||
return
|
||||
} else {
|
||||
AppendExchangeInfo(exchange, crypto, fiat, price, volume)
|
||||
}
|
||||
}
|
||||
AppendExchangeInfo(exchange, crypto, fiat, price, volume)
|
||||
|
||||
}
|
||||
|
||||
func AppendExchangeInfo(exchange, crypto, fiat string, price, volume float64) {
|
||||
if ExchangeInfoAlreadyExists(exchange, crypto, fiat, price, volume) {
|
||||
return
|
||||
}
|
||||
|
||||
exch := ExchangeInfo{}
|
||||
exch.Exchange = exchange
|
||||
exch.FirstCurrency = crypto
|
||||
|
||||
139
exchanges/stats/stats_test.go
Normal file
139
exchanges/stats/stats_test.go
Normal file
@@ -0,0 +1,139 @@
|
||||
package stats
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLenByPrice(t *testing.T) {
|
||||
exchangeInfo := ExchangeInfo{
|
||||
Exchange: "ANX",
|
||||
FirstCurrency: "BTC",
|
||||
FiatCurrency: "USD",
|
||||
Price: 1200,
|
||||
Volume: 5,
|
||||
}
|
||||
|
||||
ExchInfo = append(ExchInfo, exchangeInfo)
|
||||
if ByPrice.Len(ExchInfo) < 1 {
|
||||
t.Error("Test Failed - stats LenByPrice() length not correct.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLessByPrice(t *testing.T) {
|
||||
exchangeInfo := ExchangeInfo{
|
||||
Exchange: "alphapoint",
|
||||
FirstCurrency: "BTC",
|
||||
FiatCurrency: "USD",
|
||||
Price: 1200,
|
||||
Volume: 5,
|
||||
}
|
||||
|
||||
exchangeInfo2 := ExchangeInfo{
|
||||
Exchange: "bitfinex",
|
||||
FirstCurrency: "BTC",
|
||||
FiatCurrency: "USD",
|
||||
Price: 1198,
|
||||
Volume: 20,
|
||||
}
|
||||
|
||||
ExchInfo = append(ExchInfo, exchangeInfo)
|
||||
ExchInfo = append(ExchInfo, exchangeInfo2)
|
||||
|
||||
if !ByPrice.Less(ExchInfo, 2, 1) {
|
||||
t.Error("Test Failed - stats LessByPrice() incorrect return.")
|
||||
}
|
||||
if ByPrice.Less(ExchInfo, 1, 2) {
|
||||
t.Error("Test Failed - stats LessByPrice() incorrect return.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSwapByPrice(t *testing.T) {
|
||||
exchangeInfo := ExchangeInfo{
|
||||
Exchange: "bitstamp",
|
||||
FirstCurrency: "BTC",
|
||||
FiatCurrency: "USD",
|
||||
Price: 1324,
|
||||
Volume: 5,
|
||||
}
|
||||
|
||||
exchangeInfo2 := ExchangeInfo{
|
||||
Exchange: "btcc",
|
||||
FirstCurrency: "BTC",
|
||||
FiatCurrency: "USD",
|
||||
Price: 7863,
|
||||
Volume: 20,
|
||||
}
|
||||
|
||||
ExchInfo = append(ExchInfo, exchangeInfo)
|
||||
ExchInfo = append(ExchInfo, exchangeInfo2)
|
||||
ByPrice.Swap(ExchInfo, 3, 4)
|
||||
if ExchInfo[3].Exchange != "btcc" || ExchInfo[4].Exchange != "bitstamp" {
|
||||
t.Error("Test Failed - stats SwapByPrice did not swap values.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLenByVolume(t *testing.T) {
|
||||
if ByVolume.Len(ExchInfo) != 5 {
|
||||
t.Error("Test Failed - stats lenByVolume did not swap values.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLessByVolume(t *testing.T) {
|
||||
if !ByVolume.Less(ExchInfo, 1, 2) {
|
||||
t.Error("Test Failed - stats LessByVolume() incorrect return.")
|
||||
}
|
||||
if ByVolume.Less(ExchInfo, 2, 1) {
|
||||
t.Error("Test Failed - stats LessByVolume() incorrect return.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSwapByVolume(t *testing.T) {
|
||||
ByPrice.Swap(ExchInfo, 3, 4)
|
||||
|
||||
if ExchInfo[4].Exchange != "btcc" || ExchInfo[3].Exchange != "bitstamp" {
|
||||
t.Error("Test Failed - stats SwapByVolume did not swap values.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddExchangeInfo(t *testing.T) {
|
||||
ExchInfo = ExchInfo[:0]
|
||||
AddExchangeInfo("ANX", "BTC", "USD", 1200, 42)
|
||||
|
||||
if len(ExchInfo) < 1 {
|
||||
t.Error("Test Failed - stats AddExchangeInfo did not add exchange info.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendExchangeInfo(t *testing.T) {
|
||||
AppendExchangeInfo("sillyexchange", "BTC", "USD", 1234, 45)
|
||||
if len(ExchInfo) < 2 {
|
||||
t.Error("Test Failed - stats AppendExchangeInfo did not add exchange values.")
|
||||
}
|
||||
AppendExchangeInfo("sillyexchange", "BTC", "USD", 1234, 45)
|
||||
if len(ExchInfo) == 3 {
|
||||
t.Error("Test Failed - stats AppendExchangeInfo added exchange values")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExchangeInfoAlreadyExists(t *testing.T) {
|
||||
if !ExchangeInfoAlreadyExists("ANX", "BTC", "USD", 1200, 42) {
|
||||
t.Error("Test Failed - stats ExchangeInfoAlreadyExists exchange does not exist.")
|
||||
}
|
||||
if ExchangeInfoAlreadyExists("bla", "dii", "USD", 1234, 123) {
|
||||
t.Error("Test Failed - stats ExchangeInfoAlreadyExists found incorrect exchange.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortExchangesByVolume(t *testing.T) {
|
||||
topVolume := SortExchangesByVolume("BTC", "USD", true)
|
||||
if topVolume[0].Exchange != "sillyexchange" {
|
||||
t.Error("Test Failed - stats SortExchangesByVolume incorrectly sorted values.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortExchangesByPrice(t *testing.T) {
|
||||
topPrice := SortExchangesByPrice("BTC", "USD", true)
|
||||
if topPrice[0].Exchange != "sillyexchange" {
|
||||
t.Error("Test Failed - stats SortExchangesByPrice incorrectly sorted values.")
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
)
|
||||
|
||||
@@ -33,6 +35,7 @@ type Ticker struct {
|
||||
}
|
||||
|
||||
func (t *Ticker) PriceToString(p pair.CurrencyPair, priceType string) string {
|
||||
priceType = common.StringToLower(priceType)
|
||||
switch priceType {
|
||||
case "last":
|
||||
return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Last, 'f', -1, 64)
|
||||
@@ -118,6 +121,7 @@ func ProcessTicker(exchangeName string, p pair.CurrencyPair, tickerNew TickerPri
|
||||
tickerNew.CurrencyPair = p.Pair().String()
|
||||
if len(Tickers) == 0 {
|
||||
CreateNewTicker(exchangeName, p, tickerNew)
|
||||
//issue - not appending
|
||||
return
|
||||
} else {
|
||||
ticker, err := GetTickerByExchange(exchangeName)
|
||||
|
||||
239
exchanges/ticker/ticker_test.go
Normal file
239
exchanges/ticker/ticker_test.go
Normal file
@@ -0,0 +1,239 @@
|
||||
package ticker
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPriceToString(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
priceStruct := TickerPrice{
|
||||
FirstCurrency: "BTC",
|
||||
SecondCurrency: "USD",
|
||||
CurrencyPair: "BTCUSD",
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
newTicker := CreateNewTicker("ANX", "BTC", "USD", priceStruct)
|
||||
|
||||
if newTicker.PriceToString("BTC", "USD", "last") != "1200" {
|
||||
t.Error("Test Failed - ticker PriceToString last value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString("BTC", "USD", "high") != "1298" {
|
||||
t.Error("Test Failed - ticker PriceToString high value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString("BTC", "USD", "low") != "1148" {
|
||||
t.Error("Test Failed - ticker PriceToString low value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString("BTC", "USD", "bid") != "1195" {
|
||||
t.Error("Test Failed - ticker PriceToString bid value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString("BTC", "USD", "ask") != "1220" {
|
||||
t.Error("Test Failed - ticker PriceToString ask value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString("BTC", "USD", "volume") != "5" {
|
||||
t.Error("Test Failed - ticker PriceToString volume value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString("BTC", "USD", "ath") != "1337" {
|
||||
t.Error("Test Failed - ticker PriceToString ath value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString("BTC", "USD", "obtuse") != "" {
|
||||
t.Error("Test Failed - ticker PriceToString obtuse value is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
priceStruct := TickerPrice{
|
||||
FirstCurrency: "BTC",
|
||||
SecondCurrency: "USD",
|
||||
CurrencyPair: "BTCUSD",
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
bitfinexTicker := CreateNewTicker("bitfinex", "BTC", "USD", priceStruct)
|
||||
Tickers = append(Tickers, bitfinexTicker)
|
||||
|
||||
tickerPrice, err := GetTicker("bitfinex", "BTC", "USD")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Ticker GetTicker init error: %s", err)
|
||||
}
|
||||
if tickerPrice.CurrencyPair != "BTCUSD" {
|
||||
t.Error("Test Failed - ticker tickerPrice.CurrencyPair value is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTickerByExchange(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
priceStruct := TickerPrice{
|
||||
FirstCurrency: "BTC",
|
||||
SecondCurrency: "USD",
|
||||
CurrencyPair: "BTCUSD",
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
anxTicker := CreateNewTicker("ANX", "BTC", "USD", priceStruct)
|
||||
Tickers = append(Tickers, anxTicker)
|
||||
|
||||
tickerPtr, err := GetTickerByExchange("ANX")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - GetTickerByExchange init error: %s", err)
|
||||
}
|
||||
if tickerPtr.ExchangeName != "ANX" {
|
||||
t.Error("Test Failed - GetTickerByExchange ExchangeName value is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirstCurrencyExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
priceStruct := TickerPrice{
|
||||
FirstCurrency: "BTC",
|
||||
SecondCurrency: "USD",
|
||||
CurrencyPair: "BTCUSD",
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
alphaTicker := CreateNewTicker("alphapoint", "BTC", "USD", priceStruct)
|
||||
Tickers = append(Tickers, alphaTicker)
|
||||
|
||||
if !FirstCurrencyExists("alphapoint", "BTC") {
|
||||
t.Error("Test Failed - FirstCurrencyExists1 value return is incorrect")
|
||||
}
|
||||
if FirstCurrencyExists("alphapoint", "CATS") {
|
||||
t.Error("Test Failed - FirstCurrencyExists2 value return is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecondCurrencyExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
priceStruct := TickerPrice{
|
||||
FirstCurrency: "BTC",
|
||||
SecondCurrency: "USD",
|
||||
CurrencyPair: "BTCUSD",
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
bitstampTicker := CreateNewTicker("bitstamp", "BTC", "USD", priceStruct)
|
||||
Tickers = append(Tickers, bitstampTicker)
|
||||
|
||||
if !SecondCurrencyExists("bitstamp", "BTC", "USD") {
|
||||
t.Error("Test Failed - SecondCurrencyExists1 value return is incorrect")
|
||||
}
|
||||
if SecondCurrencyExists("bitstamp", "BTC", "DOGS") {
|
||||
t.Error("Test Failed - SecondCurrencyExists2 value return is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateNewTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
priceStruct := TickerPrice{
|
||||
FirstCurrency: "BTC",
|
||||
SecondCurrency: "USD",
|
||||
CurrencyPair: "BTCUSD",
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
newTicker := CreateNewTicker("ANX", "BTC", "USD", priceStruct)
|
||||
|
||||
if reflect.ValueOf(newTicker).NumField() != 2 {
|
||||
t.Error("Test Failed - ticker CreateNewTicker struct change/or updated")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.ExchangeName).String() != "string" {
|
||||
t.Error("Test Failed - ticker CreateNewTicker.ExchangeName value is not a string")
|
||||
}
|
||||
if newTicker.ExchangeName != "ANX" {
|
||||
t.Error("Test Failed - ticker CreateNewTicker.ExchangeName value is not ANX")
|
||||
}
|
||||
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Ask).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Ask value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Bid).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Bid value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].CurrencyPair).String() != "string" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].CurrencyPair value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].FirstCurrency).String() != "string" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].FirstCurrency value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].High).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].High value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Last).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Last value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Low).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Low value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].PriceATH).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].PriceATH value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].SecondCurrency).String() != "string" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].SecondCurrency value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Volume).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Volume value is not a float64")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessTicker(t *testing.T) { //non-appending function to tickers
|
||||
t.Parallel()
|
||||
|
||||
priceStruct := TickerPrice{
|
||||
FirstCurrency: "BTC",
|
||||
SecondCurrency: "USD",
|
||||
CurrencyPair: "BTCUSD",
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
ProcessTicker("btcc", "BTC", "USD", priceStruct)
|
||||
}
|
||||
8
main.go
8
main.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
// "github.com/gorilla/mux"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -88,7 +89,7 @@ func main() {
|
||||
bot.config = &config.Cfg
|
||||
log.Printf("Loading config file %s..\n", config.CONFIG_FILE)
|
||||
|
||||
err := bot.config.LoadConfig()
|
||||
err := bot.config.LoadConfig("")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -144,7 +145,7 @@ func main() {
|
||||
|
||||
err = currency.SeedCurrencyData(currency.BaseCurrencies)
|
||||
if err != nil {
|
||||
log.Fatalf("Fatal error retrieving config currencies. Error: ", err)
|
||||
log.Fatalf("Fatal error retrieving config currencies. Error: %s", err)
|
||||
}
|
||||
|
||||
log.Println("Successfully retrieved config currencies.")
|
||||
@@ -207,7 +208,7 @@ func HandleInterrupt() {
|
||||
func Shutdown() {
|
||||
log.Println("Bot shutting down..")
|
||||
bot.config.Portfolio = portfolio.Portfolio
|
||||
err := bot.config.SaveConfig()
|
||||
err := bot.config.SaveConfig("")
|
||||
|
||||
if err != nil {
|
||||
log.Println("Unable to save config.")
|
||||
@@ -245,5 +246,4 @@ func SeedExchangeAccountInfo(data []exchange.ExchangeAccountInfo) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func GetEnabledSMSContacts(smsCfg config.SMSGlobalConfig) int {
|
||||
return counter
|
||||
}
|
||||
|
||||
func SMSSendToAll(message string, cfg config.Config) {
|
||||
func SMSSendToAll(message string, cfg config.Config) { // return error here
|
||||
for _, contact := range cfg.SMS.Contacts {
|
||||
if contact.Enabled {
|
||||
err := SMSNotify(contact.Number, message, cfg)
|
||||
|
||||
55
smsglobal/smsglobal_test.go
Normal file
55
smsglobal/smsglobal_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package smsglobal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
)
|
||||
|
||||
func TestGetEnabledSMSContacts(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. GetEnabledSMSContacts: \nFunction return is incorrect with, %s.", err)
|
||||
}
|
||||
|
||||
numberOfContacts := GetEnabledSMSContacts(cfg.SMS)
|
||||
if numberOfContacts != len(cfg.SMS.Contacts) {
|
||||
t.Errorf("Test Failed. GetEnabledSMSContacts: \nFunction return is incorrect with, %d.", numberOfContacts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMSSendToAll(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. SMSSendToAll: \nFunction return is incorrect with, %s.", err)
|
||||
}
|
||||
|
||||
SMSSendToAll("SMSGLOBAL Test - SMSSENDTOALL", *cfg) //+60sec reply issue without account details
|
||||
}
|
||||
|
||||
func TestSMSGetNumberByName(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. SMSGetNumberByName: \nFunction return is incorrect with, %s.", err)
|
||||
}
|
||||
number := SMSGetNumberByName("StyleGherkin", cfg.SMS)
|
||||
if number == "" {
|
||||
t.Error("Test Failed. SMSNotify: \nError: No number, name not found.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMSNotify(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig("../testdata/configtest.dat")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed. SMSNotify: \nFunction return is incorrect with, %s.", err)
|
||||
}
|
||||
|
||||
err2 := SMSNotify(cfg.SMS.Contacts[0].Number, "SMSGLOBAL Test - SMS SEND TO SINGLE", *cfg)
|
||||
if err2 != nil {
|
||||
t.Error("Test Failed. SMSNotify: \nError: ", err2)
|
||||
}
|
||||
}
|
||||
273
testdata/configtest.dat
vendored
Normal file
273
testdata/configtest.dat
vendored
Normal file
@@ -0,0 +1,273 @@
|
||||
{
|
||||
"Name": "Skynet",
|
||||
"EncryptConfig": 0,
|
||||
"Cryptocurrencies": "BTC,LTC,ETH,XRP,NMC,NVC,PPC,XBT,DOGE,DASH",
|
||||
"PortfolioAddresses": {
|
||||
"Addresses": [
|
||||
{
|
||||
"Address": "1JCe8z4jJVNXSjohjM4i9Hh813dLCNx2Sy",
|
||||
"CoinType": "BTC",
|
||||
"Balance": 124178.0002442
|
||||
},
|
||||
{
|
||||
"Address": "3Nxwenay9Z8Lc9JBiywExpnEFiLp6Afp8v",
|
||||
"CoinType": "BTC",
|
||||
"Balance": 103439.83659727
|
||||
},
|
||||
{
|
||||
"Address": "LgY8ahfHRhvjVQC1zJnBhFMG5pCTMuKRqh",
|
||||
"CoinType": "LTC",
|
||||
"Balance": 3000000.05
|
||||
},
|
||||
{
|
||||
"Address": "0xb794f5ea0ba39494ce839613fffba74279579268",
|
||||
"CoinType": "ETH",
|
||||
"Balance": 5774999.820458524
|
||||
}
|
||||
]
|
||||
},
|
||||
"SMSGlobal": {
|
||||
"Enabled": true,
|
||||
"Username": "1234",
|
||||
"Password": "12334",
|
||||
"Contacts": [
|
||||
{
|
||||
"Name": "StyleGherkin",
|
||||
"Number": "1231424",
|
||||
"Enabled": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"Webserver": {
|
||||
"Enabled": false,
|
||||
"AdminUsername": "admin",
|
||||
"AdminPassword": "Password",
|
||||
"ListenAddress": ":9050"
|
||||
},
|
||||
"Exchanges": [
|
||||
{
|
||||
"Name": "ANX",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC",
|
||||
"EnabledPairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC",
|
||||
"BaseCurrencies": "USD,HKD,EUR,CAD,AUD,SGD,JPY,GBP,NZD"
|
||||
},
|
||||
{
|
||||
"Name": "Bitfinex",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC,ETCBTC,ETCUSD,BFXUSD,BFXBTC,RRTUSD,RRTBTC,ZECUSD,ZECBTC,XMRUSD,XMRBTC,DSHUSD,DSHBTC",
|
||||
"EnabledPairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC",
|
||||
"BaseCurrencies": "USD"
|
||||
},
|
||||
{
|
||||
"Name": "Bitstamp",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"ClientID": "ClientID",
|
||||
"AvailablePairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR",
|
||||
"EnabledPairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR",
|
||||
"BaseCurrencies": "USD,EUR"
|
||||
},
|
||||
{
|
||||
"Name": "BTCC",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCCNY,LTCCNY,LTCBTC",
|
||||
"EnabledPairs": "BTCCNY,LTCCNY,LTCBTC",
|
||||
"BaseCurrencies": "CNY"
|
||||
},
|
||||
{
|
||||
"Name": "BTCE",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD",
|
||||
"EnabledPairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD",
|
||||
"BaseCurrencies": "USD,RUR,EUR"
|
||||
},
|
||||
{
|
||||
"Name": "BTC Markets",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "LTC,BTC",
|
||||
"EnabledPairs": "LTC,BTC",
|
||||
"BaseCurrencies": "AUD"
|
||||
},
|
||||
{
|
||||
"Name": "GDAX",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"ClientID": "ClientID",
|
||||
"AvailablePairs": "BTCGBP,BTCEUR,ETHUSD,ETHBTC,LTCUSD,LTCBTC,BTCUSD",
|
||||
"EnabledPairs": "BTCUSD,BTCGBP,BTCEUR",
|
||||
"BaseCurrencies": "USD,GBP,EUR"
|
||||
},
|
||||
{
|
||||
"Name": "Gemini",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCUSD,ETHBTC,ETHUSD",
|
||||
"EnabledPairs": "BTCUSD",
|
||||
"BaseCurrencies": "USD"
|
||||
},
|
||||
{
|
||||
"Name": "Huobi",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCCNY,LTCCNY",
|
||||
"EnabledPairs": "BTCCNY,LTCCNY",
|
||||
"BaseCurrencies": "CNY"
|
||||
},
|
||||
{
|
||||
"Name": "ITBIT",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"ClientID": "ClientID",
|
||||
"AvailablePairs": "XBTUSD,XBTSGD,XBTEUR",
|
||||
"EnabledPairs": "XBTUSD,XBTSGD,XBTEUR",
|
||||
"BaseCurrencies": "USD,SGD,EUR"
|
||||
},
|
||||
{
|
||||
"Name": "Kraken",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "ETCUSD,ICNETH,REPXBT,ZECXBT,ETHXBT,ETHXBT.d,ETHGBP,LTCXBT,XBTGBP.d,XDGXBT,XMRUSD,ZECUSD,ETCETH,ETHJPY,XBTCAD.d,XBTJPY.d,XBTUSD.d,XLMXBT,XLMEUR,XLMUSD,XMREUR,ETCXBT,ETHCAD.d,ETHEUR.d,ETHJPY.d,XBTEUR.d,ETHEUR,ETHGBP.d,ICNXBT,LTCEUR,REPEUR,XBTGBP,XBTJPY,ETHUSD,ETHUSD.d,LTCUSD,REPETH,XBTUSD,XMRXBT,ETCEUR,ETHCAD,REPUSD,XBTCAD,XBTEUR,XRPXBT,ZECEUR",
|
||||
"EnabledPairs": "ETCUSD,XBTUSD,ETHUSD",
|
||||
"BaseCurrencies": "EUR,USD,CAD,GBP,JPY"
|
||||
},
|
||||
{
|
||||
"Name": "LakeBTC",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCUSD,BTCEUR,USDHKD,AUDUSD,BTCGBP,BTCNZD,USDJPY,BTCSGD,BTCNGN,EURUSD,USDSGD,NZDUSD,USDNGN,USDCHF,BTCJPY,BTCAUD,BTCCAD,BTCCHF,GBPUSD,USDCAD",
|
||||
"EnabledPairs": "BTCUSD,BTCAUD",
|
||||
"BaseCurrencies": "USD,EUR,HKD,AUD,GBP,NZD,JPY,SGD,NGN,CHF,CAD"
|
||||
},
|
||||
{
|
||||
"Name": "Liqui",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "TIME_BTC,ETH_BTC,GNT_BTC,WAVES_BTC,ICN_BTC,1ST_BTC,WINGS_BTC,MLN_BTC,ROUND_BTC,VSL_BTC,LTC_BTC,DCT_BTC,INCNT_BTC,PLU_BTC,DASH_BTC",
|
||||
"EnabledPairs": "ETH_BTC,LTC_BTC,DASH_BTC",
|
||||
"BaseCurrencies": "USD"
|
||||
},
|
||||
{
|
||||
"Name": "LocalBitcoins",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR",
|
||||
"EnabledPairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR",
|
||||
"BaseCurrencies": "ARS,AUD,BRL,CAD,CHF,CZK,DKK,EUR,GBP,HKD,ILS,INR,MXN,NOK,NZD,PLN,RUB,SEK,SGD,THB,USD,ZAR"
|
||||
},
|
||||
{
|
||||
"Name": "OKCOIN China",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCCNY,LTCCNY",
|
||||
"EnabledPairs": "BTCCNY,LTCCNY",
|
||||
"BaseCurrencies": "CNY"
|
||||
},
|
||||
{
|
||||
"Name": "OKCOIN International",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTCUSD,LTCUSD",
|
||||
"EnabledPairs": "BTCUSD,LTCUSD",
|
||||
"BaseCurrencies": "USD"
|
||||
},
|
||||
{
|
||||
"Name": "Poloniex",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "BTC_XUSD,BTC_FCT,BTC_MMNXT,BTC_NMC,BTC_BITUSD,BTC_RDD,BTC_XMR,BTC_XST,BTC_DSH,BTC_MAID,BTC_DGB,BTC_NEOS,BTC_BLK,BTC_NAUT,BTC_NBT,BTC_XCP,BTC_STR,BTC_BTCD,BTC_GRC,BTC_HUC,BTC_BBR,BTC_XDN,BTC_INDEX,BTC_IOC,BTC_SWARM,BTC_EMC2,BTC_MCN,BTC_NOXT,BTC_MINT,BTC_PTS,BTC_SC,BTC_GEO,BTC_XRP,BTC_FLO,BTC_BITS,BTC_HYP,BTC_XCR,BTC_LTBC,BTC_SYS,BTC_GMC,BTC_ETH,BTC_SYNC,BTC_GAP,BTC_BCN,BTC_C2,BTC_PINK,BTC_FIBRE,BTC_POT,BTC_QTL,BTC_SDC,BTC_XC,BTC_DASH,BTC_SILK,BTC_CLAM,BTC_NAV,BTC_PIGGY,BTC_BCY,BTC_MIL,BTC_XCN,BTC_YACC,BTC_BTS,BTC_QBK,BTC_SJCX,BTC_LQD,BTC_BURST,BTC_RIC,BTC_VRC,BTC_LTC,BTC_XPB,BTC_GRS,BTC_XCH,BTC_ARCH,BTC_QORA,BTC_HZ,BTC_NSR,BTC_XPM,BTC_BITCNY,BTC_EXE,BTC_XMG,BTC_BTC,BTC_BTM,BTC_NOBL,BTC_NXT,BTC_DOGE,BTC_CURE,BTC_MNTA,BTC_ADN,BTC_EXP,BTC_VTC,BTC_FLDC,BTC_MRS,BTC_MYR,BTC_OMNI,BTC_VNL,BTC_USDT,BTC_NOTE,BTC_WDC,BTC_BELA,BTC_VIA,BTC_CGA,BTC_DIEM,BTC_IFC,BTC_XDP,BTC_BLOCK,BTC_MMC,BTC_1CR,BTC_UNITY,BTC_XBC,BTC_GEMZ,BTC_FLT,BTC_PPC,BTC_XEM,BTC_RBY,BTC_CNMT,BTC_ABY,XMR_XDN,XMR_IFC,XMR_DIEM,XMR_BBR,XMR_DSH,XMR_BCN,XMR_LTC,XMR_MAID,XMR_DASH,XMR_BTCD,XMR_HYP,XMR_BLK,XMR_QORA,XMR_MNTA,XMR_NXT,USDT_BTC,USDT_ETH,USDT_XRP,USDT_DASH,USDT_LTC,USDT_NXT,USDT_XMR,USDT_STR",
|
||||
"EnabledPairs": "BTC_LTC,BTC_ETH,BTC_DOGE,BTC_DASH,BTC_XRP",
|
||||
"BaseCurrencies": "USD"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user