mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
* orderbook: export orderbook nodes for external strategy inspection * orderbook: Add in methods for locking and unlocking multiple books at the same time e.g. book1.LockWith(book2); defer book1.UnlockWith(book2) * include waiting functionality for depth change alert * backtester: add word. * log: include logger changes to impl with downstream integration * engine: reduce params for loading exchange * assort: rm verbose in tests, change wording in ob, expose sync.waitgroup for ext. sync options * ticker: reduce map look ups and contention when using RW mutex when there are over 80% writes adds find last function to get the latest rate * engine/syncmanager: add in waitgroup for step over for external package calls * cleaup * engine: linter fix * currency/fx: include all references to fiat currencies to default * orderbook: Add in fields to Unsafe type for strategies to detect potential out of sync book operations * syncmanager: changed config variable to display correct time * ordermanager: Add time when none provided * currency/manager: update getasset param to get enabled assets for minor optimizations * ftx: use get all wallet balances for a better accounts breakdown * orderbook: unlock in reverse order * bithumb: fixes bug on market buy and sell orders * bithumb: fix bug for nonce is also time window sensitive * bithumb: get orders add required parameter * bithumb: Add asset type to account struct * currency: improve log output when checking currency and it fails * bithumb: Add error return on incomplete pair * ticker:unexport all service related methods * ticker/currency: fixes * orderbook: fix comment * engine: revert variable name in LoadExchange method * sync_manager: fix panic when enabling disabling manager * engine: fix naming convention of exported function and comments * engine: update comment * orderbook: fix comment for unsafe type
127 lines
3.3 KiB
Go
127 lines
3.3 KiB
Go
package currency
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGetDefaultExchangeRates(t *testing.T) {
|
|
rates, err := GetDefaultExchangeRates()
|
|
if err != nil {
|
|
t.Error("GetDefaultExchangeRates() err", err)
|
|
}
|
|
|
|
for _, val := range rates {
|
|
if !val.IsFiat() {
|
|
t.Errorf("GetDefaultExchangeRates() %s is not fiat pair",
|
|
val)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetExchangeRates(t *testing.T) {
|
|
rates, err := GetExchangeRates()
|
|
if err != nil {
|
|
t.Error("GetExchangeRates() err", err)
|
|
}
|
|
|
|
for _, val := range rates {
|
|
if !val.IsFiat() {
|
|
t.Errorf("GetExchangeRates() %s is not fiat pair",
|
|
val)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestUpdateBaseCurrency(t *testing.T) {
|
|
err := UpdateBaseCurrency(AUD)
|
|
if err != nil {
|
|
t.Error("UpdateBaseCurrency() err", err)
|
|
}
|
|
|
|
err = UpdateBaseCurrency(LTC)
|
|
if err == nil {
|
|
t.Error("UpdateBaseCurrency() error cannot be nil")
|
|
}
|
|
|
|
if GetBaseCurrency() != AUD {
|
|
t.Errorf("GetBaseCurrency() expected %s but received %s",
|
|
AUD, GetBaseCurrency())
|
|
}
|
|
}
|
|
|
|
func TestGetDefaultBaseCurrency(t *testing.T) {
|
|
if GetDefaultBaseCurrency() != USD {
|
|
t.Errorf("GetDefaultBaseCurrency() expected %s but received %s",
|
|
USD, GetDefaultBaseCurrency())
|
|
}
|
|
}
|
|
|
|
func TestGetDefaulCryptoCurrencies(t *testing.T) {
|
|
expected := Currencies{BTC, LTC, ETH, DOGE, DASH, XRP, XMR}
|
|
if !GetDefaultCryptocurrencies().Match(expected) {
|
|
t.Errorf("GetDefaultCryptocurrencies() expected %s but received %s",
|
|
expected, GetDefaultCryptocurrencies())
|
|
}
|
|
}
|
|
|
|
func TestGetDefaultFiatCurrencies(t *testing.T) {
|
|
expected := Currencies{BZD, KYD, LRD, SAR, MKD, SRD, BMD, KHR, COP, CRC, GIP, NIO, CHF, VEF, ILS, BSD, CUP, HKD, IDR, SYP, AWG, TTD, DOP, JPY, PAB, SHP, BGN, JEP, AZN, JMD, MXN, CAD, GGP, RUR, GBP, GTQ, LBP, THB, MZN, RSD, ARS, BYN, HRK, GHS, MUR, ANG, QAR, ZWD, CLP, INR, IRR, NOK, PHP, LKR, TRY, BAM, EGP, TVD, SVC, FJD, PEN, RUB, SOS, XCD, KZT, BWP, ISK, KPW, KRW, PKR, UYU, BND, MNT, SEK, UAH, BBD, GYD, NZD, SCR, ZAR, FKP, HUF, RON, AFN, PLN, OMR, USD, CZK, YER, AUD, EUR, TWD, BRL, DKK, KGS, PYG, SBD, UZS, IMP, MYR, NAD, NPR, LAK, VND, ALL, BOB, HNL, SGD, CNY, NGN}
|
|
if !GetDefaultFiatCurrencies().Match(expected) {
|
|
t.Errorf("GetDefaultFiatCurrencies() expected %s but received %s",
|
|
expected, GetDefaultFiatCurrencies())
|
|
}
|
|
}
|
|
|
|
func TestUpdateCurrencies(t *testing.T) {
|
|
fiat := Currencies{HKN, JPY}
|
|
UpdateCurrencies(fiat, false)
|
|
rFiat := GetFiatCurrencies()
|
|
if !rFiat.Contains(HKN) || !rFiat.Contains(JPY) {
|
|
t.Error("UpdateCurrencies() currencies did not update")
|
|
}
|
|
|
|
crypto := Currencies{ZAR, ZCAD, B2}
|
|
UpdateCurrencies(crypto, true)
|
|
rCrypto := GetCryptocurrencies()
|
|
if !rCrypto.Contains(ZAR) || !rCrypto.Contains(ZCAD) || !rCrypto.Contains(B2) {
|
|
t.Error("UpdateCurrencies() currencies did not update")
|
|
}
|
|
}
|
|
|
|
func TestConvertCurrency(t *testing.T) {
|
|
_, err := ConvertCurrency(100, AUD, USD)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
r, err := ConvertCurrency(100, AUD, AUD)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if r != 100 {
|
|
t.Errorf("ConvertCurrency error, incorrect rate return %2.f but received %2.f",
|
|
100.00, r)
|
|
}
|
|
|
|
_, err = ConvertCurrency(100, USD, AUD)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, err = ConvertCurrency(100, CNY, AUD)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, err = ConvertCurrency(100, LTC, USD)
|
|
if err == nil {
|
|
t.Fatal("Expected err on non-existent currency")
|
|
}
|
|
|
|
_, err = ConvertCurrency(100, USD, LTC)
|
|
if err == nil {
|
|
t.Fatal("Expected err on non-existent currency")
|
|
}
|
|
}
|