mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 07:26:47 +00:00
* Improved error message when no config is set on startup * Change inccorect error wording * bump Bitfinex websocket orderbook return length to max * temporary fix of incorrect orderbook updates, limit to bid and ask len of 100, will be extended later if needed * Fixed issue in binance websocket that appended 0 volume bid/ask items * Fix panic when unmarshalling an empty pair from config * Add get pair asset method for exchange base Fix Bitmex orderbook stream Unbuffer Bitmex orderbook stream * force syncer to update ticker instead of fetch, which allows a stream * Fix websocket last price for coinbasepro * fix websocket ticker for coinut * Fix websocket orderbook stream Huobi * increase orderbook depth REST for Huobi * Fix websocket support and ensure data integrity * Fix time parsing issue after error checks * check error, only process enabled currency pairs, signal websocket data processing * expanded websocket functionality for okgroup * Add logic to not process zero length slice for orderbooks * fix websocket ticker only updating enabled and individual book updates * ZB fixes to order submission/retrieval/cancellation w/ general fixes * Quiet unnecessary warning * updated config entry values for REST and websocket (initial hack until I come up with a better solution for asset types) * Ch GetName function to field access modifyer & rm useless code * Add in error I missed * Nits addressed * some more fixes * Turned kraken default websocket to true and some small changes * fixes linter issues * Ensured okgroup books and sent update through to datahandler. Zb update as well. * Add test case to get asset type from pair * Add test for pairs unmarshal * Add testing and addressed nits * FIX linter issue * Addressed Gees nits * Thanks glorious spotter * more nitorinos * Addres even more nits * Add stringerino 4000 * Fix for panic cause by sort slice out of range, also nits addressed * fix linter issues * Changed from function to field access * Changed from function to field access * fix for orderbook update panic, removes quick fix - caused by sync item fetching through same protocol * Add new test and update random generator * pass in invalid string to future ob fetching, due to futures contract expire and a http 400 error is returned
190 lines
4.6 KiB
Go
190 lines
4.6 KiB
Go
package currency
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/common"
|
|
)
|
|
|
|
func TestPairsUpper(t *testing.T) {
|
|
pairs := NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"})
|
|
expected := "BTC_USD,BTC_AUD,BTC_LTC"
|
|
|
|
if pairs.Upper().Join() != expected {
|
|
t.Errorf("Pairs Join() error expected %s but received %s",
|
|
expected, pairs.Join())
|
|
}
|
|
}
|
|
|
|
func TestPairsString(t *testing.T) {
|
|
pairs := NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"})
|
|
expected := []string{"btc_usd", "btc_aud", "btc_ltc"}
|
|
|
|
for i, p := range pairs {
|
|
if p.String() != expected[i] {
|
|
t.Errorf("Pairs String() error expected %s but received %s",
|
|
expected, p.String())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPairsJoin(t *testing.T) {
|
|
pairs := NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"})
|
|
expected := "btc_usd,btc_aud,btc_ltc"
|
|
|
|
if pairs.Join() != expected {
|
|
t.Errorf("Pairs Join() error expected %s but received %s",
|
|
expected, pairs.Join())
|
|
}
|
|
}
|
|
|
|
func TestPairsFormat(t *testing.T) {
|
|
pairs := NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"})
|
|
|
|
expected := "BTC-USD,BTC-AUD,BTC-LTC"
|
|
if pairs.Format("-", "", true).Join() != expected {
|
|
t.Errorf("Pairs Join() error expected %s but received %s",
|
|
expected, pairs.Format("-", "", true).Join())
|
|
}
|
|
|
|
expected = "btc:usd,btc:aud,btc:ltc"
|
|
if pairs.Format(":", "", false).Join() != expected {
|
|
t.Errorf("Pairs Join() error expected %s but received %s",
|
|
expected, pairs.Format(":", "", false).Join())
|
|
}
|
|
|
|
if pairs.Format(":", "KRW", false).Join() != "" {
|
|
t.Errorf("Pairs Join() error expected %s but received %s",
|
|
expected, pairs.Format(":", "KRW", true).Join())
|
|
}
|
|
|
|
pairs = NewPairsFromStrings([]string{"DASHKRW", "BTCKRW"})
|
|
expected = "dash-krw,btc-krw"
|
|
if pairs.Format("-", "KRW", false).Join() != expected {
|
|
t.Errorf("Pairs Join() error expected %s but received %s",
|
|
expected, pairs.Format("-", "KRW", false).Join())
|
|
}
|
|
}
|
|
|
|
func TestPairsUnmarshalJSON(t *testing.T) {
|
|
var unmarshalHere Pairs
|
|
configPairs := ""
|
|
encoded, err := common.JSONEncode(configPairs)
|
|
if err != nil {
|
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
|
}
|
|
|
|
err = common.JSONDecode([]byte{1, 3, 3, 7}, &unmarshalHere)
|
|
if err == nil {
|
|
t.Fatal("error cannot be nil")
|
|
}
|
|
|
|
err = common.JSONDecode(encoded, &unmarshalHere)
|
|
if err != nil {
|
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
|
}
|
|
|
|
configPairs = "btc_usd,btc_aud,btc_ltc"
|
|
encoded, err = common.JSONEncode(configPairs)
|
|
if err != nil {
|
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
|
}
|
|
|
|
err = common.JSONDecode(encoded, &unmarshalHere)
|
|
if err != nil {
|
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
|
}
|
|
|
|
err = common.JSONDecode(encoded, &unmarshalHere)
|
|
if err != nil {
|
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
|
}
|
|
|
|
if unmarshalHere.Join() != configPairs {
|
|
t.Errorf("Pairs UnmarshalJSON() error expected %s but received %s",
|
|
configPairs, unmarshalHere.Join())
|
|
}
|
|
}
|
|
|
|
func TestPairsMarshalJSON(t *testing.T) {
|
|
quickstruct := struct {
|
|
Pairs Pairs `json:"soManyPairs"`
|
|
}{
|
|
Pairs: NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"}),
|
|
}
|
|
|
|
encoded, err := common.JSONEncode(quickstruct)
|
|
if err != nil {
|
|
t.Fatal("Pairs MarshalJSON() error", err)
|
|
}
|
|
|
|
expected := `{"soManyPairs":"btc_usd,btc_aud,btc_ltc"}`
|
|
if string(encoded) != expected {
|
|
t.Errorf("Pairs MarshalJSON() error expected %s but received %s",
|
|
expected, string(encoded))
|
|
}
|
|
}
|
|
|
|
func TestRemovePairsByFilter(t *testing.T) {
|
|
var pairs = Pairs{
|
|
NewPair(BTC, USD),
|
|
NewPair(LTC, USD),
|
|
NewPair(LTC, USDT),
|
|
}
|
|
|
|
pairs = pairs.RemovePairsByFilter(USDT)
|
|
if pairs.Contains(NewPair(LTC, USDT), true) {
|
|
t.Error("TestRemovePairsByFilter unexpected result")
|
|
}
|
|
}
|
|
|
|
func TestRemove(t *testing.T) {
|
|
var pairs = Pairs{
|
|
NewPair(BTC, USD),
|
|
NewPair(LTC, USD),
|
|
NewPair(LTC, USDT),
|
|
}
|
|
|
|
p := NewPair(BTC, USD)
|
|
pairs = pairs.Remove(p)
|
|
if pairs.Contains(p, true) || len(pairs) != 2 {
|
|
t.Error("TestRemove unexpected result")
|
|
}
|
|
}
|
|
|
|
func TestAdd(t *testing.T) {
|
|
var pairs = Pairs{
|
|
NewPair(BTC, USD),
|
|
NewPair(LTC, USD),
|
|
NewPair(LTC, USDT),
|
|
}
|
|
|
|
// Test adding a new pair to the list of pairs
|
|
p := NewPair(BTC, USDT)
|
|
pairs = pairs.Add(p)
|
|
if !pairs.Contains(p, true) || len(pairs) != 4 {
|
|
t.Error("TestAdd unexpected result")
|
|
}
|
|
|
|
// Now test adding a pair which already exists
|
|
pairs = pairs.Add(p)
|
|
if len(pairs) != 4 {
|
|
t.Error("TestAdd unexpected result")
|
|
}
|
|
}
|
|
|
|
func TestContains(t *testing.T) {
|
|
var pairs = Pairs{
|
|
NewPair(BTC, USD),
|
|
NewPair(LTC, USD),
|
|
}
|
|
|
|
if !pairs.Contains(NewPair(BTC, USD), true) {
|
|
t.Errorf("TestContains: Expected pair was not found")
|
|
}
|
|
|
|
if pairs.Contains(NewPair(ETH, USD), false) {
|
|
t.Errorf("TestContains: Non-existent pair was found")
|
|
}
|
|
}
|