Files
gocryptotrader/exchanges/asset/asset.go
Scott 50bbdabf43 BugFix: RPCServer cannot retrieve open orders/getOrder due to unset asset type (#634)
* Fixes issue where getorders could not work due to unset asset type in rpcserver.go. Adds test. Also adds start and end date to the cli.

* A few fixes

* lint

* fixes oopsie that affected doopsie

* Ensures dates are set for all open order implementations. Adds new filter to ensure orders without dates are returned rather than filtered. Fixes up Binance OpenOrders implementation. Adds some extra typeconverts for binance

* Add updated time to Binance GetActiveOrders. Update rpcserver.go to only set the time if its not empty. Also addressed bad expected value

* Actually fixes things this time

* Improves recvWindow to process openOrders

* Adds asset type to getOrder as well

* Fixes tests

* Adds missing date fields

* Fixes default time, updates default errors

* Default start to last month, instead of last year
2021-02-25 17:13:21 +11:00

119 lines
2.5 KiB
Go

package asset
import (
"errors"
"fmt"
"strings"
)
var (
ErrNotSupported = errors.New("received unsupported asset type")
)
// Item stores the asset type
type Item string
// Items stores a list of assets types
type Items []Item
// Const vars for asset package
const (
Spot = Item("spot")
Margin = Item("margin")
MarginFunding = Item("marginfunding")
Index = Item("index")
Binary = Item("binary")
PerpetualContract = Item("perpetualcontract")
PerpetualSwap = Item("perpetualswap")
Futures = Item("futures")
UpsideProfitContract = Item("upsideprofitcontract")
DownsideProfitContract = Item("downsideprofitcontract")
CoinMarginedFutures = Item("coinmarginedfutures")
USDTMarginedFutures = Item("usdtmarginedfutures")
)
var supported = Items{
Spot,
Margin,
MarginFunding,
Index,
Binary,
PerpetualContract,
PerpetualSwap,
Futures,
UpsideProfitContract,
DownsideProfitContract,
CoinMarginedFutures,
USDTMarginedFutures,
}
// Supported returns a list of supported asset types
func Supported() Items {
return supported
}
// returns an Item to string
func (a Item) String() string {
return string(a)
}
// Strings converts an asset type array to a string array
func (a Items) Strings() []string {
var assets []string
for x := range a {
assets = append(assets, string(a[x]))
}
return assets
}
// Contains returns whether or not the supplied asset exists
// in the list of Items
func (a Items) Contains(i Item) bool {
if !i.IsValid() {
return false
}
for x := range a {
if a[x].String() == i.String() {
return true
}
}
return false
}
// JoinToString joins an asset type array and converts it to a string
// with the supplied separator
func (a Items) JoinToString(separator string) string {
return strings.Join(a.Strings(), separator)
}
// IsValid returns whether or not the supplied asset type is valid or
// not
func (a Item) IsValid() bool {
for x := range supported {
if supported[x].String() == a.String() {
return true
}
}
return false
}
// New takes an input matches to relevant package assets
func New(input string) (Item, error) {
input = strings.ToLower(input)
for i := range supported {
if string(supported[i]) == input {
return supported[i], nil
}
}
return "", fmt.Errorf("%w %v, only supports %v",
ErrNotSupported,
input,
supported)
}
// UseDefault returns default asset type
func UseDefault() Item {
return Spot
}