mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* public endpoints methods added * Completing mapping REST endpoints * Binanceus Wrapper methods -Partially * Binanceus Wrapper methods -Partially * BinaWra functions with test funs; Not Completed * Finalizing wrapper methods & test * Fix & Complete wrapper functions * Finalizing wrapper methods & test * Adding Stream Datas * WS Test functions * CI: Fix golangci-lint linter issues * CI: Fix reverting unnessesary changes and type conversion issues * CI: Fix reverting unnessesary changes and type conversion issues * Adding Public endpoints and tests * Adding Market and Public Endpoints * Adding Public endoints * Public Trading Endpoints & Authenticated Trade order methods * Adding Authenticated Methods and Tests * Adding algo and Funding Authenticated endpoints * Adding funding trading endpoints and correspondint tests * adding authenticated endpoints * Completing Block Trading endpoints and added subaccount endpoints * Completing sub account and grid Trading endpoints * Adding Rate Limit and missing endpoints * Wrapper and Websocket handlers * Fixing Websocket Test and Push Data Handler Issues * Fixing Websocket Test and Push Data Handler Issues * Fixing linter issues, package dependency, and other slight tempos * Fixing linter and slight tempos * Update on test functions, and Rest and Websocket Endpoint handlers * Remove okex, adding comments, and slight fixes on endpoints. * Fixing linter issues and adding comments * Slight code changes, updating documentation, and n and linter issues * Fix context and configuration endpoint issues * slight fixes on config and test files * adding some missing test and fix linter issues * fix linter issue * Slight fixes on code structure, shorthand exp,and ot and other * Fix slight linter issue * Slight code fixes and fixing linter issues * fixing linter iissues * fixing linter iissues * slight linter issue fix * slight linter issue fix * Fix on models, type convert funcs and endpoints * Adding Error messages map and update of models * Fix on error message string and linter issues * Fix slight linter issue * Fix slight linter issue * Fixing type converts, models, and linter issues * Adding Ws fixes * Slight fix on websocket and other issues * Adding slight websocket fixes * Remove 'books5' channel default subscription * Small changes on default subscription and checksum * Fix slight websocket tempos * Fix Wrapper function tempost and linter issues * Resolving slight naming and other issues * Resolve slight pointer issues * resolve slight linter issues * Resolve config files issue * Update websocket and wrapper funcs with test and docs * fixs on websocket multiplexer, types, and other slight issues * fix slight linter issues * slight update on web-socket orderbook and tickers * fix slight issues and websocket runtime errors * Slight unit test fix and assing simple semaphore * FIx race issue * Update on authenticated endpoints * Fix wsSetupRun check in websocket 'setupWsAuth' func * Update wsSetupRun check in websocket 'setupWsAuth' func * Slight update on websocket handling * Fix some race conditions * fix slight tempos * fix authenticated test issues * Update on conditional statements * slight update on unit test * fix unit test tempos * Fix slight tempos * Change check map from struct valued to bool valued * slight fix trial * Slight unit test update * Fix websocket timeout error * Updating websocket subscription endpoints, and unit tests * update unit tests * Slight issue on wrapper method 'GetActiveOrders' * Overall code update * Addressing missing review comments * Fix unit test tempo and linter issue * Monor fix * Slight update * Slight unit test fix * Slight fixes * Slight fixes * Fixing on missing review comments * Adding WS Fixes * slight fix * Monor fix on unit test * Minor convert issue * Minor change on WS * Monor logic fix * Fix code structure and logic issues * Fixing small typos * fix slight data format issue * Update on trade and order wrapper methods * Adding slight update * fix on order detail * Slight update on FetchTradablePairs wrapper method * Slight update on wrapper * Update on deserialization and other slight issues * Final update * Resolve missing review comments * Slight update on config and unit test * minor fix on GetDepositAddress param * Minor fix
225 lines
4.7 KiB
Go
225 lines
4.7 KiB
Go
package stats
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
)
|
|
|
|
const (
|
|
testExchange = "Okx"
|
|
)
|
|
|
|
func TestLenByPrice(t *testing.T) {
|
|
p, err := currency.NewPairFromStrings("BTC", "USD")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
Items = []Item{
|
|
{
|
|
Exchange: testExchange,
|
|
Pair: p,
|
|
AssetType: asset.Spot,
|
|
Price: 1200,
|
|
Volume: 5,
|
|
},
|
|
}
|
|
|
|
if ByPrice.Len(Items) < 1 {
|
|
t.Error("stats LenByPrice() length not correct.")
|
|
}
|
|
}
|
|
|
|
func TestLessByPrice(t *testing.T) {
|
|
p, err := currency.NewPairFromStrings("BTC", "USD")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
Items = []Item{
|
|
{
|
|
Exchange: "alphapoint",
|
|
Pair: p,
|
|
AssetType: asset.Spot,
|
|
Price: 1200,
|
|
Volume: 5,
|
|
},
|
|
{
|
|
Exchange: "bitfinex",
|
|
Pair: p,
|
|
AssetType: asset.Spot,
|
|
Price: 1198,
|
|
Volume: 20,
|
|
},
|
|
}
|
|
|
|
if !ByPrice.Less(Items, 1, 0) {
|
|
t.Error("stats LessByPrice() incorrect return.")
|
|
}
|
|
if ByPrice.Less(Items, 0, 1) {
|
|
t.Error("stats LessByPrice() incorrect return.")
|
|
}
|
|
}
|
|
|
|
func TestSwapByPrice(t *testing.T) {
|
|
p, err := currency.NewPairFromStrings("BTC", "USD")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
Items = []Item{
|
|
{
|
|
Exchange: "bitstamp",
|
|
Pair: p,
|
|
AssetType: asset.Spot,
|
|
Price: 1324,
|
|
Volume: 5,
|
|
},
|
|
{
|
|
Exchange: "bitfinex",
|
|
Pair: p,
|
|
AssetType: asset.Spot,
|
|
Price: 7863,
|
|
Volume: 20,
|
|
},
|
|
}
|
|
|
|
ByPrice.Swap(Items, 0, 1)
|
|
if Items[0].Exchange != "bitfinex" || Items[1].Exchange != "bitstamp" {
|
|
t.Error("stats SwapByPrice did not swap values.")
|
|
}
|
|
}
|
|
|
|
func TestLenByVolume(t *testing.T) {
|
|
if ByVolume.Len(Items) != 2 {
|
|
t.Error("stats lenByVolume did not swap values.")
|
|
}
|
|
}
|
|
|
|
func TestLessByVolume(t *testing.T) {
|
|
if !ByVolume.Less(Items, 1, 0) {
|
|
t.Error("stats LessByVolume() incorrect return.")
|
|
}
|
|
if ByVolume.Less(Items, 0, 1) {
|
|
t.Error("stats LessByVolume() incorrect return.")
|
|
}
|
|
}
|
|
|
|
func TestSwapByVolume(t *testing.T) {
|
|
ByPrice.Swap(Items, 0, 1)
|
|
|
|
if Items[1].Exchange != "bitfinex" || Items[0].Exchange != "bitstamp" {
|
|
t.Error("stats SwapByVolume did not swap values.")
|
|
}
|
|
}
|
|
|
|
func TestAdd(t *testing.T) {
|
|
Items = Items[:0]
|
|
p, err := currency.NewPairFromStrings("BTC", "USD")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = Add(testExchange, p, asset.Spot, 1200, 42)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if len(Items) < 1 {
|
|
t.Error("stats Add did not add exchange info.")
|
|
}
|
|
|
|
err = Add("", p, asset.Empty, 0, 0)
|
|
if err == nil {
|
|
t.Fatal("error cannot be nil")
|
|
}
|
|
|
|
if len(Items) != 1 {
|
|
t.Error("stats Add did not add exchange info.")
|
|
}
|
|
|
|
p.Base = currency.XBT
|
|
err = Add(testExchange, p, asset.Spot, 1201, 43)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if Items[1].Pair.String() != "XBTUSD" {
|
|
t.Fatal("stats Add did not add exchange info.")
|
|
}
|
|
|
|
p, err = currency.NewPairFromStrings("ETH", "USDT")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = Add(testExchange, p, asset.Spot, 300, 1000)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if Items[2].Pair.String() != "ETHUSD" {
|
|
t.Fatal("stats Add did not add exchange info.")
|
|
}
|
|
}
|
|
|
|
func TestAppend(t *testing.T) {
|
|
p, err := currency.NewPairFromStrings("BTC", "USD")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
Append("sillyexchange", p, asset.Spot, 1234, 45)
|
|
if len(Items) < 2 {
|
|
t.Error("stats AppendResults did not add exchange values.")
|
|
}
|
|
|
|
Append("sillyexchange", p, asset.Spot, 1234, 45)
|
|
if len(Items) == 3 {
|
|
t.Error("stats AppendResults added exchange values")
|
|
}
|
|
}
|
|
|
|
func TestAlreadyExists(t *testing.T) {
|
|
p, err := currency.NewPairFromStrings("BTC", "USD")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !AlreadyExists(testExchange, p, asset.Spot, 1200, 42) {
|
|
t.Error("stats AlreadyExists exchange does not exist.")
|
|
}
|
|
p.Base = currency.NewCode("dii")
|
|
if AlreadyExists("bla", p, asset.Spot, 1234, 123) {
|
|
t.Error("stats AlreadyExists found incorrect exchange.")
|
|
}
|
|
}
|
|
|
|
func TestSortExchangesByVolume(t *testing.T) {
|
|
p, err := currency.NewPairFromStrings("BTC", "USD")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
topVolume := SortExchangesByVolume(p, asset.Spot, true)
|
|
if topVolume[0].Exchange != "sillyexchange" {
|
|
t.Error("stats SortExchangesByVolume incorrectly sorted values.")
|
|
}
|
|
|
|
topVolume = SortExchangesByVolume(p, asset.Spot, false)
|
|
if topVolume[0].Exchange != testExchange {
|
|
t.Error("stats SortExchangesByVolume incorrectly sorted values.")
|
|
}
|
|
}
|
|
|
|
func TestSortExchangesByPrice(t *testing.T) {
|
|
p, err := currency.NewPairFromStrings("BTC", "USD")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
topPrice := SortExchangesByPrice(p, asset.Spot, true)
|
|
if topPrice[0].Exchange != "sillyexchange" {
|
|
t.Error("stats SortExchangesByPrice incorrectly sorted values.")
|
|
}
|
|
|
|
topPrice = SortExchangesByPrice(p, asset.Spot, false)
|
|
if topPrice[0].Exchange != testExchange {
|
|
t.Error("stats SortExchangesByPrice incorrectly sorted values.")
|
|
}
|
|
}
|