Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exchanges: Add dynamic function checking to determine exchange functionality #1619

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ 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) | 361 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 351 |
| [thrasher-](https://github.com/thrasher-) | 706 |
| [shazbert](https://github.com/shazbert) | 362 |
| [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 |
Expand Down
103 changes: 101 additions & 2 deletions cmd/documentation/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/engine"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
Expand Down Expand Up @@ -111,6 +113,38 @@ type Attributes struct {
Year int
CapitalName string
DonationAddress string
Features []ProtocolFunctionality
}

// ProtocolFunctionality defines a protocol feature set
type ProtocolFunctionality struct {
Protocol string
Assets []AssetFunctionality
}

func (a ProtocolFunctionality) String() string {
return a.Protocol
}

// AssetFunctionality defines an asset feature set
type AssetFunctionality struct {
Asset string
Methods []MethodNameAndOperational
}

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() {
Expand Down Expand Up @@ -437,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 {
Expand Down Expand Up @@ -485,13 +523,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: GetFunctionality(name),
}
}

Expand All @@ -509,6 +549,48 @@ func GetPackageName(name string, capital bool) string {
return newStrings[i]
}

// GetFunctionality returns a dynamic list of supported functionality for a specific asset type.
func GetFunctionality(name string) []ProtocolFunctionality {
exch, _ := engine.NewSupportedExchangeByName(name)
if exch == nil {
return nil
}

exch.SetDefaults()

set := exchange.GenerateSupportedFunctionality(exch)
if set == nil {
return nil
}

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,
})
}
pName := ap.Protocol.String()
methods = common.SortStrings(methods)
lookup[pName] = append(lookup[pName], AssetFunctionality{
Asset: ap.Asset.String(),
Methods: methods,
})
}
functionalityList := make([]ProtocolFunctionality, 0, len(lookup))
for k, v := range lookup {
v = common.SortStrings(v)
functionalityList = append(functionalityList, ProtocolFunctionality{
Protocol: k,
Assets: v,
})
}
functionalityList = common.SortStrings(functionalityList)
return functionalityList
}

// GetGoDocURL returns a string for godoc package names
func GetGoDocURL(name string) string {
if strings.Contains(name, " ") {
Expand Down Expand Up @@ -621,3 +703,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)
}
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/binance.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/binanceus.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/bitfinex.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/bitflyer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/bithumb.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/bitmex.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/bitstamp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/btcmarkets.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/btse.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/bybit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/coinbasepro.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/coinut.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/deribit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/exmo.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/gateio.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/gemini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/hitbtc.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/huobi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/kraken.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/kucoin.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
+ REST Support
+ Websocket Support

{{template "features" .}}

### Subscriptions

Default Public Subscriptions:
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/lbank.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/okx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/poloniex.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/exchanges_templates/yobit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading