mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-22 23:16:48 +00:00
Engine QA (#381)
* 1) Update Dockerfile/docker-compose.yml 2) Remove inline strings for buy/sell/test pairs 3) Remove dangerous order submission values 4) Fix consistency with audit_events (all other spec files use CamelCase) 5) Update web websocket endpoint 6) Fix main param set (and induce dryrun mode on specific command line params) * Engine QA Link up exchange syncer to cmd params, disarm market selling bombs and fix OKEX endpoints * Fix linter issue after merge * Engine QA changes Template updates Wrapper code cleanup Disarmed order bombs Documentation updates * Daily engine QA Bitstamp improvements Spelling mistakes Add Coinbene exchange to support list Protect API authenticated calls for Coinbene/LBank * Engine QA changes Fix exchange_wrapper_coverage tool Add SupportsAsset to exchange interface Fix inline string usage and add BCH withdrawal support * Engine QA Fix Bitstamp types Inform user of errors when parsing time accross the codebase Change time parsing warnings to errors (as they are) Update markdown docs [with linter fixes] * Engine QA changes 1) Add test for dryrunParamInteraction 2) Disarm OKCoin/OKEX bombs if someone accidently sets canManipulateRealOrders to true and runs all package tests 3) Actually check exchange setup errors for BTSE and Coinbene, plus address this in the wrapper template 4) Hardcode missing/non-retrievable contributors and bump the contributors 5) Convert numbers/strings to meaningful types in Bitstamp and OKEX 6) If WS is supported for the exchange wrapper template, preset authWebsocketSupport var * Fix the shadow people * Link the SyncContinuously paramerino * Also show SyncContinuously in engine.PrintSettings * Address nitterinos and use correct filepath for logs * Bitstamp: Extract ALL THE APM * Fix additional nitterinos * Fix time parsing error for Bittrex
This commit is contained in:
@@ -116,6 +116,44 @@ func main() {
|
||||
err)
|
||||
}
|
||||
|
||||
// idoall's contributors were forked and merged, so his contributions
|
||||
// aren't automatically retrievable
|
||||
contributors = append(contributors, Contributor{
|
||||
Login: "idoall",
|
||||
URL: "https://github.com/idoall",
|
||||
Contributions: 1,
|
||||
})
|
||||
|
||||
// Github API missing contributors
|
||||
missingAPIContributors := []Contributor{
|
||||
{
|
||||
Login: "mattkanwisher",
|
||||
URL: "https://github.com/mattkanwisher",
|
||||
Contributions: 1,
|
||||
},
|
||||
{
|
||||
Login: "mKurrels",
|
||||
URL: "https://github.com/mKurrels",
|
||||
Contributions: 1,
|
||||
},
|
||||
{
|
||||
Login: "m1kola",
|
||||
URL: "https://github.com/m1kola",
|
||||
Contributions: 1,
|
||||
},
|
||||
{
|
||||
Login: "cavapoo2",
|
||||
URL: "https://github.com/cavapoo2",
|
||||
Contributions: 1,
|
||||
},
|
||||
{
|
||||
Login: "zeldrinn",
|
||||
URL: "https://github.com/zeldrinn",
|
||||
Contributions: 1,
|
||||
},
|
||||
}
|
||||
contributors = append(contributors, missingAPIContributors...)
|
||||
|
||||
if *verbose {
|
||||
fmt.Println("Contributor List Fetched")
|
||||
for i := range contributors {
|
||||
|
||||
@@ -30,9 +30,9 @@ main.go
|
||||
```go
|
||||
var c exchange.IBotExchange
|
||||
|
||||
for i := range bot.exchanges {
|
||||
if bot.exchanges[i].GetName() == "Coinbene" {
|
||||
c = bot.exchanges[i]
|
||||
for i := range Bot.Exchanges {
|
||||
if Bot.Exchanges[i].GetName() == "Coinbene" {
|
||||
c = Bot.Exchanges[i]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,22 +29,22 @@ main.go
|
||||
```go
|
||||
var l exchange.IBotExchange
|
||||
|
||||
for i := range bot.exchanges {
|
||||
if bot.exchanges[i].GetName() == "Lbank" {
|
||||
l = bot.exchanges[i]
|
||||
for i := range Bot.Exchanges {
|
||||
if Bot.Exchanges[i].GetName() == "Lbank" {
|
||||
l = Bot.Exchanges[i]
|
||||
}
|
||||
}
|
||||
|
||||
// Public calls - wrapper functions
|
||||
|
||||
// Fetches current ticker information
|
||||
tick, err := l.GetTickerPrice()
|
||||
tick, err := l.FetchTicker()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Fetches current orderbook information
|
||||
ob, err := l.GetOrderbookEx()
|
||||
ob, err := l.FetchOrderbook()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ const (
|
||||
packageReadme = "README.md"
|
||||
|
||||
exchangePackageLocation = "../../exchanges"
|
||||
exchangeLocation = "../../exchange.go"
|
||||
exchangeConfigPath = "../../testdata/configtest.json"
|
||||
)
|
||||
|
||||
@@ -35,7 +34,6 @@ var (
|
||||
exchangeWrapper string
|
||||
exchangeMain string
|
||||
exchangeReadme string
|
||||
exchangeJSON string
|
||||
)
|
||||
|
||||
type exchange struct {
|
||||
@@ -119,17 +117,22 @@ func main() {
|
||||
newExchConfig.Enabled = true
|
||||
newExchConfig.API.Credentials.Key = "Key"
|
||||
newExchConfig.API.Credentials.Secret = "Secret"
|
||||
|
||||
newExchConfig.CurrencyPairs = ¤cy.PairsManager{
|
||||
AssetTypes: asset.Items{
|
||||
asset.Spot,
|
||||
},
|
||||
UseGlobalFormat: true,
|
||||
RequestFormat: ¤cy.PairFormat{
|
||||
Uppercase: true,
|
||||
},
|
||||
ConfigFormat: ¤cy.PairFormat{
|
||||
Uppercase: true,
|
||||
},
|
||||
}
|
||||
|
||||
configTestFile.Exchanges = append(configTestFile.Exchanges, newExchConfig)
|
||||
// TODO sorting function so exchanges are in alphabetical order - low priority
|
||||
|
||||
err = configTestFile.SaveConfig(exchangeJSON, false)
|
||||
err = configTestFile.SaveConfig(exchangeConfigPath, false)
|
||||
if err != nil {
|
||||
log.Fatal("GoCryptoTrader: Exchange templating configuration error - cannot save")
|
||||
}
|
||||
@@ -217,12 +220,13 @@ func main() {
|
||||
}
|
||||
|
||||
fmt.Println("GoCryptoTrader: Exchange templating tool service complete")
|
||||
fmt.Println("When wrapper is finished add exchange to exchange.go")
|
||||
fmt.Println("Test exchange.go")
|
||||
fmt.Println("Update the config_test.go file")
|
||||
fmt.Println("Test config.go")
|
||||
fmt.Println("When the exchange code implementation has been completed (REST/Websocket/wrappers and tests), please add the exchange to engine/exchange.go")
|
||||
fmt.Println("Add the exchange config settings to config_example.json (it will automatically be added to testdata/configtest.json)")
|
||||
fmt.Println("Increment the available exchanges counter in config/config_test.go")
|
||||
fmt.Println("Add the exchange name to exchanges/support.go")
|
||||
fmt.Println("Ensure go test ./... -race passes")
|
||||
fmt.Println("Open a pull request")
|
||||
fmt.Println("If help is needed please post a message on Slack.")
|
||||
fmt.Println("If help is needed, please post a message in Slack.")
|
||||
}
|
||||
|
||||
func newFile(path string) {
|
||||
|
||||
@@ -2,15 +2,7 @@
|
||||
package {{.Name}}
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
// {{.CapitalName}} is the overarching type across this package
|
||||
@@ -20,91 +12,13 @@ type {{.CapitalName}} struct {
|
||||
|
||||
const (
|
||||
{{.Name}}APIURL = ""
|
||||
{{.Name}}APIVersion = ""
|
||||
{{.Name}}APIVersion = ""
|
||||
|
||||
// Public endpoints
|
||||
|
||||
// Authenticated endpoints
|
||||
|
||||
)
|
||||
|
||||
// SetDefaults sets the basic defaults for {{.CapitalName}}
|
||||
func ({{.Variable}} *{{.CapitalName}}) SetDefaults() {
|
||||
{{.Variable}}.Name = "{{.CapitalName}}"
|
||||
{{.Variable}}.Enabled = false
|
||||
{{.Variable}}.Verbose = false
|
||||
{{.Variable}}.RequestCurrencyPairFormat.Delimiter = ""
|
||||
{{.Variable}}.RequestCurrencyPairFormat.Uppercase = true
|
||||
{{.Variable}}.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
{{.Variable}}.ConfigCurrencyPairFormat.Uppercase = true
|
||||
{{.Variable}}.AssetTypes = asset.Items{asset.Spot}
|
||||
{{.Variable}}.SupportsAutoPairUpdating = false
|
||||
{{.Variable}}.SupportsRESTTickerBatching = false
|
||||
{{.Variable}}.Requester = request.New({{.Variable}}.Name,
|
||||
request.NewRateLimit(time.Second, 0),
|
||||
request.NewRateLimit(time.Second, 0),
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
||||
{{.Variable}}.API.Endpoints.URLDefault = {{.Name}}APIURL
|
||||
{{.Variable}}.API.Endpoints.URL = {{.Variable}}.API.Endpoints.URLDefault
|
||||
{{.Variable}}.Websocket = monitor.New()
|
||||
{{.Variable}}.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
{{.Variable}}.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
}
|
||||
// Start implementing public and private exchange API funcs below
|
||||
|
||||
// Setup takes in the supplied exchange configuration details and sets params
|
||||
func ({{.Variable}} *{{.CapitalName}}) Setup(exch *config.ExchangeConfig) error {
|
||||
if !exch.Enabled {
|
||||
{{.Variable}}.SetEnabled(false)
|
||||
} else {
|
||||
{{.Variable}}.Enabled = true
|
||||
{{.Variable}}.API.AuthenticatedSupport = exch.API.AuthenticatedSupport
|
||||
{{.Variable}}.API.AuthenticatedWebsocketSupport = exch.API.AuthenticatedWebsocketSupport
|
||||
{{.Variable}}.SetAPIKeys(exch.API.Credentials.Key, exch.API.Credentials.Secret, "", false)
|
||||
{{.Variable}}.SetHTTPClientTimeout(exch.HTTPTimeout)
|
||||
{{.Variable}}.SetHTTPClientUserAgent(exch.HTTPUserAgent)
|
||||
{{.Variable}}.Verbose = exch.Verbose
|
||||
{{.Variable}}.Websocket.SetWsStatusAndConnection(exch.Features.Enabled.Websocket)
|
||||
{{.Variable}}.BaseCurrencies = strings.Split(exch.BaseCurrencies, ",")
|
||||
{{.Variable}}.AvailablePairs = strings.Split(exch.AvailablePairs, ",")
|
||||
{{.Variable}}.EnabledPairs = strings.Split(exch.EnabledPairs, ",")
|
||||
err := {{.Variable}}.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = {{.Variable}}.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = {{.Variable}}.SetFeatureDefaults()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = {{.Variable}}.SetAPIURL(exch)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = {{.Variable}}.SetClientProxyAddress(exch.ProxyAddress)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// If the exchange supports websocket, update the below block
|
||||
// err = {{.Variable}}.Websocket.Setup({{.Variable}}.WsConnect,
|
||||
// exch.Name,
|
||||
// exch.Features.Enabled.Websocket,
|
||||
// {{.Name}}Websocket,
|
||||
// exch.Features.Enabled.WebsocketURL)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// {{.Variable}}.WebsocketConn = &wshandler.WebsocketConnection{
|
||||
// ExchangeName: {{.Variable}}.Name,
|
||||
// URL: {{.Variable}}.Websocket.GetWebsocketURL(),
|
||||
// ProxyURL: {{.Variable}}.Websocket.GetProxyAddress(),
|
||||
// Verbose: {{.Variable}}.Verbose,
|
||||
// ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
|
||||
// ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
|
||||
// }
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
@@ -2,35 +2,51 @@
|
||||
package {{.Name}}
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
)
|
||||
|
||||
// Please supply your own keys here for due diligence testing
|
||||
// Please supply your own keys here to do authenticated endpoint testing
|
||||
const (
|
||||
testAPIKey = ""
|
||||
testAPISecret = ""
|
||||
apiKey = ""
|
||||
apiSecret = ""
|
||||
canManipulateRealOrders = false
|
||||
)
|
||||
|
||||
var {{.Variable}} {{.CapitalName}}
|
||||
|
||||
func TestSetDefaults(t *testing.T) {
|
||||
func TestMain(m *testing.M) {
|
||||
{{.Variable}}.SetDefaults()
|
||||
}
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
cfg.LoadConfig("../../testdata/configtest.json")
|
||||
{{.Name}}Config, err := cfg.GetExchangeConfig("{{.CapitalName}}")
|
||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
||||
if err != nil {
|
||||
t.Error("{{.CapitalName}} Setup() init error")
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
{{.Name}}Config.API.AuthenticatedSupport = true
|
||||
{{.Name}}Config.API.Credentials.Key = testAPIKey
|
||||
{{.Name}}Config.API.Credentials.Secret = testAPISecret
|
||||
exchCfg, err := cfg.GetExchangeConfig("{{.CapitalName}}")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
{{.Variable}}.Setup({{.Name}}Config)
|
||||
exchCfg.API.AuthenticatedSupport = true
|
||||
{{ if .WS }} exchCfg.API.AuthenticatedWebsocketSupport = true {{ end }}
|
||||
exchCfg.API.Credentials.Key = apiKey
|
||||
exchCfg.API.Credentials.Secret = apiSecret
|
||||
|
||||
err = {{.Variable}}.Setup(exchCfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func areTestAPIKeysSet() bool {
|
||||
return {{.Variable}}.ValidateAPICredentials()
|
||||
}
|
||||
|
||||
// Implement tests for API endpoints below
|
||||
{{end}}
|
||||
|
||||
@@ -3,15 +3,150 @@ package {{.Name}}
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetDefaultConfig() (*config.ExchangeConfig, error) {
|
||||
{{.Variable}}.SetDefaults()
|
||||
exchCfg := new(config.ExchangeConfig)
|
||||
exchCfg.Name = {{.Variable}}.Name
|
||||
exchCfg.HTTPTimeout = exchange.DefaultHTTPTimeout
|
||||
exchCfg.BaseCurrencies = {{.Variable}}.BaseCurrencies
|
||||
|
||||
err := {{.Variable}}.SetupDefaults(exchCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if {{.Variable}}.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
err = {{.Variable}}.UpdateTradablePairs(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return exchCfg, nil
|
||||
}
|
||||
|
||||
// SetDefaults sets the basic defaults for {{.CapitalName}}
|
||||
func ({{.Variable}} *{{.CapitalName}}) SetDefaults() {
|
||||
{{.Variable}}.Name = "{{.CapitalName}}"
|
||||
{{.Variable}}.Enabled = true
|
||||
{{.Variable}}.Verbose = true
|
||||
{{.Variable}}.API.CredentialsValidator.RequiresKey = true
|
||||
{{.Variable}}.API.CredentialsValidator.RequiresSecret = true
|
||||
{{.Variable}}.CurrencyPairs = currency.PairsManager{
|
||||
AssetTypes: asset.Items{
|
||||
asset.Spot,
|
||||
},
|
||||
UseGlobalFormat: true,
|
||||
RequestFormat: ¤cy.PairFormat{
|
||||
Uppercase: true,
|
||||
Delimiter: "-",
|
||||
},
|
||||
ConfigFormat: ¤cy.PairFormat{
|
||||
Uppercase: true,
|
||||
Delimiter: "-",
|
||||
},
|
||||
}
|
||||
// Fill out the capabilities/features that the exchange supports
|
||||
{{.Variable}}.Features = exchange.Features{
|
||||
Supports: exchange.FeaturesSupported{
|
||||
{{ if .REST }} REST: true, {{ end }}
|
||||
{{ if .WS }} Websocket: true, {{ end }}
|
||||
RESTCapabilities: protocol.Features{
|
||||
TickerFetching: true,
|
||||
OrderbookFetching: true,
|
||||
},
|
||||
WebsocketCapabilities: protocol.Features{
|
||||
TickerFetching: true,
|
||||
OrderbookFetching: true,
|
||||
},
|
||||
WithdrawPermissions: exchange.AutoWithdrawCrypto |
|
||||
exchange.AutoWithdrawFiat,
|
||||
},
|
||||
Enabled: exchange.FeaturesEnabled{
|
||||
AutoPairUpdates: true,
|
||||
},
|
||||
}
|
||||
{{.Variable}}.Requester = request.New({{.Variable}}.Name,
|
||||
request.NewRateLimit(time.Second, 0),
|
||||
request.NewRateLimit(time.Second, 0),
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
||||
{{.Variable}}.API.Endpoints.URLDefault = {{.Name}}APIURL
|
||||
{{.Variable}}.API.Endpoints.URL = {{.Variable}}.API.Endpoints.URLDefault
|
||||
{{.Variable}}.Websocket = wshandler.New()
|
||||
{{.Variable}}.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
{{.Variable}}.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
{{.Variable}}.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
|
||||
}
|
||||
|
||||
// Setup takes in the supplied exchange configuration details and sets params
|
||||
func ({{.Variable}} *{{.CapitalName}}) Setup(exch *config.ExchangeConfig) error {
|
||||
if !exch.Enabled {
|
||||
{{.Variable}}.SetEnabled(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
err := {{.Variable}}.SetupDefaults(exch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If websocket is supported, please fill out the following
|
||||
/*
|
||||
err = {{.Variable}}.Websocket.Setup(
|
||||
&wshandler.WebsocketSetup{
|
||||
Enabled: exch.Features.Enabled.Websocket,
|
||||
Verbose: exch.Verbose,
|
||||
AuthenticatedWebsocketAPISupport: exch.API.AuthenticatedWebsocketSupport,
|
||||
WebsocketTimeout: exch.WebsocketTrafficTimeout,
|
||||
DefaultURL: {{.Name}}WSURL,
|
||||
ExchangeName: exch.Name,
|
||||
RunningURL: exch.API.Endpoints.WebsocketURL,
|
||||
Connector: {{.Variable}}.WsConnect,
|
||||
Subscriber: {{.Variable}}.Subscribe,
|
||||
UnSubscriber: {{.Variable}}.Unsubscribe,
|
||||
Features: &{{.Variable}}.Features.Supports.WebsocketCapabilities,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
{{.Variable}}.WebsocketConn = &wshandler.WebsocketConnection{
|
||||
ExchangeName: {{.Variable}}.Name,
|
||||
URL: {{.Variable}}.Websocket.GetWebsocketURL(),
|
||||
ProxyURL: {{.Variable}}.Websocket.GetProxyAddress(),
|
||||
Verbose: {{.Variable}}.Verbose,
|
||||
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
|
||||
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
|
||||
}
|
||||
|
||||
// NOTE: PLEASE ENSURE YOU SET THE ORDERBOOK BUFFER SETTINGS CORRECTLY
|
||||
{{.Variable}}.Websocket.Orderbook.Setup(
|
||||
exch.WebsocketOrderbookBufferLimit,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
exch.Name)
|
||||
*/
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start starts the {{.CapitalName}} go routine
|
||||
func ({{.Variable}} *{{.CapitalName}}) Start(wg *sync.WaitGroup) {
|
||||
wg.Add(1)
|
||||
@@ -24,38 +159,68 @@ func ({{.Variable}} *{{.CapitalName}}) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the {{.CapitalName}} wrapper
|
||||
func ({{.Variable}} *{{.CapitalName}}) Run() {
|
||||
if {{.Variable}}.Verbose {
|
||||
{{if .WS}} log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n", {{.Variable}}.Name, common.IsEnabled({{.Variable}}.Websocket.IsEnabled()), {{.Variable}}.Websocket.GetWebsocketURL()) {{end}}
|
||||
log.Debugf(log.ExchangeSys, "%s polling delay: %ds.\n", {{.Variable}}.Name, {{.Variable}}.RESTPollingDelay)
|
||||
log.Debugf(log.ExchangeSys, "%s %d currencies enabled: %s.\n", {{.Variable}}.Name, len({{.Variable}}.EnabledPairs), {{.Variable}}.EnabledPairs)
|
||||
{{ if .WS }} log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s.",
|
||||
{{.Variable}}.Name,
|
||||
common.IsEnabled({{.Variable}}.Websocket.IsEnabled())) {{ end }}
|
||||
{{.Variable}}.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
if !{{.Variable}}.GetEnabledFeatures().AutoPairUpdates {
|
||||
return
|
||||
}
|
||||
|
||||
err := {{.Variable}}.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
{{.Variable}}.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func ({{.Variable}} *{{.CapitalName}}) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
||||
// Implement fetching the exchange available pairs if supported
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
// them in the exchanges config
|
||||
func ({{.Variable}} *{{.CapitalName}}) UpdateTradablePairs(forceUpdate bool) error {
|
||||
pairs, err := {{.Variable}}.FetchTradablePairs(asset.Spot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return {{.Variable}}.UpdatePairs(currency.NewPairsFromStrings(pairs),
|
||||
asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func ({{.Variable}} *{{.CapitalName}}) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
|
||||
// NOTE: EXAMPLE FOR GETTING TICKER PRICE
|
||||
/*
|
||||
var tickerPrice ticker.Price
|
||||
// NOTE EXAMPLE FOR GETTING TICKER PRICE
|
||||
//tick, err := {{.Variable}}.GetTickers()
|
||||
//if err != nil {
|
||||
// return tickerPrice, err
|
||||
//}
|
||||
|
||||
//for _, x := range {{.Variable}}.GetEnabledPairs(assetType) {
|
||||
//curr := exchange.FormatExchangeCurrency({{.Variable}}.Name, x)
|
||||
//for y := range tick {
|
||||
// if tick[y].Symbol == curr.String() {
|
||||
// tickerPrice.Pair = x
|
||||
// tickerPrice.Ask = tick[y].AskPrice
|
||||
// tickerPrice.Bid = tick[y].BidPrice
|
||||
// tickerPrice.High = tick[y].HighPrice
|
||||
// tickerPrice.Last = tick[y].LastPrice
|
||||
// tickerPrice.Low = tick[y].LowPrice
|
||||
// tickerPrice.Volume = tick[y].Volume
|
||||
// ticker.ProcessTicker({{.Variable}}.Name, x, &tickerPrice, assetType)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//return ticker.GetTicker({{.Variable}}.Name, p, assetType)
|
||||
return tickerPrice, nil // NOTE DO NOT USE AS RETURN
|
||||
tick, err := {{.Variable}}.GetTicker(p.String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
tickerPrice = ticker.Price{
|
||||
High: tick.High,
|
||||
Low: tick.Low,
|
||||
Bid: tick.Bid,
|
||||
Ask: tick.Ask,
|
||||
Open: tick.Open,
|
||||
Close: tick.Close,
|
||||
Pair: p,
|
||||
}
|
||||
err = ticker.ProcessTicker({{.Variable}}.Name, &tickerPrice, assetType)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
*/
|
||||
return ticker.GetTicker({{.Variable}}.Name, p, assetType)
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
@@ -79,23 +244,39 @@ func ({{.Variable}} *{{.CapitalName}}) FetchOrderbook(currency currency.Pair, as
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
//NOTE UPDATE ORDERBOOK EXAMPLE
|
||||
//orderbookNew, err := {{.Variable}}.GetOrderBook(exchange.FormatExchangeCurrency({{.Variable}}.Name, p).String(), 1000)
|
||||
//if err != nil {
|
||||
// return orderBook, err
|
||||
//}
|
||||
// NOTE: UPDATE ORDERBOOK EXAMPLE
|
||||
/*
|
||||
orderbookNew, err := {{.Variable}}.GetOrderBook(exchange.FormatExchangeCurrency({{.Variable}}.Name, p).String(), 1000)
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
//for _, bids := range orderbookNew.Bids {
|
||||
// orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: bids.Quantity, Price: bids.Price})
|
||||
//}
|
||||
for x := range orderbookNew.Bids {
|
||||
orderBook.Bids = append(orderBook.Bids, orderbook.Item{
|
||||
Amount: orderbookNew.Bids[x].Quantity,
|
||||
Price: orderbookNew.Bids[x].Price,
|
||||
})
|
||||
}
|
||||
|
||||
//for _, asks := range orderbookNew.Asks {
|
||||
// orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: asks.Quantity, Price: asks.Price})
|
||||
//}
|
||||
for x := range orderbookNew.Asks {
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{
|
||||
Amount: orderBook.Asks[x].Quantity,
|
||||
Price: orderBook.Asks[x].Price,
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
//orderbook.ProcessOrderbook(b.Name, p, orderBook, assetType)
|
||||
//return orderbook.Get({{.Variable}}.Name, p, assetType)
|
||||
return orderBook, nil // NOTE DO NOT USE AS RETURN
|
||||
|
||||
orderBook.Pair = p
|
||||
orderBook.ExchangeName = {{.Variable}}.Name
|
||||
orderBook.AssetType = assetType
|
||||
|
||||
err := orderBook.Process()
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
return orderbook.Get({{.Variable}}.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetAccountInfo retrieves balances for all enabled currencies for the
|
||||
@@ -116,8 +297,12 @@ func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p currency.Pair, asset
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p currency.Pair, side order.Side, orderType order.Type, amount, price float64, clientID string) (order.SubmitResponse, error) {
|
||||
return order.SubmitResponse{}, common.ErrNotYetImplemented
|
||||
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
return submitOrderResponse, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
@@ -142,30 +327,30 @@ func ({{.Variable}} *{{.CapitalName}}) GetOrderInfo(orderID string) (order.Detai
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.WithdrawRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *exchange.WithdrawRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.WithdrawRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetWebsocket() (*exchange.Websocket, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetWebsocket() (*wshandler.Websocket, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -187,20 +372,20 @@ func ({{.Variable}} *{{.CapitalName}}) GetFeeByType(feeBuilder *exchange.FeeBuil
|
||||
|
||||
// SubscribeToWebsocketChannels appends to ChannelsToSubscribe
|
||||
// which lets websocket.manageSubscriptions handle subscribing
|
||||
func ({{.Variable}} *{{.CapitalName}}) SubscribeToWebsocketChannels(channels []monitor.WebsocketChannelSubscription) error {
|
||||
func ({{.Variable}} *{{.CapitalName}}) SubscribeToWebsocketChannels(channels []wshandler.WebsocketChannelSubscription) error {
|
||||
{{.Variable}}.Websocket.SubscribeToChannels(channels)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnsubscribeToWebsocketChannels removes from ChannelsToSubscribe
|
||||
// which lets websocket.manageSubscriptions handle unsubscribing
|
||||
func ({{.Variable}} *{{.CapitalName}}) UnsubscribeToWebsocketChannels(channels []monitor.WebsocketChannelSubscription) error {
|
||||
{{.Variable}}.Websocket.UnubscribeToChannels(channels)
|
||||
func ({{.Variable}} *{{.CapitalName}}) UnsubscribeToWebsocketChannels(channels []wshandler.WebsocketChannelSubscription) error {
|
||||
{{.Variable}}.Websocket.RemoveSubscribedChannels(channels)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSubscriptions returns a copied list of subscriptions
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetSubscriptions() ([]monitor.WebsocketChannelSubscription, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetSubscriptions() ([]wshandler.WebsocketChannelSubscription, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
@@ -70,6 +72,12 @@ func main() {
|
||||
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))]
|
||||
}
|
||||
|
||||
var funcs []string
|
||||
|
||||
_, err := e.FetchTicker(p, assetType)
|
||||
|
||||
@@ -91,6 +91,11 @@
|
||||
"clientID": "ClientID",
|
||||
"otpSecret": "-"
|
||||
},
|
||||
"coinbene": {
|
||||
"key": "Key",
|
||||
"secret": "Secret",
|
||||
"otpSecret": "-"
|
||||
},
|
||||
"coinut": {
|
||||
"key": "Key",
|
||||
"clientID": "ClientID",
|
||||
@@ -136,7 +141,11 @@
|
||||
"secret": "Secret",
|
||||
"otpSecret": "-"
|
||||
},
|
||||
"lbank": {},
|
||||
"lbank": {
|
||||
"key": "Key",
|
||||
"secret": "Secret",
|
||||
"otpSecret": "-"
|
||||
},
|
||||
"localbitcoins": {
|
||||
"key": "Key",
|
||||
"secret": "Secret",
|
||||
|
||||
Reference in New Issue
Block a user