From f23b57b670693ef77d99000caacb527cafee4509 Mon Sep 17 00:00:00 2001 From: shazbert Date: Sun, 18 Aug 2024 14:30:34 +1000 Subject: [PATCH 01/11] Add initial POC --- CONTRIBUTORS | 6 +- README.md | 8 +- cmd/documentation/documentation.go | 71 ++++++++++++- .../exchanges_templates/gateio.tmpl | 2 + cmd/documentation/sub_templates/features.tmpl | 18 ++++ engine/currency_state_manager.md | 74 ++++++------- engine/engine.go | 9 +- exchanges/exchange_test.go | 2 +- exchanges/exchange_types.go | 22 ++-- exchanges/gateio/README.md | 69 ++++++++++++ exchanges/preflight.go | 100 ++++++++++++++++++ exchanges/preflight_test.go | 22 ++++ exchanges/protocol/features.go | 31 ++++++ 13 files changed, 380 insertions(+), 54 deletions(-) create mode 100644 cmd/documentation/sub_templates/features.tmpl create mode 100644 exchanges/preflight.go create mode 100644 exchanges/preflight_test.go diff --git a/CONTRIBUTORS b/CONTRIBUTORS index f3f7013a8de..70b251f2b44 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -20,12 +20,13 @@ geseq | https://github.com/geseq marcofranssen | https://github.com/marcofranssen 140am | https://github.com/140am TaltaM | https://github.com/TaltaM -dackroyd | https://github.com/dackroyd cranktakular | https://github.com/cranktakular +dackroyd | https://github.com/dackroyd khcchiu | https://github.com/khcchiu yangrq1018 | https://github.com/yangrq1018 woshidama323 | https://github.com/woshidama323 crackcomm | https://github.com/crackcomm +mshogin | https://github.com/mshogin herenow | https://github.com/herenow tk42 | https://github.com/tk42 soxipy | https://github.com/soxipy @@ -35,10 +36,13 @@ bretep | https://github.com/bretep Christian-Achilli | https://github.com/Christian-Achilli cornelk | https://github.com/cornelk gam-phon | https://github.com/gam-phon +herenow | https://github.com/herenow if1live | https://github.com/if1live lozdog245 | https://github.com/lozdog245 MarkDzulko | https://github.com/MarkDzulko mshogin | https://github.com/mshogin +soxipy | https://github.com/soxipy +tk42 | https://github.com/tk42 blombard | https://github.com/blombard cavapoo2 | https://github.com/cavapoo2 CodeLingoTeam | https://github.com/CodeLingoTeam diff --git a/README.md b/README.md index be393b5a672..8be7fb51c1a 100644 --- a/README.md +++ b/README.md @@ -142,12 +142,12 @@ Binaries will be published once the codebase reaches a stable condition. |User|Contribution Amount| |--|--| -| [thrasher-](https://github.com/thrasher-) | 692 | -| [shazbert](https://github.com/shazbert) | 333 | -| [dependabot[bot]](https://github.com/apps/dependabot) | 293 | +| [thrasher-](https://github.com/thrasher-) | 693 | +| [shazbert](https://github.com/shazbert) | 335 | +| [dependabot[bot]](https://github.com/apps/dependabot) | 296 | | [gloriousCode](https://github.com/gloriousCode) | 234 | | [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 | -| [gbjk](https://github.com/gbjk) | 80 | +| [gbjk](https://github.com/gbjk) | 82 | | [xtda](https://github.com/xtda) | 47 | | [lrascao](https://github.com/lrascao) | 27 | | [Beadko](https://github.com/Beadko) | 17 | diff --git a/cmd/documentation/documentation.go b/cmd/documentation/documentation.go index 9416108ec98..309089f95f9 100644 --- a/cmd/documentation/documentation.go +++ b/cmd/documentation/documentation.go @@ -10,6 +10,7 @@ import ( "net/http" "os" "path/filepath" + "reflect" "strings" "text/template" "time" @@ -17,6 +18,8 @@ import ( "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/common/file" "github.com/thrasher-corp/gocryptotrader/core" + "github.com/thrasher-corp/gocryptotrader/engine" + exchange "github.com/thrasher-corp/gocryptotrader/exchanges" "golang.org/x/text/cases" "golang.org/x/text/language" ) @@ -111,6 +114,27 @@ type Attributes struct { Year int CapitalName string DonationAddress string + Features []ProtocolFeature +} + +// ProtocolFeature defines a protocol feature set +type ProtocolFeature struct { + Protocol string + Assets []AssetFeature +} + +func (a ProtocolFeature) String() string { + return a.Protocol +} + +// AssetFeature defines an asset feature set +type AssetFeature struct { + Asset string + Methods []string +} + +func (a AssetFeature) String() string { + return a.Asset } func main() { @@ -505,13 +529,15 @@ func GetContributorList(repo string, verbose bool) ([]Contributor, error) { // GetDocumentationAttributes returns specific attributes for a file template func GetDocumentationAttributes(packageName string, contributors []Contributor) Attributes { + name := GetPackageName(packageName, false) return Attributes{ - Name: GetPackageName(packageName, false), + Name: name, Contributors: contributors, NameURL: GetGoDocURL(packageName), Year: time.Now().Year(), CapitalName: GetPackageName(packageName, true), DonationAddress: core.BitcoinDonationAddress, + Features: GetFeatures(name), } } @@ -529,6 +555,49 @@ func GetPackageName(name string, capital bool) string { return newStrings[i] } +// GetFeatures returns a dynamic list of supported functionality for a specific asset type. +func GetFeatures(name string) []ProtocolFeature { + if name != "gateio" { // TODO: Remove and implement across all exchanges after POC. + return nil + } + exch, _ := engine.NewExchangeByNameWithDefaults(context.Background(), name) + if exch == nil { + return nil + } + + set := exchange.AutomaticPreFlightCheck(exch) + if set == nil { + return nil + } + + lookup := make(map[string][]AssetFeature) + for k, v := range set { + var f AssetFeature + f.Asset = k.Asset.String() + t := reflect.TypeOf(v) + + // Iterate over the struct fields + for i := 0; i < t.NumField(); i++ { + value := reflect.ValueOf(v).Field(i) + if value.Kind() != reflect.Bool || !value.Bool() { + continue + } + f.Methods = append(f.Methods, t.Field(i).Name) + } + lookup[k.Protocol.String()] = append(lookup[k.Protocol.String()], f) + } + features := make([]ProtocolFeature, 0) + for k, v := range lookup { + v = common.SortStrings(v) + features = append(features, ProtocolFeature{ + Protocol: k, + Assets: v, + }) + } + features = common.SortStrings(features) + return features +} + // GetGoDocURL returns a string for godoc package names func GetGoDocURL(name string) string { if strings.Contains(name, " ") { diff --git a/cmd/documentation/exchanges_templates/gateio.tmpl b/cmd/documentation/exchanges_templates/gateio.tmpl index e099048d9e4..9a66e04d680 100644 --- a/cmd/documentation/exchanges_templates/gateio.tmpl +++ b/cmd/documentation/exchanges_templates/gateio.tmpl @@ -99,6 +99,8 @@ if err != nil { // supplied then ``` +{{template "features" .}} + ### Please click GoDocs chevron above to view current GoDoc information for this package {{template "contributions"}} {{template "donations" .}} diff --git a/cmd/documentation/sub_templates/features.tmpl b/cmd/documentation/sub_templates/features.tmpl new file mode 100644 index 00000000000..bfc8e0258a1 --- /dev/null +++ b/cmd/documentation/sub_templates/features.tmpl @@ -0,0 +1,18 @@ +{{define "features" -}} +## Trading Methods Supported + +{{range $feature := .Features -}} +### Protocol: {{$feature.Protocol}} + +{{range $assetFeatures := $feature.Assets -}} +#### Asset: {{$assetFeatures.Asset}} + +Supported Methods: +{{- range $method := $assetFeatures.Methods }} +- {{$method}} +{{- end }} + +{{end}} +{{end}} + +{{end}} \ No newline at end of file diff --git a/engine/currency_state_manager.md b/engine/currency_state_manager.md index e84b08aa23d..b3ec29aa552 100644 --- a/engine/currency_state_manager.md +++ b/engine/currency_state_manager.md @@ -1,22 +1,22 @@ -# GoCryptoTrader package Currency state manager - - - - -[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml) -[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE) -[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/engine/currency_state_manager) -[![Coverage Status](http://codecov.io/github/thrasher-corp/gocryptotrader/coverage.svg?branch=master)](http://codecov.io/github/thrasher-corp/gocryptotrader?branch=master) -[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader) - - -This currency_state_manager package is part of the GoCryptoTrader codebase. - -## This is still in active development - -You can track ideas, planned features and what's in progress on this Trello board: [https://trello.com/b/ZAhMhpOy/gocryptotrader](https://trello.com/b/ZAhMhpOy/gocryptotrader). - -Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk) +# GoCryptoTrader package Currency state manager + + + + +[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml) +[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE) +[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/engine/currency_state_manager) +[![Coverage Status](http://codecov.io/github/thrasher-corp/gocryptotrader/coverage.svg?branch=master)](http://codecov.io/github/thrasher-corp/gocryptotrader?branch=master) +[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader) + + +This currency_state_manager package is part of the GoCryptoTrader codebase. + +## This is still in active development + +You can track ideas, planned features and what's in progress on this Trello board: [https://trello.com/b/ZAhMhpOy/gocryptotrader](https://trello.com/b/ZAhMhpOy/gocryptotrader). + +Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk) ## Current Features for Currency state manager + The state manager keeps currency states up to date, which include: @@ -27,22 +27,22 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + This allows for an internal state check to compliment internal and external strategies. - -## Contribution - -Please feel free to submit any pull requests or suggest any desired features to be added. - -When submitting a PR, please abide by our coding guidelines: - -+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). -+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. -+ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md). -+ Pull requests need to be based on and opened against the `master` branch. - -## Donations - - - -If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to: - + +## Contribution + +Please feel free to submit any pull requests or suggest any desired features to be added. + +When submitting a PR, please abide by our coding guidelines: + ++ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). ++ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. ++ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md). ++ Pull requests need to be based on and opened against the `master` branch. + +## Donations + + + +If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to: + ***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc*** diff --git a/engine/engine.go b/engine/engine.go index 2b836600681..4080c85e2ae 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -846,7 +846,14 @@ func (bot *Engine) LoadExchange(name string) error { } } - return exchange.Bootstrap(context.TODO(), exch) + err = exchange.Bootstrap(context.TODO(), exch) + if err != nil { + return err + } + + // Update prototocol capabilities with dynamic pre flight check. + exch.GetBase().ProtocolCapabilities = exchange.AutomaticPreFlightCheck(exch) + return nil } func (bot *Engine) dryRunParamInteraction(param string) { diff --git a/exchanges/exchange_test.go b/exchanges/exchange_test.go index fd4cf117373..2cd7d185572 100644 --- a/exchanges/exchange_test.go +++ b/exchanges/exchange_test.go @@ -3003,7 +3003,7 @@ func (f *FakeBase) GetFeeByType(context.Context, *FeeBuilder) (float64, error) { } func (f *FakeBase) SubmitOrder(context.Context, *order.Submit) (*order.SubmitResponse, error) { - return nil, nil + return nil, errors.New("random error") } func (f *FakeBase) ModifyOrder(context.Context, *order.Modify) (*order.ModifyResponse, error) { diff --git a/exchanges/exchange_types.go b/exchanges/exchange_types.go index dfd325af057..98be482c542 100644 --- a/exchanges/exchange_types.go +++ b/exchanges/exchange_types.go @@ -230,15 +230,19 @@ type API struct { // Base stores the individual exchange information type Base struct { - Name string - Enabled bool - Verbose bool - LoadedByConfig bool - SkipAuthCheck bool - API API - BaseCurrencies currency.Currencies - CurrencyPairs currency.PairsManager - Features Features + Name string + Enabled bool + Verbose bool + LoadedByConfig bool + SkipAuthCheck bool + API API + BaseCurrencies currency.Currencies + CurrencyPairs currency.PairsManager + Features Features + // ProtocolCapabilities is a map of supported features for each asset type + // and protocol type. This is mapped in the preflight check to determine + // if the method is functional and ready for that asset type. + ProtocolCapabilities protocol.FeatureSet HTTPTimeout time.Duration HTTPRecording bool HTTPDebugging bool diff --git a/exchanges/gateio/README.md b/exchanges/gateio/README.md index b9a4b43ba02..e17877361aa 100644 --- a/exchanges/gateio/README.md +++ b/exchanges/gateio/README.md @@ -117,6 +117,75 @@ if err != nil { // supplied then ``` +## Trading Methods Supported + +### Protocol: REST + +#### Asset: cross_margin + +Supported Methods: +- GetOrder +- GetOrders +- CancelOrders +- CancelOrder +- SubmitOrder +- UserTradeHistory + +#### Asset: delivery + +Supported Methods: +- GetOrder +- GetOrders +- CancelOrders +- CancelOrder +- SubmitOrder +- UserTradeHistory + +#### Asset: futures + +Supported Methods: +- GetOrder +- GetOrders +- CancelOrders +- CancelOrder +- SubmitOrder +- UserTradeHistory + +#### Asset: margin + +Supported Methods: +- GetOrder +- GetOrders +- CancelOrders +- CancelOrder +- SubmitOrder +- UserTradeHistory + +#### Asset: options + +Supported Methods: +- GetOrder +- GetOrders +- CancelOrders +- CancelOrder +- SubmitOrder +- UserTradeHistory + +#### Asset: spot + +Supported Methods: +- GetOrder +- GetOrders +- CancelOrders +- CancelOrder +- SubmitOrder +- UserTradeHistory + + + + + + ### Please click GoDocs chevron above to view current GoDoc information for this package ## Contribution diff --git a/exchanges/preflight.go b/exchanges/preflight.go new file mode 100644 index 00000000000..786131fd82e --- /dev/null +++ b/exchanges/preflight.go @@ -0,0 +1,100 @@ +package exchange + +import ( + "context" + "errors" + "fmt" + "reflect" + "time" + + "github.com/thrasher-corp/gocryptotrader/common" + "github.com/thrasher-corp/gocryptotrader/currency" + "github.com/thrasher-corp/gocryptotrader/exchanges/asset" + "github.com/thrasher-corp/gocryptotrader/exchanges/order" + "github.com/thrasher-corp/gocryptotrader/exchanges/protocol" + "github.com/thrasher-corp/gocryptotrader/log" +) + +type setter struct { + fn func(f *protocol.Features) *bool + args func(asset.Item) []interface{} +} + +// AutomaticPreFlightCheck analyzes the exchange's supported asset types +// and protocols, returning a set of dynamically discovered features +// (ProtocolCapabilities) that the exchange supports. This process is +// based on the exchange's specific implementation of wrapper functions. +func AutomaticPreFlightCheck(exch IBotExchange) protocol.FeatureSet { + if exch == nil { + return nil + } + + // TODO: Explicit differentiation between protocol methods on IBOTExchange + set := protocol.FeatureSet{} + + // Use a context with a deadline to ensure that the pre-flight check does not + // send any outbound requests. + ctx, cancel := context.WithDeadline(context.Background(), time.Now()) + cancel() + + // TODO: Make this more dynamic and reflect off interface.go interfaces. + methodToFeature := map[string]setter{ + "SubmitOrder": {fn: func(f *protocol.Features) *bool { return &f.SubmitOrder }, args: func(a asset.Item) []interface{} { + return []interface{}{ctx, &order.Submit{Exchange: "bruh", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}} + }}, + "ModifyOrder": {fn: func(f *protocol.Features) *bool { return &f.ModifyOrder }, args: func(a asset.Item) []interface{} { + return []interface{}{ctx, &order.Modify{Exchange: "bruh", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}} + }}, + "CancelOrder": {fn: func(f *protocol.Features) *bool { return &f.CancelOrder }, args: func(a asset.Item) []interface{} { + return []interface{}{ctx, &order.Cancel{Exchange: "bruh", AssetType: a, Pair: currency.NewBTCUSD(), OrderID: "bruh"}} + }}, + "CancelAllOrders": {fn: func(f *protocol.Features) *bool { return &f.CancelOrders }, args: func(a asset.Item) []interface{} { + return []interface{}{ctx, &order.Cancel{Exchange: "bruh", AssetType: a, Pair: currency.NewBTCUSD()}} + }}, + "GetOrderInfo": {fn: func(f *protocol.Features) *bool { return &f.GetOrder }, args: func(a asset.Item) []interface{} { return []interface{}{ctx, "someID", currency.NewBTCUSD(), a} }}, + "GetActiveOrders": {fn: func(f *protocol.Features) *bool { return &f.GetOrders }, args: func(a asset.Item) []interface{} { + return []interface{}{ctx, &order.MultiOrderRequest{AssetType: a, Pairs: currency.Pairs{currency.NewBTCUSD()}, Side: order.Buy, Type: order.Limit}} + }}, + "GetOrderHistory": {fn: func(f *protocol.Features) *bool { return &f.UserTradeHistory }, args: func(a asset.Item) []interface{} { + return []interface{}{ctx, &order.MultiOrderRequest{AssetType: a, Pairs: currency.Pairs{currency.NewBTCUSD()}, Side: order.Buy, Type: order.Limit}} + }}, + } + + for _, a := range exch.GetAssetTypes(false) { + target := protocol.Target{ + Asset: a, + Protocol: protocol.REST, + } + + features := protocol.Features{} + for methodName, featureSetter := range methodToFeature { + method := reflect.ValueOf(exch).MethodByName(methodName) + if !method.IsValid() { + log.Errorf(log.ExchangeSys, "Failed pre flight check for %s. Does not have method %s", exch.GetName(), methodName) + return nil + } + + args := featureSetter.args(a) + reflectArgs := make([]reflect.Value, len(args)) + for i, val := range args { + reflectArgs[i] = reflect.ValueOf(val) + } + + result := method.Call(reflectArgs) + err, _ := result[len(result)-1].Interface().(error) + if err == nil || + errors.Is(err, common.ErrFunctionNotSupported) || + errors.Is(err, common.ErrNotYetImplemented) || + errors.Is(err, asset.ErrNotSupported) { + continue + } + + fmt.Println(err, methodName, a) + feature := featureSetter.fn(&features) + *feature = true + } + set[target] = features + } + + return set +} diff --git a/exchanges/preflight_test.go b/exchanges/preflight_test.go new file mode 100644 index 00000000000..360a72a748e --- /dev/null +++ b/exchanges/preflight_test.go @@ -0,0 +1,22 @@ +package exchange + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/thrasher-corp/gocryptotrader/currency" + "github.com/thrasher-corp/gocryptotrader/exchanges/asset" + "github.com/thrasher-corp/gocryptotrader/exchanges/protocol" +) + +func TestAutomaticPreflightCheck(t *testing.T) { + require.Nil(t, AutomaticPreFlightCheck(nil)) + fake := &FakeBase{} + require.Empty(t, AutomaticPreFlightCheck(fake), "no assets supported") + require.NoError(t, fake.CurrencyPairs.Store(asset.Spot, ¤cy.PairStore{})) + require.NoError(t, fake.CurrencyPairs.SetAssetEnabled(asset.Spot, true)) + set := AutomaticPreFlightCheck(fake) + require.NotEmpty(t, set, "assets supported") + restSpot := set[protocol.Target{Asset: asset.Spot, Protocol: protocol.REST}] + require.True(t, restSpot.SubmitOrder, "submit order should be functional for this protocol and this asset") +} diff --git a/exchanges/protocol/features.go b/exchanges/protocol/features.go index b3c0c66662b..4f661b9ef1d 100644 --- a/exchanges/protocol/features.go +++ b/exchanges/protocol/features.go @@ -1,5 +1,7 @@ package protocol +import "github.com/thrasher-corp/gocryptotrader/exchanges/asset" + // Features holds all variables for the exchanges supported features // for a protocol (e.g REST or Websocket) type Features struct { @@ -69,3 +71,32 @@ type TradingRequirements struct { // the client and is required for order submission. ClientOrderID bool } + +// Type is a protocol type +type Type uint8 + +// String returns the protocol type as a string +func (t Type) String() string { + switch t { + case REST: + return "REST" + case Websocket: + return "Websocket" + default: + return "Unknown" + } +} + +// const for protocol types +const ( + REST Type = 0 + Websocket Type = 1 +) + +type Target struct { + Asset asset.Item + Protocol Type +} + +// FeatureSet holds the protocol type and asset type +type FeatureSet map[Target]Features From 40a53974c2d3f52d4d84efa1a8397497f760edc3 Mon Sep 17 00:00:00 2001 From: shazbert Date: Sun, 18 Aug 2024 14:43:20 +1000 Subject: [PATCH 02/11] linter: fix --- cmd/documentation/documentation.go | 2 +- exchanges/protocol/features.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/documentation/documentation.go b/cmd/documentation/documentation.go index 309089f95f9..db58ed8e0c2 100644 --- a/cmd/documentation/documentation.go +++ b/cmd/documentation/documentation.go @@ -577,7 +577,7 @@ func GetFeatures(name string) []ProtocolFeature { t := reflect.TypeOf(v) // Iterate over the struct fields - for i := 0; i < t.NumField(); i++ { + for i := range t.NumField() { value := reflect.ValueOf(v).Field(i) if value.Kind() != reflect.Bool || !value.Bool() { continue diff --git a/exchanges/protocol/features.go b/exchanges/protocol/features.go index 4f661b9ef1d..717ca8b59d4 100644 --- a/exchanges/protocol/features.go +++ b/exchanges/protocol/features.go @@ -93,6 +93,7 @@ const ( Websocket Type = 1 ) +// Target holds the asset and protocol type for a map lookup type Target struct { Asset asset.Item Protocol Type From 5e23cc177e26365213829fe51872877b061bf22c Mon Sep 17 00:00:00 2001 From: shazbert Date: Tue, 14 Jan 2025 09:02:10 +1100 Subject: [PATCH 03/11] rm fmt print call --- CONTRIBUTORS | 1 - LICENSE | 2 +- README.md | 8 ++++---- cmd/documentation/sub_templates/features.tmpl | 4 ++-- exchanges/gateio/README.md | 4 ---- exchanges/preflight.go | 10 ++++------ 6 files changed, 11 insertions(+), 18 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index fa4e12ad6ef..78590bffc2f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -36,7 +36,6 @@ bretep | https://github.com/bretep Christian-Achilli | https://github.com/Christian-Achilli cornelk | https://github.com/cornelk gam-phon | https://github.com/gam-phon -herenow | https://github.com/herenow if1live | https://github.com/if1live lozdog245 | https://github.com/lozdog245 MarkDzulko | https://github.com/MarkDzulko diff --git a/LICENSE b/LICENSE index 3abf50b2f4f..299e2c79afe 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2024 The GoCryptoTrader Developers +Copyright (c) 2014-2025 The GoCryptoTrader Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b76c4bc3ade..f6b1ad7054e 100644 --- a/README.md +++ b/README.md @@ -148,11 +148,11 @@ Binaries will be published once the codebase reaches a stable condition. |User|Contribution Amount| |--|--| -| [thrasher-](https://github.com/thrasher-) | 703 | -| [shazbert](https://github.com/shazbert) | 355 | -| [dependabot[bot]](https://github.com/apps/dependabot) | 331 | +| [thrasher-](https://github.com/thrasher-) | 704 | +| [shazbert](https://github.com/shazbert) | 356 | +| [dependabot[bot]](https://github.com/apps/dependabot) | 341 | | [gloriousCode](https://github.com/gloriousCode) | 236 | -| [gbjk](https://github.com/gbjk) | 107 | +| [gbjk](https://github.com/gbjk) | 110 | | [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 | | [xtda](https://github.com/xtda) | 47 | | [lrascao](https://github.com/lrascao) | 27 | diff --git a/cmd/documentation/sub_templates/features.tmpl b/cmd/documentation/sub_templates/features.tmpl index bfc8e0258a1..6ffb095b699 100644 --- a/cmd/documentation/sub_templates/features.tmpl +++ b/cmd/documentation/sub_templates/features.tmpl @@ -13,6 +13,6 @@ Supported Methods: {{- end }} {{end}} -{{end}} +{{- end }} -{{end}} \ No newline at end of file +{{- end }} \ No newline at end of file diff --git a/exchanges/gateio/README.md b/exchanges/gateio/README.md index f2002b17450..5dedfd452bb 100644 --- a/exchanges/gateio/README.md +++ b/exchanges/gateio/README.md @@ -135,7 +135,6 @@ Supported Methods: Supported Methods: - GetOrder -- GetOrders - CancelOrders - CancelOrder - SubmitOrder @@ -183,9 +182,6 @@ Supported Methods: - - - ### Please click GoDocs chevron above to view current GoDoc information for this package ## Contribution diff --git a/exchanges/preflight.go b/exchanges/preflight.go index 786131fd82e..af14ac43bc9 100644 --- a/exchanges/preflight.go +++ b/exchanges/preflight.go @@ -3,7 +3,6 @@ package exchange import ( "context" "errors" - "fmt" "reflect" "time" @@ -40,16 +39,16 @@ func AutomaticPreFlightCheck(exch IBotExchange) protocol.FeatureSet { // TODO: Make this more dynamic and reflect off interface.go interfaces. methodToFeature := map[string]setter{ "SubmitOrder": {fn: func(f *protocol.Features) *bool { return &f.SubmitOrder }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.Submit{Exchange: "bruh", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}} + return []interface{}{ctx, &order.Submit{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}} }}, "ModifyOrder": {fn: func(f *protocol.Features) *bool { return &f.ModifyOrder }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.Modify{Exchange: "bruh", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}} + return []interface{}{ctx, &order.Modify{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}} }}, "CancelOrder": {fn: func(f *protocol.Features) *bool { return &f.CancelOrder }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.Cancel{Exchange: "bruh", AssetType: a, Pair: currency.NewBTCUSD(), OrderID: "bruh"}} + return []interface{}{ctx, &order.Cancel{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), OrderID: "bruh"}} }}, "CancelAllOrders": {fn: func(f *protocol.Features) *bool { return &f.CancelOrders }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.Cancel{Exchange: "bruh", AssetType: a, Pair: currency.NewBTCUSD()}} + return []interface{}{ctx, &order.Cancel{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD()}} }}, "GetOrderInfo": {fn: func(f *protocol.Features) *bool { return &f.GetOrder }, args: func(a asset.Item) []interface{} { return []interface{}{ctx, "someID", currency.NewBTCUSD(), a} }}, "GetActiveOrders": {fn: func(f *protocol.Features) *bool { return &f.GetOrders }, args: func(a asset.Item) []interface{} { @@ -89,7 +88,6 @@ func AutomaticPreFlightCheck(exch IBotExchange) protocol.FeatureSet { continue } - fmt.Println(err, methodName, a) feature := featureSetter.fn(&features) *feature = true } From db3a07d945f4bdc0ecb15360b6660853af2e10a0 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Fri, 14 Feb 2025 12:55:10 +1100 Subject: [PATCH 04/11] glorious: nits --- README.md | 10 +- cmd/documentation/documentation.go | 100 +++++++++----- .../exchanges_templates/binance.tmpl | 2 + .../exchanges_templates/binanceus.tmpl | 2 + .../exchanges_templates/bitfinex.tmpl | 2 + .../exchanges_templates/bitflyer.tmpl | 2 + .../exchanges_templates/bithumb.tmpl | 2 + .../exchanges_templates/bitmex.tmpl | 2 + .../exchanges_templates/bitstamp.tmpl | 2 + .../exchanges_templates/btcmarkets.tmpl | 2 + .../exchanges_templates/btse.tmpl | 2 + .../exchanges_templates/bybit.tmpl | 2 + .../exchanges_templates/coinbasepro.tmpl | 2 + .../exchanges_templates/coinut.tmpl | 2 + .../exchanges_templates/deribit.tmpl | 2 + .../exchanges_mock_readme.tmpl | 2 + .../exchanges_templates/exmo.tmpl | 2 + .../exchanges_templates/gateio.tmpl | 4 +- .../exchanges_templates/gemini.tmpl | 2 + .../exchanges_templates/hitbtc.tmpl | 2 + .../exchanges_templates/huobi.tmpl | 2 + .../exchanges_templates/kraken.tmpl | 2 + .../exchanges_templates/kucoin.tmpl | 2 + .../exchanges_templates/lbank.tmpl | 2 + .../exchanges_templates/okx.tmpl | 2 + .../exchanges_templates/poloniex.tmpl | 2 + .../exchanges_templates/yobit.tmpl | 2 + cmd/documentation/sub_templates/features.tmpl | 43 ++++-- engine/currency_state_manager.md | 74 +++++------ engine/engine.go | 4 +- exchanges/binance/README.md | 15 +++ exchanges/binanceus/README.md | 15 +++ exchanges/bitfinex/README.md | 15 +++ exchanges/bitflyer/README.md | 15 +++ exchanges/bithumb/README.md | 15 +++ exchanges/bitmex/README.md | 15 +++ exchanges/bitstamp/README.md | 15 +++ exchanges/btcmarkets/README.md | 4 + exchanges/btse/README.md | 4 + exchanges/bybit/README.md | 15 +++ exchanges/coinbasepro/README.md | 4 + exchanges/coinut/README.md | 15 +++ exchanges/deribit/README.md | 15 +++ exchanges/exchange_test.go | 2 +- exchanges/exchange_types.go | 7 +- exchanges/exmo/README.md | 15 +++ exchanges/gateio/README.md | 80 +++--------- exchanges/gemini/README.md | 15 +++ exchanges/hitbtc/README.md | 15 +++ exchanges/huobi/README.md | 15 +++ exchanges/kraken/README.md | 15 +++ exchanges/kucoin/README.md | 15 +++ exchanges/lbank/README.md | 15 +++ exchanges/mock/README.md | 4 + exchanges/okx/README.md | 15 +++ exchanges/poloniex/README.md | 4 + exchanges/preflight.go | 98 -------------- exchanges/preflight_test.go | 22 ---- exchanges/protocol/features.go | 11 +- exchanges/supported_functionality.go | 123 ++++++++++++++++++ exchanges/supported_functionality_test.go | 37 ++++++ exchanges/yobit/README.md | 15 +++ 62 files changed, 684 insertions(+), 284 deletions(-) delete mode 100644 exchanges/preflight.go delete mode 100644 exchanges/preflight_test.go create mode 100644 exchanges/supported_functionality.go create mode 100644 exchanges/supported_functionality_test.go diff --git a/README.md b/README.md index f6b1ad7054e..4f2e4532209 100644 --- a/README.md +++ b/README.md @@ -149,20 +149,20 @@ Binaries will be published once the codebase reaches a stable condition. |User|Contribution Amount| |--|--| | [thrasher-](https://github.com/thrasher-) | 704 | -| [shazbert](https://github.com/shazbert) | 356 | -| [dependabot[bot]](https://github.com/apps/dependabot) | 341 | +| [shazbert](https://github.com/shazbert) | 358 | +| [dependabot[bot]](https://github.com/apps/dependabot) | 350 | | [gloriousCode](https://github.com/gloriousCode) | 236 | -| [gbjk](https://github.com/gbjk) | 110 | +| [gbjk](https://github.com/gbjk) | 112 | | [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 | | [xtda](https://github.com/xtda) | 47 | | [lrascao](https://github.com/lrascao) | 27 | -| [Beadko](https://github.com/Beadko) | 17 | +| [Beadko](https://github.com/Beadko) | 18 | | [Rots](https://github.com/Rots) | 15 | | [vazha](https://github.com/vazha) | 15 | | [ydm](https://github.com/ydm) | 15 | | [ermalguni](https://github.com/ermalguni) | 14 | | [MadCozBadd](https://github.com/MadCozBadd) | 13 | -| [samuael](https://github.com/samuael) | 10 | +| [samuael](https://github.com/samuael) | 11 | | [vadimzhukck](https://github.com/vadimzhukck) | 10 | | [140am](https://github.com/140am) | 8 | | [marcofranssen](https://github.com/marcofranssen) | 8 | diff --git a/cmd/documentation/documentation.go b/cmd/documentation/documentation.go index 43139e9cb13..b422aeaed15 100644 --- a/cmd/documentation/documentation.go +++ b/cmd/documentation/documentation.go @@ -10,7 +10,6 @@ import ( "net/http" "os" "path/filepath" - "reflect" "strings" "text/template" "time" @@ -114,29 +113,40 @@ type Attributes struct { Year int CapitalName string DonationAddress string - Features []ProtocolFeature + Features []ProtocolFunctionality } -// ProtocolFeature defines a protocol feature set -type ProtocolFeature struct { +// ProtocolFunctionality defines a protocol feature set +type ProtocolFunctionality struct { Protocol string - Assets []AssetFeature + Assets []AssetFunctionality } -func (a ProtocolFeature) String() string { +func (a ProtocolFunctionality) String() string { return a.Protocol } -// AssetFeature defines an asset feature set -type AssetFeature struct { +// AssetFunctionality defines an asset feature set +type AssetFunctionality struct { Asset string - Methods []string + Methods []MethodNameAndOperational } -func (a AssetFeature) String() string { +func (a AssetFunctionality) String() string { return a.Asset } +// MethodNameAndOperational defines a method name and if it is operational +type MethodNameAndOperational struct { + MethodName string + Operational bool +} + +// String returns the method name +func (m MethodNameAndOperational) String() string { + return m.MethodName +} + func main() { flag.BoolVar(&verbose, "v", false, "Verbose output") flag.StringVar(&toolDir, "tooldir", "", "Pass in the documentation tool directory if outside tool folder") @@ -461,7 +471,11 @@ func GetProjectDirectoryTree(c *Config) ([]string, error) { // GetTemplateFiles parses and returns all template files in the documentation // tree func GetTemplateFiles() (*template.Template, error) { - tmpl := template.New("") + tmpl := template.New("").Funcs(template.FuncMap{ + "contains": contains, + "append": _append, + "emptySlice": emptySlice, + }) walkFn := func(path string, info os.FileInfo, err error) error { if err != nil { @@ -517,7 +531,7 @@ func GetDocumentationAttributes(packageName string, contributors []Contributor) Year: time.Now().Year(), CapitalName: GetPackageName(packageName, true), DonationAddress: core.BitcoinDonationAddress, - Features: GetFeatures(name), + Features: GetFunctionality(name), } } @@ -535,47 +549,44 @@ func GetPackageName(name string, capital bool) string { return newStrings[i] } -// GetFeatures returns a dynamic list of supported functionality for a specific asset type. -func GetFeatures(name string) []ProtocolFeature { - if name != "gateio" { // TODO: Remove and implement across all exchanges after POC. - return nil - } +// GetFunctionality returns a dynamic list of supported functionality for a specific asset type. +func GetFunctionality(name string) []ProtocolFunctionality { exch, _ := engine.NewExchangeByNameWithDefaults(context.Background(), name) if exch == nil { return nil } - set := exchange.AutomaticPreFlightCheck(exch) + set := exchange.GenerateSupportedFunctionality(exch) if set == nil { return nil } - lookup := make(map[string][]AssetFeature) - for k, v := range set { - var f AssetFeature - f.Asset = k.Asset.String() - t := reflect.TypeOf(v) - - // Iterate over the struct fields - for i := range t.NumField() { - value := reflect.ValueOf(v).Field(i) - if value.Kind() != reflect.Bool || !value.Bool() { - continue - } - f.Methods = append(f.Methods, t.Field(i).Name) + lookup := make(map[string][]AssetFunctionality) + for ap, availableFunctionality := range set { + methods := make([]MethodNameAndOperational, 0, len(availableFunctionality)) + for k, v := range availableFunctionality { + methods = append(methods, MethodNameAndOperational{ + MethodName: k, + Operational: v, + }) } - lookup[k.Protocol.String()] = append(lookup[k.Protocol.String()], f) + pName := ap.Protocol.String() + methods = common.SortStrings(methods) + lookup[pName] = append(lookup[pName], AssetFunctionality{ + Asset: ap.Asset.String(), + Methods: methods, + }) } - features := make([]ProtocolFeature, 0) + functionalityList := make([]ProtocolFunctionality, 0, len(lookup)) for k, v := range lookup { v = common.SortStrings(v) - features = append(features, ProtocolFeature{ + functionalityList = append(functionalityList, ProtocolFunctionality{ Protocol: k, Assets: v, }) } - features = common.SortStrings(features) - return features + functionalityList = common.SortStrings(functionalityList) + return functionalityList } // GetGoDocURL returns a string for godoc package names @@ -690,3 +701,20 @@ func runTemplate(details DocumentationDetails, mainPath, name string) error { attr := GetDocumentationAttributes(name, details.Contributors) return details.Tmpl.ExecuteTemplate(f, name, attr) } + +func contains(slice []string, item string) bool { + for _, v := range slice { + if v == item { + return true + } + } + return false +} + +func emptySlice() []string { + return []string{} +} + +func _append(slice []string, item string) []string { + return append(slice, item) +} diff --git a/cmd/documentation/exchanges_templates/binance.tmpl b/cmd/documentation/exchanges_templates/binance.tmpl index 02f805d10e0..45994fefaad 100644 --- a/cmd/documentation/exchanges_templates/binance.tmpl +++ b/cmd/documentation/exchanges_templates/binance.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/binanceus.tmpl b/cmd/documentation/exchanges_templates/binanceus.tmpl index 5ddeeb801cd..4b6b7f6593d 100644 --- a/cmd/documentation/exchanges_templates/binanceus.tmpl +++ b/cmd/documentation/exchanges_templates/binanceus.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/bitfinex.tmpl b/cmd/documentation/exchanges_templates/bitfinex.tmpl index 526d8244275..55894ccb6e2 100644 --- a/cmd/documentation/exchanges_templates/bitfinex.tmpl +++ b/cmd/documentation/exchanges_templates/bitfinex.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/bitflyer.tmpl b/cmd/documentation/exchanges_templates/bitflyer.tmpl index 58c9c853ead..d4ed71eac88 100644 --- a/cmd/documentation/exchanges_templates/bitflyer.tmpl +++ b/cmd/documentation/exchanges_templates/bitflyer.tmpl @@ -6,6 +6,8 @@ + REST Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/bithumb.tmpl b/cmd/documentation/exchanges_templates/bithumb.tmpl index deaa140912d..d40fdb3bb96 100644 --- a/cmd/documentation/exchanges_templates/bithumb.tmpl +++ b/cmd/documentation/exchanges_templates/bithumb.tmpl @@ -6,6 +6,8 @@ + REST Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/bitmex.tmpl b/cmd/documentation/exchanges_templates/bitmex.tmpl index 8876c335de7..e690cf05216 100644 --- a/cmd/documentation/exchanges_templates/bitmex.tmpl +++ b/cmd/documentation/exchanges_templates/bitmex.tmpl @@ -6,6 +6,8 @@ + REST Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/bitstamp.tmpl b/cmd/documentation/exchanges_templates/bitstamp.tmpl index 17ed7bca075..e38cf202d65 100644 --- a/cmd/documentation/exchanges_templates/bitstamp.tmpl +++ b/cmd/documentation/exchanges_templates/bitstamp.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/btcmarkets.tmpl b/cmd/documentation/exchanges_templates/btcmarkets.tmpl index f9d04b3d199..8d8f5a303cc 100644 --- a/cmd/documentation/exchanges_templates/btcmarkets.tmpl +++ b/cmd/documentation/exchanges_templates/btcmarkets.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/btse.tmpl b/cmd/documentation/exchanges_templates/btse.tmpl index 6d979c4d839..3c224da2683 100644 --- a/cmd/documentation/exchanges_templates/btse.tmpl +++ b/cmd/documentation/exchanges_templates/btse.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/bybit.tmpl b/cmd/documentation/exchanges_templates/bybit.tmpl index ceabf2dfaf8..acb59215643 100644 --- a/cmd/documentation/exchanges_templates/bybit.tmpl +++ b/cmd/documentation/exchanges_templates/bybit.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/coinbasepro.tmpl b/cmd/documentation/exchanges_templates/coinbasepro.tmpl index 2a6dc9d9f97..7e91aad38de 100644 --- a/cmd/documentation/exchanges_templates/coinbasepro.tmpl +++ b/cmd/documentation/exchanges_templates/coinbasepro.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/coinut.tmpl b/cmd/documentation/exchanges_templates/coinut.tmpl index 605bb6a24ef..28fda90bf8f 100644 --- a/cmd/documentation/exchanges_templates/coinut.tmpl +++ b/cmd/documentation/exchanges_templates/coinut.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/deribit.tmpl b/cmd/documentation/exchanges_templates/deribit.tmpl index 1277ed1a3e7..53d147f0046 100644 --- a/cmd/documentation/exchanges_templates/deribit.tmpl +++ b/cmd/documentation/exchanges_templates/deribit.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/exchanges_mock_readme.tmpl b/cmd/documentation/exchanges_templates/exchanges_mock_readme.tmpl index 4598583c074..292a137a8db 100644 --- a/cmd/documentation/exchanges_templates/exchanges_mock_readme.tmpl +++ b/cmd/documentation/exchanges_templates/exchanges_mock_readme.tmpl @@ -6,6 +6,8 @@ + REST recording service + REST mock response server +{{template "features" .}} + ### How to enable + Any exchange with mock testing will be enabled by default. This is done using build tags which are highlighted in the examples below via `//+build mock_test_off`. To disable and run live endpoint testing parse `-tags=mock_test_off` as a go test param. diff --git a/cmd/documentation/exchanges_templates/exmo.tmpl b/cmd/documentation/exchanges_templates/exmo.tmpl index dd0c4b50da7..5a346a49439 100644 --- a/cmd/documentation/exchanges_templates/exmo.tmpl +++ b/cmd/documentation/exchanges_templates/exmo.tmpl @@ -6,6 +6,8 @@ + REST Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/gateio.tmpl b/cmd/documentation/exchanges_templates/gateio.tmpl index 9a66e04d680..c7f14484125 100644 --- a/cmd/documentation/exchanges_templates/gateio.tmpl +++ b/cmd/documentation/exchanges_templates/gateio.tmpl @@ -6,6 +6,8 @@ + REST functions +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) @@ -99,8 +101,6 @@ if err != nil { // supplied then ``` -{{template "features" .}} - ### Please click GoDocs chevron above to view current GoDoc information for this package {{template "contributions"}} {{template "donations" .}} diff --git a/cmd/documentation/exchanges_templates/gemini.tmpl b/cmd/documentation/exchanges_templates/gemini.tmpl index 7c10e257c92..6b3d6ec817a 100644 --- a/cmd/documentation/exchanges_templates/gemini.tmpl +++ b/cmd/documentation/exchanges_templates/gemini.tmpl @@ -6,6 +6,8 @@ + REST Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/hitbtc.tmpl b/cmd/documentation/exchanges_templates/hitbtc.tmpl index e8d9f488e80..a3e0ca4286e 100644 --- a/cmd/documentation/exchanges_templates/hitbtc.tmpl +++ b/cmd/documentation/exchanges_templates/hitbtc.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/huobi.tmpl b/cmd/documentation/exchanges_templates/huobi.tmpl index d4966962f6a..a58f14c7325 100644 --- a/cmd/documentation/exchanges_templates/huobi.tmpl +++ b/cmd/documentation/exchanges_templates/huobi.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/kraken.tmpl b/cmd/documentation/exchanges_templates/kraken.tmpl index caf691d1652..b7653f4f193 100644 --- a/cmd/documentation/exchanges_templates/kraken.tmpl +++ b/cmd/documentation/exchanges_templates/kraken.tmpl @@ -6,6 +6,8 @@ + REST Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/kucoin.tmpl b/cmd/documentation/exchanges_templates/kucoin.tmpl index 1ae61cc437c..6d15755ba5b 100644 --- a/cmd/documentation/exchanges_templates/kucoin.tmpl +++ b/cmd/documentation/exchanges_templates/kucoin.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### Subscriptions Default Public Subscriptions: diff --git a/cmd/documentation/exchanges_templates/lbank.tmpl b/cmd/documentation/exchanges_templates/lbank.tmpl index 0a7d6252a32..ba430582cfd 100644 --- a/cmd/documentation/exchanges_templates/lbank.tmpl +++ b/cmd/documentation/exchanges_templates/lbank.tmpl @@ -6,6 +6,8 @@ + REST Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://githul.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/okx.tmpl b/cmd/documentation/exchanges_templates/okx.tmpl index 4d827848d21..cc5b050ba1d 100644 --- a/cmd/documentation/exchanges_templates/okx.tmpl +++ b/cmd/documentation/exchanges_templates/okx.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/poloniex.tmpl b/cmd/documentation/exchanges_templates/poloniex.tmpl index 5f033c824bb..351d98f855a 100644 --- a/cmd/documentation/exchanges_templates/poloniex.tmpl +++ b/cmd/documentation/exchanges_templates/poloniex.tmpl @@ -7,6 +7,8 @@ + REST Support + Websocket Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/exchanges_templates/yobit.tmpl b/cmd/documentation/exchanges_templates/yobit.tmpl index 1d8cc4e46bf..f5420443af2 100644 --- a/cmd/documentation/exchanges_templates/yobit.tmpl +++ b/cmd/documentation/exchanges_templates/yobit.tmpl @@ -6,6 +6,8 @@ + REST Support +{{template "features" .}} + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/cmd/documentation/sub_templates/features.tmpl b/cmd/documentation/sub_templates/features.tmpl index 6ffb095b699..445414f12bf 100644 --- a/cmd/documentation/sub_templates/features.tmpl +++ b/cmd/documentation/sub_templates/features.tmpl @@ -2,17 +2,44 @@ ## Trading Methods Supported {{range $feature := .Features -}} -### Protocol: {{$feature.Protocol}} +### Protocol: {{$feature.Protocol -}} -{{range $assetFeatures := $feature.Assets -}} -#### Asset: {{$assetFeatures.Asset}} +{{- $assetTypes := emptySlice }} +{{- $methodNames := emptySlice }} -Supported Methods: -{{- range $method := $assetFeatures.Methods }} -- {{$method}} +{{- /* Collect all unique asset types */ -}} +{{- range $asset := $feature.Assets }} + {{- $assetTypes = append $assetTypes $asset.Asset }} + {{- range $method := $asset.Methods }} + {{- if not (contains $methodNames $method.MethodName) }} + {{- $methodNames = append $methodNames $method.MethodName }} + {{- end }} + {{- end }} {{- end }} -{{end}} +| Method Name |{{range $asset := $assetTypes}} {{$asset}} |{{end}} +|------------|{{range $asset := $assetTypes}}---|{{end}} + +{{- /* Iterate over all unique method names */ -}} +{{- range $methodName := $methodNames }} +| {{$methodName}} | + {{- range $asset := $assetTypes }} + {{- $found := false }} + {{- range $lookup := $feature.Assets }} + {{- if eq $lookup.Asset $asset }} + {{- range $m := $lookup.Methods }} + {{- if eq $m.MethodName $methodName }} + {{- if $m.Operational }} 🟢 {{else}} 🚫 {{end}} + {{- $found = true }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- if not $found }} 🚫 {{end}} | + {{- end }} {{- end }} -{{- end }} \ No newline at end of file +{{- end -}} + + +{{- end -}} \ No newline at end of file diff --git a/engine/currency_state_manager.md b/engine/currency_state_manager.md index 5e938e72fab..cb6a44d9a57 100644 --- a/engine/currency_state_manager.md +++ b/engine/currency_state_manager.md @@ -1,22 +1,22 @@ -# GoCryptoTrader package Currency state manager - - - - -[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml) -[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE) -[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/engine/currency_state_manager) -[![Coverage Status](https://codecov.io/gh/thrasher-corp/gocryptotrader/graph/badge.svg?token=41784B23TS)](https://codecov.io/gh/thrasher-corp/gocryptotrader) -[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader) - - -This currency_state_manager package is part of the GoCryptoTrader codebase. - -## This is still in active development - -You can track ideas, planned features and what's in progress on our [GoCryptoTrader Kanban board](https://github.com/orgs/thrasher-corp/projects/3). - -Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk) +# GoCryptoTrader package Currency state manager + + + + +[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml) +[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE) +[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/engine/currency_state_manager) +[![Coverage Status](https://codecov.io/gh/thrasher-corp/gocryptotrader/graph/badge.svg?token=41784B23TS)](https://codecov.io/gh/thrasher-corp/gocryptotrader) +[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader) + + +This currency_state_manager package is part of the GoCryptoTrader codebase. + +## This is still in active development + +You can track ideas, planned features and what's in progress on our [GoCryptoTrader Kanban board](https://github.com/orgs/thrasher-corp/projects/3). + +Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk) ## Current Features for Currency state manager + The state manager keeps currency states up to date, which include: @@ -27,22 +27,22 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + This allows for an internal state check to compliment internal and external strategies. - -## Contribution - -Please feel free to submit any pull requests or suggest any desired features to be added. - -When submitting a PR, please abide by our coding guidelines: - -+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). -+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. -+ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md). -+ Pull requests need to be based on and opened against the `master` branch. - -## Donations - - - -If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to: - + +## Contribution + +Please feel free to submit any pull requests or suggest any desired features to be added. + +When submitting a PR, please abide by our coding guidelines: + ++ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). ++ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. ++ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md). ++ Pull requests need to be based on and opened against the `master` branch. + +## Donations + + + +If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to: + ***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc*** diff --git a/engine/engine.go b/engine/engine.go index d018c3789ac..cb00e713fb6 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -834,8 +834,8 @@ func (bot *Engine) LoadExchange(name string) error { return err } - // Update prototocol capabilities with dynamic pre flight check. - exch.GetBase().ProtocolCapabilities = exchange.AutomaticPreFlightCheck(exch) + // Update prototocol capabilities with dynamic supported functionality check + exch.GetBase().ProtocolCapabilities = exchange.GenerateSupportedFunctionality(exch) return nil } diff --git a/exchanges/binance/README.md b/exchanges/binance/README.md index 162612f70d3..e7d09e1fffc 100644 --- a/exchanges/binance/README.md +++ b/exchanges/binance/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | coinmarginedfutures | margin | spot | usdtmarginedfutures | +|------------|---|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelBatchOrders | 🚫 | 🚫 | 🚫 | 🚫 | +| CancelOrder | 🟢 | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🚫 | 🚫 | 🚫 | 🚫 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/binanceus/README.md b/exchanges/binanceus/README.md index 0dc93d3e409..f734c882d0d 100644 --- a/exchanges/binanceus/README.md +++ b/exchanges/binanceus/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🚫 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/bitfinex/README.md b/exchanges/bitfinex/README.md index 9792b7f75ef..c284fd00391 100644 --- a/exchanges/bitfinex/README.md +++ b/exchanges/bitfinex/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | margin | marginfunding | spot | +|------------|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🟢 | +| CancelBatchOrders | 🚫 | 🚫 | 🚫 | +| CancelOrder | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🟢 | 🟢 | 🟢 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/bitflyer/README.md b/exchanges/bitflyer/README.md index c127446b46c..d618c841a9c 100644 --- a/exchanges/bitflyer/README.md +++ b/exchanges/bitflyer/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | futures | spot | +|------------|---|---| +| CancelAllOrders | 🚫 | 🚫 | +| CancelBatchOrders | 🚫 | 🚫 | +| CancelOrder | 🚫 | 🚫 | +| GetActiveOrders | 🚫 | 🚫 | +| GetOrderHistory | 🚫 | 🚫 | +| GetOrderInfo | 🚫 | 🚫 | +| ModifyOrder | 🚫 | 🚫 | +| SubmitOrder | 🚫 | 🚫 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/bithumb/README.md b/exchanges/bithumb/README.md index a9593064b65..ef20ae7b062 100644 --- a/exchanges/bithumb/README.md +++ b/exchanges/bithumb/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/bitmex/README.md b/exchanges/bitmex/README.md index d60caf37849..4d64d93110b 100644 --- a/exchanges/bitmex/README.md +++ b/exchanges/bitmex/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | futures | index | perpetualcontract | spot | +|------------|---|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelBatchOrders | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelOrder | 🟢 | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🟢 | 🟢 | 🟢 | 🟢 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/bitstamp/README.md b/exchanges/bitstamp/README.md index cdf65b96e5f..e69f8497bd6 100644 --- a/exchanges/bitstamp/README.md +++ b/exchanges/bitstamp/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/btcmarkets/README.md b/exchanges/btcmarkets/README.md index 940d103e960..0f9380f734b 100644 --- a/exchanges/btcmarkets/README.md +++ b/exchanges/btcmarkets/README.md @@ -25,6 +25,10 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + + + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/btse/README.md b/exchanges/btse/README.md index 6c8f671a86f..1ce71f28804 100644 --- a/exchanges/btse/README.md +++ b/exchanges/btse/README.md @@ -25,6 +25,10 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + + + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/bybit/README.md b/exchanges/bybit/README.md index bffee5e1794..c75525e7772 100644 --- a/exchanges/bybit/README.md +++ b/exchanges/bybit/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | coinmarginedfutures | options | spot | usdcmarginedfutures | usdtmarginedfutures | +|------------|---|---|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelBatchOrders | 🚫 | 🟢 | 🚫 | 🚫 | 🚫 | +| CancelOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/coinbasepro/README.md b/exchanges/coinbasepro/README.md index 25be64ecc13..bda549a539c 100644 --- a/exchanges/coinbasepro/README.md +++ b/exchanges/coinbasepro/README.md @@ -25,6 +25,10 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + + + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/coinut/README.md b/exchanges/coinut/README.md index 5a0e4d832ce..35929ff7f0d 100644 --- a/exchanges/coinut/README.md +++ b/exchanges/coinut/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🚫 | +| CancelBatchOrders | 🟢 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🚫 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/deribit/README.md b/exchanges/deribit/README.md index 3e6595258f7..7671eb6ac8e 100644 --- a/exchanges/deribit/README.md +++ b/exchanges/deribit/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | future_combo | futures | option_combo | options | spot | +|------------|---|---|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelBatchOrders | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | +| CancelOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/exchange_test.go b/exchanges/exchange_test.go index 22f3c2e5723..a5db589d047 100644 --- a/exchanges/exchange_test.go +++ b/exchanges/exchange_test.go @@ -3003,7 +3003,7 @@ func (f *FakeBase) GetFeeByType(context.Context, *FeeBuilder) (float64, error) { } func (f *FakeBase) SubmitOrder(context.Context, *order.Submit) (*order.SubmitResponse, error) { - return nil, errors.New("random error") + return nil, nil } func (f *FakeBase) ModifyOrder(context.Context, *order.Modify) (*order.ModifyResponse, error) { diff --git a/exchanges/exchange_types.go b/exchanges/exchange_types.go index 98be482c542..b561b4541e5 100644 --- a/exchanges/exchange_types.go +++ b/exchanges/exchange_types.go @@ -239,10 +239,9 @@ type Base struct { BaseCurrencies currency.Currencies CurrencyPairs currency.PairsManager Features Features - // ProtocolCapabilities is a map of supported features for each asset type - // and protocol type. This is mapped in the preflight check to determine - // if the method is functional and ready for that asset type. - ProtocolCapabilities protocol.FeatureSet + // ProtocolCapabilities is a map of supported functionality for each asset type and protocol type. This is mapped in + // the supported features check to determine if the method is functional and ready for that asset type. + ProtocolCapabilities protocol.FunctionalitySet HTTPTimeout time.Duration HTTPRecording bool HTTPDebugging bool diff --git a/exchanges/exmo/README.md b/exchanges/exmo/README.md index 0337d45b903..0d97e89866d 100644 --- a/exchanges/exmo/README.md +++ b/exchanges/exmo/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🚫 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/gateio/README.md b/exchanges/gateio/README.md index 5dedfd452bb..3a33651d124 100644 --- a/exchanges/gateio/README.md +++ b/exchanges/gateio/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST functions +## Trading Methods Supported + +### Protocol: REST + +| Method Name | cross_margin | delivery | futures | margin | options | spot | +|------------|---|---|---|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelBatchOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) @@ -117,71 +132,6 @@ if err != nil { // supplied then ``` -## Trading Methods Supported - -### Protocol: REST - -#### Asset: cross_margin - -Supported Methods: -- GetOrder -- GetOrders -- CancelOrders -- CancelOrder -- SubmitOrder -- UserTradeHistory - -#### Asset: delivery - -Supported Methods: -- GetOrder -- CancelOrders -- CancelOrder -- SubmitOrder -- UserTradeHistory - -#### Asset: futures - -Supported Methods: -- GetOrder -- GetOrders -- CancelOrders -- CancelOrder -- SubmitOrder -- UserTradeHistory - -#### Asset: margin - -Supported Methods: -- GetOrder -- GetOrders -- CancelOrders -- CancelOrder -- SubmitOrder -- UserTradeHistory - -#### Asset: options - -Supported Methods: -- GetOrder -- GetOrders -- CancelOrders -- CancelOrder -- SubmitOrder -- UserTradeHistory - -#### Asset: spot - -Supported Methods: -- GetOrder -- GetOrders -- CancelOrders -- CancelOrder -- SubmitOrder -- UserTradeHistory - - - ### Please click GoDocs chevron above to view current GoDoc information for this package ## Contribution diff --git a/exchanges/gemini/README.md b/exchanges/gemini/README.md index 1984e823114..af2511885b4 100644 --- a/exchanges/gemini/README.md +++ b/exchanges/gemini/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/hitbtc/README.md b/exchanges/hitbtc/README.md index 3c9a5fac708..aa4786e5c50 100644 --- a/exchanges/hitbtc/README.md +++ b/exchanges/hitbtc/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/huobi/README.md b/exchanges/huobi/README.md index 7c3a465596b..f4f6a33bd7e 100644 --- a/exchanges/huobi/README.md +++ b/exchanges/huobi/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | coinmarginedfutures | futures | spot | +|------------|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🚫 | +| CancelBatchOrders | 🟢 | 🟢 | 🟢 | +| CancelOrder | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🚫 | 🚫 | 🚫 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/kraken/README.md b/exchanges/kraken/README.md index 3284721a4d5..89efaab795f 100644 --- a/exchanges/kraken/README.md +++ b/exchanges/kraken/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | futures | spot | +|------------|---|---| +| CancelAllOrders | 🟢 | 🟢 | +| CancelBatchOrders | 🚫 | 🚫 | +| CancelOrder | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | +| ModifyOrder | 🚫 | 🚫 | +| SubmitOrder | 🟢 | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/kucoin/README.md b/exchanges/kucoin/README.md index b027535efcd..e8d5b0c1d19 100644 --- a/exchanges/kucoin/README.md +++ b/exchanges/kucoin/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | futures | margin | spot | +|------------|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🟢 | +| CancelBatchOrders | 🚫 | 🚫 | 🚫 | +| CancelOrder | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🚫 | 🚫 | 🚫 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | + ### Subscriptions Default Public Subscriptions: diff --git a/exchanges/lbank/README.md b/exchanges/lbank/README.md index 72997abd5e1..3688fe0af4f 100644 --- a/exchanges/lbank/README.md +++ b/exchanges/lbank/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://githul.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/mock/README.md b/exchanges/mock/README.md index 71bc21e9cf4..fe474cd3ecf 100644 --- a/exchanges/mock/README.md +++ b/exchanges/mock/README.md @@ -24,6 +24,10 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST recording service + REST mock response server +## Trading Methods Supported + + + ### How to enable + Any exchange with mock testing will be enabled by default. This is done using build tags which are highlighted in the examples below via `//+build mock_test_off`. To disable and run live endpoint testing parse `-tags=mock_test_off` as a go test param. diff --git a/exchanges/okx/README.md b/exchanges/okx/README.md index 642d8ad184d..43c70ea5a8f 100644 --- a/exchanges/okx/README.md +++ b/exchanges/okx/README.md @@ -25,6 +25,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | futures | margin | options | perpetualswap | spot | spread | +|------------|---|---|---|---|---|---| +| CancelAllOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelBatchOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| CancelOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetActiveOrders | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderHistory | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| GetOrderInfo | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| ModifyOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| SubmitOrder | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | + ### How to enable [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/poloniex/README.md b/exchanges/poloniex/README.md index 1d83fef9a8c..fbedad779db 100644 --- a/exchanges/poloniex/README.md +++ b/exchanges/poloniex/README.md @@ -25,6 +25,10 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support + Websocket Support +## Trading Methods Supported + + + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) diff --git a/exchanges/preflight.go b/exchanges/preflight.go deleted file mode 100644 index af14ac43bc9..00000000000 --- a/exchanges/preflight.go +++ /dev/null @@ -1,98 +0,0 @@ -package exchange - -import ( - "context" - "errors" - "reflect" - "time" - - "github.com/thrasher-corp/gocryptotrader/common" - "github.com/thrasher-corp/gocryptotrader/currency" - "github.com/thrasher-corp/gocryptotrader/exchanges/asset" - "github.com/thrasher-corp/gocryptotrader/exchanges/order" - "github.com/thrasher-corp/gocryptotrader/exchanges/protocol" - "github.com/thrasher-corp/gocryptotrader/log" -) - -type setter struct { - fn func(f *protocol.Features) *bool - args func(asset.Item) []interface{} -} - -// AutomaticPreFlightCheck analyzes the exchange's supported asset types -// and protocols, returning a set of dynamically discovered features -// (ProtocolCapabilities) that the exchange supports. This process is -// based on the exchange's specific implementation of wrapper functions. -func AutomaticPreFlightCheck(exch IBotExchange) protocol.FeatureSet { - if exch == nil { - return nil - } - - // TODO: Explicit differentiation between protocol methods on IBOTExchange - set := protocol.FeatureSet{} - - // Use a context with a deadline to ensure that the pre-flight check does not - // send any outbound requests. - ctx, cancel := context.WithDeadline(context.Background(), time.Now()) - cancel() - - // TODO: Make this more dynamic and reflect off interface.go interfaces. - methodToFeature := map[string]setter{ - "SubmitOrder": {fn: func(f *protocol.Features) *bool { return &f.SubmitOrder }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.Submit{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}} - }}, - "ModifyOrder": {fn: func(f *protocol.Features) *bool { return &f.ModifyOrder }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.Modify{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}} - }}, - "CancelOrder": {fn: func(f *protocol.Features) *bool { return &f.CancelOrder }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.Cancel{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), OrderID: "bruh"}} - }}, - "CancelAllOrders": {fn: func(f *protocol.Features) *bool { return &f.CancelOrders }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.Cancel{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD()}} - }}, - "GetOrderInfo": {fn: func(f *protocol.Features) *bool { return &f.GetOrder }, args: func(a asset.Item) []interface{} { return []interface{}{ctx, "someID", currency.NewBTCUSD(), a} }}, - "GetActiveOrders": {fn: func(f *protocol.Features) *bool { return &f.GetOrders }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.MultiOrderRequest{AssetType: a, Pairs: currency.Pairs{currency.NewBTCUSD()}, Side: order.Buy, Type: order.Limit}} - }}, - "GetOrderHistory": {fn: func(f *protocol.Features) *bool { return &f.UserTradeHistory }, args: func(a asset.Item) []interface{} { - return []interface{}{ctx, &order.MultiOrderRequest{AssetType: a, Pairs: currency.Pairs{currency.NewBTCUSD()}, Side: order.Buy, Type: order.Limit}} - }}, - } - - for _, a := range exch.GetAssetTypes(false) { - target := protocol.Target{ - Asset: a, - Protocol: protocol.REST, - } - - features := protocol.Features{} - for methodName, featureSetter := range methodToFeature { - method := reflect.ValueOf(exch).MethodByName(methodName) - if !method.IsValid() { - log.Errorf(log.ExchangeSys, "Failed pre flight check for %s. Does not have method %s", exch.GetName(), methodName) - return nil - } - - args := featureSetter.args(a) - reflectArgs := make([]reflect.Value, len(args)) - for i, val := range args { - reflectArgs[i] = reflect.ValueOf(val) - } - - result := method.Call(reflectArgs) - err, _ := result[len(result)-1].Interface().(error) - if err == nil || - errors.Is(err, common.ErrFunctionNotSupported) || - errors.Is(err, common.ErrNotYetImplemented) || - errors.Is(err, asset.ErrNotSupported) { - continue - } - - feature := featureSetter.fn(&features) - *feature = true - } - set[target] = features - } - - return set -} diff --git a/exchanges/preflight_test.go b/exchanges/preflight_test.go deleted file mode 100644 index 360a72a748e..00000000000 --- a/exchanges/preflight_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package exchange - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/thrasher-corp/gocryptotrader/currency" - "github.com/thrasher-corp/gocryptotrader/exchanges/asset" - "github.com/thrasher-corp/gocryptotrader/exchanges/protocol" -) - -func TestAutomaticPreflightCheck(t *testing.T) { - require.Nil(t, AutomaticPreFlightCheck(nil)) - fake := &FakeBase{} - require.Empty(t, AutomaticPreFlightCheck(fake), "no assets supported") - require.NoError(t, fake.CurrencyPairs.Store(asset.Spot, ¤cy.PairStore{})) - require.NoError(t, fake.CurrencyPairs.SetAssetEnabled(asset.Spot, true)) - set := AutomaticPreFlightCheck(fake) - require.NotEmpty(t, set, "assets supported") - restSpot := set[protocol.Target{Asset: asset.Spot, Protocol: protocol.REST}] - require.True(t, restSpot.SubmitOrder, "submit order should be functional for this protocol and this asset") -} diff --git a/exchanges/protocol/features.go b/exchanges/protocol/features.go index a27304455c4..491fa79e4a0 100644 --- a/exchanges/protocol/features.go +++ b/exchanges/protocol/features.go @@ -86,8 +86,8 @@ func (t Type) String() string { // const for protocol types const ( - REST Type = 0 - Websocket Type = 1 + REST Type = iota + 1 + Websocket ) // Target holds the asset and protocol type for a map lookup @@ -96,5 +96,8 @@ type Target struct { Protocol Type } -// FeatureSet holds the protocol type and asset type -type FeatureSet map[Target]Features +// FunctionalitySet holds the protocol type and asset type +type FunctionalitySet map[Target]Functionality + +// Functionality holds the functionality map +type Functionality map[string]bool diff --git a/exchanges/supported_functionality.go b/exchanges/supported_functionality.go new file mode 100644 index 00000000000..8f98b151878 --- /dev/null +++ b/exchanges/supported_functionality.go @@ -0,0 +1,123 @@ +package exchange + +import ( + "context" + "errors" + "fmt" + "reflect" + "time" + + "github.com/thrasher-corp/gocryptotrader/common" + "github.com/thrasher-corp/gocryptotrader/currency" + "github.com/thrasher-corp/gocryptotrader/exchanges/asset" + "github.com/thrasher-corp/gocryptotrader/exchanges/order" + "github.com/thrasher-corp/gocryptotrader/exchanges/protocol" + "github.com/thrasher-corp/gocryptotrader/log" +) + +type setter struct { + fn func(f *protocol.Features) *bool + args func(asset.Item) []interface{} +} + +// GenerateSupportedFunctionality analyzes the exchange's supported asset types and protocols, returning a set of dynamically +// discovered features (ProtocolCapabilities) that the exchange supports. This process is based on the exchange's +// specific implementation of wrapper functions. +func GenerateSupportedFunctionality(exch IBotExchange) protocol.FunctionalitySet { + if exch == nil { + return nil + } + + // TODO: Explicit differentiation between protocol methods on IBOTExchange + set := protocol.FunctionalitySet{} + + // Use a context with a deadline to ensure that the pre-flight check does not + // send any outbound requests. + ctx, cancel := context.WithDeadline(context.Background(), time.Now()) + cancel() + + for _, a := range exch.GetAssetTypes(false) { + var restTrading OrderManagement + restTradingType := reflect.TypeOf(&restTrading).Elem() // Get the type of the interface + + functionality := make(protocol.Functionality) + for i := 0; i < restTradingType.NumMethod(); i++ { + restTradingmethod := restTradingType.Method(i) + + methodName := restTradingmethod.Name + method, ok := restTradingType.MethodByName(methodName) + if !ok { + fmt.Println("Method not found") + log.Warnf(log.Global, "generate supported functionality: method %s not found for %s", methodName, exch.GetName()) + continue + } + methodValue := reflect.ValueOf(exch).MethodByName(methodName) + + args, err := generateArgs(ctx, a, method) + if err != nil { + fmt.Println("Args generation failed") + log.Warnf(log.Global, "generate supported functionality: method %s args generation failed for %s: %v", methodName, exch.GetName(), err) + continue + } + reflectArgs := make([]reflect.Value, len(args)) + for i, val := range args { + reflectArgs[i] = reflect.ValueOf(val) + } + + result := methodValue.Call(reflectArgs) + err, _ = result[len(result)-1].Interface().(error) + // if !ok { + // fmt.Println("Error type assertion failed", methodName) + // for i := range result { + // fmt.Println(result[i].Interface()) + // } + // log.Warnf(log.Global, "generate supported functionality: method %s result error type assertion failed for %s", methodName, exch.GetName()) + // continue + // } + + isFunctional := err != nil && !errors.Is(err, common.ErrFunctionNotSupported) && !errors.Is(err, common.ErrNotYetImplemented) && !errors.Is(err, asset.ErrNotSupported) + + functionality[methodName] = isFunctional + } + + set[protocol.Target{Asset: a, Protocol: protocol.REST}] = functionality + } + + return set +} + +// generateArgs generates the args function based on the method's parameter types +func generateArgs(ctx context.Context, a asset.Item, method reflect.Method) ([]interface{}, error) { + // Create a slice to hold the arguments + args := make([]interface{}, 0) + + // Iterate over the method's input parameters + for j := 0; j < method.Type.NumIn(); j++ { + paramType := method.Type.In(j) + + // Handle specific parameter types + switch paramType { + case reflect.TypeOf((*context.Context)(nil)).Elem(): + args = append(args, ctx) + case reflect.TypeOf((*order.Submit)(nil)): + args = append(args, &order.Submit{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}) + case reflect.TypeOf((*order.Modify)(nil)): + args = append(args, &order.Modify{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}) + case reflect.TypeOf((*order.Cancel)(nil)): + args = append(args, &order.Cancel{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), OrderID: "bruh"}) + case reflect.TypeOf(([]order.Cancel)(nil)): + args = append(args, []order.Cancel{{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), OrderID: "bruh"}}) + case reflect.TypeOf((*order.MultiOrderRequest)(nil)): + args = append(args, &order.MultiOrderRequest{AssetType: a, Pairs: currency.Pairs{currency.NewBTCUSD()}, Side: order.Buy, Type: order.Limit}) + case reflect.TypeOf(""): + args = append(args, "someID") + case reflect.TypeOf(currency.Pair{}): + args = append(args, currency.NewBTCUSD()) + case reflect.TypeOf(asset.Item(0)): + args = append(args, a) + default: + return nil, errors.New("unsupported parameter type") + } + } + return args, nil +} diff --git a/exchanges/supported_functionality_test.go b/exchanges/supported_functionality_test.go new file mode 100644 index 00000000000..53e835e9939 --- /dev/null +++ b/exchanges/supported_functionality_test.go @@ -0,0 +1,37 @@ +package exchange + +import ( + "context" + "errors" + "testing" + + "github.com/stretchr/testify/require" + "github.com/thrasher-corp/gocryptotrader/currency" + "github.com/thrasher-corp/gocryptotrader/exchanges/asset" + "github.com/thrasher-corp/gocryptotrader/exchanges/order" + "github.com/thrasher-corp/gocryptotrader/exchanges/protocol" +) + +type evenFakerBase struct { + FakeBase +} + +func (e *evenFakerBase) SubmitOrder(context.Context, *order.Submit) (*order.SubmitResponse, error) { + return nil, errors.New("random error that denotes functionality is here but outbound requests are not possible") +} + +func TestGenerateSupportedFunctionality(t *testing.T) { + require.Nil(t, GenerateSupportedFunctionality(nil)) + fake := &evenFakerBase{} + require.Empty(t, GenerateSupportedFunctionality(fake), "no assets supported") + require.NoError(t, fake.CurrencyPairs.Store(asset.Spot, ¤cy.PairStore{})) + require.NoError(t, fake.CurrencyPairs.SetAssetEnabled(asset.Spot, true)) + set := GenerateSupportedFunctionality(fake) + require.NotEmpty(t, set, "assets supported") + + _, ok := set[protocol.Target{Asset: asset.Spot, Protocol: protocol.Websocket}] + require.False(t, ok, "no websocket support for this asset") + restSpotfunctionality, ok := set[protocol.Target{Asset: asset.Spot, Protocol: protocol.REST}] + require.True(t, ok, "rest support for this asset") + require.True(t, restSpotfunctionality["SubmitOrder"], "submit order must be functional for this protocol and this asset") +} diff --git a/exchanges/yobit/README.md b/exchanges/yobit/README.md index d429afc8ac6..c2c8cc3a701 100644 --- a/exchanges/yobit/README.md +++ b/exchanges/yobit/README.md @@ -24,6 +24,21 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + REST Support +## Trading Methods Supported + +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | + ### How to enable + [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example) From 9c66b768fe88ba30371ecafd1a9dabcf63a3ad99 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Fri, 14 Feb 2025 12:57:05 +1100 Subject: [PATCH 05/11] rm unused code --- exchanges/supported_functionality.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/exchanges/supported_functionality.go b/exchanges/supported_functionality.go index 8f98b151878..fc638690c5b 100644 --- a/exchanges/supported_functionality.go +++ b/exchanges/supported_functionality.go @@ -66,14 +66,6 @@ func GenerateSupportedFunctionality(exch IBotExchange) protocol.FunctionalitySet result := methodValue.Call(reflectArgs) err, _ = result[len(result)-1].Interface().(error) - // if !ok { - // fmt.Println("Error type assertion failed", methodName) - // for i := range result { - // fmt.Println(result[i].Interface()) - // } - // log.Warnf(log.Global, "generate supported functionality: method %s result error type assertion failed for %s", methodName, exch.GetName()) - // continue - // } isFunctional := err != nil && !errors.Is(err, common.ErrFunctionNotSupported) && !errors.Is(err, common.ErrNotYetImplemented) && !errors.Is(err, asset.ErrNotSupported) From 2be95698b1b48f0f89c6bd635c4ddc6254fb47cf Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Fri, 14 Feb 2025 13:14:15 +1100 Subject: [PATCH 06/11] rm more code --- exchanges/supported_functionality.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/exchanges/supported_functionality.go b/exchanges/supported_functionality.go index fc638690c5b..77dec7ead88 100644 --- a/exchanges/supported_functionality.go +++ b/exchanges/supported_functionality.go @@ -15,11 +15,6 @@ import ( "github.com/thrasher-corp/gocryptotrader/log" ) -type setter struct { - fn func(f *protocol.Features) *bool - args func(asset.Item) []interface{} -} - // GenerateSupportedFunctionality analyzes the exchange's supported asset types and protocols, returning a set of dynamically // discovered features (ProtocolCapabilities) that the exchange supports. This process is based on the exchange's // specific implementation of wrapper functions. From 67e7be27c07ba4b698acd53388cfb088f48a6c7c Mon Sep 17 00:00:00 2001 From: shazbert Date: Tue, 25 Feb 2025 11:50:35 +1100 Subject: [PATCH 07/11] Don't fetch tradable pairs just set defaults on current supported operation --- cmd/documentation/documentation.go | 4 +++- exchanges/bithumb/README.md | 2 +- exchanges/coinbasepro/README.md | 13 ++++++++++++- exchanges/huobi/README.md | 2 +- exchanges/lbank/README.md | 6 +++--- exchanges/poloniex/README.md | 13 ++++++++++++- exchanges/yobit/README.md | 2 +- 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/cmd/documentation/documentation.go b/cmd/documentation/documentation.go index c40a8758a54..1545d372630 100644 --- a/cmd/documentation/documentation.go +++ b/cmd/documentation/documentation.go @@ -551,11 +551,13 @@ func GetPackageName(name string, capital bool) string { // GetFunctionality returns a dynamic list of supported functionality for a specific asset type. func GetFunctionality(name string) []ProtocolFunctionality { - exch, _ := engine.NewExchangeByNameWithDefaults(context.Background(), name) + exch, _ := engine.NewSupportedExchangeByName(name) if exch == nil { return nil } + exch.SetDefaults() + set := exchange.GenerateSupportedFunctionality(exch) if set == nil { return nil diff --git a/exchanges/bithumb/README.md b/exchanges/bithumb/README.md index 992a4dc81ac..348fdc19a1e 100644 --- a/exchanges/bithumb/README.md +++ b/exchanges/bithumb/README.md @@ -30,7 +30,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader | Method Name | spot | |------------|---| -| CancelAllOrders | 🟢 | +| CancelAllOrders | 🚫 | | CancelBatchOrders | 🚫 | | CancelOrder | 🟢 | | GetActiveOrders | 🟢 | diff --git a/exchanges/coinbasepro/README.md b/exchanges/coinbasepro/README.md index a473d028ca8..bf7eea40140 100644 --- a/exchanges/coinbasepro/README.md +++ b/exchanges/coinbasepro/README.md @@ -27,7 +27,18 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader ## Trading Methods Supported - +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🚫 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🚫 | +| SubmitOrder | 🟢 | ### How to enable diff --git a/exchanges/huobi/README.md b/exchanges/huobi/README.md index 76d82e0f61c..77a7efe76c9 100644 --- a/exchanges/huobi/README.md +++ b/exchanges/huobi/README.md @@ -31,7 +31,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader | Method Name | coinmarginedfutures | futures | spot | |------------|---|---|---| -| CancelAllOrders | 🟢 | 🟢 | 🟢 | +| CancelAllOrders | 🟢 | 🟢 | 🚫 | | CancelBatchOrders | 🟢 | 🟢 | 🟢 | | CancelOrder | 🟢 | 🟢 | 🟢 | | GetActiveOrders | 🟢 | 🟢 | 🟢 | diff --git a/exchanges/lbank/README.md b/exchanges/lbank/README.md index bb094bf436a..5d4f6d3f00b 100644 --- a/exchanges/lbank/README.md +++ b/exchanges/lbank/README.md @@ -30,12 +30,12 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader | Method Name | spot | |------------|---| -| CancelAllOrders | 🟢 | +| CancelAllOrders | 🚫 | | CancelBatchOrders | 🚫 | | CancelOrder | 🟢 | -| GetActiveOrders | 🟢 | +| GetActiveOrders | 🚫 | | GetOrderHistory | 🟢 | -| GetOrderInfo | 🟢 | +| GetOrderInfo | 🚫 | | ModifyOrder | 🚫 | | SubmitOrder | 🟢 | diff --git a/exchanges/poloniex/README.md b/exchanges/poloniex/README.md index c812cdc2c1e..c51d19243f0 100644 --- a/exchanges/poloniex/README.md +++ b/exchanges/poloniex/README.md @@ -27,7 +27,18 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader ## Trading Methods Supported - +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🟢 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🟢 | +| SubmitOrder | 🟢 | ### How to enable diff --git a/exchanges/yobit/README.md b/exchanges/yobit/README.md index 13c2c8ef407..48d843ea275 100644 --- a/exchanges/yobit/README.md +++ b/exchanges/yobit/README.md @@ -30,7 +30,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader | Method Name | spot | |------------|---| -| CancelAllOrders | 🟢 | +| CancelAllOrders | 🚫 | | CancelBatchOrders | 🚫 | | CancelOrder | 🟢 | | GetActiveOrders | 🟢 | From 3c0a00f4e945900615aa8bb6d9bb8e194e98a941 Mon Sep 17 00:00:00 2001 From: shazbert Date: Tue, 25 Feb 2025 12:43:31 +1100 Subject: [PATCH 08/11] linter: fix --- exchanges/supported_functionality.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/exchanges/supported_functionality.go b/exchanges/supported_functionality.go index 77dec7ead88..b1ac6a0d585 100644 --- a/exchanges/supported_functionality.go +++ b/exchanges/supported_functionality.go @@ -3,7 +3,6 @@ package exchange import ( "context" "errors" - "fmt" "reflect" "time" @@ -36,21 +35,19 @@ func GenerateSupportedFunctionality(exch IBotExchange) protocol.FunctionalitySet restTradingType := reflect.TypeOf(&restTrading).Elem() // Get the type of the interface functionality := make(protocol.Functionality) - for i := 0; i < restTradingType.NumMethod(); i++ { + for i := range restTradingType.NumMethod() { restTradingmethod := restTradingType.Method(i) methodName := restTradingmethod.Name method, ok := restTradingType.MethodByName(methodName) if !ok { - fmt.Println("Method not found") log.Warnf(log.Global, "generate supported functionality: method %s not found for %s", methodName, exch.GetName()) continue } methodValue := reflect.ValueOf(exch).MethodByName(methodName) - args, err := generateArgs(ctx, a, method) + args, err := generateArgs(ctx, a, &method) if err != nil { - fmt.Println("Args generation failed") log.Warnf(log.Global, "generate supported functionality: method %s args generation failed for %s: %v", methodName, exch.GetName(), err) continue } @@ -74,12 +71,12 @@ func GenerateSupportedFunctionality(exch IBotExchange) protocol.FunctionalitySet } // generateArgs generates the args function based on the method's parameter types -func generateArgs(ctx context.Context, a asset.Item, method reflect.Method) ([]interface{}, error) { +func generateArgs(ctx context.Context, a asset.Item, method *reflect.Method) ([]interface{}, error) { // Create a slice to hold the arguments args := make([]interface{}, 0) // Iterate over the method's input parameters - for j := 0; j < method.Type.NumIn(); j++ { + for j := range method.Type.NumIn() { paramType := method.Type.In(j) // Handle specific parameter types @@ -92,7 +89,7 @@ func generateArgs(ctx context.Context, a asset.Item, method reflect.Method) ([]i args = append(args, &order.Modify{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), Side: order.Buy, Type: order.Market, Price: 1, Amount: 1}) case reflect.TypeOf((*order.Cancel)(nil)): args = append(args, &order.Cancel{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), OrderID: "bruh"}) - case reflect.TypeOf(([]order.Cancel)(nil)): + case reflect.TypeOf([]order.Cancel(nil)): args = append(args, []order.Cancel{{Exchange: "preflight", AssetType: a, Pair: currency.NewBTCUSD(), OrderID: "bruh"}}) case reflect.TypeOf((*order.MultiOrderRequest)(nil)): args = append(args, &order.MultiOrderRequest{AssetType: a, Pairs: currency.Pairs{currency.NewBTCUSD()}, Side: order.Buy, Type: order.Limit}) From 8342c023428f48f5ccc25e9920e6d86d24d923e2 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Wed, 5 Mar 2025 13:08:47 +1100 Subject: [PATCH 09/11] glorious: nits --- README.md | 4 +- engine/currency_state_manager.md | 74 ++++++++++++++++---------------- engine/helpers.go | 4 +- exchanges/btcmarkets/README.md | 13 +++++- 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 7715fce3f46..d5885bb74e1 100644 --- a/README.md +++ b/README.md @@ -153,13 +153,13 @@ Binaries will be published once the codebase reaches a stable condition. |--|--| | [thrasher-](https://github.com/thrasher-) | 706 | | [shazbert](https://github.com/shazbert) | 362 | -| [dependabot[bot]](https://github.com/apps/dependabot) | 353 | +| [dependabot[bot]](https://github.com/apps/dependabot) | 354 | | [gloriousCode](https://github.com/gloriousCode) | 236 | | [gbjk](https://github.com/gbjk) | 115 | | [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 | | [xtda](https://github.com/xtda) | 47 | | [lrascao](https://github.com/lrascao) | 27 | -| [Beadko](https://github.com/Beadko) | 18 | +| [Beadko](https://github.com/Beadko) | 19 | | [Rots](https://github.com/Rots) | 15 | | [vazha](https://github.com/vazha) | 15 | | [ydm](https://github.com/ydm) | 15 | diff --git a/engine/currency_state_manager.md b/engine/currency_state_manager.md index 5e938e72fab..cb6a44d9a57 100644 --- a/engine/currency_state_manager.md +++ b/engine/currency_state_manager.md @@ -1,22 +1,22 @@ -# GoCryptoTrader package Currency state manager - - - - -[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml) -[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE) -[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/engine/currency_state_manager) -[![Coverage Status](https://codecov.io/gh/thrasher-corp/gocryptotrader/graph/badge.svg?token=41784B23TS)](https://codecov.io/gh/thrasher-corp/gocryptotrader) -[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader) - - -This currency_state_manager package is part of the GoCryptoTrader codebase. - -## This is still in active development - -You can track ideas, planned features and what's in progress on our [GoCryptoTrader Kanban board](https://github.com/orgs/thrasher-corp/projects/3). - -Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk) +# GoCryptoTrader package Currency state manager + + + + +[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml) +[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE) +[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/engine/currency_state_manager) +[![Coverage Status](https://codecov.io/gh/thrasher-corp/gocryptotrader/graph/badge.svg?token=41784B23TS)](https://codecov.io/gh/thrasher-corp/gocryptotrader) +[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader) + + +This currency_state_manager package is part of the GoCryptoTrader codebase. + +## This is still in active development + +You can track ideas, planned features and what's in progress on our [GoCryptoTrader Kanban board](https://github.com/orgs/thrasher-corp/projects/3). + +Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk) ## Current Features for Currency state manager + The state manager keeps currency states up to date, which include: @@ -27,22 +27,22 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader + This allows for an internal state check to compliment internal and external strategies. - -## Contribution - -Please feel free to submit any pull requests or suggest any desired features to be added. - -When submitting a PR, please abide by our coding guidelines: - -+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). -+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. -+ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md). -+ Pull requests need to be based on and opened against the `master` branch. - -## Donations - - - -If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to: - + +## Contribution + +Please feel free to submit any pull requests or suggest any desired features to be added. + +When submitting a PR, please abide by our coding guidelines: + ++ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). ++ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. ++ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md). ++ Pull requests need to be based on and opened against the `master` branch. + +## Donations + + + +If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to: + ***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc*** diff --git a/engine/helpers.go b/engine/helpers.go index f8cc22928c1..ffb2dc84cd5 100644 --- a/engine/helpers.go +++ b/engine/helpers.go @@ -965,7 +965,7 @@ func genCert(targetDir string) error { // supported by GCT. This function will return an error if the exchange is not // supported. func NewSupportedExchangeByName(name string) (exchange.IBotExchange, error) { - switch strings.ToLower(name) { + switch strings.ToLower(strings.ReplaceAll(name, " ", "")) { case "binanceus": return new(binanceus.Binanceus), nil case "binance": @@ -980,7 +980,7 @@ func NewSupportedExchangeByName(name string) (exchange.IBotExchange, error) { return new(bitmex.Bitmex), nil case "bitstamp": return new(bitstamp.Bitstamp), nil - case "btc markets": + case "btcmarkets": return new(btcmarkets.BTCMarkets), nil case "btse": return new(btse.BTSE), nil diff --git a/exchanges/btcmarkets/README.md b/exchanges/btcmarkets/README.md index 7279b4e7d2f..35f3f9ddbd7 100644 --- a/exchanges/btcmarkets/README.md +++ b/exchanges/btcmarkets/README.md @@ -27,7 +27,18 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader ## Trading Methods Supported - +### Protocol: REST + +| Method Name | spot | +|------------|---| +| CancelAllOrders | 🟢 | +| CancelBatchOrders | 🟢 | +| CancelOrder | 🟢 | +| GetActiveOrders | 🟢 | +| GetOrderHistory | 🟢 | +| GetOrderInfo | 🟢 | +| ModifyOrder | 🟢 | +| SubmitOrder | 🟢 | ### How to enable From 3b7e78132da289c1256e64c9a175590fd6469649 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Thu, 6 Mar 2025 10:52:28 +1100 Subject: [PATCH 10/11] Update exchanges/supported_functionality_test.go Co-authored-by: Scott --- exchanges/supported_functionality_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exchanges/supported_functionality_test.go b/exchanges/supported_functionality_test.go index 53e835e9939..75408e37b56 100644 --- a/exchanges/supported_functionality_test.go +++ b/exchanges/supported_functionality_test.go @@ -31,7 +31,7 @@ func TestGenerateSupportedFunctionality(t *testing.T) { _, ok := set[protocol.Target{Asset: asset.Spot, Protocol: protocol.Websocket}] require.False(t, ok, "no websocket support for this asset") - restSpotfunctionality, ok := set[protocol.Target{Asset: asset.Spot, Protocol: protocol.REST}] + restSpotFunctionality, ok := set[protocol.Target{Asset: asset.Spot, Protocol: protocol.REST}] require.True(t, ok, "rest support for this asset") - require.True(t, restSpotfunctionality["SubmitOrder"], "submit order must be functional for this protocol and this asset") + require.True(t, restSpotFunctionality["SubmitOrder"], "submit order must be functional for this protocol and this asset") } From 7b2c21d3e9c1e05f3cb9d76df58b111fe9d7da24 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Thu, 6 Mar 2025 10:52:40 +1100 Subject: [PATCH 11/11] Update engine/engine.go Co-authored-by: Scott --- engine/engine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/engine.go b/engine/engine.go index cb00e713fb6..ca52e7f86be 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -834,7 +834,7 @@ func (bot *Engine) LoadExchange(name string) error { return err } - // Update prototocol capabilities with dynamic supported functionality check + // Update protocol capabilities with dynamic supported functionality check exch.GetBase().ProtocolCapabilities = exchange.GenerateSupportedFunctionality(exch) return nil }