-
Notifications
You must be signed in to change notification settings - Fork 844
exchanges: Add dynamic function checking to determine exchange functionality #1619
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1619 +/- ##
==========================================
+ Coverage 36.36% 36.39% +0.03%
==========================================
Files 422 424 +2
Lines 183105 183221 +116
==========================================
+ Hits 66588 66692 +104
- Misses 108475 108481 +6
- Partials 8042 8048 +6
|
This PR is stale because it has been open 30 days with no activity. Please provide an update on the progress of this PR. |
This PR is stale because it has been open 30 days with no activity. Please provide an update on the progress of this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a worthwhile feature to expand across the exchanges now. I like automation
var supported bool
if butts, ok := b.ProtocolCapabilities[protocol.Target{
Asset: asset.Spot,
Protocol: protocol.REST,
}]; ok {
supported = butts.AccountBalance
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done with the revamp. Looks like BTC markets needs a looky and then you're good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tHANKS
Co-authored-by: Scott <[email protected]>
Co-authored-by: Scott <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work 👍
At first I was skeptical about the complexity of using reflect, and how it shouldn't be so hard for us to just do this.
But then I don't see a better way across all exchanges and assets with what we currently have.
Naming was my biggest initial thing.
I definitely thing we shouldn't pollute runtime Base fields with this when it's only need for docs; Correct me if I'm wrong.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐒
- I think the naming could use some revision here.
MethodNameAndOperational
should just be aMethod
- MethodNameAndOperational.MethodName should just be Method.Name
- Operational feels like another term we've already used, like "Supported" ?
- Method and Features seems to be overloaded terms, but I think that's okay.
- Should these really be slices instead of maps; Feels like we're hiding the unique relationship and forcing a
lookup
usage later
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 | |
AvailableMethods ProtocolMethods | |
} | |
type ProtocolMethods map[Protocol]AssetMethods | |
type AssetMethods map[Asset]MethodSupported | |
type Asset string // Or asset.Item? | |
type MethodSupported map[Method]bool | |
type Method string |
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like we have n+ things using public methods.
Could we make a type Package
and then have methods on it for Functionaliy, GoDocURL, etc ?
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// GetFunctionality returns a dynamic list of supported functionality for a specific asset type. | |
// GetFunctionality returns a list of supported functionality grouped by protocol and asset type |
// 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func GenerateSupportedFunctionality(exch IBotExchange) protocol.FunctionalitySet { | |
func GetSupportedFunctionality(exch IBotExchange) protocol.FunctionalitySet { |
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func GetFunctionality(name string) []ProtocolFunctionality { | |
func GetFeatures(name string) FeatureMap { |
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considered using sprig.has ?
tmpl := template.New("") | ||
tmpl := template.New("").Funcs(template.FuncMap{ | ||
"contains": contains, | ||
"append": _append, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considered using sprig.append ?
{{- /* 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 }} | ||
|
||
| 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 }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a lot of logic in the template, because of the state vars you've had to create, etc.
I feel like you should be able to get the asset types, the methods and their status inside a func and have a much simpler text template here.
return err | ||
} | ||
|
||
// Update protocol capabilities with dynamic supported functionality check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this comment is adding anything :)
// Update protocol capabilities with dynamic supported functionality check |
Features Features | ||
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a while to work out why this bothered me:
- Capabilities are Features
- And ProtocolFeatures is just Features re-envisioned, right?
So should we not just change Features itself?
I know it's a lot more work, but if it's the right thing to do...
Alternative thought is: Do we even need to store the FeatureMap? We're not using it often enough to make it a field on Base, IMO. Maybe we derive it when needed
This PR is stale because it has been open 30 days with no activity. Please provide an update on the progress of this PR. |
PR Description
AutomaticPreFlightCheck
function to determine functionality support between protocols and asset types.Type of change
Please delete options that are not relevant and add an
x
in[]
as item is complete.How has this been tested
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.
Checklist