mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* Remove pointer reference * Fix portfolio withdraw tests * Add nil protection in validator method to reduce prospective panics and for future outbound checking * Updated tests * ch order var to not ref package * rm comparison * Add order ID validation check * Add exchange name validation check * Add in test details * fix tests * fix linter issues * linter issues strikes again * linter rabbit hole * Addr nitterinos * Add validation variadic interface to define sets of functionality check POC * didn't want to add an amount other than 0, didn't want to add address to exchange withdraw, didn't want to whitlist, can change if need be * add coverage * Add validation method options for exchange wrappers and abstracted validation into its own package * Add validation code for structs in exchange template generation * remove extra validation call as this is done in wrapper * fix niterinos for examplerinos * Add template to documentation tool and regenerated documentation * Addr niticles * Fix tests due to validation update * Add more validation checks for modify/submit orders * update tests * fix more tests * Add asset type to submit variable in tests and rpc call. Regen funcs. * Add field to modify struct in tests * applied field asset to cancel struct across project * fix woopsy
185 lines
4.5 KiB
Go
185 lines
4.5 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"math/rand"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/common"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/engine"
|
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
)
|
|
|
|
const (
|
|
totalWrappers = 20
|
|
)
|
|
|
|
func main() {
|
|
var err error
|
|
engine.Bot, err = engine.New()
|
|
if err != nil {
|
|
log.Fatalf("Failed to initialise engine. Err: %s", err)
|
|
}
|
|
|
|
engine.Bot.Settings = engine.Settings{
|
|
DisableExchangeAutoPairUpdates: true,
|
|
}
|
|
|
|
log.Printf("Loading exchanges..")
|
|
var wg sync.WaitGroup
|
|
for x := range exchange.Exchanges {
|
|
err := engine.Bot.LoadExchange(exchange.Exchanges[x], true, &wg)
|
|
if err != nil {
|
|
log.Printf("Failed to load exchange %s. Err: %s",
|
|
exchange.Exchanges[x],
|
|
err)
|
|
continue
|
|
}
|
|
}
|
|
wg.Wait()
|
|
log.Println("Done.")
|
|
|
|
log.Printf("Testing exchange wrappers..")
|
|
results := make(map[string][]string)
|
|
wg = sync.WaitGroup{}
|
|
exchanges := engine.Bot.GetExchanges()
|
|
for x := range exchanges {
|
|
exch := exchanges[x]
|
|
wg.Add(1)
|
|
go func(e exchange.IBotExchange) {
|
|
results[e.GetName()] = testWrappers(e)
|
|
wg.Done()
|
|
}(exch)
|
|
}
|
|
wg.Wait()
|
|
log.Println("Done.")
|
|
|
|
log.Println()
|
|
for name, funcs := range results {
|
|
pct := float64(totalWrappers-len(funcs)) / float64(totalWrappers) * 100
|
|
log.Printf("Exchange %s wrapper coverage [%d/%d - %.2f%%] | Total missing: %d", name, totalWrappers-len(funcs), totalWrappers, pct, len(funcs))
|
|
log.Printf("\t Wrappers not implemented:")
|
|
|
|
for x := range funcs {
|
|
log.Printf("\t - %s", funcs[x])
|
|
}
|
|
log.Println()
|
|
}
|
|
}
|
|
|
|
func testWrappers(e exchange.IBotExchange) []string {
|
|
p := currency.NewPair(currency.BTC, currency.USD)
|
|
assetType := asset.Spot
|
|
if !e.SupportsAsset(assetType) {
|
|
assets := e.GetAssetTypes()
|
|
rand.Seed(time.Now().Unix())
|
|
assetType = assets[rand.Intn(len(assets))] // nolint:gosec // basic number generation required, no need for crypo/rand
|
|
}
|
|
|
|
var funcs []string
|
|
|
|
_, err := e.FetchTicker(p, assetType)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "FetchTicker")
|
|
}
|
|
|
|
_, err = e.UpdateTicker(p, assetType)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "UpdateTicker")
|
|
}
|
|
|
|
_, err = e.FetchOrderbook(p, assetType)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "FetchOrderbook")
|
|
}
|
|
|
|
_, err = e.UpdateOrderbook(p, assetType)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "UpdateOrderbook")
|
|
}
|
|
|
|
_, err = e.FetchTradablePairs(asset.Spot)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "FetchTradablePairs")
|
|
}
|
|
|
|
err = e.UpdateTradablePairs(false)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "UpdateTradablePairs")
|
|
}
|
|
|
|
_, err = e.FetchAccountInfo()
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "GetAccountInfo")
|
|
}
|
|
|
|
_, err = e.GetExchangeHistory(p, assetType, time.Time{}, time.Time{})
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "GetExchangeHistory")
|
|
}
|
|
|
|
_, err = e.GetFundingHistory()
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "GetFundingHistory")
|
|
}
|
|
|
|
_, err = e.SubmitOrder(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "SubmitOrder")
|
|
}
|
|
|
|
_, err = e.ModifyOrder(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "ModifyOrder")
|
|
}
|
|
|
|
err = e.CancelOrder(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "CancelOrder")
|
|
}
|
|
|
|
_, err = e.CancelAllOrders(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "CancelAllOrders")
|
|
}
|
|
|
|
_, err = e.GetOrderInfo("1")
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "GetOrderInfo")
|
|
}
|
|
|
|
_, err = e.GetOrderHistory(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "GetOrderHistory")
|
|
}
|
|
|
|
_, err = e.GetActiveOrders(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "GetActiveOrders")
|
|
}
|
|
|
|
_, err = e.GetDepositAddress(currency.BTC, "")
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "GetDepositAddress")
|
|
}
|
|
|
|
_, err = e.WithdrawCryptocurrencyFunds(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "WithdrawCryptocurrencyFunds")
|
|
}
|
|
|
|
_, err = e.WithdrawFiatFunds(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "WithdrawFiatFunds")
|
|
}
|
|
_, err = e.WithdrawFiatFundsToInternationalBank(nil)
|
|
if err == common.ErrNotYetImplemented {
|
|
funcs = append(funcs, "WithdrawFiatFundsToInternationalBank")
|
|
}
|
|
|
|
return funcs
|
|
}
|