Asset update to fix minor stutter (#316)

This commit is contained in:
Ryan O'Hara-Reid
2019-06-17 09:02:07 +10:00
committed by Adrian Gallagher
parent b901c4b670
commit 20c24601fb
87 changed files with 976 additions and 966 deletions

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
const (
@@ -121,8 +121,8 @@ func main() {
newExchConfig.API.Credentials.Secret = "Secret"
newExchConfig.CurrencyPairs = &currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
}

View File

@@ -36,7 +36,7 @@ func ({{.Variable}} *{{.CapitalName}}) SetDefaults() {
{{.Variable}}.RequestCurrencyPairFormat.Uppercase = true
{{.Variable}}.ConfigCurrencyPairFormat.Delimiter = ""
{{.Variable}}.ConfigCurrencyPairFormat.Uppercase = true
{{.Variable}}.AssetTypes = assets.AssetTypes{assets.AssetTypeSpot}
{{.Variable}}.AssetTypes = asset.Items{asset.Spot}
{{.Variable}}.SupportsAutoPairUpdating = false
{{.Variable}}.SupportsRESTTickerBatching = false
{{.Variable}}.Requester = request.New({{.Variable}}.Name,

View File

@@ -31,7 +31,7 @@ func ({{.Variable}} *{{.CapitalName}}) Run() {
}
// UpdateTicker updates and returns the ticker for a currency pair
func ({{.Variable}} *{{.CapitalName}}) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func ({{.Variable}} *{{.CapitalName}}) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
// NOTE EXAMPLE FOR GETTING TICKER PRICE
//tick, err := {{.Variable}}.GetTickers()
@@ -59,7 +59,7 @@ func ({{.Variable}} *{{.CapitalName}}) UpdateTicker(p currency.Pair, assetType a
}
// FetchTicker returns the ticker for a currency pair
func ({{.Variable}} *{{.CapitalName}}) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func ({{.Variable}} *{{.CapitalName}}) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker({{.Variable}}.GetName(), p, assetType)
if err != nil {
return {{.Variable}}.UpdateTicker(p, assetType)
@@ -68,7 +68,7 @@ func ({{.Variable}} *{{.CapitalName}}) FetchTicker(p currency.Pair, assetType as
}
// FetchOrderbook returns orderbook base on the currency pair
func ({{.Variable}} *{{.CapitalName}}) FetchOrderbook(currency currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func ({{.Variable}} *{{.CapitalName}}) FetchOrderbook(currency currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get({{.Variable}}.GetName(), currency, assetType)
if err != nil {
return {{.Variable}}.UpdateOrderbook(currency, assetType)
@@ -77,7 +77,7 @@ func ({{.Variable}} *{{.CapitalName}}) FetchOrderbook(currency currency.Pair, as
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
//NOTE UPDATE ORDERBOOK EXAMPLE
//orderbookNew, err := {{.Variable}}.GetOrderBook(exchange.FormatExchangeCurrency({{.Variable}}.Name, p).String(), 1000)
@@ -111,7 +111,7 @@ func ({{.Variable}} *{{.CapitalName}}) GetFundingHistory() ([]exchange.FundHisto
}
// GetExchangeHistory returns historic trade data since exchange opening.
func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}

View File

@@ -8,7 +8,7 @@ import (
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/engine"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
const (
@@ -68,7 +68,7 @@ func main() {
func testWrappers(e exchange.IBotExchange) []string {
p := currency.NewPair(currency.BTC, currency.USD)
assetType := assets.AssetTypeSpot
assetType := asset.Spot
var funcs []string
_, err := e.FetchTicker(p, assetType)
@@ -91,7 +91,7 @@ func testWrappers(e exchange.IBotExchange) []string {
funcs = append(funcs, "UpdateOrderbook")
}
_, err = e.FetchTradablePairs(assets.AssetTypeSpot)
_, err = e.FetchTradablePairs(asset.Spot)
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "FetchTradablePairs")
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// Vars for the websocket client
@@ -44,7 +44,7 @@ type WebsocketEventResponse struct {
type WebsocketOrderbookTickerRequest struct {
Exchange string `json:"exchangeName"`
Currency string `json:"currency"`
AssetType assets.AssetType `json:"assetType"`
AssetType asset.Item `json:"assetType"`
}
// SendWebsocketEvent sends a websocket event message
@@ -157,7 +157,7 @@ func main() {
dataReq := WebsocketOrderbookTickerRequest{
Exchange: "Bitfinex",
Currency: "BTCUSD",
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
}
err = SendWebsocketEvent("GetTicker", dataReq, &wsResp)

View File

@@ -22,7 +22,7 @@ import (
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -402,21 +402,21 @@ func (c *Config) CheckCommunicationsConfig() {
}
// GetExchangeAssetTypes returns the exchanges supported asset types
func (c *Config) GetExchangeAssetTypes(exchName string) (assets.AssetTypes, error) {
func (c *Config) GetExchangeAssetTypes(exchName string) (asset.Items, error) {
exchCfg, err := c.GetExchangeConfig(exchName)
if err != nil {
return assets.AssetTypes{}, err
return nil, err
}
if exchCfg.CurrencyPairs == nil {
return assets.AssetTypes{}, fmt.Errorf("exchange %s currency pairs is nil", exchName)
return nil, fmt.Errorf("exchange %s currency pairs is nil", exchName)
}
return exchCfg.CurrencyPairs.AssetTypes, nil
}
// SupportsExchangeAssetType returns whether or not the exchange supports the supplied asset type
func (c *Config) SupportsExchangeAssetType(exchName string, assetType assets.AssetType) (bool, error) {
func (c *Config) SupportsExchangeAssetType(exchName string, assetType asset.Item) (bool, error) {
exchCfg, err := c.GetExchangeConfig(exchName)
if err != nil {
return false, err
@@ -426,7 +426,7 @@ func (c *Config) SupportsExchangeAssetType(exchName string, assetType assets.Ass
return false, fmt.Errorf("exchange %s currency pairs is nil", exchName)
}
if !assets.IsValid(assetType) {
if !asset.IsValid(assetType) {
return false, fmt.Errorf("exchange %s invalid asset types", exchName)
}
@@ -460,7 +460,7 @@ func (c *Config) CheckExchangeAssetsConsistency(exchName string) {
}
// SetPairs sets the exchanges currency pairs
func (c *Config) SetPairs(exchName string, assetType assets.AssetType, enabled bool, pairs currency.Pairs) error {
func (c *Config) SetPairs(exchName string, assetType asset.Item, enabled bool, pairs currency.Pairs) error {
exchCfg, err := c.GetExchangeConfig(exchName)
if err != nil {
return err
@@ -480,7 +480,7 @@ func (c *Config) SetPairs(exchName string, assetType assets.AssetType, enabled b
}
// GetCurrencyPairConfig returns currency pair config for the desired exchange and asset type
func (c *Config) GetCurrencyPairConfig(exchName string, assetType assets.AssetType) (*currency.PairStore, error) {
func (c *Config) GetCurrencyPairConfig(exchName string, assetType asset.Item) (*currency.PairStore, error) {
exchCfg, err := c.GetExchangeConfig(exchName)
if err != nil {
return nil, err
@@ -636,7 +636,7 @@ func (c *Config) CheckPairConsistency(exchName string) error {
// SupportsPair returns true or not whether the exchange supports the supplied
// pair
func (c *Config) SupportsPair(exchName string, p currency.Pair, assetType assets.AssetType) (bool, error) {
func (c *Config) SupportsPair(exchName string, p currency.Pair, assetType asset.Item) (bool, error) {
pairs, err := c.GetAvailablePairs(exchName, assetType)
if err != nil {
return false, err
@@ -645,7 +645,7 @@ func (c *Config) SupportsPair(exchName string, p currency.Pair, assetType assets
}
// GetPairFormat returns the exchanges pair config storage format
func (c *Config) GetPairFormat(exchName string, assetType assets.AssetType) (currency.PairFormat, error) {
func (c *Config) GetPairFormat(exchName string, assetType asset.Item) (currency.PairFormat, error) {
exchCfg, err := c.GetExchangeConfig(exchName)
if err != nil {
return currency.PairFormat{}, err
@@ -663,7 +663,7 @@ func (c *Config) GetPairFormat(exchName string, assetType assets.AssetType) (cur
}
// GetAvailablePairs returns a list of currency pairs for a specifc exchange
func (c *Config) GetAvailablePairs(exchName string, assetType assets.AssetType) (currency.Pairs, error) {
func (c *Config) GetAvailablePairs(exchName string, assetType asset.Item) (currency.Pairs, error) {
exchCfg, err := c.GetExchangeConfig(exchName)
if err != nil {
return nil, err
@@ -684,7 +684,7 @@ func (c *Config) GetAvailablePairs(exchName string, assetType assets.AssetType)
}
// GetEnabledPairs returns a list of currency pairs for a specifc exchange
func (c *Config) GetEnabledPairs(exchName string, assetType assets.AssetType) ([]currency.Pair, error) {
func (c *Config) GetEnabledPairs(exchName string, assetType asset.Item) ([]currency.Pair, error) {
exchCfg, err := c.GetExchangeConfig(exchName)
if err != nil {
return nil, err
@@ -909,7 +909,7 @@ func (c *Config) CheckExchangeConfigValues() error {
// Check if see if the new currency pairs format is empty and flesh it out if so
if c.Exchanges[i].CurrencyPairs == nil {
c.Exchanges[i].CurrencyPairs = new(currency.PairsManager)
c.Exchanges[i].CurrencyPairs.Pairs = make(map[assets.AssetType]*currency.PairStore)
c.Exchanges[i].CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
if c.Exchanges[i].PairsLastUpdated != nil {
c.Exchanges[i].CurrencyPairs.LastUpdated = *c.Exchanges[i].PairsLastUpdated
@@ -917,9 +917,9 @@ func (c *Config) CheckExchangeConfigValues() error {
c.Exchanges[i].CurrencyPairs.ConfigFormat = c.Exchanges[i].ConfigCurrencyPairFormat
c.Exchanges[i].CurrencyPairs.RequestFormat = c.Exchanges[i].RequestCurrencyPairFormat
c.Exchanges[i].CurrencyPairs.AssetTypes = assets.New(strings.ToLower(*c.Exchanges[i].AssetTypes))
c.Exchanges[i].CurrencyPairs.AssetTypes = asset.New(strings.ToLower(*c.Exchanges[i].AssetTypes))
c.Exchanges[i].CurrencyPairs.UseGlobalFormat = true
c.Exchanges[i].CurrencyPairs.Store(assets.AssetTypeSpot,
c.Exchanges[i].CurrencyPairs.Store(asset.Spot,
currency.PairStore{
Available: *c.Exchanges[i].AvailablePairs,
Enabled: *c.Exchanges[i].EnabledPairs,
@@ -1197,9 +1197,9 @@ func (c *Config) RetrieveConfigCurrencyPairs(enabledOnly bool) error {
var pairs []currency.Pair
var err error
if !c.Exchanges[x].Enabled && enabledOnly {
pairs, err = c.GetEnabledPairs(c.Exchanges[x].Name, assets.AssetTypeSpot)
pairs, err = c.GetEnabledPairs(c.Exchanges[x].Name, asset.Spot)
} else {
pairs, err = c.GetAvailablePairs(c.Exchanges[x].Name, assets.AssetTypeSpot)
pairs, err = c.GetAvailablePairs(c.Exchanges[x].Name, asset.Spot)
}
if err != nil {

View File

@@ -6,7 +6,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
log "github.com/thrasher-/gocryptotrader/logger"
"github.com/thrasher-/gocryptotrader/ntpclient"
)
@@ -285,7 +285,7 @@ func TestCheckPairConsistency(t *testing.T) {
Uppercase: true,
},
}
pairsMan.Store(assets.AssetTypeSpot, currency.PairStore{
pairsMan.Store(asset.Spot, currency.PairStore{
Available: currency.NewPairsFromStrings([]string{"DOGE_USD,DOGE_AUD"}),
Enabled: currency.NewPairsFromStrings([]string{"DOGE_USD,DOGE_AUD,DOGE_BTC"}),
})
@@ -311,7 +311,7 @@ func TestCheckPairConsistency(t *testing.T) {
t.Error("Test failed. CheckPairConsistency error:", err)
}
tec.CurrencyPairs.StorePairs(assets.AssetTypeSpot, currency.NewPairsFromStrings([]string{"DOGE_LTC,BTC_LTC"}), false)
tec.CurrencyPairs.StorePairs(asset.Spot, currency.NewPairsFromStrings([]string{"DOGE_LTC,BTC_LTC"}), false)
err = cfg.UpdateExchangeConfig(tec)
if err != nil {
t.Error("Test failed. CheckPairConsistency Update config failed, error:", err)
@@ -332,7 +332,7 @@ func TestSupportsPair(t *testing.T) {
)
}
assetType := assets.AssetTypeSpot
assetType := asset.Spot
_, err = cfg.SupportsPair("asdf",
currency.NewPair(currency.BTC, currency.USD), assetType)
if err == nil {
@@ -358,7 +358,7 @@ func TestGetAvailablePairs(t *testing.T) {
"Test failed. TestGetAvailablePairs. LoadConfig Error: %s", err.Error())
}
assetType := assets.AssetTypeSpot
assetType := asset.Spot
_, err = cfg.GetAvailablePairs("asdf", assetType)
if err == nil {
t.Error(
@@ -380,7 +380,7 @@ func TestGetEnabledPairs(t *testing.T) {
"Test failed. TestGetEnabledPairs. LoadConfig Error: %s", err.Error())
}
assetType := assets.AssetTypeSpot
assetType := asset.Spot
_, err = cfg.GetEnabledPairs("asdf", assetType)
if err == nil {
t.Error(

View File

@@ -1,14 +1,14 @@
package currency
import (
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// GetAssetTypes returns a list of stored asset types
func (p *PairsManager) GetAssetTypes() assets.AssetTypes {
func (p *PairsManager) GetAssetTypes() asset.Items {
p.m.Lock()
defer p.m.Unlock()
var assetTypes assets.AssetTypes
var assetTypes asset.Items
for k := range p.Pairs {
assetTypes = append(assetTypes, k)
}
@@ -16,7 +16,7 @@ func (p *PairsManager) GetAssetTypes() assets.AssetTypes {
}
// Get gets the currency pair config based on the asset type
func (p *PairsManager) Get(a assets.AssetType) *PairStore {
func (p *PairsManager) Get(a asset.Item) *PairStore {
p.m.Lock()
defer p.m.Unlock()
c, ok := p.Pairs[a]
@@ -27,11 +27,11 @@ func (p *PairsManager) Get(a assets.AssetType) *PairStore {
}
// Store stores a new currency pair config based on its asset type
func (p *PairsManager) Store(a assets.AssetType, ps PairStore) {
func (p *PairsManager) Store(a asset.Item, ps PairStore) {
p.m.Lock()
if p.Pairs == nil {
p.Pairs = make(map[assets.AssetType]*PairStore)
p.Pairs = make(map[asset.Item]*PairStore)
}
if !p.AssetTypes.Contains(a) {
@@ -43,7 +43,7 @@ func (p *PairsManager) Store(a assets.AssetType, ps PairStore) {
}
// Delete deletes a map entry based on the supplied asset type
func (p *PairsManager) Delete(a assets.AssetType) {
func (p *PairsManager) Delete(a asset.Item) {
p.m.Lock()
defer p.m.Unlock()
if p.Pairs == nil {
@@ -60,7 +60,7 @@ func (p *PairsManager) Delete(a assets.AssetType) {
// GetPairs gets a list of stored pairs based on the asset type and whether
// they're enabled or not
func (p *PairsManager) GetPairs(a assets.AssetType, enabled bool) Pairs {
func (p *PairsManager) GetPairs(a asset.Item, enabled bool) Pairs {
p.m.Lock()
defer p.m.Unlock()
if p.Pairs == nil {
@@ -84,12 +84,12 @@ func (p *PairsManager) GetPairs(a assets.AssetType, enabled bool) Pairs {
// StorePairs stores a list of pairs based on the asset type and whether
// they're enabled or not
func (p *PairsManager) StorePairs(a assets.AssetType, pairs Pairs, enabled bool) {
func (p *PairsManager) StorePairs(a asset.Item, pairs Pairs, enabled bool) {
p.m.Lock()
defer p.m.Unlock()
if p.Pairs == nil {
p.Pairs = make(map[assets.AssetType]*PairStore)
p.Pairs = make(map[asset.Item]*PairStore)
}
c, ok := p.Pairs[a]

View File

@@ -3,13 +3,13 @@ package currency
import (
"testing"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
var p PairsManager
func initTest() {
p.Store(assets.AssetTypeSpot,
p.Store(asset.Spot,
PairStore{
Available: NewPairsFromStrings([]string{"BTC-USD", "LTC-USD"}),
Enabled: NewPairsFromStrings([]string{"BTC-USD"}),
@@ -32,7 +32,7 @@ func TestGetAssetTypes(t *testing.T) {
t.Errorf("Test failed. GetAssetTypes shouldn't be nil")
}
if !a.Contains(assets.AssetTypeSpot) {
if !a.Contains(asset.Spot) {
t.Errorf("Test failed. AssetTypeSpot should be in the assets list")
}
}
@@ -40,17 +40,17 @@ func TestGetAssetTypes(t *testing.T) {
func TestGet(t *testing.T) {
initTest()
if p.Get(assets.AssetTypeSpot) == nil {
if p.Get(asset.Spot) == nil {
t.Error("Test failed. Spot assets shouldn't be nil")
}
if p.Get(assets.AssetTypeFutures) != nil {
if p.Get(asset.Futures) != nil {
t.Error("Test Failed. Futures should be nil")
}
}
func TestStore(t *testing.T) {
p.Store(assets.AssetTypeFutures,
p.Store(asset.Futures,
PairStore{
Available: NewPairsFromStrings([]string{"BTC-USD", "LTC-USD"}),
Enabled: NewPairsFromStrings([]string{"BTC-USD"}),
@@ -64,27 +64,27 @@ func TestStore(t *testing.T) {
},
)
if p.Get(assets.AssetTypeFutures) == nil {
if p.Get(asset.Futures) == nil {
t.Error("Test failed. Futures assets shouldn't be nil")
}
}
func TestDelete(t *testing.T) {
p.Pairs = nil
p.Delete(assets.AssetTypeSpot)
p.Delete(asset.Spot)
p.Store(assets.AssetTypeSpot,
p.Store(asset.Spot,
PairStore{
Available: NewPairsFromStrings([]string{"BTC-USD"}),
},
)
p.Delete(assets.AssetTypeUpsideProfitContract)
if p.Get(assets.AssetTypeSpot) == nil {
p.Delete(asset.UpsideProfitContract)
if p.Get(asset.Spot) == nil {
t.Error("Test failed. AssetTypeSpot should exist")
}
p.Delete(assets.AssetTypeSpot)
if p.Get(assets.AssetTypeSpot) != nil {
p.Delete(asset.Spot)
if p.Get(asset.Spot) != nil {
t.Error("Test failed. Delete should have deleted AssetTypeSpot")
}
@@ -92,13 +92,13 @@ func TestDelete(t *testing.T) {
func TestGetPairs(t *testing.T) {
p.Pairs = nil
pairs := p.GetPairs(assets.AssetTypeSpot, true)
pairs := p.GetPairs(asset.Spot, true)
if pairs != nil {
t.Fatal("pairs shouldn't be populated")
}
initTest()
pairs = p.GetPairs(assets.AssetTypeSpot, true)
pairs = p.GetPairs(asset.Spot, true)
if pairs == nil {
t.Fatal("pairs should be populated")
}
@@ -111,15 +111,15 @@ func TestGetPairs(t *testing.T) {
func TestStorePairs(t *testing.T) {
p.Pairs = nil
p.StorePairs(assets.AssetTypeSpot, NewPairsFromStrings([]string{"ETH-USD"}), false)
pairs := p.GetPairs(assets.AssetTypeSpot, false)
p.StorePairs(asset.Spot, NewPairsFromStrings([]string{"ETH-USD"}), false)
pairs := p.GetPairs(asset.Spot, false)
if !pairs.Contains(NewPairFromString("ETH-USD"), true) {
t.Errorf("TestStorePairs failed, unexpected result")
}
initTest()
p.StorePairs(assets.AssetTypeSpot, NewPairsFromStrings([]string{"ETH-USD"}), false)
pairs = p.GetPairs(assets.AssetTypeSpot, false)
p.StorePairs(asset.Spot, NewPairsFromStrings([]string{"ETH-USD"}), false)
pairs = p.GetPairs(asset.Spot, false)
if pairs == nil {
t.Errorf("pairs should be populated")
}
@@ -128,8 +128,8 @@ func TestStorePairs(t *testing.T) {
t.Errorf("TestStorePairs failed, unexpected result")
}
p.StorePairs(assets.AssetTypeFutures, NewPairsFromStrings([]string{"ETH-KRW"}), true)
pairs = p.GetPairs(assets.AssetTypeFutures, true)
p.StorePairs(asset.Futures, NewPairsFromStrings([]string{"ETH-KRW"}), true)
pairs = p.GetPairs(asset.Futures, true)
if pairs == nil {
t.Errorf("pairs futures should be populated")
}

View File

@@ -3,17 +3,17 @@ package currency
import (
"sync"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// PairsManager manages asset pairs
type PairsManager struct {
RequestFormat *PairFormat `json:"requestFormat,omitempty"`
ConfigFormat *PairFormat `json:"configFormat,omitempty"`
UseGlobalFormat bool `json:"useGlobalFormat,omitempty"`
LastUpdated int64 `json:"lastUpdated,omitempty"`
AssetTypes assets.AssetTypes `json:"assetTypes"`
Pairs map[assets.AssetType]*PairStore `json:"pairs"`
RequestFormat *PairFormat `json:"requestFormat,omitempty"`
ConfigFormat *PairFormat `json:"configFormat,omitempty"`
UseGlobalFormat bool `json:"useGlobalFormat,omitempty"`
LastUpdated int64 `json:"lastUpdated,omitempty"`
AssetTypes asset.Items `json:"assetTypes"`
Pairs map[asset.Item]*PairStore `json:"pairs"`
m sync.Mutex
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/communications/base"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
log "github.com/thrasher-/gocryptotrader/logger"
@@ -61,7 +61,7 @@ type Event struct {
Item string
Condition EventConditionParams
Pair currency.Pair
Asset assets.AssetType
Asset asset.Item
Action string
Executed bool
}
@@ -72,7 +72,7 @@ var Events []*Event
// Add adds an event to the Events chain and returns an index/eventID
// and an error
func Add(exchange, item string, condition EventConditionParams, currencyPair currency.Pair, asset assets.AssetType, action string) (int64, error) {
func Add(exchange, item string, condition EventConditionParams, currencyPair currency.Pair, asset asset.Item, action string) (int64, error) {
err := IsValidEvent(exchange, item, condition, action)
if err != nil {
return 0, err

View File

@@ -4,7 +4,7 @@ import (
"testing"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
@@ -22,7 +22,7 @@ func addValidEvent() (int64, error) {
ItemPrice,
EventConditionParams{Condition: ConditionGreaterThan, Price: 1},
currency.NewPair(currency.BTC, currency.USD),
assets.AssetTypeSpot,
asset.Spot,
"SMS,test")
}
@@ -124,7 +124,7 @@ func TestString(t *testing.T) {
Price: 1,
},
Pair: currency.NewPair(currency.BTC, currency.USD),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Action: "SMS,ALL",
}
@@ -142,7 +142,7 @@ func TestProcessTicker(t *testing.T) {
e := Event{
Exchange: testExchange,
Pair: currency.NewPair(currency.BTC, currency.USD),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Condition: EventConditionParams{
Condition: ConditionGreaterThan,
Price: 1,
@@ -214,7 +214,7 @@ func TestProcessOrderbook(t *testing.T) {
e := Event{
Exchange: testExchange,
Pair: currency.NewPair(currency.BTC, currency.USD),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Condition: EventConditionParams{
Condition: ConditionGreaterThan,
CheckBidsAndAsks: true,

View File

@@ -20,7 +20,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/stats"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -179,7 +179,7 @@ func GetAvailableExchanges() []string {
// GetAllAvailablePairs returns a list of all available pairs on either enabled
// or disabled exchanges
func GetAllAvailablePairs(enabledExchangesOnly bool, assetType assets.AssetType) currency.Pairs {
func GetAllAvailablePairs(enabledExchangesOnly bool, assetType asset.Item) currency.Pairs {
var pairList currency.Pairs
for x := range Bot.Config.Exchanges {
if enabledExchangesOnly && !Bot.Config.Exchanges[x].Enabled {
@@ -204,7 +204,7 @@ func GetAllAvailablePairs(enabledExchangesOnly bool, assetType assets.AssetType)
// GetSpecificAvailablePairs returns a list of supported pairs based on specific
// parameters
func GetSpecificAvailablePairs(enabledExchangesOnly, fiatPairs, includeUSDT, cryptoPairs bool, assetType assets.AssetType) currency.Pairs {
func GetSpecificAvailablePairs(enabledExchangesOnly, fiatPairs, includeUSDT, cryptoPairs bool, assetType asset.Item) currency.Pairs {
var pairList currency.Pairs
supportedPairs := GetAllAvailablePairs(enabledExchangesOnly, assetType)
@@ -251,7 +251,7 @@ func IsRelatablePairs(p1, p2 currency.Pair, includeUSDT bool) bool {
// MapCurrenciesByExchange returns a list of currency pairs mapped to an
// exchange
func MapCurrenciesByExchange(p currency.Pairs, enabledExchangesOnly bool, assetType assets.AssetType) map[string]currency.Pairs {
func MapCurrenciesByExchange(p currency.Pairs, enabledExchangesOnly bool, assetType asset.Item) map[string]currency.Pairs {
currencyExchange := make(map[string]currency.Pairs)
for x := range p {
for y := range Bot.Config.Exchanges {
@@ -283,7 +283,7 @@ func MapCurrenciesByExchange(p currency.Pairs, enabledExchangesOnly bool, assetT
// GetExchangeNamesByCurrency returns a list of exchanges supporting
// a currency pair based on whether the exchange is enabled or not
func GetExchangeNamesByCurrency(p currency.Pair, enabled bool, assetType assets.AssetType) []string {
func GetExchangeNamesByCurrency(p currency.Pair, enabled bool, assetType asset.Item) []string {
var exchanges []string
for x := range Bot.Config.Exchanges {
if enabled != Bot.Config.Exchanges[x].Enabled {
@@ -400,7 +400,7 @@ func GetRelatableCurrencies(p currency.Pair, incOrig, incUSDT bool) currency.Pai
// GetSpecificOrderbook returns a specific orderbook given the currency,
// exchangeName and assetType
func GetSpecificOrderbook(p currency.Pair, exchangeName string, assetType assets.AssetType) (orderbook.Base, error) {
func GetSpecificOrderbook(p currency.Pair, exchangeName string, assetType asset.Item) (orderbook.Base, error) {
var specificOrderbook orderbook.Base
var err error
for x := range Bot.Exchanges {
@@ -419,7 +419,7 @@ func GetSpecificOrderbook(p currency.Pair, exchangeName string, assetType assets
// GetSpecificTicker returns a specific ticker given the currency,
// exchangeName and assetType
func GetSpecificTicker(p currency.Pair, exchangeName string, assetType assets.AssetType) (ticker.Price, error) {
func GetSpecificTicker(p currency.Pair, exchangeName string, assetType asset.Item) (ticker.Price, error) {
var specificTicker ticker.Price
var err error
for x := range Bot.Exchanges {
@@ -475,7 +475,7 @@ func GetAccountCurrencyInfoByExchangeName(accounts []exchange.AccountInfo, excha
// GetExchangeHighestPriceByCurrencyPair returns the exchange with the highest
// price for a given currency pair and asset type
func GetExchangeHighestPriceByCurrencyPair(p currency.Pair, assetType assets.AssetType) (string, error) {
func GetExchangeHighestPriceByCurrencyPair(p currency.Pair, assetType asset.Item) (string, error) {
result := stats.SortExchangesByPrice(p, assetType, true)
if len(result) == 0 {
return "", fmt.Errorf("no stats for supplied currency pair and asset type")
@@ -486,7 +486,7 @@ func GetExchangeHighestPriceByCurrencyPair(p currency.Pair, assetType assets.Ass
// GetExchangeLowestPriceByCurrencyPair returns the exchange with the lowest
// price for a given currency pair and asset type
func GetExchangeLowestPriceByCurrencyPair(p currency.Pair, assetType assets.AssetType) (string, error) {
func GetExchangeLowestPriceByCurrencyPair(p currency.Pair, assetType asset.Item) (string, error) {
result := stats.SortExchangesByPrice(p, assetType, false)
if len(result) == 0 {
return "", fmt.Errorf("no stats for supplied currency pair and asset type")
@@ -586,7 +586,7 @@ func SeedExchangeAccountInfo(data []exchange.AccountInfo) {
}
// GetCryptocurrenciesByExchange returns a list of cryptocurrencies the exchange supports
func GetCryptocurrenciesByExchange(exchangeName string, enabledExchangesOnly, enabledPairs bool, assetType assets.AssetType) ([]string, error) {
func GetCryptocurrenciesByExchange(exchangeName string, enabledExchangesOnly, enabledPairs bool, assetType asset.Item) ([]string, error) {
var cryptocurrencies []string
for x := range Bot.Config.Exchanges {
if Bot.Config.Exchanges[x].Name != exchangeName {
@@ -656,7 +656,7 @@ func GetExchangeCryptocurrencyDepositAddresses() map[string]map[string]string {
continue
}
cryptoCurrencies, err := GetCryptocurrenciesByExchange(exchName, true, true, assets.AssetTypeSpot)
cryptoCurrencies, err := GetCryptocurrenciesByExchange(exchName, true, true, asset.Spot)
if err != nil {
log.Debugf("%s failed to get cryptocurrency deposit addresses. Err: %s", exchName, err)
continue

View File

@@ -8,7 +8,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/stats"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -151,7 +151,7 @@ func TestGetAvailableExchanges(t *testing.T) {
func TestGetSpecificAvailablePairs(t *testing.T) {
SetupTestHelpers(t)
assetType := assets.AssetTypeSpot
assetType := asset.Spot
result := GetSpecificAvailablePairs(true, true, true, false, assetType)
if !result.Contains(currency.NewPairFromStrings("BTC", "USD"), true) {
@@ -341,7 +341,7 @@ func TestMapCurrenciesByExchange(t *testing.T) {
currency.NewPair(currency.BTC, currency.EUR),
}
result := MapCurrenciesByExchange(pairs, true, assets.AssetTypeSpot)
result := MapCurrenciesByExchange(pairs, true, asset.Spot)
pairs, ok := result["Bitstamp"]
if !ok {
t.Fatal("Unexpected result")
@@ -354,19 +354,25 @@ func TestMapCurrenciesByExchange(t *testing.T) {
func TestGetExchangeNamesByCurrency(t *testing.T) {
SetupTestHelpers(t)
assetType := assets.AssetTypeSpot
assetType := asset.Spot
result := GetExchangeNamesByCurrency(currency.NewPairFromStrings("BTC", "USD"), true, assetType)
result := GetExchangeNamesByCurrency(currency.NewPairFromStrings("BTC", "USD"),
true,
assetType)
if !common.StringDataCompare(result, "Bitstamp") {
t.Fatal("Unexpected result")
}
result = GetExchangeNamesByCurrency(currency.NewPairFromStrings("BTC", "JPY"), true, assetType)
result = GetExchangeNamesByCurrency(currency.NewPairFromStrings("BTC", "JPY"),
true,
assetType)
if !common.StringDataCompare(result, "Bitflyer") {
t.Fatal("Unexpected result")
}
result = GetExchangeNamesByCurrency(currency.NewPairFromStrings("blah", "JPY"), true, assetType)
result = GetExchangeNamesByCurrency(currency.NewPairFromStrings("blah", "JPY"),
true,
assetType)
if len(result) > 0 {
t.Fatal("Unexpected result")
}
@@ -379,13 +385,12 @@ func TestGetSpecificOrderbook(t *testing.T) {
var bids []orderbook.Item
bids = append(bids, orderbook.Item{Price: 1000, Amount: 1})
asset := assets.AssetTypeSpot
base := orderbook.Base{
Pair: currency.NewPair(currency.BTC, currency.USD),
Bids: bids,
ExchangeName: "Bitstamp",
AssetType: asset,
AssetType: asset.Spot,
}
err := base.Process()
@@ -393,7 +398,9 @@ func TestGetSpecificOrderbook(t *testing.T) {
t.Fatal("Unexpected result", err)
}
ob, err := GetSpecificOrderbook(currency.NewPairFromString("BTCUSD"), "Bitstamp", assets.AssetTypeSpot)
ob, err := GetSpecificOrderbook(currency.NewPairFromString("BTCUSD"),
"Bitstamp",
asset.Spot)
if err != nil {
t.Fatal(err)
}
@@ -402,7 +409,9 @@ func TestGetSpecificOrderbook(t *testing.T) {
t.Fatal("Unexpected result")
}
ob, err = GetSpecificOrderbook(currency.NewPairFromStrings("ETH", "LTC"), "Bitstamp", asset)
ob, err = GetSpecificOrderbook(currency.NewPairFromStrings("ETH", "LTC"),
"Bitstamp",
asset.Spot)
if err == nil {
t.Fatal("Unexpected result")
}
@@ -415,15 +424,15 @@ func TestGetSpecificTicker(t *testing.T) {
LoadExchange("Bitstamp", false, nil)
p := currency.NewPairFromStrings("BTC", "USD")
asset := assets.AssetTypeSpot
err := ticker.ProcessTicker("Bitstamp",
&ticker.Price{Pair: p, Last: 1000},
assets.AssetTypeSpot)
asset.Spot)
if err != nil {
t.Fatal("Test failed. ProcessTicker error", err)
}
tick, err := GetSpecificTicker(currency.NewPairFromStrings("BTC", "USD"), "Bitstamp", asset)
tick, err := GetSpecificTicker(currency.NewPairFromStrings("BTC", "USD"), "Bitstamp",
asset.Spot)
if err != nil {
t.Fatal(err)
}
@@ -432,7 +441,8 @@ func TestGetSpecificTicker(t *testing.T) {
t.Fatal("Unexpected result")
}
tick, err = GetSpecificTicker(currency.NewPairFromStrings("ETH", "LTC"), "Bitstamp", asset)
tick, err = GetSpecificTicker(currency.NewPairFromStrings("ETH", "LTC"), "Bitstamp",
asset.Spot)
if err == nil {
t.Fatal("Unexpected result")
}
@@ -532,10 +542,9 @@ func TestGetExchangeHighestPriceByCurrencyPair(t *testing.T) {
SetupTestHelpers(t)
p := currency.NewPairFromStrings("BTC", "USD")
asset := assets.AssetTypeSpot
stats.Add("Bitfinex", p, assets.AssetTypeSpot, 1000, 10000)
stats.Add("Bitstamp", p, assets.AssetTypeSpot, 1337, 10000)
exchangeName, err := GetExchangeHighestPriceByCurrencyPair(p, asset)
stats.Add("Bitfinex", p, asset.Spot, 1000, 10000)
stats.Add("Bitstamp", p, asset.Spot, 1337, 10000)
exchangeName, err := GetExchangeHighestPriceByCurrencyPair(p, asset.Spot)
if err != nil {
t.Error(err)
}
@@ -544,7 +553,8 @@ func TestGetExchangeHighestPriceByCurrencyPair(t *testing.T) {
t.Error("Unexpected result")
}
_, err = GetExchangeHighestPriceByCurrencyPair(currency.NewPairFromStrings("BTC", "AUD"), asset)
_, err = GetExchangeHighestPriceByCurrencyPair(currency.NewPairFromStrings("BTC", "AUD"),
asset.Spot)
if err == nil {
t.Error("Unexpected result")
}
@@ -554,10 +564,9 @@ func TestGetExchangeLowestPriceByCurrencyPair(t *testing.T) {
SetupTestHelpers(t)
p := currency.NewPairFromStrings("BTC", "USD")
asset := assets.AssetTypeSpot
stats.Add("Bitfinex", p, assets.AssetTypeSpot, 1000, 10000)
stats.Add("Bitstamp", p, assets.AssetTypeSpot, 1337, 10000)
exchangeName, err := GetExchangeLowestPriceByCurrencyPair(p, asset)
stats.Add("Bitfinex", p, asset.Spot, 1000, 10000)
stats.Add("Bitstamp", p, asset.Spot, 1337, 10000)
exchangeName, err := GetExchangeLowestPriceByCurrencyPair(p, asset.Spot)
if err != nil {
t.Error(err)
}
@@ -566,7 +575,8 @@ func TestGetExchangeLowestPriceByCurrencyPair(t *testing.T) {
t.Error("Unexpected result")
}
_, err = GetExchangeLowestPriceByCurrencyPair(currency.NewPairFromStrings("BTC", "AUD"), asset)
_, err = GetExchangeLowestPriceByCurrencyPair(currency.NewPairFromStrings("BTC", "AUD"),
asset.Spot)
if err == nil {
t.Error("Unexpected reuslt")
}
@@ -575,7 +585,7 @@ func TestGetExchangeLowestPriceByCurrencyPair(t *testing.T) {
func TestGetCryptocurrenciesByExchange(t *testing.T) {
SetupTestHelpers(t)
_, err := GetCryptocurrenciesByExchange("Bitfinex", false, false, assets.AssetTypeSpot)
_, err := GetCryptocurrenciesByExchange("Bitfinex", false, false, asset.Spot)
if err != nil {
t.Fatalf("Test failed. Err %s", err)
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/stats"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -57,7 +57,7 @@ func printConvertCurrencyFormat(origCurrency currency.Code, origPrice float64) s
)
}
func printTickerSummary(result *ticker.Price, p currency.Pair, assetType assets.AssetType, exchangeName string, err error) {
func printTickerSummary(result *ticker.Price, p currency.Pair, assetType asset.Item, exchangeName string, err error) {
if err != nil {
log.Errorf("Failed to get %s %s ticker. Error: %s",
p.String(),
@@ -108,7 +108,7 @@ func printTickerSummary(result *ticker.Price, p currency.Pair, assetType assets.
}
}
func printOrderbookSummary(result *orderbook.Base, p currency.Pair, assetType assets.AssetType, exchangeName string, err error) {
func printOrderbookSummary(result *orderbook.Base, p currency.Pair, assetType asset.Item, exchangeName string, err error) {
if err != nil {
log.Errorf("Failed to get %s %s orderbook of type %s. Error: %s",
p,
@@ -204,7 +204,7 @@ func TickerUpdaterRoutine() {
supportsBatching := Bot.Exchanges[x].SupportsRESTTickerBatchUpdates()
assetTypes := Bot.Exchanges[x].GetAssetTypes()
processTicker := func(exch exchange.IBotExchange, update bool, c currency.Pair, assetType assets.AssetType) {
processTicker := func(exch exchange.IBotExchange, update bool, c currency.Pair, assetType asset.Item) {
var result ticker.Price
var err error
if update {
@@ -256,7 +256,7 @@ func OrderbookUpdaterRoutine() {
exchangeName := Bot.Exchanges[x].GetName()
assetTypes := Bot.Exchanges[x].GetAssetTypes()
processOrderbook := func(exch exchange.IBotExchange, c currency.Pair, assetType assets.AssetType) {
processOrderbook := func(exch exchange.IBotExchange, c currency.Pair, assetType asset.Item) {
result, err := exch.UpdateOrderbook(c, assetType)
printOrderbookSummary(&result, c, assetType, exchangeName, err)
if err == nil {

View File

@@ -16,7 +16,7 @@ import (
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/gctrpc"
"github.com/thrasher-/gocryptotrader/gctrpc/auth"
log "github.com/thrasher-/gocryptotrader/logger"
@@ -281,7 +281,7 @@ func (s *RPCServer) GetTicker(ctx context.Context, r *gctrpc.GetTickerRequest) (
Quote: currency.NewCode(r.Pair.Quote),
},
r.Exchange,
assets.AssetType(r.AssetType),
asset.Item(r.AssetType),
)
if err != nil {
return nil, err
@@ -345,7 +345,7 @@ func (s *RPCServer) GetOrderbook(ctx context.Context, r *gctrpc.GetOrderbookRequ
Quote: currency.NewCode(r.Pair.Quote),
},
r.Exchange,
assets.AssetType(r.AssetType),
asset.Item(r.AssetType),
)
if err != nil {
return nil, err
@@ -622,7 +622,7 @@ func (s *RPCServer) GetOrders(ctx context.Context, r *gctrpc.GetOrdersRequest) (
Id: resp[x].ID,
BaseCurrency: resp[x].CurrencyPair.Base.String(),
QuoteCurrency: resp[x].CurrencyPair.Quote.String(),
AssetType: assets.AssetTypeSpot.String(),
AssetType: asset.Spot.String(),
OrderType: resp[x].OrderType.ToString(),
OrderSide: resp[x].OrderSide.ToString(),
CreationTime: resp[x].OrderDate.Unix(),
@@ -705,7 +705,7 @@ func (s *RPCServer) AddEvent(ctx context.Context, r *gctrpc.AddEventRequest) (*g
p := currency.NewPairWithDelimiter(r.Pair.Base,
r.Pair.Quote, r.Pair.Delimiter)
id, err := Add(r.Exchange, r.Item, evtCondition, p, assets.AssetType(r.AssetType), r.Action)
id, err := Add(r.Exchange, r.Item, evtCondition, p, asset.Item(r.AssetType), r.Action)
if err != nil {
return nil, err
}

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -58,7 +58,7 @@ func NewCurrencyPairSyncer(c CurrencyPairSyncerConfig) (*ExchangeCurrencyPairSyn
return &s, nil
}
func (e *ExchangeCurrencyPairSyncer) get(exchangeName string, p currency.Pair, a assets.AssetType) (*CurrencyPairSyncAgent, error) {
func (e *ExchangeCurrencyPairSyncer) get(exchangeName string, p currency.Pair, a asset.Item) (*CurrencyPairSyncAgent, error) {
e.mux.Lock()
defer e.mux.Unlock()
@@ -73,7 +73,7 @@ func (e *ExchangeCurrencyPairSyncer) get(exchangeName string, p currency.Pair, a
return nil, errors.New("exchange currency pair syncer not found")
}
func (e *ExchangeCurrencyPairSyncer) exists(exchangeName string, p currency.Pair, a assets.AssetType) bool {
func (e *ExchangeCurrencyPairSyncer) exists(exchangeName string, p currency.Pair, a asset.Item) bool {
e.mux.Lock()
defer e.mux.Unlock()
@@ -136,7 +136,7 @@ func (e *ExchangeCurrencyPairSyncer) remove(c *CurrencyPairSyncAgent) {
}
}
func (e *ExchangeCurrencyPairSyncer) isProcessing(exchangeName string, p currency.Pair, a assets.AssetType, syncType int) bool {
func (e *ExchangeCurrencyPairSyncer) isProcessing(exchangeName string, p currency.Pair, a asset.Item, syncType int) bool {
e.mux.Lock()
defer e.mux.Unlock()
@@ -158,7 +158,7 @@ func (e *ExchangeCurrencyPairSyncer) isProcessing(exchangeName string, p currenc
return false
}
func (e *ExchangeCurrencyPairSyncer) setProcessing(exchangeName string, p currency.Pair, a assets.AssetType, syncType int, processing bool) {
func (e *ExchangeCurrencyPairSyncer) setProcessing(exchangeName string, p currency.Pair, a asset.Item, syncType int, processing bool) {
e.mux.Lock()
defer e.mux.Unlock()
@@ -178,7 +178,7 @@ func (e *ExchangeCurrencyPairSyncer) setProcessing(exchangeName string, p curren
}
}
func (e *ExchangeCurrencyPairSyncer) update(exchangeName string, p currency.Pair, a assets.AssetType, syncType int, err error) {
func (e *ExchangeCurrencyPairSyncer) update(exchangeName string, p currency.Pair, a asset.Item, syncType int, err error) {
if atomic.LoadInt32(&e.initSyncStarted) != 1 {
return
}

View File

@@ -5,7 +5,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// CurrencyPairSyncerConfig stores the currency pair config
@@ -53,7 +53,7 @@ type SyncBase struct {
type CurrencyPairSyncAgent struct {
Created time.Time
Exchange string
AssetType assets.AssetType
AssetType asset.Item
Pair currency.Pair
Ticker SyncBase
Orderbook SyncBase

View File

@@ -10,7 +10,7 @@ import (
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -347,7 +347,7 @@ func wsGetTicker(client *WebsocketClient, data interface{}) error {
}
result, err := GetSpecificTicker(currency.NewPairFromString(tickerReq.Currency),
tickerReq.Exchange, assets.AssetType(tickerReq.AssetType))
tickerReq.Exchange, asset.Item(tickerReq.AssetType))
if err != nil {
wsResp.Error = err.Error()
@@ -379,7 +379,7 @@ func wsGetOrderbook(client *WebsocketClient, data interface{}) error {
}
result, err := GetSpecificOrderbook(currency.NewPairFromString(orderbookReq.Currency),
orderbookReq.Exchange, assets.AssetType(orderbookReq.AssetType))
orderbookReq.Exchange, asset.Item(orderbookReq.AssetType))
if err != nil {
wsResp.Error = err.Error()

View File

@@ -10,7 +10,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -31,8 +31,8 @@ func (a *Alphapoint) SetDefaults() {
a.API.CredentialsValidator.RequiresKey = true
a.API.CredentialsValidator.RequiresSecret = true
a.CurrencyPairs.AssetTypes = assets.AssetTypes{
assets.AssetTypeSpot,
a.CurrencyPairs.AssetTypes = asset.Items{
asset.Spot,
}
a.Features = exchange.Features{
@@ -62,7 +62,7 @@ func (a *Alphapoint) SetDefaults() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (a *Alphapoint) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (a *Alphapoint) FetchTradablePairs(asset asset.Item) ([]string, error) {
return nil, common.ErrFunctionNotSupported
}
@@ -100,7 +100,7 @@ func (a *Alphapoint) GetAccountInfo() (exchange.AccountInfo, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (a *Alphapoint) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (a *Alphapoint) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := a.GetTicker(p.String())
if err != nil {
@@ -124,7 +124,7 @@ func (a *Alphapoint) UpdateTicker(p currency.Pair, assetType assets.AssetType) (
}
// FetchTicker returns the ticker for a currency pair
func (a *Alphapoint) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (a *Alphapoint) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := ticker.GetTicker(a.GetName(), p, assetType)
if err != nil {
return a.UpdateTicker(p, assetType)
@@ -133,7 +133,7 @@ func (a *Alphapoint) FetchTicker(p currency.Pair, assetType assets.AssetType) (t
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (a *Alphapoint) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (a *Alphapoint) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := a.GetOrderbook(p.String())
if err != nil {
@@ -165,7 +165,7 @@ func (a *Alphapoint) UpdateOrderbook(p currency.Pair, assetType assets.AssetType
}
// FetchOrderbook returns the orderbook for a currency pair
func (a *Alphapoint) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (a *Alphapoint) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(a.GetName(), p, assetType)
if err != nil {
return a.UpdateOrderbook(p, assetType)
@@ -182,7 +182,7 @@ func (a *Alphapoint) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (a *Alphapoint) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (a *Alphapoint) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// Please supply your own keys here for due diligence testing
@@ -65,7 +65,7 @@ func TestGetCurrencies(t *testing.T) {
}
func TestFetchTradablePairs(t *testing.T) {
_, err := a.FetchTradablePairs(assets.AssetTypeSpot)
_, err := a.FetchTradablePairs(asset.Spot)
if err != nil {
t.Fatalf("Test failed. TestGetTradablePairs failed. Err: %s", err)
}

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -61,8 +61,8 @@ func (a *ANX) SetDefaults() {
a.API.CredentialsValidator.RequiresSecret = true
a.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -127,13 +127,13 @@ func (a *ANX) Run() {
}
forceUpdate := false
if !common.StringDataContains(a.GetEnabledPairs(assets.AssetTypeSpot).Strings(), "_") ||
!common.StringDataContains(a.GetAvailablePairs(assets.AssetTypeSpot).Strings(), "_") {
if !common.StringDataContains(a.GetEnabledPairs(asset.Spot).Strings(), "_") ||
!common.StringDataContains(a.GetAvailablePairs(asset.Spot).Strings(), "_") {
enabledPairs := currency.NewPairsFromStrings([]string{"BTC_USD,BTC_HKD,BTC_EUR,BTC_CAD,BTC_AUD,BTC_SGD,BTC_JPY,BTC_GBP,BTC_NZD,LTC_BTC,DOG_EBTC,STR_BTC,XRP_BTC"})
log.Warn("WARNING: Enabled pairs for ANX reset due to config upgrade, please enable the ones you would like again.")
forceUpdate = true
err := a.UpdatePairs(enabledPairs, assets.AssetTypeSpot, true, true)
err := a.UpdatePairs(enabledPairs, asset.Spot, true, true)
if err != nil {
log.Errorf("%s failed to update currencies.\n", a.GetName())
return
@@ -153,16 +153,16 @@ func (a *ANX) Run() {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (a *ANX) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := a.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := a.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return a.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return a.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (a *ANX) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (a *ANX) FetchTradablePairs(asset asset.Item) ([]string, error) {
result, err := a.GetCurrencies()
if err != nil {
return nil, err
@@ -177,7 +177,7 @@ func (a *ANX) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (a *ANX) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (a *ANX) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := a.GetTicker(a.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -249,7 +249,7 @@ func (a *ANX) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.
}
// FetchTicker returns the ticker for a currency pair
func (a *ANX) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (a *ANX) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(a.GetName(), p, assetType)
if err != nil {
return a.UpdateTicker(p, assetType)
@@ -258,7 +258,7 @@ func (a *ANX) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.P
}
// FetchOrderbook returns the orderbook for a currency pair
func (a *ANX) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (a *ANX) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(a.GetName(), p, assetType)
if err != nil {
return a.UpdateOrderbook(p, assetType)
@@ -267,7 +267,7 @@ func (a *ANX) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (order
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (a *ANX) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (a *ANX) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := a.GetDepth(a.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -334,7 +334,7 @@ func (a *ANX) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (a *ANX) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (a *ANX) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -485,7 +485,7 @@ func (a *ANX) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]ex
Amount: resp[i].TradedCurrencyAmount,
CurrencyPair: currency.NewPairWithDelimiter(resp[i].TradedCurrency,
resp[i].SettlementCurrency,
a.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
a.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
OrderDate: orderDate,
Exchange: a.Name,
ID: resp[i].OrderID,
@@ -527,7 +527,7 @@ func (a *ANX) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]ex
Status: resp[i].OrderStatus,
CurrencyPair: currency.NewPairWithDelimiter(resp[i].TradedCurrency,
resp[i].SettlementCurrency,
a.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
a.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
}
orders = append(orders, orderDetail)

112
exchanges/asset/asset.go Normal file
View File

@@ -0,0 +1,112 @@
package asset
import (
"strings"
)
// 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")
Index = Item("index")
Binary = Item("binary")
PerpetualContract = Item("perpetualcontract")
PerpetualSwap = Item("perpetualswap")
Futures = Item("futures")
UpsideProfitContract = Item("upsideprofitcontract")
DownsideProfitContract = Item("downsideprofitcontract")
)
// Supported returns a list of supported asset types
func Supported() Items {
var a Items
a = append(a,
Spot,
Margin,
Index,
Binary,
PerpetualContract,
PerpetualSwap,
Futures,
UpsideProfitContract,
DownsideProfitContract,
)
return a
}
// 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(asset Item) bool {
if !IsValid(asset) {
return false
}
for x := range a {
if a[x] == asset {
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 IsValid(input Item) bool {
a := Supported()
for x := range a {
if strings.EqualFold(a[x].String(), input.String()) {
return true
}
}
return false
}
// New takes an input of asset types as string and returns an Items
// array
func New(input string) Items {
if !strings.Contains(input, ",") {
if IsValid(Item(input)) {
return Items{
Item(input),
}
}
return nil
}
assets := strings.Split(input, ",")
var result Items
for x := range assets {
if !IsValid(Item(assets[x])) {
return nil
}
result = append(result, Item(assets[x]))
}
return result
}

View File

@@ -1,4 +1,4 @@
package assets
package asset
import (
"testing"
@@ -7,14 +7,14 @@ import (
)
func TestString(t *testing.T) {
a := AssetTypeSpot
a := Spot
if a.String() != "spot" {
t.Fatal("Test failed - TestString returned an unexpected result")
}
}
func TestToStringArray(t *testing.T) {
a := AssetTypes{AssetTypeSpot, AssetTypeFutures}
a := Items{Spot, Futures}
result := a.Strings()
for x := range a {
if !common.StringDataCompare(result, a[x].String()) {
@@ -24,22 +24,22 @@ func TestToStringArray(t *testing.T) {
}
func TestContains(t *testing.T) {
a := AssetTypes{AssetTypeSpot, AssetTypeFutures}
a := Items{Spot, Futures}
if a.Contains("meow") {
t.Fatal("Test failed - TestContains returned an unexpected result")
}
if !a.Contains(AssetTypeSpot) {
if !a.Contains(Spot) {
t.Fatal("Test failed - TestContains returned an unexpected result")
}
if a.Contains(AssetTypeBinary) {
if a.Contains(Binary) {
t.Fatal("Test failed - TestContains returned an unexpected result")
}
}
func TestJoinToString(t *testing.T) {
a := AssetTypes{AssetTypeSpot, AssetTypeFutures}
a := Items{Spot, Futures}
if a.JoinToString(",") != "spot,futures" {
t.Fatal("Test failed - TestJoinToString returned an unexpected result")
}
@@ -50,7 +50,7 @@ func TestIsValid(t *testing.T) {
t.Fatal("Test failed - TestIsValid returned an unexpected result")
}
if !IsValid(AssetTypeSpot) {
if !IsValid(Spot) {
t.Fatal("Test failed - TestIsValid returned an unexpected result")
}
}

View File

@@ -1,112 +0,0 @@
package assets
import (
"strings"
)
// AssetType stores the asset type
type AssetType string
// AssetTypes stores a list of assets
type AssetTypes []AssetType
// Const vars for asset package
const (
AssetTypeSpot = AssetType("spot")
AssetTypeMargin = AssetType("margin")
AssetTypeIndex = AssetType("index")
AssetTypeBinary = AssetType("binary")
AssetTypePerpetualContract = AssetType("perpetualcontract")
AssetTypePerpetualSwap = AssetType("perpetualswap")
AssetTypeFutures = AssetType("futures")
AssetTypeUpsideProfitContract = AssetType("upsideprofitcontract")
AssetTypeDownsideProfitContract = AssetType("downsideprofitcontract")
)
// Supported returns a list of supported asset types
func Supported() AssetTypes {
var a AssetTypes
a = append(a,
AssetTypeSpot,
AssetTypeMargin,
AssetTypeIndex,
AssetTypeBinary,
AssetTypePerpetualContract,
AssetTypePerpetualSwap,
AssetTypeFutures,
AssetTypeUpsideProfitContract,
AssetTypeDownsideProfitContract,
)
return a
}
// returns an AssetType to string
func (a AssetType) String() string {
return string(a)
}
// Strings converts an asset type array to a string array
func (a AssetTypes) 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 AssetTypes
func (a AssetTypes) Contains(asset AssetType) bool {
if !IsValid(asset) {
return false
}
for x := range a {
if a[x] == asset {
return true
}
}
return false
}
// JoinToString joins an asset type array and converts it to a string
// with the supplied separator
func (a AssetTypes) JoinToString(separator string) string {
return strings.Join(a.Strings(), separator)
}
// IsValid returns whether or not the supplied asset type is valid or
// not
func IsValid(input AssetType) bool {
a := Supported()
for x := range a {
if strings.EqualFold(a[x].String(), input.String()) {
return true
}
}
return false
}
// New takes an input of asset types as string and returns an AssetTypes
// array
func New(input string) AssetTypes {
if !strings.Contains(input, ",") {
if IsValid(AssetType(input)) {
return AssetTypes{
AssetType(input),
}
}
return nil
}
assets := strings.Split(input, ",")
var result AssetTypes
for x := range assets {
if !IsValid(AssetType(assets[x])) {
return nil
}
result = append(result, AssetType(assets[x]))
}
return result
}

View File

@@ -17,7 +17,7 @@ import (
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -537,7 +537,7 @@ func (b *Binance) CheckLimit(limit int) error {
}
// CheckSymbol checks value against a variable list
func (b *Binance) CheckSymbol(symbol string, assetType assets.AssetType) error {
func (b *Binance) CheckSymbol(symbol string, assetType asset.Item) error {
enPairs := b.GetAvailablePairs(assetType)
for x := range enPairs {
if b.FormatExchangeCurrency(enPairs[x], assetType).String() == symbol {

View File

@@ -7,7 +7,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// Please supply your own keys here for due diligence testing
@@ -39,7 +39,7 @@ func TestSetup(t *testing.T) {
func TestFetchTradablePairs(t *testing.T) {
t.Parallel()
_, err := b.FetchTradablePairs(assets.AssetTypeSpot)
_, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
t.Error("Test Failed - Binance FetchTradablePairs(asset asets.AssetType) error", err)
}

View File

@@ -14,7 +14,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
)
@@ -29,7 +29,7 @@ var m sync.Mutex
func (b *Binance) SeedLocalCache(p currency.Pair) error {
var newOrderBook orderbook.Base
formattedPair := b.FormatExchangeCurrency(p, assets.AssetTypeSpot)
formattedPair := b.FormatExchangeCurrency(p, asset.Spot)
orderbookNew, err := b.GetOrderBook(
OrderBookDataRequestParams{
@@ -59,7 +59,7 @@ func (b *Binance) SeedLocalCache(p currency.Pair) error {
}
newOrderBook.Pair = currency.NewPairFromString(formattedPair.String())
newOrderBook.AssetType = assets.AssetTypeSpot
newOrderBook.AssetType = asset.Spot
return b.Websocket.Orderbook.LoadSnapshot(&newOrderBook, b.GetName(), false)
}
@@ -117,7 +117,7 @@ func (b *Binance) UpdateLocalCache(ob *WebsocketDepthStream) error {
currencyPair,
updatedTime,
b.GetName(),
assets.AssetTypeSpot)
asset.Spot)
}
// WSConnect intiates a websocket connection
@@ -129,7 +129,7 @@ func (b *Binance) WSConnect() error {
var Dialer websocket.Dialer
var err error
pairs := b.GetEnabledPairs(assets.AssetTypeSpot).Strings()
pairs := b.GetEnabledPairs(asset.Spot).Strings()
tick := strings.ToLower(
strings.Replace(
strings.Join(pairs, "@ticker/"), "-", "", -1)) + "@ticker"
@@ -164,7 +164,7 @@ func (b *Binance) WSConnect() error {
Dialer.Proxy = http.ProxyURL(u)
}
for _, ePair := range b.GetEnabledPairs(assets.AssetTypeSpot) {
for _, ePair := range b.GetEnabledPairs(asset.Spot) {
err = b.SeedLocalCache(ePair)
if err != nil {
return err
@@ -254,7 +254,7 @@ func (b *Binance) WsHandleData() {
Price: price,
Amount: amount,
Exchange: b.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Side: trade.EventType,
}
continue
@@ -272,7 +272,7 @@ func (b *Binance) WsHandleData() {
wsTicker.Timestamp = time.Unix(t.EventTime/1000, 0)
wsTicker.Pair = currency.NewPairFromString(t.Symbol)
wsTicker.AssetType = assets.AssetTypeSpot
wsTicker.AssetType = asset.Spot
wsTicker.Exchange = b.GetName()
wsTicker.ClosePrice, _ = strconv.ParseFloat(t.CurrDayClose, 64)
wsTicker.Quantity, _ = strconv.ParseFloat(t.TotalTradedVolume, 64)
@@ -297,7 +297,7 @@ func (b *Binance) WsHandleData() {
wsKline.Timestamp = time.Unix(0, kline.EventTime)
wsKline.Pair = currency.NewPairFromString(kline.Symbol)
wsKline.AssetType = assets.AssetTypeSpot
wsKline.AssetType = asset.Spot
wsKline.Exchange = b.GetName()
wsKline.StartTime = time.Unix(0, kline.Kline.StartTime)
wsKline.CloseTime = time.Unix(0, kline.Kline.CloseTime)
@@ -331,7 +331,7 @@ func (b *Binance) WsHandleData() {
b.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: currencyPair,
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: b.GetName(),
}
continue

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -52,8 +52,8 @@ func (b *Binance) SetDefaults() {
b.SetValues()
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
@@ -136,13 +136,13 @@ func (b *Binance) Run() {
}
forceUpdate := false
if !common.StringDataContains(b.GetEnabledPairs(assets.AssetTypeSpot).Strings(), "-") ||
!common.StringDataContains(b.GetAvailablePairs(assets.AssetTypeSpot).Strings(), "-") {
if !common.StringDataContains(b.GetEnabledPairs(asset.Spot).Strings(), "-") ||
!common.StringDataContains(b.GetAvailablePairs(asset.Spot).Strings(), "-") {
enabledPairs := currency.NewPairsFromStrings([]string{"BTC-USDT"})
log.Warn("WARNING: Available pairs for Binance reset due to config upgrade, please enable the ones you would like again")
forceUpdate = true
err := b.UpdatePairs(enabledPairs, assets.AssetTypeSpot, true, true)
err := b.UpdatePairs(enabledPairs, asset.Spot, true, true)
if err != nil {
log.Errorf("%s failed to update currencies. Err: %s\n", b.Name, err)
}
@@ -159,7 +159,7 @@ func (b *Binance) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Binance) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (b *Binance) FetchTradablePairs(asset asset.Item) ([]string, error) {
var validCurrencyPairs []string
info, err := b.GetExchangeInfo()
@@ -179,16 +179,16 @@ func (b *Binance) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *Binance) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Binance) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Binance) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := b.GetTickers()
if err != nil {
@@ -215,7 +215,7 @@ func (b *Binance) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tic
}
// FetchTicker returns the ticker for a currency pair
func (b *Binance) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Binance) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -224,7 +224,7 @@ func (b *Binance) FetchTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchOrderbook returns orderbook base on the currency pair
func (b *Binance) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Binance) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -233,7 +233,7 @@ func (b *Binance) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (o
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Binance) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Binance) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderBook(OrderBookDataRequestParams{Symbol: b.FormatExchangeCurrency(p,
assetType).String(), Limit: 1000})
@@ -307,7 +307,7 @@ func (b *Binance) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Binance) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *Binance) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -456,7 +456,7 @@ func (b *Binance) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
var orders []exchange.OrderDetail
for _, c := range getOrdersRequest.Currencies {
resp, err := b.OpenOrders(b.FormatExchangeCurrency(c,
assets.AssetTypeSpot).String())
asset.Spot).String())
if err != nil {
return nil, err
}
@@ -496,7 +496,7 @@ func (b *Binance) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
var orders []exchange.OrderDetail
for _, c := range getOrdersRequest.Currencies {
resp, err := b.AllOrders(b.FormatExchangeCurrency(c,
assets.AssetTypeSpot).String(), "", "1000")
asset.Spot).String(), "", "1000")
if err != nil {
return nil, err
}

View File

@@ -14,7 +14,7 @@ import (
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -282,7 +282,7 @@ func (b *Bitfinex) WsDataHandler() {
if len(newOrderbook) > 1 {
err := b.WsInsertSnapshot(currency.NewPairFromString(chanInfo.Pair),
assets.AssetTypeSpot,
asset.Spot,
newOrderbook)
if err != nil {
@@ -293,7 +293,7 @@ func (b *Bitfinex) WsDataHandler() {
}
err := b.WsUpdateOrderbook(currency.NewPairFromString(chanInfo.Pair),
assets.AssetTypeSpot,
asset.Spot,
newOrderbook[0])
if err != nil {
@@ -309,7 +309,7 @@ func (b *Bitfinex) WsDataHandler() {
LowPrice: chanData[10].(float64),
Pair: currency.NewPairFromString(chanInfo.Pair),
Exchange: b.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
}
case "account":
@@ -465,7 +465,7 @@ func (b *Bitfinex) WsDataHandler() {
Price: trades[0].Price,
Amount: newAmount,
Exchange: b.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Side: side,
}
}
@@ -478,7 +478,7 @@ func (b *Bitfinex) WsDataHandler() {
// WsInsertSnapshot add the initial orderbook snapshot when subscribed to a
// channel
func (b *Bitfinex) WsInsertSnapshot(p currency.Pair, assetType assets.AssetType, books []WebsocketBook) error {
func (b *Bitfinex) WsInsertSnapshot(p currency.Pair, assetType asset.Item, books []WebsocketBook) error {
if len(books) == 0 {
return errors.New("bitfinex.go error - no orderbooks submitted")
}
@@ -515,7 +515,7 @@ func (b *Bitfinex) WsInsertSnapshot(p currency.Pair, assetType assets.AssetType,
// WsUpdateOrderbook updates the orderbook list, removing and adding to the
// orderbook sides
func (b *Bitfinex) WsUpdateOrderbook(p currency.Pair, assetType assets.AssetType, book WebsocketBook) error {
func (b *Bitfinex) WsUpdateOrderbook(p currency.Pair, assetType asset.Item, book WebsocketBook) error {
if book.Count > 0 {
if book.Amount > 0 {
@@ -605,7 +605,7 @@ func (b *Bitfinex) GenerateDefaultSubscriptions() {
var channels = []string{"book", "trades", "ticker"}
subscriptions := []exchange.WebsocketChannelSubscription{}
for i := range channels {
enabledPairs := b.GetEnabledPairs(assets.AssetTypeSpot)
enabledPairs := b.GetEnabledPairs(asset.Spot)
for j := range enabledPairs {
params := make(map[string]interface{})
if channels[i] == "book" {

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -53,8 +53,8 @@ func (b *Bitfinex) SetDefaults() {
b.API.CredentialsValidator.RequiresSecret = true
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -145,23 +145,23 @@ func (b *Bitfinex) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Bitfinex) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (b *Bitfinex) FetchTradablePairs(asset asset.Item) ([]string, error) {
return b.GetSymbols()
}
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *Bitfinex) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bitfinex) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bitfinex) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
enabledPairs := b.GetEnabledPairs(assetType)
@@ -197,8 +197,8 @@ func (b *Bitfinex) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ti
}
// FetchTicker returns the ticker for a currency pair
func (b *Bitfinex) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
tick, err := ticker.GetTicker(b.GetName(), p, assets.AssetTypeSpot)
func (b *Bitfinex) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := ticker.GetTicker(b.GetName(), p, asset.Spot)
if err != nil {
return b.UpdateTicker(p, assetType)
}
@@ -206,7 +206,7 @@ func (b *Bitfinex) FetchTicker(p currency.Pair, assetType assets.AssetType) (tic
}
// FetchOrderbook returns the orderbook for a currency pair
func (b *Bitfinex) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bitfinex) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -215,7 +215,7 @@ func (b *Bitfinex) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bitfinex) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bitfinex) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
urlVals := url.Values{}
urlVals.Set("limit_bids", "100")
@@ -290,7 +290,7 @@ func (b *Bitfinex) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Bitfinex) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *Bitfinex) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -135,7 +135,7 @@ func TestFetchTicker(t *testing.T) {
t.Parallel()
var p currency.Pair
currencies := b.GetAvailablePairs(assets.AssetTypeSpot)
currencies := b.GetAvailablePairs(asset.Spot)
for _, pair := range currencies {
if pair.String() == "FXBTC_JPY" {
p = pair
@@ -143,7 +143,7 @@ func TestFetchTicker(t *testing.T) {
}
}
_, err := b.FetchTicker(p, assets.AssetTypeSpot)
_, err := b.FetchTicker(p, asset.Spot)
if err != nil {
t.Error("test failed - Bitflyer - FetchTicker() error", err)
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -49,9 +49,9 @@ func (b *Bitflyer) SetDefaults() {
b.API.CredentialsValidator.RequiresSecret = true
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
assets.AssetTypeFutures,
AssetTypes: asset.Items{
asset.Spot,
asset.Futures,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -127,7 +127,7 @@ func (b *Bitflyer) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Bitflyer) FetchTradablePairs(assetType assets.AssetType) ([]string, error) {
func (b *Bitflyer) FetchTradablePairs(assetType asset.Item) ([]string, error) {
pairs, err := b.GetMarkets()
if err != nil {
return nil, err
@@ -135,9 +135,9 @@ func (b *Bitflyer) FetchTradablePairs(assetType assets.AssetType) ([]string, err
var products []string
for _, info := range pairs {
if info.Alias != "" && assetType == assets.AssetTypeFutures {
if info.Alias != "" && assetType == asset.Futures {
products = append(products, info.Alias)
} else if info.Alias == "" && assetType == assets.AssetTypeSpot && strings.Contains(info.ProductCode, "_") {
} else if info.Alias == "" && assetType == asset.Spot && strings.Contains(info.ProductCode, "_") {
products = append(products, info.ProductCode)
}
}
@@ -163,7 +163,7 @@ func (b *Bitflyer) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bitflyer) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bitflyer) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
p = b.CheckFXString(p)
@@ -189,7 +189,7 @@ func (b *Bitflyer) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ti
}
// FetchTicker returns the ticker for a currency pair
func (b *Bitflyer) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bitflyer) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -207,7 +207,7 @@ func (b *Bitflyer) CheckFXString(p currency.Pair) currency.Pair {
}
// FetchOrderbook returns the orderbook for a currency pair
func (b *Bitflyer) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bitflyer) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -216,7 +216,7 @@ func (b *Bitflyer) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bitflyer) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bitflyer) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
p = b.CheckFXString(p)
@@ -272,7 +272,7 @@ func (b *Bitflyer) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Bitflyer) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *Bitflyer) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -52,8 +52,8 @@ func (b *Bithumb) SetDefaults() {
b.API.CredentialsValidator.RequiresSecret = true
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
@@ -126,7 +126,7 @@ func (b *Bithumb) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Bithumb) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (b *Bithumb) FetchTradablePairs(asset asset.Item) ([]string, error) {
currencies, err := b.GetTradablePairs()
if err != nil {
return nil, err
@@ -142,16 +142,16 @@ func (b *Bithumb) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *Bithumb) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bithumb) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bithumb) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tickers, err := b.GetAllTickers()
@@ -179,7 +179,7 @@ func (b *Bithumb) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tic
}
// FetchTicker returns the ticker for a currency pair
func (b *Bithumb) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bithumb) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -188,7 +188,7 @@ func (b *Bithumb) FetchTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchOrderbook returns orderbook base on the currency pair
func (b *Bithumb) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bithumb) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -197,7 +197,7 @@ func (b *Bithumb) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (o
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bithumb) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bithumb) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
currency := p.Base.String()
@@ -266,7 +266,7 @@ func (b *Bithumb) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Bithumb) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *Bithumb) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -334,7 +334,7 @@ func (b *Bithumb) CancelAllOrders(orderCancellation *exchange.OrderCancellation)
}
var allOrders []OrderData
for _, currency := range b.GetEnabledPairs(assets.AssetTypeSpot) {
for _, currency := range b.GetEnabledPairs(asset.Spot) {
orders, err := b.GetOrders("",
orderCancellation.Side.ToString(),
"100",
@@ -447,7 +447,7 @@ func (b *Bithumb) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
Status: string(exchange.ActiveOrderStatus),
CurrencyPair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
resp.Data[i].PaymentCurrency,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
}
if resp.Data[i].Type == "bid" {
@@ -490,7 +490,7 @@ func (b *Bithumb) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
RemainingAmount: resp.Data[i].UnitsRemaining,
CurrencyPair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
resp.Data[i].PaymentCurrency,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
}
if resp.Data[i].Type == "bid" {

View File

@@ -14,7 +14,7 @@ import (
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -289,17 +289,17 @@ func (b *Bitmex) wsHandleIncomingData() {
}
}
var snapshotloaded = make(map[currency.Pair]map[assets.AssetType]bool)
var snapshotloaded = make(map[currency.Pair]map[asset.Item]bool)
// ProcessOrderbook processes orderbook updates
func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPair currency.Pair, assetType assets.AssetType) error { // nolint: unparam
func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPair currency.Pair, assetType asset.Item) error { // nolint: unparam
if len(data) < 1 {
return errors.New("bitmex_websocket.go error - no orderbook data")
}
_, ok := snapshotloaded[currencyPair]
if !ok {
snapshotloaded[currencyPair] = make(map[assets.AssetType]bool)
snapshotloaded[currencyPair] = make(map[asset.Item]bool)
}
_, ok = snapshotloaded[currencyPair][assetType]
@@ -389,7 +389,7 @@ func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPai
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (b *Bitmex) GenerateDefaultSubscriptions() {
contracts := b.GetEnabledPairs(assets.AssetTypePerpetualContract)
contracts := b.GetEnabledPairs(asset.PerpetualContract)
channels := []string{bitmexWSOrderbookL2, bitmexWSTrade}
subscriptions := []exchange.WebsocketChannelSubscription{
{

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,11 +51,11 @@ func (b *Bitmex) SetDefaults() {
b.API.CredentialsValidator.RequiresSecret = true
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypePerpetualContract,
assets.AssetTypeFutures,
assets.AssetTypeDownsideProfitContract,
assets.AssetTypeUpsideProfitContract,
AssetTypes: asset.Items{
asset.PerpetualContract,
asset.Futures,
asset.DownsideProfitContract,
asset.UpsideProfitContract,
},
UseGlobalFormat: false,
}
@@ -69,8 +69,8 @@ func (b *Bitmex) SetDefaults() {
Uppercase: true,
},
}
b.CurrencyPairs.Store(assets.AssetTypePerpetualContract, fmt1)
b.CurrencyPairs.Store(assets.AssetTypeFutures, fmt1)
b.CurrencyPairs.Store(asset.PerpetualContract, fmt1)
b.CurrencyPairs.Store(asset.Futures, fmt1)
// Upside and Downside profit contracts use the same format
fmt2 := currency.PairStore{
@@ -83,8 +83,8 @@ func (b *Bitmex) SetDefaults() {
Uppercase: true,
},
}
b.CurrencyPairs.Store(assets.AssetTypeDownsideProfitContract, fmt2)
b.CurrencyPairs.Store(assets.AssetTypeUpsideProfitContract, fmt2)
b.CurrencyPairs.Store(asset.DownsideProfitContract, fmt2)
b.CurrencyPairs.Store(asset.UpsideProfitContract, fmt2)
b.Features = exchange.Features{
Supports: exchange.FeaturesSupported{
@@ -167,7 +167,7 @@ func (b *Bitmex) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Bitmex) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (b *Bitmex) FetchTradablePairs(asset asset.Item) ([]string, error) {
marketInfo, err := b.GetActiveInstruments(&GenericRequestParams{})
if err != nil {
return nil, err
@@ -184,7 +184,7 @@ func (b *Bitmex) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *Bitmex) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
@@ -192,25 +192,25 @@ func (b *Bitmex) UpdateTradablePairs(forceUpdate bool) error {
var assetPairs []string
for x := range b.CurrencyPairs.AssetTypes {
switch b.CurrencyPairs.AssetTypes[x] {
case assets.AssetTypePerpetualContract:
case asset.PerpetualContract:
for y := range pairs {
if strings.Contains(pairs[y], "USD") {
assetPairs = append(assetPairs, pairs[y])
}
}
case assets.AssetTypeFutures:
case asset.Futures:
for y := range pairs {
if strings.Contains(pairs[y], "19") {
assetPairs = append(assetPairs, pairs[y])
}
}
case assets.AssetTypeDownsideProfitContract:
case asset.DownsideProfitContract:
for y := range pairs {
if strings.Contains(pairs[y], "_D") {
assetPairs = append(assetPairs, pairs[y])
}
}
case assets.AssetTypeUpsideProfitContract:
case asset.UpsideProfitContract:
for y := range pairs {
if strings.Contains(pairs[y], "_U") {
assetPairs = append(assetPairs, pairs[y])
@@ -228,7 +228,7 @@ func (b *Bitmex) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bitmex) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bitmex) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
currency := b.FormatExchangeCurrency(p, assetType)
@@ -251,7 +251,7 @@ func (b *Bitmex) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchTicker returns the ticker for a currency pair
func (b *Bitmex) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bitmex) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -260,7 +260,7 @@ func (b *Bitmex) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchOrderbook returns orderbook base on the currency pair
func (b *Bitmex) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bitmex) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -269,7 +269,7 @@ func (b *Bitmex) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (or
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bitmex) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bitmex) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderbook(OrderBookGetL2Params{
@@ -338,7 +338,7 @@ func (b *Bitmex) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Bitmex) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *Bitmex) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -519,7 +519,7 @@ func (b *Bitmex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
Status: resp[i].OrdStatus,
CurrencyPair: currency.NewPairWithDelimiter(resp[i].Symbol,
resp[i].SettlCurrency,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
}
orders = append(orders, orderDetail)
@@ -561,7 +561,7 @@ func (b *Bitmex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
Status: resp[i].OrdStatus,
CurrencyPair: currency.NewPairWithDelimiter(resp[i].Symbol,
resp[i].SettlCurrency,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
}
orders = append(orders, orderDetail)

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -121,7 +121,7 @@ func (b *Bitstamp) WsHandleData() {
currencyPair := strings.Split(wsResponse.Channel, "_")
p := currency.NewPairFromString(strings.ToUpper(currencyPair[3]))
err = b.wsUpdateOrderbook(wsOrderBookTemp.Data, p, assets.AssetTypeSpot)
err = b.wsUpdateOrderbook(wsOrderBookTemp.Data, p, asset.Spot)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -144,7 +144,7 @@ func (b *Bitstamp) WsHandleData() {
Amount: wsTradeTemp.Data.Amount,
CurrencyPair: p,
Exchange: b.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
}
}
}
@@ -153,7 +153,7 @@ func (b *Bitstamp) WsHandleData() {
func (b *Bitstamp) generateDefaultSubscriptions() {
var channels = []string{"live_trades_", "diff_order_book_"}
enabledCurrencies := b.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := b.GetEnabledPairs(asset.Spot)
subscriptions := []exchange.WebsocketChannelSubscription{}
for i := range channels {
for j := range enabledCurrencies {
@@ -193,7 +193,7 @@ func (b *Bitstamp) Unsubscribe(channelToSubscribe exchange.WebsocketChannelSubsc
return b.WebsocketConn.WriteJSON(req)
}
func (b *Bitstamp) wsUpdateOrderbook(ob websocketOrderBook, p currency.Pair, assetType assets.AssetType) error {
func (b *Bitstamp) wsUpdateOrderbook(ob websocketOrderBook, p currency.Pair, assetType asset.Item) error {
if len(ob.Asks) == 0 && len(ob.Bids) == 0 {
return errors.New("bitstamp_websocket.go error - no orderbook data")
}
@@ -251,7 +251,7 @@ func (b *Bitstamp) wsUpdateOrderbook(ob websocketOrderBook, p currency.Pair, ass
}
func (b *Bitstamp) seedOrderBook() error {
p := b.GetEnabledPairs(assets.AssetTypeSpot)
p := b.GetEnabledPairs(asset.Spot)
for x := range p {
orderbookSeed, err := b.GetOrderbook(p[x].String())
if err != nil {
@@ -278,7 +278,7 @@ func (b *Bitstamp) seedOrderBook() error {
newOrderBook.Asks = asks
newOrderBook.Bids = bids
newOrderBook.Pair = p[x]
newOrderBook.AssetType = assets.AssetTypeSpot
newOrderBook.AssetType = asset.Spot
err = b.Websocket.Orderbook.LoadSnapshot(&newOrderBook, b.GetName(), false)
if err != nil {
@@ -287,7 +287,7 @@ func (b *Bitstamp) seedOrderBook() error {
b.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: p[x],
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: b.GetName(),
}
}

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -52,8 +52,8 @@ func (b *Bitstamp) SetDefaults() {
b.API.CredentialsValidator.RequiresClientID = true
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -144,7 +144,7 @@ func (b *Bitstamp) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Bitstamp) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (b *Bitstamp) FetchTradablePairs(asset asset.Item) ([]string, error) {
pairs, err := b.GetTradingPairs()
if err != nil {
return nil, err
@@ -166,16 +166,16 @@ func (b *Bitstamp) FetchTradablePairs(asset assets.AssetType) ([]string, error)
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *Bitstamp) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bitstamp) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bitstamp) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := b.GetTicker(p.String(), false)
if err != nil {
@@ -199,7 +199,7 @@ func (b *Bitstamp) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ti
}
// FetchTicker returns the ticker for a currency pair
func (b *Bitstamp) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bitstamp) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -218,7 +218,7 @@ func (b *Bitstamp) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error
}
// FetchOrderbook returns the orderbook for a currency pair
func (b *Bitstamp) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bitstamp) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -227,7 +227,7 @@ func (b *Bitstamp) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bitstamp) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bitstamp) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderbook(p.String())
if err != nil {
@@ -303,7 +303,7 @@ func (b *Bitstamp) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Bitstamp) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *Bitstamp) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -505,7 +505,7 @@ func (b *Bitstamp) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
if quoteCurrency.String() != "" && baseCurrency.String() != "" {
currPair = currency.NewPairWithDelimiter(baseCurrency.String(),
quoteCurrency.String(),
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
}
orderDate := time.Unix(order.Date, 0)
orders = append(orders, exchange.OrderDetail{

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -50,8 +50,8 @@ func (b *Bittrex) SetDefaults() {
b.API.CredentialsValidator.RequiresSecret = true
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -115,13 +115,13 @@ func (b *Bittrex) Run() {
}
forceUpdate := false
if !common.StringDataContains(b.GetEnabledPairs(assets.AssetTypeSpot).Strings(), "-") ||
!common.StringDataContains(b.GetAvailablePairs(assets.AssetTypeSpot).Strings(), "-") {
if !common.StringDataContains(b.GetEnabledPairs(asset.Spot).Strings(), "-") ||
!common.StringDataContains(b.GetAvailablePairs(asset.Spot).Strings(), "-") {
forceUpdate = true
enabledPairs := []string{"USDT-BTC"}
log.Warn("WARNING: Available pairs for Bittrex reset due to config upgrade, please enable the ones you would like again")
err := b.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), assets.AssetTypeSpot, true, true)
err := b.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), asset.Spot, true, true)
if err != nil {
log.Errorf("%s failed to update currencies. Err: %s\n", b.Name, err)
}
@@ -138,7 +138,7 @@ func (b *Bittrex) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Bittrex) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (b *Bittrex) FetchTradablePairs(asset asset.Item) ([]string, error) {
markets, err := b.GetMarkets()
if err != nil {
return nil, err
@@ -158,12 +158,12 @@ func (b *Bittrex) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *Bittrex) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// GetAccountInfo Retrieves balances for all enabled currencies for the
@@ -193,7 +193,7 @@ func (b *Bittrex) GetAccountInfo() (exchange.AccountInfo, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bittrex) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bittrex) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := b.GetMarketSummaries()
if err != nil {
@@ -220,7 +220,7 @@ func (b *Bittrex) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tic
}
// FetchTicker returns the ticker for a currency pair
func (b *Bittrex) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *Bittrex) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -229,7 +229,7 @@ func (b *Bittrex) FetchTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchOrderbook returns the orderbook for a currency pair
func (b *Bittrex) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bittrex) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -238,7 +238,7 @@ func (b *Bittrex) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (o
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bittrex) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *Bittrex) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderbook(b.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -283,7 +283,7 @@ func (b *Bittrex) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Bittrex) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *Bittrex) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -429,7 +429,7 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
}
pair := currency.NewPairDelimiter(resp.Result[i].Exchange,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderType := exchange.OrderType(strings.ToUpper(resp.Result[i].Type))
orders = append(orders, exchange.OrderDetail{
@@ -473,7 +473,7 @@ func (b *Bittrex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
}
pair := currency.NewPairDelimiter(resp.Result[i].Exchange,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderType := exchange.OrderType(strings.ToUpper(resp.Result[i].Type))
orders = append(orders, exchange.OrderDetail{

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -54,8 +54,8 @@ func (b *BTCMarkets) SetDefaults() {
b.API.Endpoints.URL = b.API.Endpoints.URLDefault
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -115,13 +115,13 @@ func (b *BTCMarkets) Run() {
}
forceUpdate := false
if !common.StringDataContains(b.GetEnabledPairs(assets.AssetTypeSpot).Strings(), "-") ||
!common.StringDataContains(b.GetAvailablePairs(assets.AssetTypeSpot).Strings(), "-") {
if !common.StringDataContains(b.GetEnabledPairs(asset.Spot).Strings(), "-") ||
!common.StringDataContains(b.GetAvailablePairs(asset.Spot).Strings(), "-") {
enabledPairs := []string{"BTC-AUD"}
log.Println("WARNING: Available pairs for BTC Makrets reset due to config upgrade, please enable the pairs you would like again.")
forceUpdate = true
err := b.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), assets.AssetTypeSpot, true, true)
err := b.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), asset.Spot, true, true)
if err != nil {
log.Errorf("%s failed to update currencies. Err: %s", b.Name, err)
}
@@ -138,7 +138,7 @@ func (b *BTCMarkets) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *BTCMarkets) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (b *BTCMarkets) FetchTradablePairs(asset asset.Item) ([]string, error) {
markets, err := b.GetMarkets()
if err != nil {
return nil, err
@@ -155,16 +155,16 @@ func (b *BTCMarkets) FetchTradablePairs(asset assets.AssetType) ([]string, error
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *BTCMarkets) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *BTCMarkets) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *BTCMarkets) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := b.GetTicker(p.Base.String(), p.Quote.String())
if err != nil {
@@ -184,7 +184,7 @@ func (b *BTCMarkets) UpdateTicker(p currency.Pair, assetType assets.AssetType) (
}
// FetchTicker returns the ticker for a currency pair
func (b *BTCMarkets) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *BTCMarkets) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -193,7 +193,7 @@ func (b *BTCMarkets) FetchTicker(p currency.Pair, assetType assets.AssetType) (t
}
// FetchOrderbook returns orderbook base on the currency pair
func (b *BTCMarkets) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *BTCMarkets) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -202,7 +202,7 @@ func (b *BTCMarkets) FetchOrderbook(p currency.Pair, assetType assets.AssetType)
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *BTCMarkets) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *BTCMarkets) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderbook(p.Base.String(),
p.Quote.String())
@@ -268,7 +268,7 @@ func (b *BTCMarkets) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *BTCMarkets) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *BTCMarkets) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -399,7 +399,7 @@ func (b *BTCMarkets) GetOrderInfo(orderID string) (exchange.OrderDetail, error)
OrderDetail.Status = orders[i].Status
OrderDetail.CurrencyPair = currency.NewPairWithDelimiter(orders[i].Instrument,
orders[i].Currency,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
}
return OrderDetail, nil
@@ -542,7 +542,7 @@ func (b *BTCMarkets) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest
Status: respOrders[i].Status,
CurrencyPair: currency.NewPairWithDelimiter(respOrders[i].Instrument,
respOrders[i].Currency,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
}
for j := range respOrders[i].Trades {

View File

@@ -9,7 +9,7 @@ import (
"strings"
"time"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/gorilla/websocket"
"github.com/thrasher-/gocryptotrader/common"
@@ -123,7 +123,7 @@ func (b *BTSE) WsHandleData() {
b.Websocket.DataHandler <- exchange.TickerData{
Timestamp: time.Now(),
Pair: currency.NewPairDelimiter(t.ProductID, "-"),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: b.GetName(),
ClosePrice: price,
Quantity: t.LastSize,
@@ -184,7 +184,7 @@ func (b *BTSE) wsProcessSnapshot(snapshot *websocketOrderbookSnapshot) error {
}
p := currency.NewPairDelimiter(snapshot.ProductID, "-")
base.AssetType = assets.AssetTypeSpot
base.AssetType = asset.Spot
base.Pair = p
base.LastUpdated = time.Now()
base.ExchangeName = b.Name
@@ -196,7 +196,7 @@ func (b *BTSE) wsProcessSnapshot(snapshot *websocketOrderbookSnapshot) error {
b.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: p,
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: b.GetName(),
}
@@ -206,7 +206,7 @@ func (b *BTSE) wsProcessSnapshot(snapshot *websocketOrderbookSnapshot) error {
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (b *BTSE) GenerateDefaultSubscriptions() {
var channels = []string{"snapshot", "ticker"}
enabledCurrencies := b.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := b.GetEnabledPairs(asset.Spot)
subscriptions := []exchange.WebsocketChannelSubscription{}
for i := range channels {
for j := range enabledCurrencies {

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -50,8 +50,8 @@ func (b *BTSE) SetDefaults() {
b.API.CredentialsValidator.RequiresSecret = true
b.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -140,7 +140,7 @@ func (b *BTSE) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *BTSE) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (b *BTSE) FetchTradablePairs(asset asset.Item) ([]string, error) {
markets, err := b.GetMarkets()
if err != nil {
return nil, err
@@ -157,16 +157,16 @@ func (b *BTSE) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *BTSE) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return b.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *BTSE) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *BTSE) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
t, err := b.GetTicker(b.FormatExchangeCurrency(p,
@@ -198,7 +198,7 @@ func (b *BTSE) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker
}
// FetchTicker returns the ticker for a currency pair
func (b *BTSE) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (b *BTSE) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -207,7 +207,7 @@ func (b *BTSE) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.
}
// FetchOrderbook returns orderbook base on the currency pair
func (b *BTSE) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *BTSE) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
@@ -216,7 +216,7 @@ func (b *BTSE) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orde
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *BTSE) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (b *BTSE) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
return orderbook.Base{}, common.ErrFunctionNotSupported
}
@@ -255,7 +255,7 @@ func (b *BTSE) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *BTSE) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (b *BTSE) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -272,7 +272,7 @@ func (b *BTSE) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrde
r, err := b.CreateOrder(order.Amount, order.Price, order.OrderSide.ToString(),
order.OrderType.ToString(), b.FormatExchangeCurrency(order.Pair,
assets.AssetTypeSpot).String(), "GTC", order.ClientID)
asset.Spot).String(), "GTC", order.ClientID)
if err != nil {
return resp, err
}
@@ -295,7 +295,7 @@ func (b *BTSE) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
func (b *BTSE) CancelOrder(order *exchange.OrderCancellation) error {
r, err := b.CancelExistingOrder(order.OrderID,
b.FormatExchangeCurrency(order.CurrencyPair,
assets.AssetTypeSpot).String())
asset.Spot).String())
if err != nil {
return err
}
@@ -316,7 +316,7 @@ func (b *BTSE) CancelOrder(order *exchange.OrderCancellation) error {
func (b *BTSE) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
var resp exchange.CancelAllOrdersResponse
r, err := b.CancelOrders(b.FormatExchangeCurrency(
orderCancellation.CurrencyPair, assets.AssetTypeSpot).String())
orderCancellation.CurrencyPair, asset.Spot).String())
if err != nil {
return resp, err
}
@@ -355,7 +355,7 @@ func (b *BTSE) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
}
od.CurrencyPair = currency.NewPairDelimiter(o.ProductID,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
od.Exchange = b.Name
od.Amount = o.Amount
od.ID = o.ID
@@ -432,7 +432,7 @@ func (b *BTSE) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]e
openOrder := exchange.OrderDetail{
CurrencyPair: currency.NewPairDelimiter(order.ProductID,
b.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
b.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
Exchange: b.Name,
Amount: order.Amount,
ID: order.ID,

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -113,7 +113,7 @@ func (c *CoinbasePro) WsHandleData() {
c.Websocket.DataHandler <- exchange.TickerData{
Timestamp: ticker.Time,
Pair: currency.NewPairFromString(ticker.ProductID),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: c.GetName(),
OpenPrice: ticker.Open24H,
HighPrice: ticker.High24H,
@@ -188,7 +188,7 @@ func (c *CoinbasePro) ProcessSnapshot(snapshot *WebsocketOrderbookSnapshot) erro
}
p := currency.NewPairFromString(snapshot.ProductID)
base.AssetType = assets.AssetTypeSpot
base.AssetType = asset.Spot
base.Pair = p
base.LastUpdated = time.Now()
@@ -199,7 +199,7 @@ func (c *CoinbasePro) ProcessSnapshot(snapshot *WebsocketOrderbookSnapshot) erro
c.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: p,
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: c.GetName(),
}
@@ -227,14 +227,14 @@ func (c *CoinbasePro) ProcessUpdate(update WebsocketL2Update) error {
p := currency.NewPairFromString(update.ProductID)
err := c.Websocket.Orderbook.Update(Bids, Asks, p, time.Now(), c.GetName(), assets.AssetTypeSpot)
err := c.Websocket.Orderbook.Update(Bids, Asks, p, time.Now(), c.GetName(), asset.Spot)
if err != nil {
return err
}
c.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: p,
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: c.GetName(),
}
@@ -244,7 +244,7 @@ func (c *CoinbasePro) ProcessUpdate(update WebsocketL2Update) error {
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (c *CoinbasePro) GenerateDefaultSubscriptions() {
var channels = []string{"heartbeat", "level2", "ticker"}
enabledCurrencies := c.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := c.GetEnabledPairs(asset.Spot)
subscriptions := []exchange.WebsocketChannelSubscription{}
for i := range channels {
for j := range enabledCurrencies {

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -52,8 +52,8 @@ func (c *CoinbasePro) SetDefaults() {
c.API.CredentialsValidator.RequiresBase64DecodeSecret = true
c.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -144,7 +144,7 @@ func (c *CoinbasePro) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (c *CoinbasePro) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (c *CoinbasePro) FetchTradablePairs(asset asset.Item) ([]string, error) {
pairs, err := c.GetProducts()
if err != nil {
return nil, err
@@ -161,12 +161,12 @@ func (c *CoinbasePro) FetchTradablePairs(asset assets.AssetType) ([]string, erro
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (c *CoinbasePro) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := c.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := c.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return c.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return c.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// GetAccountInfo retrieves balances for all enabled currencies for the
@@ -197,7 +197,7 @@ func (c *CoinbasePro) GetAccountInfo() (exchange.AccountInfo, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (c *CoinbasePro) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (c *CoinbasePro) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := c.GetTicker(c.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -225,7 +225,7 @@ func (c *CoinbasePro) UpdateTicker(p currency.Pair, assetType assets.AssetType)
}
// FetchTicker returns the ticker for a currency pair
func (c *CoinbasePro) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (c *CoinbasePro) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(c.GetName(), p, assetType)
if err != nil {
return c.UpdateTicker(p, assetType)
@@ -234,7 +234,7 @@ func (c *CoinbasePro) FetchTicker(p currency.Pair, assetType assets.AssetType) (
}
// FetchOrderbook returns orderbook base on the currency pair
func (c *CoinbasePro) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (c *CoinbasePro) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(c.GetName(), p, assetType)
if err != nil {
return c.UpdateOrderbook(p, assetType)
@@ -243,7 +243,7 @@ func (c *CoinbasePro) FetchOrderbook(p currency.Pair, assetType assets.AssetType
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (c *CoinbasePro) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (c *CoinbasePro) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := c.GetOrderbook(c.FormatExchangeCurrency(p, assetType).String(), 2)
if err != nil {
@@ -280,7 +280,7 @@ func (c *CoinbasePro) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (c *CoinbasePro) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (c *CoinbasePro) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -418,7 +418,7 @@ func (c *CoinbasePro) GetActiveOrders(getOrdersRequest *exchange.GetOrdersReques
var respOrders []GeneralizedOrderResponse
for i := range getOrdersRequest.Currencies {
resp, err := c.GetOrders([]string{"open", "pending", "active"},
c.FormatExchangeCurrency(getOrdersRequest.Currencies[i], assets.AssetTypeSpot).String())
c.FormatExchangeCurrency(getOrdersRequest.Currencies[i], asset.Spot).String())
if err != nil {
return nil, err
}
@@ -428,7 +428,7 @@ func (c *CoinbasePro) GetActiveOrders(getOrdersRequest *exchange.GetOrdersReques
var orders []exchange.OrderDetail
for i := range respOrders {
currency := currency.NewPairDelimiter(respOrders[i].ProductID,
c.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
c.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderSide := exchange.OrderSide(strings.ToUpper(respOrders[i].Side))
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].Type))
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
@@ -461,7 +461,7 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersReques
var respOrders []GeneralizedOrderResponse
for _, currency := range getOrdersRequest.Currencies {
resp, err := c.GetOrders([]string{"done", "settled"},
c.FormatExchangeCurrency(currency, assets.AssetTypeSpot).String())
c.FormatExchangeCurrency(currency, asset.Spot).String())
if err != nil {
return nil, err
}
@@ -471,7 +471,7 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersReques
var orders []exchange.OrderDetail
for i := range respOrders {
currency := currency.NewPairDelimiter(respOrders[i].ProductID,
c.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
c.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderSide := exchange.OrderSide(strings.ToUpper(respOrders[i].Side))
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].Type))
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)

View File

@@ -10,7 +10,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -83,7 +83,7 @@ func (c *COINUT) WsHandleData() {
Timestamp: time.Unix(0, ticker.Timestamp),
Pair: currency.NewPairFromString(currencyPair),
Exchange: c.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
HighPrice: ticker.HighestBuy,
LowPrice: ticker.LowestSell,
ClosePrice: ticker.Last,
@@ -108,7 +108,7 @@ func (c *COINUT) WsHandleData() {
c.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Exchange: c.GetName(),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Pair: currency.NewPairFromString(currencyPair),
}
@@ -130,7 +130,7 @@ func (c *COINUT) WsHandleData() {
c.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Exchange: c.GetName(),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Pair: currency.NewPairFromString(currencyPair),
}
@@ -155,7 +155,7 @@ func (c *COINUT) WsHandleData() {
c.Websocket.DataHandler <- exchange.TradeData{
Timestamp: time.Unix(tradeUpdate.Timestamp, 0),
CurrencyPair: currency.NewPairFromString(currencyPair),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: c.GetName(),
Price: tradeUpdate.Price,
Side: tradeUpdate.Side,
@@ -281,7 +281,7 @@ func (c *COINUT) WsProcessOrderbookSnapshot(ob *WsOrderbookSnapshot) error {
newOrderBook.Asks = asks
newOrderBook.Bids = bids
newOrderBook.Pair = currency.NewPairFromString(instrumentListByCode[ob.InstID])
newOrderBook.AssetType = assets.AssetTypeSpot
newOrderBook.AssetType = asset.Spot
newOrderBook.LastUpdated = time.Now()
return c.Websocket.Orderbook.LoadSnapshot(&newOrderBook, c.GetName(), false)
@@ -298,7 +298,7 @@ func (c *COINUT) WsProcessOrderbookUpdate(ob *WsOrderbookUpdate) error {
p,
time.Now(),
c.GetName(),
assets.AssetTypeSpot)
asset.Spot)
}
return c.Websocket.Orderbook.Update([]orderbook.Item{
@@ -307,14 +307,14 @@ func (c *COINUT) WsProcessOrderbookUpdate(ob *WsOrderbookUpdate) error {
p,
time.Now(),
c.GetName(),
assets.AssetTypeSpot)
asset.Spot)
}
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (c *COINUT) GenerateDefaultSubscriptions() {
var channels = []string{"inst_tick", "inst_order_book"}
subscriptions := []exchange.WebsocketChannelSubscription{}
enabledCurrencies := c.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := c.GetEnabledPairs(asset.Spot)
for i := range channels {
for j := range enabledCurrencies {
subscriptions = append(subscriptions, exchange.WebsocketChannelSubscription{

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -50,8 +50,8 @@ func (c *COINUT) SetDefaults() {
c.API.CredentialsValidator.RequiresClientID = true
c.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -142,7 +142,7 @@ func (c *COINUT) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (c *COINUT) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (c *COINUT) FetchTradablePairs(asset asset.Item) ([]string, error) {
i, err := c.GetInstruments()
if err != nil {
return nil, err
@@ -161,12 +161,12 @@ func (c *COINUT) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (c *COINUT) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := c.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := c.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return c.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return c.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// GetAccountInfo retrieves balances for all enabled currencies for the
@@ -245,7 +245,7 @@ func (c *COINUT) GetAccountInfo() (exchange.AccountInfo, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (c *COINUT) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (c *COINUT) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := c.GetInstrumentTicker(c.InstrumentMap[p.String()])
if err != nil {
@@ -268,7 +268,7 @@ func (c *COINUT) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchTicker returns the ticker for a currency pair
func (c *COINUT) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (c *COINUT) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(c.GetName(), p, assetType)
if err != nil {
return c.UpdateTicker(p, assetType)
@@ -277,7 +277,7 @@ func (c *COINUT) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchOrderbook returns orderbook base on the currency pair
func (c *COINUT) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (c *COINUT) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(c.GetName(), p, assetType)
if err != nil {
return c.UpdateOrderbook(p, assetType)
@@ -286,7 +286,7 @@ func (c *COINUT) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (or
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (c *COINUT) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (c *COINUT) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := c.GetInstrumentOrderbook(c.InstrumentMap[p.String()], 200)
if err != nil {
@@ -322,7 +322,7 @@ func (c *COINUT) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (c *COINUT) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (c *COINUT) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -521,7 +521,7 @@ func (c *COINUT) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
for _, currency := range getOrdersRequest.Currencies {
currStr := fmt.Sprintf("%v%v%v",
currency.Base.String(),
c.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter,
c.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter,
currency.Quote.String())
if strings.EqualFold(currStr, instrument) {
openOrders, err := c.GetOpenOrders(instrumentData.InstID)

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/request"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -221,7 +221,7 @@ func (e *Base) SetAssetTypes() {
}
// GetAssetTypes returns the available asset types for an individual exchange
func (e *Base) GetAssetTypes() assets.AssetTypes {
func (e *Base) GetAssetTypes() asset.Items {
return e.CurrencyPairs.AssetTypes
}
@@ -303,7 +303,7 @@ func (e *Base) GetSupportedFeatures() FeaturesSupported {
// GetPairFormat returns the pair format based on the exchange and
// asset type
func (e *Base) GetPairFormat(assetType assets.AssetType, requestFormat bool) currency.PairFormat {
func (e *Base) GetPairFormat(assetType asset.Item, requestFormat bool) currency.PairFormat {
if e.CurrencyPairs.UseGlobalFormat {
if requestFormat {
return *e.CurrencyPairs.RequestFormat
@@ -319,7 +319,7 @@ func (e *Base) GetPairFormat(assetType assets.AssetType, requestFormat bool) cur
// GetEnabledPairs is a method that returns the enabled currency pairs of
// the exchange by asset type
func (e *Base) GetEnabledPairs(assetType assets.AssetType) currency.Pairs {
func (e *Base) GetEnabledPairs(assetType asset.Item) currency.Pairs {
format := e.GetPairFormat(assetType, false)
pairs := e.CurrencyPairs.GetPairs(assetType, true)
return pairs.Format(format.Delimiter, format.Index, format.Uppercase)
@@ -327,7 +327,7 @@ func (e *Base) GetEnabledPairs(assetType assets.AssetType) currency.Pairs {
// GetAvailablePairs is a method that returns the available currency pairs
// of the exchange by asset type
func (e *Base) GetAvailablePairs(assetType assets.AssetType) currency.Pairs {
func (e *Base) GetAvailablePairs(assetType asset.Item) currency.Pairs {
format := e.GetPairFormat(assetType, false)
pairs := e.CurrencyPairs.GetPairs(assetType, false)
return pairs.Format(format.Delimiter, format.Index, format.Uppercase)
@@ -335,7 +335,7 @@ func (e *Base) GetAvailablePairs(assetType assets.AssetType) currency.Pairs {
// SupportsPair returns true or not whether a currency pair exists in the
// exchange available currencies or not
func (e *Base) SupportsPair(p currency.Pair, enabledPairs bool, assetType assets.AssetType) bool {
func (e *Base) SupportsPair(p currency.Pair, enabledPairs bool, assetType asset.Item) bool {
if enabledPairs {
return e.GetEnabledPairs(assetType).Contains(p, false)
}
@@ -344,7 +344,7 @@ func (e *Base) SupportsPair(p currency.Pair, enabledPairs bool, assetType assets
// FormatExchangeCurrencies returns a string containing
// the exchanges formatted currency pairs
func (e *Base) FormatExchangeCurrencies(pairs []currency.Pair, assetType assets.AssetType) (string, error) {
func (e *Base) FormatExchangeCurrencies(pairs []currency.Pair, assetType asset.Item) (string, error) {
var currencyItems string
pairFmt := e.GetPairFormat(assetType, true)
@@ -364,7 +364,7 @@ func (e *Base) FormatExchangeCurrencies(pairs []currency.Pair, assetType assets.
// FormatExchangeCurrency is a method that formats and returns a currency pair
// based on the user currency display preferences
func (e *Base) FormatExchangeCurrency(p currency.Pair, assetType assets.AssetType) currency.Pair {
func (e *Base) FormatExchangeCurrency(p currency.Pair, assetType asset.Item) currency.Pair {
pairFmt := e.GetPairFormat(assetType, true)
return p.Format(pairFmt.Delimiter, pairFmt.Uppercase)
}
@@ -520,7 +520,7 @@ func (e *Base) ValidateAPICredentials() bool {
// SetPairs sets the exchange currency pairs for either enabledPairs or
// availablePairs
func (e *Base) SetPairs(pairs currency.Pairs, assetType assets.AssetType, enabled bool) error {
func (e *Base) SetPairs(pairs currency.Pairs, assetType asset.Item, enabled bool) error {
if len(pairs) == 0 {
return fmt.Errorf("%s SetPairs error - pairs is empty", e.Name)
}
@@ -539,7 +539,7 @@ func (e *Base) SetPairs(pairs currency.Pairs, assetType assets.AssetType, enable
// UpdatePairs updates the exchange currency pairs for either enabledPairs or
// availablePairs
func (e *Base) UpdatePairs(exchangeProducts currency.Pairs, assetType assets.AssetType, enabled, force bool) error {
func (e *Base) UpdatePairs(exchangeProducts currency.Pairs, assetType asset.Item, enabled, force bool) error {
if len(exchangeProducts) == 0 {
return fmt.Errorf("%s UpdatePairs error - exchangeProducts is empty", e.Name)
}
@@ -710,7 +710,7 @@ func (e *Base) FormatWithdrawPermissions() string {
// IsAssetTypeSupported whether or not the supplied asset is supported
// by the exchange
func (e *Base) IsAssetTypeSupported(asset assets.AssetType) bool {
func (e *Base) IsAssetTypeSupported(asset asset.Item) bool {
return e.CurrencyPairs.AssetTypes.Contains(asset)
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/request"
)
@@ -172,13 +172,13 @@ func TestSetAssetTypes(t *testing.T) {
}
b.Name = "ANX"
b.CurrencyPairs.AssetTypes = assets.AssetTypes{assets.AssetTypeSpot}
b.CurrencyPairs.AssetTypes = asset.Items{asset.Spot}
exch, err := cfg.GetExchangeConfig(b.Name)
if err != nil {
t.Fatalf("Test failed. TestSetAssetTypes load config failed. Error %s", err)
}
exch.CurrencyPairs.AssetTypes = assets.New("")
exch.CurrencyPairs.AssetTypes = asset.New("")
err = cfg.UpdateExchangeConfig(exch)
if err != nil {
t.Fatalf("Test failed. TestSetAssetTypes update config failed. Error %s", err)
@@ -195,7 +195,7 @@ func TestSetAssetTypes(t *testing.T) {
}
b.SetAssetTypes()
if !common.StringDataCompare(b.CurrencyPairs.AssetTypes.Strings(), assets.AssetTypeSpot.String()) {
if !common.StringDataCompare(b.CurrencyPairs.AssetTypes.Strings(), asset.Spot.String()) {
t.Fatal("Test failed. TestSetAssetTypes assetTypes is not set")
}
}
@@ -203,10 +203,10 @@ func TestSetAssetTypes(t *testing.T) {
func TestGetAssetTypes(t *testing.T) {
testExchange := Base{
CurrencyPairs: currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
assets.AssetTypeBinary,
assets.AssetTypeFutures,
AssetTypes: asset.Items{
asset.Spot,
asset.Binary,
asset.Futures,
},
},
}
@@ -237,7 +237,7 @@ func TestSetCurrencyPairFormat(t *testing.T) {
}
b.Config = exch
b.SetCurrencyPairFormat()
if exch.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter != "-" && !exch.CurrencyPairs.ConfigFormat.Uppercase {
if exch.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter != "-" && !exch.CurrencyPairs.ConfigFormat.Uppercase {
t.Fatal("Test failed. TestSetCurrencyPairFormat exch values are not nil")
}
@@ -258,7 +258,7 @@ func TestSetCurrencyPairFormat(t *testing.T) {
}
b.SetCurrencyPairFormat()
if exch.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter != "-" && !exch.CurrencyPairs.ConfigFormat.Uppercase {
if exch.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter != "-" && !exch.CurrencyPairs.ConfigFormat.Uppercase {
t.Fatal("Test failed. TestSetCurrencyPairFormat exch values are not nil")
}
}
@@ -286,7 +286,7 @@ func TestGetEnabledPairs(t *testing.T) {
Name: "TESTNAME",
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTC-USD"}), true)
format := currency.PairFormat{
Delimiter: "-",
@@ -294,7 +294,7 @@ func TestGetEnabledPairs(t *testing.T) {
Uppercase: true,
}
assetType := assets.AssetTypeSpot
assetType := asset.Spot
b.CurrencyPairs.UseGlobalFormat = true
b.CurrencyPairs.RequestFormat = &format
b.CurrencyPairs.ConfigFormat = &format
@@ -318,7 +318,7 @@ func TestGetEnabledPairs(t *testing.T) {
t.Error("Test Failed - Exchange GetAvailablePairs() incorrect string")
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTCDOGE"}), true)
format.Index = currency.BTC.String()
b.CurrencyPairs.ConfigFormat = &format
@@ -327,7 +327,7 @@ func TestGetEnabledPairs(t *testing.T) {
t.Error("Test Failed - Exchange GetAvailablePairs() incorrect string")
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTC_USD"}), true)
b.CurrencyPairs.RequestFormat.Delimiter = ""
b.CurrencyPairs.ConfigFormat.Delimiter = "_"
@@ -336,7 +336,7 @@ func TestGetEnabledPairs(t *testing.T) {
t.Error("Test Failed - Exchange GetAvailablePairs() incorrect string")
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTCDOGE"}), true)
b.CurrencyPairs.RequestFormat.Delimiter = ""
b.CurrencyPairs.ConfigFormat.Delimiter = ""
@@ -346,7 +346,7 @@ func TestGetEnabledPairs(t *testing.T) {
t.Error("Test Failed - Exchange GetAvailablePairs() incorrect string")
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTCUSD"}), true)
b.CurrencyPairs.ConfigFormat.Index = ""
c = b.GetEnabledPairs(assetType)
@@ -360,7 +360,7 @@ func TestGetAvailablePairs(t *testing.T) {
Name: "TESTNAME",
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{defaultTestCurrencyPair}), false)
format := currency.PairFormat{
Delimiter: "-",
@@ -368,7 +368,7 @@ func TestGetAvailablePairs(t *testing.T) {
Uppercase: true,
}
assetType := assets.AssetTypeSpot
assetType := asset.Spot
b.CurrencyPairs.UseGlobalFormat = true
b.CurrencyPairs.RequestFormat = &format
b.CurrencyPairs.ConfigFormat = &format
@@ -392,7 +392,7 @@ func TestGetAvailablePairs(t *testing.T) {
t.Error("Test Failed - Exchange GetAvailablePairs() incorrect string")
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTCDOGE"}), false)
format.Index = currency.BTC.String()
b.CurrencyPairs.ConfigFormat = &format
@@ -401,7 +401,7 @@ func TestGetAvailablePairs(t *testing.T) {
t.Error("Test Failed - Exchange GetAvailablePairs() incorrect string")
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTC_USD"}), false)
b.CurrencyPairs.RequestFormat.Delimiter = ""
b.CurrencyPairs.ConfigFormat.Delimiter = "_"
@@ -410,7 +410,7 @@ func TestGetAvailablePairs(t *testing.T) {
t.Error("Test Failed - Exchange GetAvailablePairs() incorrect string")
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTCDOGE"}), false)
b.CurrencyPairs.RequestFormat.Delimiter = ""
b.CurrencyPairs.ConfigFormat.Delimiter = "_"
@@ -420,7 +420,7 @@ func TestGetAvailablePairs(t *testing.T) {
t.Error("Test Failed - Exchange GetAvailablePairs() incorrect string")
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTCUSD"}), false)
b.CurrencyPairs.ConfigFormat.Index = ""
c = b.GetAvailablePairs(assetType)
@@ -434,10 +434,10 @@ func TestSupportsPair(t *testing.T) {
Name: "TESTNAME",
}
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{
defaultTestCurrencyPair, "ETH-USD"}), false)
b.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
b.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{defaultTestCurrencyPair}), true)
format := &currency.PairFormat{
@@ -448,7 +448,7 @@ func TestSupportsPair(t *testing.T) {
b.CurrencyPairs.UseGlobalFormat = true
b.CurrencyPairs.RequestFormat = format
b.CurrencyPairs.ConfigFormat = format
assetType := assets.AssetTypeSpot
assetType := asset.Spot
if !b.SupportsPair(currency.NewPair(currency.BTC, currency.USD), true, assetType) {
t.Error("Test Failed - Exchange SupportsPair() incorrect value")
@@ -486,7 +486,7 @@ func TestFormatExchangeCurrencies(t *testing.T) {
currency.NewPairDelimiter("LTC_BTC", "_"),
}
actual, err := e.FormatExchangeCurrencies(pairs, assets.AssetTypeSpot)
actual, err := e.FormatExchangeCurrencies(pairs, asset.Spot)
if err != nil {
t.Errorf("Test failed - Exchange TestFormatExchangeCurrencies error %s", err)
}
@@ -508,7 +508,7 @@ func TestFormatExchangeCurrency(t *testing.T) {
p := currency.NewPair(currency.BTC, currency.USD)
expected := defaultTestCurrencyPair
actual := b.FormatExchangeCurrency(p, assets.AssetTypeSpot)
actual := b.FormatExchangeCurrency(p, asset.Spot)
if actual.String() != expected {
t.Errorf("Test failed - Exchange TestFormatExchangeCurrency %s != %s",
@@ -569,7 +569,7 @@ func TestSetPairs(t *testing.T) {
}
newPair := currency.NewPairDelimiter("ETH_USDT", "_")
assetType := assets.AssetTypeSpot
assetType := asset.Spot
var UAC Base
UAC.Name = "ANX"
@@ -579,7 +579,7 @@ func TestSetPairs(t *testing.T) {
t.Fatalf("Test failed. TestSetPairs unable to set defaults: %s", err)
}
err = UAC.SetPairs([]currency.Pair{newPair}, assets.AssetTypeSpot, true)
err = UAC.SetPairs([]currency.Pair{newPair}, asset.Spot, true)
if err != nil {
t.Fatalf("Test failed. TestSetPairs failed to set currencies: %s", err)
}
@@ -588,12 +588,12 @@ func TestSetPairs(t *testing.T) {
t.Fatal("Test failed. TestSetPairs failed to set currencies")
}
UAC.SetPairs([]currency.Pair{newPair}, assets.AssetTypeSpot, false)
UAC.SetPairs([]currency.Pair{newPair}, asset.Spot, false)
if !UAC.GetAvailablePairs(assetType).Contains(newPair, true) {
t.Fatal("Test failed. TestSetPairs failed to set currencies")
}
err = UAC.SetPairs(nil, assets.AssetTypeSpot, false)
err = UAC.SetPairs(nil, asset.Spot, false)
if err == nil {
t.Fatal("Test failed. TestSetPairs should return an error when attempting to set an empty pairs array")
}
@@ -614,20 +614,20 @@ func TestUpdatePairs(t *testing.T) {
UAC := Base{Name: "ANX"}
UAC.Config = anxCfg
exchangeProducts := currency.NewPairsFromStrings([]string{"ltc", "btc", "usd", "aud", ""})
err = UAC.UpdatePairs(exchangeProducts, assets.AssetTypeSpot, true, false)
err = UAC.UpdatePairs(exchangeProducts, asset.Spot, true, false)
if err != nil {
t.Errorf("Test Failed - TestUpdatePairs error: %s", err)
}
// Test updating the same new products, diff should be 0
err = UAC.UpdatePairs(exchangeProducts, assets.AssetTypeSpot, true, false)
err = UAC.UpdatePairs(exchangeProducts, asset.Spot, true, false)
if err != nil {
t.Errorf("Test Failed - TestUpdatePairs error: %s", err)
}
// Test force updating to only one product
exchangeProducts = currency.NewPairsFromStrings([]string{"btc"})
err = UAC.UpdatePairs(exchangeProducts, assets.AssetTypeSpot, true, true)
err = UAC.UpdatePairs(exchangeProducts, asset.Spot, true, true)
if err != nil {
t.Errorf("Test Failed - TestUpdatePairs error: %s", err)
}
@@ -635,34 +635,34 @@ func TestUpdatePairs(t *testing.T) {
// Test updating exchange products
exchangeProducts = currency.NewPairsFromStrings([]string{"ltc", "btc", "usd", "aud"})
UAC.Name = "ANX"
err = UAC.UpdatePairs(exchangeProducts, assets.AssetTypeSpot, false, false)
err = UAC.UpdatePairs(exchangeProducts, asset.Spot, false, false)
if err != nil {
t.Errorf("Test Failed - Exchange UpdatePairs() error: %s", err)
}
// Test updating the same new products, diff should be 0
err = UAC.UpdatePairs(exchangeProducts, assets.AssetTypeSpot, false, false)
err = UAC.UpdatePairs(exchangeProducts, asset.Spot, false, false)
if err != nil {
t.Errorf("Test Failed - Exchange UpdatePairs() error: %s", err)
}
// Test force updating to only one product
exchangeProducts = currency.NewPairsFromStrings([]string{"btc"})
err = UAC.UpdatePairs(exchangeProducts, assets.AssetTypeSpot, false, true)
err = UAC.UpdatePairs(exchangeProducts, asset.Spot, false, true)
if err != nil {
t.Errorf("Test Failed - Forced Exchange UpdatePairs() error: %s", err)
}
// Test update currency pairs with btc excluded
exchangeProducts = currency.NewPairsFromStrings([]string{"ltc", "eth"})
err = UAC.UpdatePairs(exchangeProducts, assets.AssetTypeSpot, false, false)
err = UAC.UpdatePairs(exchangeProducts, asset.Spot, false, false)
if err != nil {
t.Errorf("Test Failed - Forced Exchange UpdatePairs() error: %s", err)
}
// Test that empty exchange products should return an error
exchangeProducts = nil
err = UAC.UpdatePairs(exchangeProducts, assets.AssetTypeSpot, false, false)
err = UAC.UpdatePairs(exchangeProducts, asset.Spot, false, false)
if err == nil {
t.Errorf("Test failed - empty available pairs should return an error")
}

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (e *EXMO) SetDefaults() {
e.API.CredentialsValidator.RequiresSecret = true
e.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -127,7 +127,7 @@ func (e *EXMO) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (e *EXMO) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (e *EXMO) FetchTradablePairs(asset asset.Item) ([]string, error) {
pairs, err := e.GetPairSettings()
if err != nil {
return nil, err
@@ -144,16 +144,16 @@ func (e *EXMO) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (e *EXMO) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := e.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := e.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return e.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return e.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (e *EXMO) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (e *EXMO) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
pairsCollated, err := e.FormatExchangeCurrencies(e.GetEnabledPairs(assetType), assetType)
if err != nil {
@@ -186,7 +186,7 @@ func (e *EXMO) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker
}
// FetchTicker returns the ticker for a currency pair
func (e *EXMO) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (e *EXMO) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := ticker.GetTicker(e.GetName(), p, assetType)
if err != nil {
return e.UpdateTicker(p, assetType)
@@ -195,7 +195,7 @@ func (e *EXMO) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.
}
// FetchOrderbook returns the orderbook for a currency pair
func (e *EXMO) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (e *EXMO) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(e.GetName(), p, assetType)
if err != nil {
return e.UpdateOrderbook(p, assetType)
@@ -204,7 +204,7 @@ func (e *EXMO) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orde
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
pairsCollated, err := e.FormatExchangeCurrencies(e.GetEnabledPairs(assetType), assetType)
if err != nil {
@@ -293,7 +293,7 @@ func (e *EXMO) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (e *EXMO) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (e *EXMO) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -465,7 +465,7 @@ func (e *EXMO) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]e
var allTrades []UserTrades
for _, currency := range getOrdersRequest.Currencies {
resp, err := e.GetUserTrades(e.FormatExchangeCurrency(currency, assets.AssetTypeSpot).String(), "", "10000")
resp, err := e.GetUserTrades(e.FormatExchangeCurrency(currency, asset.Spot).String(), "", "10000")
if err != nil {
return nil, err
}

View File

@@ -15,7 +15,7 @@ import (
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -188,7 +188,7 @@ func (g *Gateio) WsHandleData() {
g.Websocket.DataHandler <- exchange.TickerData{
Timestamp: time.Now(),
Pair: currency.NewPairFromString(c),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: g.GetName(),
ClosePrice: ticker.Close,
Quantity: ticker.BaseVolume,
@@ -216,7 +216,7 @@ func (g *Gateio) WsHandleData() {
g.Websocket.DataHandler <- exchange.TradeData{
Timestamp: time.Now(),
CurrencyPair: currency.NewPairFromString(c),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: g.GetName(),
Price: trade.Price,
Amount: trade.Amount,
@@ -284,7 +284,7 @@ func (g *Gateio) WsHandleData() {
var newOrderBook orderbook.Base
newOrderBook.Asks = asks
newOrderBook.Bids = bids
newOrderBook.AssetType = assets.AssetTypeSpot
newOrderBook.AssetType = asset.Spot
newOrderBook.LastUpdated = time.Now()
newOrderBook.Pair = currency.NewPairFromString(c)
@@ -300,7 +300,7 @@ func (g *Gateio) WsHandleData() {
currency.NewPairFromString(c),
time.Now(),
g.GetName(),
assets.AssetTypeSpot)
asset.Spot)
if err != nil {
g.Websocket.DataHandler <- err
}
@@ -308,7 +308,7 @@ func (g *Gateio) WsHandleData() {
g.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: currency.NewPairFromString(c),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: g.GetName(),
}
@@ -329,7 +329,7 @@ func (g *Gateio) WsHandleData() {
g.Websocket.DataHandler <- exchange.KlineData{
Timestamp: time.Now(),
Pair: currency.NewPairFromString(data[7].(string)),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: g.GetName(),
OpenPrice: open,
ClosePrice: closePrice,
@@ -350,7 +350,7 @@ func (g *Gateio) GenerateDefaultSubscriptions() {
}
subscriptions := []exchange.WebsocketChannelSubscription{}
enabledCurrencies := g.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := g.GetEnabledPairs(asset.Spot)
for i := range channels {
for j := range enabledCurrencies {
params := make(map[string]interface{})

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (g *Gateio) SetDefaults() {
g.API.CredentialsValidator.RequiresSecret = true
g.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -147,23 +147,23 @@ func (g *Gateio) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (g *Gateio) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (g *Gateio) FetchTradablePairs(asset asset.Item) ([]string, error) {
return g.GetSymbols()
}
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (g *Gateio) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := g.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := g.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return g.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return g.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (g *Gateio) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (g *Gateio) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
result, err := g.GetTickers()
if err != nil {
@@ -190,7 +190,7 @@ func (g *Gateio) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchTicker returns the ticker for a currency pair
func (g *Gateio) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (g *Gateio) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(g.GetName(), p, assetType)
if err != nil {
return g.UpdateTicker(p, assetType)
@@ -199,7 +199,7 @@ func (g *Gateio) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchOrderbook returns orderbook base on the currency pair
func (g *Gateio) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (g *Gateio) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(g.GetName(), p, assetType)
if err != nil {
return g.UpdateOrderbook(p, assetType)
@@ -208,7 +208,7 @@ func (g *Gateio) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (or
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (g *Gateio) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (g *Gateio) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
currency := g.FormatExchangeCurrency(p, assetType).String()
@@ -312,7 +312,7 @@ func (g *Gateio) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (g *Gateio) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (g *Gateio) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -419,7 +419,7 @@ func (g *Gateio) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
orderDetail.Status = orders.Orders[x].Status
orderDetail.Price = orders.Orders[x].Rate
orderDetail.CurrencyPair = currency.NewPairDelimiter(orders.Orders[x].CurrencyPair,
g.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
g.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
if strings.EqualFold(orders.Orders[x].Type, exchange.AskOrderSide.ToString()) {
orderDetail.OrderSide = exchange.AskOrderSide
} else if strings.EqualFold(orders.Orders[x].Type, exchange.BidOrderSide.ToString()) {
@@ -505,7 +505,7 @@ func (g *Gateio) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
}
symbol := currency.NewPairDelimiter(resp.Orders[i].CurrencyPair,
g.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
g.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
side := exchange.OrderSide(strings.ToUpper(resp.Orders[i].Type))
orderDate := time.Unix(resp.Orders[i].Timestamp, 0)
@@ -542,7 +542,7 @@ func (g *Gateio) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
var orders []exchange.OrderDetail
for _, trade := range trades {
symbol := currency.NewPairDelimiter(trade.Pair,
g.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
g.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
side := exchange.OrderSide(strings.ToUpper(trade.Type))
orderDate := time.Unix(trade.TimeUnix, 0)
orders = append(orders, exchange.OrderDetail{

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
)
@@ -49,7 +49,7 @@ func (g *Gemini) WsConnect() error {
// WsSubscribe subscribes to the full websocket suite on gemini exchange
func (g *Gemini) WsSubscribe(dialer *websocket.Dialer) error {
enabledCurrencies := g.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := g.GetEnabledPairs(asset.Spot)
for i, c := range enabledCurrencies {
val := url.Values{}
val.Set("heartbeat", "true")
@@ -157,7 +157,7 @@ func (g *Gemini) WsHandleData() {
var newOrderBook orderbook.Base
newOrderBook.Asks = asks
newOrderBook.Bids = bids
newOrderBook.AssetType = assets.AssetTypeSpot
newOrderBook.AssetType = asset.Spot
newOrderBook.LastUpdated = time.Now()
newOrderBook.Pair = resp.Currency
@@ -170,7 +170,7 @@ func (g *Gemini) WsHandleData() {
}
g.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{Pair: resp.Currency,
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: g.GetName()}
} else {
@@ -179,7 +179,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- exchange.TradeData{
Timestamp: time.Now(),
CurrencyPair: resp.Currency,
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: g.GetName(),
EventTime: result.Timestamp,
Price: event.Price,
@@ -197,7 +197,7 @@ func (g *Gemini) WsHandleData() {
resp.Currency,
time.Now(),
g.GetName(),
assets.AssetTypeSpot)
asset.Spot)
if err != nil {
g.Websocket.DataHandler <- err
}
@@ -207,7 +207,7 @@ func (g *Gemini) WsHandleData() {
resp.Currency,
time.Now(),
g.GetName(),
assets.AssetTypeSpot)
asset.Spot)
if err != nil {
g.Websocket.DataHandler <- err
}
@@ -216,7 +216,7 @@ func (g *Gemini) WsHandleData() {
}
g.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{Pair: resp.Currency,
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: g.GetName()}
}

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -52,8 +52,8 @@ func (g *Gemini) SetDefaults() {
g.API.CredentialsValidator.RequiresSecret = true
g.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -145,7 +145,7 @@ func (g *Gemini) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (g *Gemini) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (g *Gemini) FetchTradablePairs(asset asset.Item) ([]string, error) {
return g.GetSymbols()
}
@@ -157,7 +157,7 @@ func (g *Gemini) UpdateTradablePairs(forceUpdate bool) error {
return err
}
return g.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return g.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// GetAccountInfo Retrieves balances for all enabled currencies for the
@@ -187,7 +187,7 @@ func (g *Gemini) GetAccountInfo() (exchange.AccountInfo, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (g *Gemini) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (g *Gemini) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := g.GetTicker(p.String())
if err != nil {
@@ -208,7 +208,7 @@ func (g *Gemini) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchTicker returns the ticker for a currency pair
func (g *Gemini) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (g *Gemini) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(g.GetName(), p, assetType)
if err != nil {
return g.UpdateTicker(p, assetType)
@@ -217,7 +217,7 @@ func (g *Gemini) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchOrderbook returns orderbook base on the currency pair
func (g *Gemini) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (g *Gemini) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(g.GetName(), p, assetType)
if err != nil {
return g.UpdateOrderbook(p, assetType)
@@ -226,7 +226,7 @@ func (g *Gemini) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (or
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (g *Gemini) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (g *Gemini) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := g.GetOrderbook(p.String(), url.Values{})
if err != nil {
@@ -261,7 +261,7 @@ func (g *Gemini) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (g *Gemini) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (g *Gemini) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -389,7 +389,7 @@ func (g *Gemini) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
var orders []exchange.OrderDetail
for i := range resp {
symbol := currency.NewPairDelimiter(resp[i].Symbol,
g.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
g.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
var orderType exchange.OrderType
if resp[i].Type == "exchange limit" {
orderType = exchange.LimitOrderType
@@ -432,7 +432,7 @@ func (g *Gemini) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
var trades []TradeHistory
for _, currency := range getOrdersRequest.Currencies {
resp, err := g.GetTradeHistory(g.FormatExchangeCurrency(currency,
assets.AssetTypeSpot).String(), getOrdersRequest.StartTicks.Unix())
asset.Spot).String(), getOrdersRequest.StartTicks.Unix())
if err != nil {
return nil, err
}
@@ -459,7 +459,7 @@ func (g *Gemini) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
Price: trades[i].Price,
CurrencyPair: currency.NewPairWithDelimiter(trades[i].BaseCurrency,
trades[i].QuoteCurrency,
g.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
g.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
})
}

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -117,7 +117,7 @@ func (h *HitBTC) WsHandleData() {
h.Websocket.DataHandler <- exchange.TickerData{
Exchange: h.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Pair: currency.NewPairFromString(ticker.Params.Symbol),
Quantity: ticker.Params.Volume,
Timestamp: ts,
@@ -191,7 +191,7 @@ func (h *HitBTC) WsProcessOrderbookSnapshot(ob WsOrderbook) error {
var newOrderBook orderbook.Base
newOrderBook.Asks = asks
newOrderBook.Bids = bids
newOrderBook.AssetType = assets.AssetTypeSpot
newOrderBook.AssetType = asset.Spot
newOrderBook.LastUpdated = time.Now()
newOrderBook.Pair = p
@@ -202,7 +202,7 @@ func (h *HitBTC) WsProcessOrderbookSnapshot(ob WsOrderbook) error {
h.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Exchange: h.GetName(),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Pair: p,
}
@@ -226,14 +226,14 @@ func (h *HitBTC) WsProcessOrderbookUpdate(ob WsOrderbook) error {
p := currency.NewPairFromString(ob.Params.Symbol)
err := h.Websocket.Orderbook.Update(bids, asks, p, time.Now(), h.GetName(), assets.AssetTypeSpot)
err := h.Websocket.Orderbook.Update(bids, asks, p, time.Now(), h.GetName(), asset.Spot)
if err != nil {
return err
}
h.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Exchange: h.GetName(),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Pair: p,
}
return nil
@@ -243,7 +243,7 @@ func (h *HitBTC) WsProcessOrderbookUpdate(ob WsOrderbook) error {
func (h *HitBTC) GenerateDefaultSubscriptions() {
var channels = []string{"subscribeTicker", "subscribeOrderbook", "subscribeTrades", "subscribeCandles"}
subscriptions := []exchange.WebsocketChannelSubscription{}
enabledCurrencies := h.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := h.GetEnabledPairs(asset.Spot)
for i := range channels {
for j := range enabledCurrencies {
enabledCurrencies[j].Delimiter = ""

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (h *HitBTC) SetDefaults() {
h.API.CredentialsValidator.RequiresSecret = true
h.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -131,13 +131,13 @@ func (h *HitBTC) Run() {
}
forceUpdate := false
if !common.StringDataContains(h.GetEnabledPairs(assets.AssetTypeSpot).Strings(), "-") ||
!common.StringDataContains(h.GetAvailablePairs(assets.AssetTypeSpot).Strings(), "-") {
if !common.StringDataContains(h.GetEnabledPairs(asset.Spot).Strings(), "-") ||
!common.StringDataContains(h.GetAvailablePairs(asset.Spot).Strings(), "-") {
enabledPairs := []string{"BTC-USD"}
log.Warn("WARNING: Available pairs for HitBTC reset due to config upgrade, please enable the ones you would like again.")
forceUpdate = true
err := h.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), assets.AssetTypeSpot, true, true)
err := h.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), asset.Spot, true, true)
if err != nil {
log.Errorf("%s failed to update enabled currencies.\n", h.GetName())
}
@@ -154,7 +154,7 @@ func (h *HitBTC) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (h *HitBTC) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (h *HitBTC) FetchTradablePairs(asset asset.Item) ([]string, error) {
symbols, err := h.GetSymbolsDetailed()
if err != nil {
return nil, err
@@ -170,16 +170,16 @@ func (h *HitBTC) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (h *HitBTC) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := h.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := h.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return h.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return h.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (h *HitBTC) UpdateTicker(currencyPair currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (h *HitBTC) UpdateTicker(currencyPair currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := h.GetTicker("")
if err != nil {
return ticker.Price{}, err
@@ -205,7 +205,7 @@ func (h *HitBTC) UpdateTicker(currencyPair currency.Pair, assetType assets.Asset
}
// FetchTicker returns the ticker for a currency pair
func (h *HitBTC) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (h *HitBTC) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(h.GetName(), p, assetType)
if err != nil {
return h.UpdateTicker(p, assetType)
@@ -214,7 +214,7 @@ func (h *HitBTC) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchOrderbook returns orderbook base on the currency pair
func (h *HitBTC) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (h *HitBTC) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(h.GetName(), p, assetType)
if err != nil {
return h.UpdateOrderbook(p, assetType)
@@ -223,7 +223,7 @@ func (h *HitBTC) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (or
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (h *HitBTC) UpdateOrderbook(currencyPair currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (h *HitBTC) UpdateOrderbook(currencyPair currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := h.GetOrderbook(h.FormatExchangeCurrency(currencyPair, assetType).String(), 1000)
if err != nil {
@@ -286,7 +286,7 @@ func (h *HitBTC) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (h *HitBTC) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (h *HitBTC) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -425,7 +425,7 @@ func (h *HitBTC) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
var orders []exchange.OrderDetail
for i := range allOrders {
symbol := currency.NewPairDelimiter(allOrders[i].Symbol,
h.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
h.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
side := exchange.OrderSide(strings.ToUpper(allOrders[i].Side))
orderDate, err := time.Parse(time.RFC3339, allOrders[i].CreatedAt)
if err != nil {
@@ -469,7 +469,7 @@ func (h *HitBTC) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
var orders []exchange.OrderDetail
for i := range allOrders {
symbol := currency.NewPairDelimiter(allOrders[i].Symbol,
h.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
h.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
side := exchange.OrderSide(strings.ToUpper(allOrders[i].Side))
orderDate, err := time.Parse(time.RFC3339, allOrders[i].CreatedAt)
if err != nil {

View File

@@ -15,7 +15,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -152,7 +152,7 @@ func (h *HUOBI) WsHandleData() {
h.Websocket.DataHandler <- exchange.KlineData{
Timestamp: time.Unix(0, kline.Timestamp),
Exchange: h.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Pair: currency.NewPairFromString(data[1]),
OpenPrice: kline.Tick.Open,
ClosePrice: kline.Tick.Close,
@@ -173,7 +173,7 @@ func (h *HUOBI) WsHandleData() {
h.Websocket.DataHandler <- exchange.TradeData{
Exchange: h.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
CurrencyPair: currency.NewPairFromString(data[1]),
Timestamp: time.Unix(0, trade.Tick.Timestamp),
}
@@ -213,7 +213,7 @@ func (h *HUOBI) WsProcessOrderbook(ob *WsDepth, symbol string) error {
h.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: p,
Exchange: h.GetName(),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
}
return nil
@@ -222,7 +222,7 @@ func (h *HUOBI) WsProcessOrderbook(ob *WsDepth, symbol string) error {
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (h *HUOBI) GenerateDefaultSubscriptions() {
var channels = []string{wsMarketKline, wsMarketDepth, wsMarketTrade}
enabledCurrencies := h.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := h.GetEnabledPairs(asset.Spot)
subscriptions := []exchange.WebsocketChannelSubscription{}
for i := range channels {
for j := range enabledCurrencies {

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (h *HUOBI) SetDefaults() {
h.API.CredentialsValidator.RequiresSecret = true
h.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
@@ -138,8 +138,8 @@ func (h *HUOBI) Run() {
}
var forceUpdate bool
if common.StringDataContains(h.GetEnabledPairs(assets.AssetTypeSpot).Strings(), "CNY") ||
common.StringDataContains(h.GetAvailablePairs(assets.AssetTypeSpot).Strings(), "CNY") {
if common.StringDataContains(h.GetEnabledPairs(asset.Spot).Strings(), "CNY") ||
common.StringDataContains(h.GetAvailablePairs(asset.Spot).Strings(), "CNY") {
forceUpdate = true
}
@@ -163,7 +163,7 @@ func (h *HUOBI) Run() {
}
log.Warn("WARNING: Available and enabled pairs for Huobi reset due to config upgrade, please enable the ones you would like again")
err := h.UpdatePairs(enabledPairs, assets.AssetTypeSpot, true, true)
err := h.UpdatePairs(enabledPairs, asset.Spot, true, true)
if err != nil {
log.Errorf("%s Failed to update enabled currencies.\n", h.GetName())
}
@@ -180,7 +180,7 @@ func (h *HUOBI) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (h *HUOBI) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (h *HUOBI) FetchTradablePairs(asset asset.Item) ([]string, error) {
symbols, err := h.GetSymbols()
if err != nil {
return nil, err
@@ -197,16 +197,16 @@ func (h *HUOBI) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (h *HUOBI) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := h.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := h.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return h.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return h.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (h *HUOBI) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (h *HUOBI) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := h.GetMarketDetailMerged(h.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -236,7 +236,7 @@ func (h *HUOBI) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchTicker returns the ticker for a currency pair
func (h *HUOBI) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (h *HUOBI) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(h.GetName(), p, assetType)
if err != nil {
return h.UpdateTicker(p, assetType)
@@ -245,7 +245,7 @@ func (h *HUOBI) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker
}
// FetchOrderbook returns orderbook base on the currency pair
func (h *HUOBI) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (h *HUOBI) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(h.GetName(), p, assetType)
if err != nil {
return h.UpdateOrderbook(p, assetType)
@@ -254,7 +254,7 @@ func (h *HUOBI) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (ord
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (h *HUOBI) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (h *HUOBI) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := h.GetDepth(OrderBookDataRequestParams{
Symbol: h.FormatExchangeCurrency(p, assetType).String(),
@@ -374,7 +374,7 @@ func (h *HUOBI) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (h *HUOBI) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (h *HUOBI) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -448,9 +448,9 @@ func (h *HUOBI) CancelOrder(order *exchange.OrderCancellation) error {
// CancelAllOrders cancels all orders associated with a currency pair
func (h *HUOBI) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
var cancelAllOrdersResponse exchange.CancelAllOrdersResponse
for _, currency := range h.GetEnabledPairs(assets.AssetTypeSpot) {
for _, currency := range h.GetEnabledPairs(asset.Spot) {
resp, err := h.CancelOpenOrdersBatch(orderCancellation.AccountID,
h.FormatExchangeCurrency(currency, assets.AssetTypeSpot).String())
h.FormatExchangeCurrency(currency, asset.Spot).String())
if err != nil {
return cancelAllOrdersResponse, err
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// Please supply your own APIKEYS here for due diligence testing
@@ -51,8 +51,8 @@ func getDefaultConfig() config.ExchangeConfig {
HTTPTimeout: 15000000000,
CurrencyPairs: &currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
ConfigFormat: &currency.PairFormat{
@@ -67,10 +67,10 @@ func getDefaultConfig() config.ExchangeConfig {
BaseCurrencies: currency.NewCurrenciesFromStringArray([]string{"USD"}),
}
exchCfg.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
exchCfg.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTC-USDT", "BCH-USDT"}),
false)
exchCfg.CurrencyPairs.StorePairs(assets.AssetTypeSpot,
exchCfg.CurrencyPairs.StorePairs(asset.Spot,
currency.NewPairsFromStrings([]string{"BTC-USDT"}),
true)

View File

@@ -15,7 +15,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -155,7 +155,7 @@ func (h *HUOBIHADAX) WsHandleData() {
h.Websocket.DataHandler <- exchange.KlineData{
Timestamp: time.Unix(0, kline.Timestamp),
Exchange: h.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Pair: currency.NewPairFromString(data[1]),
OpenPrice: kline.Tick.Open,
ClosePrice: kline.Tick.Close,
@@ -176,7 +176,7 @@ func (h *HUOBIHADAX) WsHandleData() {
h.Websocket.DataHandler <- exchange.TradeData{
Exchange: h.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
CurrencyPair: currency.NewPairFromString(data[1]),
Timestamp: time.Unix(0, trade.Tick.Timestamp),
}
@@ -216,7 +216,7 @@ func (h *HUOBIHADAX) WsProcessOrderbook(ob *WsDepth, symbol string) error {
h.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: p,
Exchange: h.GetName(),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
}
return nil
@@ -225,7 +225,7 @@ func (h *HUOBIHADAX) WsProcessOrderbook(ob *WsDepth, symbol string) error {
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (h *HUOBIHADAX) GenerateDefaultSubscriptions() {
var channels = []string{wsMarketKline, wsMarketDepth, wsMarketTrade}
enabledCurrencies := h.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := h.GetEnabledPairs(asset.Spot)
subscriptions := []exchange.WebsocketChannelSubscription{}
for i := range channels {
for j := range enabledCurrencies {

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (h *HUOBIHADAX) SetDefaults() {
h.API.CredentialsValidator.RequiresSecret = true
h.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
@@ -144,7 +144,7 @@ func (h *HUOBIHADAX) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (h *HUOBIHADAX) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (h *HUOBIHADAX) FetchTradablePairs(asset asset.Item) ([]string, error) {
symbols, err := h.GetSymbols()
if err != nil {
return nil, err
@@ -161,16 +161,16 @@ func (h *HUOBIHADAX) FetchTradablePairs(asset assets.AssetType) ([]string, error
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (h *HUOBIHADAX) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := h.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := h.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return h.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return h.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (h *HUOBIHADAX) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (h *HUOBIHADAX) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := h.GetMarketDetailMerged(h.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -200,7 +200,7 @@ func (h *HUOBIHADAX) UpdateTicker(p currency.Pair, assetType assets.AssetType) (
}
// FetchTicker returns the ticker for a currency pair
func (h *HUOBIHADAX) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (h *HUOBIHADAX) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(h.GetName(), p, assetType)
if err != nil {
return h.UpdateTicker(p, assetType)
@@ -209,7 +209,7 @@ func (h *HUOBIHADAX) FetchTicker(p currency.Pair, assetType assets.AssetType) (t
}
// FetchOrderbook returns orderbook base on the currency pair
func (h *HUOBIHADAX) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (h *HUOBIHADAX) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(h.GetName(), p, assetType)
if err != nil {
return h.UpdateOrderbook(p, assetType)
@@ -218,7 +218,7 @@ func (h *HUOBIHADAX) FetchOrderbook(p currency.Pair, assetType assets.AssetType)
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (h *HUOBIHADAX) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (h *HUOBIHADAX) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := h.GetDepth(h.FormatExchangeCurrency(p, assetType).String(), "step1")
if err != nil {
@@ -335,7 +335,7 @@ func (h *HUOBIHADAX) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (h *HUOBIHADAX) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (h *HUOBIHADAX) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -409,9 +409,9 @@ func (h *HUOBIHADAX) CancelOrder(order *exchange.OrderCancellation) error {
// CancelAllOrders cancels all orders associated with a currency pair
func (h *HUOBIHADAX) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
var cancelAllOrdersResponse exchange.CancelAllOrdersResponse
for _, currency := range h.GetEnabledPairs(assets.AssetTypeSpot) {
for _, currency := range h.GetEnabledPairs(asset.Spot) {
resp, err := h.CancelOpenOrdersBatch(orderCancellation.AccountID,
h.FormatExchangeCurrency(currency, assets.AssetTypeSpot).String())
h.FormatExchangeCurrency(currency, asset.Spot).String())
if err != nil {
return cancelAllOrdersResponse, err
}
@@ -500,7 +500,7 @@ func (h *HUOBIHADAX) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest
var orders []exchange.OrderDetail
for i := range allOrders {
symbol := currency.NewPairDelimiter(allOrders[i].Symbol,
h.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
h.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(0, allOrders[i].CreatedAt*int64(time.Millisecond))
orders = append(orders, exchange.OrderDetail{
@@ -546,7 +546,7 @@ func (h *HUOBIHADAX) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest
var orders []exchange.OrderDetail
for i := range allOrders {
symbol := currency.NewPairDelimiter(allOrders[i].Symbol,
h.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
h.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(0, allOrders[i].CreatedAt*int64(time.Millisecond))
orders = append(orders, exchange.OrderDetail{

View File

@@ -5,7 +5,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
@@ -19,19 +19,19 @@ type IBotExchange interface {
GetName() string
IsEnabled() bool
SetEnabled(bool)
FetchTicker(currency currency.Pair, assetType assets.AssetType) (ticker.Price, error)
UpdateTicker(currency currency.Pair, assetType assets.AssetType) (ticker.Price, error)
FetchOrderbook(currency currency.Pair, assetType assets.AssetType) (orderbook.Base, error)
UpdateOrderbook(currency currency.Pair, assetType assets.AssetType) (orderbook.Base, error)
FetchTradablePairs(assetType assets.AssetType) ([]string, error)
FetchTicker(currency currency.Pair, assetType asset.Item) (ticker.Price, error)
UpdateTicker(currency currency.Pair, assetType asset.Item) (ticker.Price, error)
FetchOrderbook(currency currency.Pair, assetType asset.Item) (orderbook.Base, error)
UpdateOrderbook(currency currency.Pair, assetType asset.Item) (orderbook.Base, error)
FetchTradablePairs(assetType asset.Item) ([]string, error)
UpdateTradablePairs(forceUpdate bool) error
GetEnabledPairs(assetType assets.AssetType) currency.Pairs
GetAvailablePairs(assetType assets.AssetType) currency.Pairs
GetEnabledPairs(assetType asset.Item) currency.Pairs
GetAvailablePairs(assetType asset.Item) currency.Pairs
GetAccountInfo() (AccountInfo, error)
GetAuthenticatedAPISupport() bool
SetPairs(pairs currency.Pairs, assetType assets.AssetType, enabled bool) error
GetAssetTypes() assets.AssetTypes
GetExchangeHistory(currencyPair currency.Pair, assetType assets.AssetType) ([]TradeHistory, error)
SetPairs(pairs currency.Pairs, assetType asset.Item, enabled bool) error
GetAssetTypes() asset.Items
GetExchangeHistory(currencyPair currency.Pair, assetType asset.Item) ([]TradeHistory, error)
SupportsAutoPairUpdates() bool
SupportsRESTTickerBatchUpdates() bool
GetFeeByType(feeBuilder *FeeBuilder) (float64, error)

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (i *ItBit) SetDefaults() {
i.API.CredentialsValidator.RequiresSecret = true
i.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -115,7 +115,7 @@ func (i *ItBit) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (i *ItBit) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (i *ItBit) FetchTradablePairs(asset asset.Item) ([]string, error) {
return nil, common.ErrFunctionNotSupported
}
@@ -126,7 +126,7 @@ func (i *ItBit) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (i *ItBit) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (i *ItBit) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := i.GetTicker(i.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -150,7 +150,7 @@ func (i *ItBit) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchTicker returns the ticker for a currency pair
func (i *ItBit) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (i *ItBit) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(i.GetName(), p, assetType)
if err != nil {
return i.UpdateTicker(p, assetType)
@@ -159,7 +159,7 @@ func (i *ItBit) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker
}
// FetchOrderbook returns orderbook base on the currency pair
func (i *ItBit) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (i *ItBit) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(i.GetName(), p, assetType)
if err != nil {
return i.UpdateOrderbook(p, assetType)
@@ -168,7 +168,7 @@ func (i *ItBit) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (ord
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (i *ItBit) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (i *ItBit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := i.GetOrderbook(i.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -268,7 +268,7 @@ func (i *ItBit) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (i *ItBit) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (i *ItBit) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -420,7 +420,7 @@ func (i *ItBit) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
var orders []exchange.OrderDetail
for j := range allOrders {
symbol := currency.NewPairDelimiter(allOrders[j].Instrument,
i.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
i.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
side := exchange.OrderSide(strings.ToUpper(allOrders[j].Side))
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
if err != nil {
@@ -471,7 +471,7 @@ func (i *ItBit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
}
symbol := currency.NewPairDelimiter(allOrders[j].Instrument,
i.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
i.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
side := exchange.OrderSide(strings.ToUpper(allOrders[j].Side))
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
if err != nil {

View File

@@ -18,7 +18,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -751,7 +751,7 @@ func (k *Kraken) wsProcessCandles(channelData *WebsocketChannelData, data interf
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (k *Kraken) GenerateDefaultSubscriptions() {
enabledCurrencies := k.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := k.GetEnabledPairs(asset.Spot)
subscriptions := []exchange.WebsocketChannelSubscription{}
for i := range defaultSubscribedChannels {
for j := range enabledCurrencies {

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (k *Kraken) SetDefaults() {
k.API.CredentialsValidator.RequiresBase64DecodeSecret = true
k.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
@@ -140,13 +140,13 @@ func (k *Kraken) Run() {
}
forceUpdate := false
if !common.StringDataContains(k.GetEnabledPairs(assets.AssetTypeSpot).Strings(), "-") ||
!common.StringDataContains(k.GetAvailablePairs(assets.AssetTypeSpot).Strings(), "-") {
if !common.StringDataContains(k.GetEnabledPairs(asset.Spot).Strings(), "-") ||
!common.StringDataContains(k.GetAvailablePairs(asset.Spot).Strings(), "-") {
enabledPairs := currency.NewPairsFromStrings([]string{"XBT-USD"})
log.Warn("WARNING: Available pairs for Kraken reset due to config upgrade, please enable the ones you would like again")
forceUpdate = true
err := k.UpdatePairs(enabledPairs, assets.AssetTypeSpot, true, true)
err := k.UpdatePairs(enabledPairs, asset.Spot, true, true)
if err != nil {
log.Errorf("%s failed to update currencies. Err: %s\n", k.Name, err)
}
@@ -163,7 +163,7 @@ func (k *Kraken) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (k *Kraken) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (k *Kraken) FetchTradablePairs(asset asset.Item) ([]string, error) {
pairs, err := k.GetAssetPairs()
if err != nil {
return nil, err
@@ -191,16 +191,16 @@ func (k *Kraken) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (k *Kraken) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := k.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := k.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return k.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return k.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (k *Kraken) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (k *Kraken) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
pairs := k.GetEnabledPairs(assetType)
pairsCollated, err := k.FormatExchangeCurrencies(pairs, assetType)
@@ -233,7 +233,7 @@ func (k *Kraken) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchTicker returns the ticker for a currency pair
func (k *Kraken) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (k *Kraken) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(k.GetName(), p, assetType)
if err != nil {
return k.UpdateTicker(p, assetType)
@@ -242,7 +242,7 @@ func (k *Kraken) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchOrderbook returns orderbook base on the currency pair
func (k *Kraken) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (k *Kraken) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(k.GetName(), p, assetType)
if err != nil {
return k.UpdateOrderbook(p, assetType)
@@ -251,7 +251,7 @@ func (k *Kraken) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (or
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (k *Kraken) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (k *Kraken) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := k.GetDepth(k.FormatExchangeCurrency(p,
assetType).String())
@@ -313,7 +313,7 @@ func (k *Kraken) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (k *Kraken) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (k *Kraken) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -447,7 +447,7 @@ func (k *Kraken) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
var orders []exchange.OrderDetail
for i := range resp.Open {
symbol := currency.NewPairDelimiter(resp.Open[i].Descr.Pair,
k.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
k.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(int64(resp.Open[i].StartTm), 0)
side := exchange.OrderSide(strings.ToUpper(resp.Open[i].Descr.Type))
@@ -490,7 +490,7 @@ func (k *Kraken) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
var orders []exchange.OrderDetail
for i := range resp.Closed {
symbol := currency.NewPairDelimiter(resp.Closed[i].Descr.Pair,
k.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
k.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(int64(resp.Closed[i].StartTm), 0)
side := exchange.OrderSide(strings.ToUpper(resp.Closed[i].Descr.Type))

View File

@@ -7,7 +7,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
var l LakeBTC
@@ -39,7 +39,7 @@ func TestSetup(t *testing.T) {
func TestFetchTradablePairs(t *testing.T) {
t.Parallel()
_, err := l.FetchTradablePairs(assets.AssetTypeSpot)
_, err := l.FetchTradablePairs(asset.Spot)
if err != nil {
t.Fatalf("Test failed. GetTradablePairs err: %s", err)
}

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (l *LakeBTC) SetDefaults() {
l.API.CredentialsValidator.RequiresSecret = true
l.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
@@ -125,7 +125,7 @@ func (l *LakeBTC) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (l *LakeBTC) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (l *LakeBTC) FetchTradablePairs(asset asset.Item) ([]string, error) {
result, err := l.GetTicker()
if err != nil {
return nil, err
@@ -142,16 +142,16 @@ func (l *LakeBTC) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (l *LakeBTC) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := l.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := l.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return l.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return l.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (l *LakeBTC) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (l *LakeBTC) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := l.GetTicker()
if err != nil {
return ticker.Price{}, err
@@ -177,7 +177,7 @@ func (l *LakeBTC) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tic
}
// FetchTicker returns the ticker for a currency pair
func (l *LakeBTC) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (l *LakeBTC) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(l.GetName(), p, assetType)
if err != nil {
return l.UpdateTicker(p, assetType)
@@ -186,7 +186,7 @@ func (l *LakeBTC) FetchTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchOrderbook returns orderbook base on the currency pair
func (l *LakeBTC) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (l *LakeBTC) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(l.GetName(), p, assetType)
if err != nil {
return l.UpdateOrderbook(p, assetType)
@@ -195,7 +195,7 @@ func (l *LakeBTC) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (o
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (l *LakeBTC) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (l *LakeBTC) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := l.GetOrderBook(p.String())
if err != nil {
@@ -261,7 +261,7 @@ func (l *LakeBTC) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (l *LakeBTC) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (l *LakeBTC) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -394,7 +394,7 @@ func (l *LakeBTC) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
var orders []exchange.OrderDetail
for _, order := range resp {
symbol := currency.NewPairDelimiter(order.Symbol, l.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
symbol := currency.NewPairDelimiter(order.Symbol, l.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(order.At, 0)
side := exchange.OrderSide(strings.ToUpper(order.Type))
@@ -431,7 +431,7 @@ func (l *LakeBTC) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
}
symbol := currency.NewPairDelimiter(order.Symbol,
l.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
l.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(order.At, 0)
side := exchange.OrderSide(strings.ToUpper(order.Type))

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -52,8 +52,8 @@ func (l *LocalBitcoins) SetDefaults() {
l.API.CredentialsValidator.RequiresSecret = true
l.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
@@ -126,7 +126,7 @@ func (l *LocalBitcoins) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (l *LocalBitcoins) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (l *LocalBitcoins) FetchTradablePairs(asset asset.Item) ([]string, error) {
currencies, err := l.GetTradableCurrencies()
if err != nil {
return nil, err
@@ -143,16 +143,16 @@ func (l *LocalBitcoins) FetchTradablePairs(asset assets.AssetType) ([]string, er
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (l *LocalBitcoins) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := l.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := l.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return l.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return l.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (l *LocalBitcoins) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (l *LocalBitcoins) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := l.GetTicker()
if err != nil {
@@ -176,7 +176,7 @@ func (l *LocalBitcoins) UpdateTicker(p currency.Pair, assetType assets.AssetType
}
// FetchTicker returns the ticker for a currency pair
func (l *LocalBitcoins) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (l *LocalBitcoins) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(l.GetName(), p, assetType)
if err != nil {
return l.UpdateTicker(p, assetType)
@@ -185,7 +185,7 @@ func (l *LocalBitcoins) FetchTicker(p currency.Pair, assetType assets.AssetType)
}
// FetchOrderbook returns orderbook base on the currency pair
func (l *LocalBitcoins) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (l *LocalBitcoins) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(l.GetName(), p, assetType)
if err != nil {
return l.UpdateOrderbook(p, assetType)
@@ -194,7 +194,7 @@ func (l *LocalBitcoins) FetchOrderbook(p currency.Pair, assetType assets.AssetTy
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (l *LocalBitcoins) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (l *LocalBitcoins) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := l.GetOrderbook(p.Quote.String())
if err != nil {
@@ -250,7 +250,7 @@ func (l *LocalBitcoins) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (l *LocalBitcoins) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (l *LocalBitcoins) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -443,7 +443,7 @@ func (l *LocalBitcoins) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequ
OrderSide: side,
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
resp[i].Data.Currency,
l.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
l.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
Exchange: l.Name,
})
}
@@ -516,7 +516,7 @@ func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequ
Status: status,
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
allTrades[i].Data.Currency,
l.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
l.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
Exchange: l.Name,
})
}

View File

@@ -8,7 +8,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/request"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -49,9 +49,9 @@ func (o *OKCoin) SetDefaults() {
o.API.CredentialsValidator.RequiresClientID = true
o.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
assets.AssetTypeMargin,
AssetTypes: asset.Items{
asset.Spot,
asset.Margin,
},
UseGlobalFormat: true,
@@ -127,7 +127,7 @@ func (o *OKCoin) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (o *OKCoin) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (o *OKCoin) FetchTradablePairs(asset asset.Item) ([]string, error) {
prods, err := o.GetSpotTokenPairDetails()
if err != nil {
return nil, err
@@ -144,11 +144,11 @@ func (o *OKCoin) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (o *OKCoin) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := o.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := o.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return o.UpdatePairs(currency.NewPairsFromStrings(pairs),
assets.AssetTypeSpot, false, forceUpdate)
asset.Spot, false, forceUpdate)
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/request"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -49,11 +49,11 @@ func (o *OKEX) SetDefaults() {
o.API.CredentialsValidator.RequiresClientID = true
o.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
assets.AssetTypeFutures,
assets.AssetTypePerpetualSwap,
assets.AssetTypeIndex,
AssetTypes: asset.Items{
asset.Spot,
asset.Futures,
asset.PerpetualSwap,
asset.Index,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -127,10 +127,10 @@ func (o *OKEX) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (o *OKEX) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (o *OKEX) FetchTradablePairs(i asset.Item) ([]string, error) {
var pairs []string
switch asset {
case assets.AssetTypeSpot:
switch i {
case asset.Spot:
prods, err := o.GetSpotTokenPairDetails()
if err != nil {
return nil, err
@@ -140,7 +140,7 @@ func (o *OKEX) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
pairs = append(pairs, prods[x].BaseCurrency+"_"+prods[x].QuoteCurrency)
}
return pairs, nil
case assets.AssetTypeFutures:
case asset.Futures:
prods, err := o.GetFuturesContractInformation()
if err != nil {
return nil, err
@@ -152,7 +152,7 @@ func (o *OKEX) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
}
return pairs, nil
case assets.AssetTypePerpetualSwap:
case asset.PerpetualSwap:
prods, err := o.GetSwapContractInformation()
if err != nil {
return nil, err
@@ -163,7 +163,7 @@ func (o *OKEX) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
pairs = append(pairs, prods[x].UnderlyingIndex+"_"+prods[x].QuoteCurrency+"_SWAP")
}
return pairs, nil
case assets.AssetTypeIndex:
case asset.Index:
return []string{"BTC_USD"}, nil
}

View File

@@ -16,7 +16,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/currency"
@@ -363,9 +363,9 @@ func (o *OKGroup) GetWsChannelWithoutOrderType(table string) string {
// GetAssetTypeFromTableName gets the asset type from the table name
// eg "spot/ticker:BTCUSD" results in "SPOT"
func (o *OKGroup) GetAssetTypeFromTableName(table string) assets.AssetType {
func (o *OKGroup) GetAssetTypeFromTableName(table string) asset.Item {
assetIndex := strings.Index(table, "/")
return assets.AssetType(strings.ToUpper(table[:assetIndex]))
return asset.Item(strings.ToUpper(table[:assetIndex]))
}
// WsHandleDataResponse classifies the WS response and sends to appropriate handler
@@ -683,7 +683,7 @@ func (o *OKGroup) CalculateUpdateOrderbookChecksum(orderbookData *orderbook.Base
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
func (o *OKGroup) GenerateDefaultSubscriptions() {
enabledCurrencies := o.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := o.GetEnabledPairs(asset.Spot)
subscriptions := []exchange.WebsocketChannelSubscription{}
for i := range defaultSubscribedChannels {
for j := range enabledCurrencies {

View File

@@ -9,7 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
log "github.com/thrasher-/gocryptotrader/logger"
@@ -42,7 +42,7 @@ func (o *OKGroup) Setup(exch *config.ExchangeConfig) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (o *OKGroup) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tickerData ticker.Price, err error) {
func (o *OKGroup) UpdateTicker(p currency.Pair, assetType asset.Item) (tickerData ticker.Price, err error) {
resp, err := o.GetSpotAllTokenPairsInformationForCurrency(o.FormatExchangeCurrency(p, assetType).String())
if err != nil {
return
@@ -63,7 +63,7 @@ func (o *OKGroup) UpdateTicker(p currency.Pair, assetType assets.AssetType) (tic
}
// FetchTicker returns the ticker for a currency pair
func (o *OKGroup) FetchTicker(p currency.Pair, assetType assets.AssetType) (tickerData ticker.Price, err error) {
func (o *OKGroup) FetchTicker(p currency.Pair, assetType asset.Item) (tickerData ticker.Price, err error) {
tickerData, err = ticker.GetTicker(o.GetName(), p, assetType)
if err != nil {
return o.UpdateTicker(p, assetType)
@@ -72,7 +72,7 @@ func (o *OKGroup) FetchTicker(p currency.Pair, assetType assets.AssetType) (tick
}
// FetchOrderbook returns orderbook base on the currency pair
func (o *OKGroup) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (resp orderbook.Base, err error) {
func (o *OKGroup) FetchOrderbook(p currency.Pair, assetType asset.Item) (resp orderbook.Base, err error) {
ob, err := orderbook.Get(o.GetName(), p, assetType)
if err != nil {
return o.UpdateOrderbook(p, assetType)
@@ -81,7 +81,7 @@ func (o *OKGroup) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (r
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (o *OKGroup) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (resp orderbook.Base, err error) {
func (o *OKGroup) UpdateOrderbook(p currency.Pair, assetType asset.Item) (resp orderbook.Base, err error) {
orderbookNew, err := o.GetSpotOrderBook(GetSpotOrderBookRequest{
InstrumentID: o.FormatExchangeCurrency(p, assetType).String(),
})
@@ -201,7 +201,7 @@ func (o *OKGroup) GetFundingHistory() (resp []exchange.FundHistory, err error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (o *OKGroup) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (o *OKGroup) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -218,7 +218,7 @@ func (o *OKGroup) SubmitOrder(order *exchange.OrderSubmission) (resp exchange.Su
request := PlaceSpotOrderRequest{
ClientOID: order.ClientID,
InstrumentID: o.FormatExchangeCurrency(order.Pair, assets.AssetTypeSpot).String(),
InstrumentID: o.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
Side: strings.ToLower(order.OrderSide.ToString()),
Type: strings.ToLower(order.OrderType.ToString()),
Size: strconv.FormatFloat(order.Amount, 'f', -1, 64),
@@ -251,7 +251,7 @@ func (o *OKGroup) CancelOrder(orderCancellation *exchange.OrderCancellation) (er
}
orderCancellationResponse, err := o.CancelSpotOrder(CancelSpotOrderRequest{
InstrumentID: o.FormatExchangeCurrency(orderCancellation.CurrencyPair,
assets.AssetTypeSpot).String(),
asset.Spot).String(),
OrderID: orderID,
})
if !orderCancellationResponse.Result {
@@ -277,7 +277,7 @@ func (o *OKGroup) CancelAllOrders(orderCancellation *exchange.OrderCancellation)
cancelOrdersResponse, err := o.CancelMultipleSpotOrders(CancelMultipleSpotOrdersRequest{
InstrumentID: o.FormatExchangeCurrency(orderCancellation.CurrencyPair,
assets.AssetTypeSpot).String(),
asset.Spot).String(),
OrderIDs: orderIDNumbers,
})
if err != nil {
@@ -302,7 +302,7 @@ func (o *OKGroup) GetOrderInfo(orderID string) (resp exchange.OrderDetail, err e
resp = exchange.OrderDetail{
Amount: order.Size,
CurrencyPair: currency.NewPairDelimiter(order.InstrumentID,
o.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter),
o.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter),
Exchange: o.Name,
OrderDate: order.Timestamp,
ExecutedAmount: order.FilledSize,
@@ -359,7 +359,7 @@ func (o *OKGroup) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
for _, currency := range getOrdersRequest.Currencies {
spotOpenOrders, err := o.GetSpotOpenOrders(GetSpotOpenOrdersRequest{
InstrumentID: o.FormatExchangeCurrency(currency,
assets.AssetTypeSpot).String(),
asset.Spot).String(),
})
if err != nil {
return resp, err
@@ -390,7 +390,7 @@ func (o *OKGroup) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
spotOpenOrders, err := o.GetSpotOrders(GetSpotOrdersRequest{
Status: strings.Join([]string{"filled", "cancelled", "failure"}, "|"),
InstrumentID: o.FormatExchangeCurrency(currency,
assets.AssetTypeSpot).String(),
asset.Spot).String(),
})
if err != nil {
return resp, err

View File

@@ -8,7 +8,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// vars related to orders
@@ -153,7 +153,7 @@ type OrderCancellation struct {
AccountID string
OrderID string
CurrencyPair currency.Pair
AssetType assets.AssetType
AssetType asset.Item
WalletAddress string
Side OrderSide
}

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// Const values for orderbook package
@@ -31,17 +31,17 @@ type Item struct {
// Base holds the fields for the orderbook base
type Base struct {
Pair currency.Pair `json:"pair"`
Bids []Item `json:"bids"`
Asks []Item `json:"asks"`
LastUpdated time.Time `json:"lastUpdated"`
AssetType assets.AssetType `json:"assetType"`
ExchangeName string `json:"exchangeName"`
Pair currency.Pair `json:"pair"`
Bids []Item `json:"bids"`
Asks []Item `json:"asks"`
LastUpdated time.Time `json:"lastUpdated"`
AssetType asset.Item `json:"assetType"`
ExchangeName string `json:"exchangeName"`
}
// Orderbook holds the orderbook information for a currency pair and type
type Orderbook struct {
Orderbook map[*currency.Item]map[*currency.Item]map[assets.AssetType]Base
Orderbook map[*currency.Item]map[*currency.Item]map[asset.Item]Base
ExchangeName string
}
@@ -74,7 +74,7 @@ func (o *Base) Update(bids, asks []Item) {
// Get checks and returns the orderbook given an exchange name and currency pair
// if it exists
func Get(exchange string, p currency.Pair, orderbookType assets.AssetType) (Base, error) {
func Get(exchange string, p currency.Pair, orderbookType asset.Item) (Base, error) {
orderbook, err := GetByExchange(exchange)
if err != nil {
return Base{}, err
@@ -136,14 +136,14 @@ func QuoteCurrencyExists(exchange string, p currency.Pair) bool {
}
// CreateNewOrderbook creates a new orderbook
func CreateNewOrderbook(exchangeName string, orderbookNew *Base, orderbookType assets.AssetType) *Orderbook {
func CreateNewOrderbook(exchangeName string, orderbookNew *Base, orderbookType asset.Item) *Orderbook {
m.Lock()
defer m.Unlock()
orderbook := Orderbook{}
orderbook.ExchangeName = exchangeName
orderbook.Orderbook = make(map[*currency.Item]map[*currency.Item]map[assets.AssetType]Base)
a := make(map[*currency.Item]map[assets.AssetType]Base)
b := make(map[assets.AssetType]Base)
orderbook.Orderbook = make(map[*currency.Item]map[*currency.Item]map[asset.Item]Base)
a := make(map[*currency.Item]map[asset.Item]Base)
b := make(map[asset.Item]Base)
b[orderbookType] = *orderbookNew
a[orderbookNew.Pair.Quote.Item] = b
orderbook.Orderbook[orderbookNew.Pair.Base.Item] = a
@@ -174,7 +174,7 @@ func (o *Base) Process() error {
if BaseCurrencyExists(o.ExchangeName, o.Pair.Base) {
m.Lock()
a := make(map[assets.AssetType]Base)
a := make(map[asset.Item]Base)
a[o.AssetType] = *o
orderbook.Orderbook[o.Pair.Base.Item][o.Pair.Quote.Item] = a
m.Unlock()
@@ -182,8 +182,8 @@ func (o *Base) Process() error {
}
m.Lock()
a := make(map[*currency.Item]map[assets.AssetType]Base)
b := make(map[assets.AssetType]Base)
a := make(map[*currency.Item]map[asset.Item]Base)
b := make(map[asset.Item]Base)
b[o.AssetType] = *o
a[o.Pair.Quote.Item] = b
orderbook.Orderbook[o.Pair.Base.Item] = a

View File

@@ -8,7 +8,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -80,9 +80,9 @@ func TestGetOrderbook(t *testing.T) {
Bids: []Item{{Price: 200, Amount: 10}},
}
CreateNewOrderbook("Exchange", &base, assets.AssetTypeSpot)
CreateNewOrderbook("Exchange", &base, asset.Spot)
result, err := Get("Exchange", c, assets.AssetTypeSpot)
result, err := Get("Exchange", c, asset.Spot)
if err != nil {
t.Fatalf("Test failed. TestGetOrderbook failed to get orderbook. Error %s",
err)
@@ -91,19 +91,19 @@ func TestGetOrderbook(t *testing.T) {
t.Fatal("Test failed. TestGetOrderbook failed. Mismatched pairs")
}
_, err = Get("nonexistent", c, assets.AssetTypeSpot)
_, err = Get("nonexistent", c, asset.Spot)
if err == nil {
t.Fatal("Test failed. TestGetOrderbook retrieved non-existent orderbook")
}
c.Base = currency.NewCode("blah")
_, err = Get("Exchange", c, assets.AssetTypeSpot)
_, err = Get("Exchange", c, asset.Spot)
if err == nil {
t.Fatal("Test failed. TestGetOrderbook retrieved non-existent orderbook using invalid first currency")
}
newCurrency := currency.NewPairFromStrings("BTC", "AUD")
_, err = Get("Exchange", newCurrency, assets.AssetTypeSpot)
_, err = Get("Exchange", newCurrency, asset.Spot)
if err == nil {
t.Fatal("Test failed. TestGetOrderbook retrieved non-existent orderbook using invalid second currency")
}
@@ -117,7 +117,7 @@ func TestGetOrderbookByExchange(t *testing.T) {
Bids: []Item{{Price: 200, Amount: 10}},
}
CreateNewOrderbook("Exchange", &base, assets.AssetTypeSpot)
CreateNewOrderbook("Exchange", &base, asset.Spot)
_, err := GetByExchange("Exchange")
if err != nil {
@@ -139,7 +139,7 @@ func TestFirstCurrencyExists(t *testing.T) {
Bids: []Item{{Price: 200, Amount: 10}},
}
CreateNewOrderbook("Exchange", &base, assets.AssetTypeSpot)
CreateNewOrderbook("Exchange", &base, asset.Spot)
if !BaseCurrencyExists("Exchange", c.Base) {
t.Fatal("Test failed. TestFirstCurrencyExists expected first currency doesn't exist")
@@ -159,7 +159,7 @@ func TestSecondCurrencyExists(t *testing.T) {
Bids: []Item{{Price: 200, Amount: 10}},
}
CreateNewOrderbook("Exchange", &base, assets.AssetTypeSpot)
CreateNewOrderbook("Exchange", &base, asset.Spot)
if !QuoteCurrencyExists("Exchange", c) {
t.Fatal("Test failed. TestSecondCurrencyExists expected first currency doesn't exist")
@@ -179,9 +179,9 @@ func TestCreateNewOrderbook(t *testing.T) {
Bids: []Item{{Price: 200, Amount: 10}},
}
CreateNewOrderbook("Exchange", &base, assets.AssetTypeSpot)
CreateNewOrderbook("Exchange", &base, asset.Spot)
result, err := Get("Exchange", c, assets.AssetTypeSpot)
result, err := Get("Exchange", c, asset.Spot)
if err != nil {
t.Fatal("Test failed. TestCreateNewOrderbook failed to create new orderbook")
}
@@ -209,7 +209,7 @@ func TestProcessOrderbook(t *testing.T) {
Asks: []Item{{Price: 100, Amount: 10}},
Bids: []Item{{Price: 200, Amount: 10}},
ExchangeName: "Exchange",
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
}
err := base.Process()
@@ -217,7 +217,7 @@ func TestProcessOrderbook(t *testing.T) {
t.Error("Test Failed - Process() error", err)
}
result, err := Get("Exchange", c, assets.AssetTypeSpot)
result, err := Get("Exchange", c, asset.Spot)
if err != nil {
t.Fatal("Test failed. TestProcessOrderbook failed to create new orderbook")
}
@@ -234,7 +234,7 @@ func TestProcessOrderbook(t *testing.T) {
t.Error("Test Failed - Process() error", err)
}
result, err = Get("Exchange", c, assets.AssetTypeSpot)
result, err = Get("Exchange", c, asset.Spot)
if err != nil {
t.Fatal("Test failed. TestProcessOrderbook failed to retrieve new orderbook")
}
@@ -311,7 +311,7 @@ func TestProcessOrderbook(t *testing.T) {
Asks: asks,
Bids: bids,
ExchangeName: newName,
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
}
m.Lock()
@@ -338,7 +338,7 @@ func TestProcessOrderbook(t *testing.T) {
wg.Add(1)
fatalErr := false
go func(test quick) {
result, err := Get(test.Name, test.P, assets.AssetTypeSpot)
result, err := Get(test.Name, test.P, asset.Spot)
if err != nil {
fatalErr = true
return

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -163,7 +163,7 @@ func (p *Poloniex) WsHandleData() {
Timestamp: time.Now(),
Pair: currency.NewPairDelimiter(currencyPair, "_"),
Exchange: p.GetName(),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
ClosePrice: t.LastPrice,
LowPrice: t.LowestAsk,
HighPrice: t.HighestBid,
@@ -201,7 +201,7 @@ func (p *Poloniex) WsHandleData() {
p.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Exchange: p.GetName(),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Pair: currency.NewPairFromString(currencyPair),
}
case "o":
@@ -214,7 +214,7 @@ func (p *Poloniex) WsHandleData() {
p.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Exchange: p.GetName(),
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Pair: currency.NewPairFromString(currencyPair),
}
case "t":
@@ -292,7 +292,7 @@ func (p *Poloniex) WsProcessOrderbookSnapshot(ob []interface{}, symbol string) e
var newOrderBook orderbook.Base
newOrderBook.Asks = asks
newOrderBook.Bids = bids
newOrderBook.AssetType = assets.AssetTypeSpot
newOrderBook.AssetType = asset.Spot
newOrderBook.LastUpdated = time.Now()
newOrderBook.Pair = currency.NewPairFromString(symbol)
@@ -321,7 +321,7 @@ func (p *Poloniex) WsProcessOrderbookUpdate(target []interface{}, symbol string)
cP,
time.Now(),
p.GetName(),
assets.AssetTypeSpot)
asset.Spot)
}
return p.Websocket.Orderbook.Update([]orderbook.Item{{Price: price, Amount: volume}},
@@ -329,7 +329,7 @@ func (p *Poloniex) WsProcessOrderbookUpdate(target []interface{}, symbol string)
cP,
time.Now(),
p.GetName(),
assets.AssetTypeSpot)
asset.Spot)
}
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
@@ -340,7 +340,7 @@ func (p *Poloniex) GenerateDefaultSubscriptions() {
Channel: fmt.Sprintf("%v", wsTickerDataID),
})
enabledCurrencies := p.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := p.GetEnabledPairs(asset.Spot)
for j := range enabledCurrencies {
enabledCurrencies[j].Delimiter = "_"
subscriptions = append(subscriptions, exchange.WebsocketChannelSubscription{

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -50,8 +50,8 @@ func (p *Poloniex) SetDefaults() {
p.API.CredentialsValidator.RequiresSecret = true
p.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -134,7 +134,7 @@ func (p *Poloniex) Run() {
}
forceUpdate := false
if common.StringDataCompare(p.GetAvailablePairs(assets.AssetTypeSpot).Strings(), "BTC_USDT") {
if common.StringDataCompare(p.GetAvailablePairs(asset.Spot).Strings(), "BTC_USDT") {
log.Warnf("%s contains invalid pair, forcing upgrade of available currencies.\n",
p.Name)
forceUpdate = true
@@ -151,7 +151,7 @@ func (p *Poloniex) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (p *Poloniex) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (p *Poloniex) FetchTradablePairs(asset asset.Item) ([]string, error) {
resp, err := p.GetTicker()
if err != nil {
return nil, err
@@ -168,16 +168,16 @@ func (p *Poloniex) FetchTradablePairs(asset assets.AssetType) ([]string, error)
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (p *Poloniex) UpdateTradablePairs(forceUpgrade bool) error {
pairs, err := p.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := p.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return p.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpgrade)
return p.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpgrade)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (p *Poloniex) UpdateTicker(currencyPair currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (p *Poloniex) UpdateTicker(currencyPair currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := p.GetTicker()
if err != nil {
@@ -204,7 +204,7 @@ func (p *Poloniex) UpdateTicker(currencyPair currency.Pair, assetType assets.Ass
}
// FetchTicker returns the ticker for a currency pair
func (p *Poloniex) FetchTicker(currencyPair currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (p *Poloniex) FetchTicker(currencyPair currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(p.GetName(), currencyPair, assetType)
if err != nil {
return p.UpdateTicker(currencyPair, assetType)
@@ -213,7 +213,7 @@ func (p *Poloniex) FetchTicker(currencyPair currency.Pair, assetType assets.Asse
}
// FetchOrderbook returns orderbook base on the currency pair
func (p *Poloniex) FetchOrderbook(currencyPair currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (p *Poloniex) FetchOrderbook(currencyPair currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(p.GetName(), currencyPair, assetType)
if err != nil {
return p.UpdateOrderbook(currencyPair, assetType)
@@ -222,7 +222,7 @@ func (p *Poloniex) FetchOrderbook(currencyPair currency.Pair, assetType assets.A
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (p *Poloniex) UpdateOrderbook(currencyPair currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (p *Poloniex) UpdateOrderbook(currencyPair currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := p.GetOrderbook("", 1000)
if err != nil {
@@ -297,7 +297,7 @@ func (p *Poloniex) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (p *Poloniex) GetExchangeHistory(currencyPair currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (p *Poloniex) GetExchangeHistory(currencyPair currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -446,7 +446,7 @@ func (p *Poloniex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest)
var orders []exchange.OrderDetail
for currencyPair, openOrders := range resp.Data {
symbol := currency.NewPairDelimiter(currencyPair,
p.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
p.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
for _, order := range openOrders {
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
@@ -488,7 +488,7 @@ func (p *Poloniex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
var orders []exchange.OrderDetail
for currencyPair, historicOrders := range resp.Data {
symbol := currency.NewPairDelimiter(currencyPair,
p.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
p.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
for _, order := range historicOrders {
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))

View File

@@ -4,14 +4,14 @@ import (
"sort"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// Item holds various fields for storing currency pair stats
type Item struct {
Exchange string
Pair currency.Pair
AssetType assets.AssetType
AssetType asset.Item
Price float64
Volume float64
}
@@ -50,7 +50,7 @@ func (b ByVolume) Swap(i, j int) {
}
// Add adds or updates the item stats
func Add(exchange string, p currency.Pair, assetType assets.AssetType, price, volume float64) {
func Add(exchange string, p currency.Pair, assetType asset.Item, price, volume float64) {
if exchange == "" ||
assetType == "" ||
price == 0 ||
@@ -75,7 +75,7 @@ func Add(exchange string, p currency.Pair, assetType assets.AssetType, price, vo
// Append adds or updates the item stats for a specific
// currency pair and asset type
func Append(exchange string, p currency.Pair, assetType assets.AssetType, price, volume float64) {
func Append(exchange string, p currency.Pair, assetType asset.Item, price, volume float64) {
if AlreadyExists(exchange, p, assetType, price, volume) {
return
}
@@ -93,7 +93,7 @@ func Append(exchange string, p currency.Pair, assetType assets.AssetType, price,
// AlreadyExists checks to see if item info already exists
// for a specific currency pair and asset type
func AlreadyExists(exchange string, p currency.Pair, assetType assets.AssetType, price, volume float64) bool {
func AlreadyExists(exchange string, p currency.Pair, assetType asset.Item, price, volume float64) bool {
for i := range Items {
if Items[i].Exchange == exchange &&
Items[i].Pair.EqualIncludeReciprocal(p) &&
@@ -108,7 +108,7 @@ func AlreadyExists(exchange string, p currency.Pair, assetType assets.AssetType,
// SortExchangesByVolume sorts item info by volume for a specific
// currency pair and asset type. Reverse will reverse the order from lowest to
// highest
func SortExchangesByVolume(p currency.Pair, assetType assets.AssetType, reverse bool) []Item {
func SortExchangesByVolume(p currency.Pair, assetType asset.Item, reverse bool) []Item {
var result []Item
for x := range Items {
if Items[x].Pair.EqualIncludeReciprocal(p) &&
@@ -128,7 +128,7 @@ func SortExchangesByVolume(p currency.Pair, assetType assets.AssetType, reverse
// SortExchangesByPrice sorts item info by volume for a specific
// currency pair and asset type. Reverse will reverse the order from lowest to
// highest
func SortExchangesByPrice(p currency.Pair, assetType assets.AssetType, reverse bool) []Item {
func SortExchangesByPrice(p currency.Pair, assetType asset.Item, reverse bool) []Item {
var result []Item
for x := range Items {
if Items[x].Pair.EqualIncludeReciprocal(p) &&

View File

@@ -4,7 +4,7 @@ import (
"testing"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
func TestLenByPrice(t *testing.T) {
@@ -13,7 +13,7 @@ func TestLenByPrice(t *testing.T) {
{
Exchange: "ANX",
Pair: p,
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Price: 1200,
Volume: 5,
},
@@ -31,14 +31,14 @@ func TestLessByPrice(t *testing.T) {
{
Exchange: "alphapoint",
Pair: p,
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Price: 1200,
Volume: 5,
},
{
Exchange: "bitfinex",
Pair: p,
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Price: 1198,
Volume: 20,
},
@@ -59,14 +59,14 @@ func TestSwapByPrice(t *testing.T) {
{
Exchange: "bitstamp",
Pair: p,
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Price: 1324,
Volume: 5,
},
{
Exchange: "bitfinex",
Pair: p,
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Price: 7863,
Volume: 20,
},
@@ -104,7 +104,7 @@ func TestSwapByVolume(t *testing.T) {
func TestAdd(t *testing.T) {
Items = Items[:0]
p := currency.NewPairFromStrings("BTC", "USD")
Add("ANX", p, assets.AssetTypeSpot, 1200, 42)
Add("ANX", p, asset.Spot, 1200, 42)
if len(Items) < 1 {
t.Error("Test Failed - stats Add did not add exchange info.")
@@ -117,14 +117,14 @@ func TestAdd(t *testing.T) {
}
p.Base = currency.XBT
Add("ANX", p, assets.AssetTypeSpot, 1201, 43)
Add("ANX", p, asset.Spot, 1201, 43)
if Items[1].Pair.String() != "XBTUSD" {
t.Fatal("Test failed. stats Add did not add exchange info.")
}
p = currency.NewPairFromStrings("ETH", "USDT")
Add("ANX", p, assets.AssetTypeSpot, 300, 1000)
Add("ANX", p, asset.Spot, 300, 1000)
if Items[2].Pair.String() != "ETHUSD" {
t.Fatal("Test failed. stats Add did not add exchange info.")
@@ -133,12 +133,12 @@ func TestAdd(t *testing.T) {
func TestAppend(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
Append("sillyexchange", p, assets.AssetTypeSpot, 1234, 45)
Append("sillyexchange", p, asset.Spot, 1234, 45)
if len(Items) < 2 {
t.Error("Test Failed - stats Append did not add exchange values.")
}
Append("sillyexchange", p, assets.AssetTypeSpot, 1234, 45)
Append("sillyexchange", p, asset.Spot, 1234, 45)
if len(Items) == 3 {
t.Error("Test Failed - stats Append added exchange values")
}
@@ -146,23 +146,23 @@ func TestAppend(t *testing.T) {
func TestAlreadyExists(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
if !AlreadyExists("ANX", p, assets.AssetTypeSpot, 1200, 42) {
if !AlreadyExists("ANX", p, asset.Spot, 1200, 42) {
t.Error("Test Failed - stats AlreadyExists exchange does not exist.")
}
p.Base = currency.NewCode("dii")
if AlreadyExists("bla", p, assets.AssetTypeSpot, 1234, 123) {
if AlreadyExists("bla", p, asset.Spot, 1234, 123) {
t.Error("Test Failed - stats AlreadyExists found incorrect exchange.")
}
}
func TestSortExchangesByVolume(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
topVolume := SortExchangesByVolume(p, assets.AssetTypeSpot, true)
topVolume := SortExchangesByVolume(p, asset.Spot, true)
if topVolume[0].Exchange != "sillyexchange" {
t.Error("Test Failed - stats SortExchangesByVolume incorrectly sorted values.")
}
topVolume = SortExchangesByVolume(p, assets.AssetTypeSpot, false)
topVolume = SortExchangesByVolume(p, asset.Spot, false)
if topVolume[0].Exchange != "ANX" {
t.Error("Test Failed - stats SortExchangesByVolume incorrectly sorted values.")
}
@@ -170,12 +170,12 @@ func TestSortExchangesByVolume(t *testing.T) {
func TestSortExchangesByPrice(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
topPrice := SortExchangesByPrice(p, assets.AssetTypeSpot, true)
topPrice := SortExchangesByPrice(p, asset.Spot, true)
if topPrice[0].Exchange != "sillyexchange" {
t.Error("Test Failed - stats SortExchangesByPrice incorrectly sorted values.")
}
topPrice = SortExchangesByPrice(p, assets.AssetTypeSpot, false)
topPrice = SortExchangesByPrice(p, asset.Spot, false)
if topPrice[0].Exchange != "ANX" {
t.Error("Test Failed - stats SortExchangesByPrice incorrectly sorted values.")
}

View File

@@ -8,7 +8,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
// Const values for the ticker package
@@ -44,7 +44,7 @@ type Ticker struct {
}
// PriceToString returns the string version of a stored price field
func (t *Ticker) PriceToString(p currency.Pair, priceType string, tickerType assets.AssetType) string {
func (t *Ticker) PriceToString(p currency.Pair, priceType string, tickerType asset.Item) string {
priceType = strings.ToLower(priceType)
switch priceType {
@@ -68,7 +68,7 @@ func (t *Ticker) PriceToString(p currency.Pair, priceType string, tickerType ass
}
// GetTicker checks and returns a requested ticker if it exists
func GetTicker(exchange string, p currency.Pair, tickerType assets.AssetType) (Price, error) {
func GetTicker(exchange string, p currency.Pair, tickerType asset.Item) (Price, error) {
ticker, err := GetTickerByExchange(exchange)
if err != nil {
return Price{}, err
@@ -130,7 +130,7 @@ func SecondCurrencyExists(exchange string, p currency.Pair) bool {
}
// CreateNewTicker creates a new Ticker
func CreateNewTicker(exchangeName string, tickerNew *Price, tickerType assets.AssetType) Ticker {
func CreateNewTicker(exchangeName string, tickerNew *Price, tickerType asset.Item) Ticker {
m.Lock()
defer m.Unlock()
ticker := Ticker{}
@@ -147,7 +147,7 @@ func CreateNewTicker(exchangeName string, tickerNew *Price, tickerType assets.As
// ProcessTicker processes incoming tickers, creating or updating the Tickers
// list
func ProcessTicker(exchangeName string, tickerNew *Price, tickerType assets.AssetType) error {
func ProcessTicker(exchangeName string, tickerNew *Price, tickerType asset.Item) error {
if tickerNew.Pair.String() == "" {
return errors.New("")
}

View File

@@ -9,7 +9,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -26,30 +26,30 @@ func TestPriceToString(t *testing.T) {
PriceATH: 1337,
}
newTicker := CreateNewTicker("ANX", &priceStruct, assets.AssetTypeSpot)
newTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
if newTicker.PriceToString(newPair, "last", assets.AssetTypeSpot) != "1200" {
if newTicker.PriceToString(newPair, "last", asset.Spot) != "1200" {
t.Error("Test Failed - ticker PriceToString last value is incorrect")
}
if newTicker.PriceToString(newPair, "high", assets.AssetTypeSpot) != "1298" {
if newTicker.PriceToString(newPair, "high", asset.Spot) != "1298" {
t.Error("Test Failed - ticker PriceToString high value is incorrect")
}
if newTicker.PriceToString(newPair, "low", assets.AssetTypeSpot) != "1148" {
if newTicker.PriceToString(newPair, "low", asset.Spot) != "1148" {
t.Error("Test Failed - ticker PriceToString low value is incorrect")
}
if newTicker.PriceToString(newPair, "bid", assets.AssetTypeSpot) != "1195" {
if newTicker.PriceToString(newPair, "bid", asset.Spot) != "1195" {
t.Error("Test Failed - ticker PriceToString bid value is incorrect")
}
if newTicker.PriceToString(newPair, "ask", assets.AssetTypeSpot) != "1220" {
if newTicker.PriceToString(newPair, "ask", asset.Spot) != "1220" {
t.Error("Test Failed - ticker PriceToString ask value is incorrect")
}
if newTicker.PriceToString(newPair, "volume", assets.AssetTypeSpot) != "5" {
if newTicker.PriceToString(newPair, "volume", asset.Spot) != "5" {
t.Error("Test Failed - ticker PriceToString volume value is incorrect")
}
if newTicker.PriceToString(newPair, "ath", assets.AssetTypeSpot) != "1337" {
if newTicker.PriceToString(newPair, "ath", asset.Spot) != "1337" {
t.Error("Test Failed - ticker PriceToString ath value is incorrect")
}
if newTicker.PriceToString(newPair, "obtuse", assets.AssetTypeSpot) != "" {
if newTicker.PriceToString(newPair, "obtuse", asset.Spot) != "" {
t.Error("Test Failed - ticker PriceToString obtuse value is incorrect")
}
}
@@ -67,12 +67,12 @@ func TestGetTicker(t *testing.T) {
PriceATH: 1337,
}
err := ProcessTicker("bitfinex", &priceStruct, assets.AssetTypeSpot)
err := ProcessTicker("bitfinex", &priceStruct, asset.Spot)
if err != nil {
t.Fatal("Test failed. ProcessTicker error", err)
}
tickerPrice, err := GetTicker("bitfinex", newPair, assets.AssetTypeSpot)
tickerPrice, err := GetTicker("bitfinex", newPair, asset.Spot)
if err != nil {
t.Errorf("Test Failed - Ticker GetTicker init error: %s", err)
}
@@ -80,19 +80,19 @@ func TestGetTicker(t *testing.T) {
t.Error("Test Failed - ticker tickerPrice.CurrencyPair value is incorrect")
}
_, err = GetTicker("blah", newPair, assets.AssetTypeSpot)
_, err = GetTicker("blah", newPair, asset.Spot)
if err == nil {
t.Fatal("Test Failed. TestGetTicker returned nil error on invalid exchange")
}
newPair.Base = currency.ETH
_, err = GetTicker("bitfinex", newPair, assets.AssetTypeSpot)
_, err = GetTicker("bitfinex", newPair, asset.Spot)
if err == nil {
t.Fatal("Test Failed. TestGetTicker returned ticker for invalid first currency")
}
btcltcPair := currency.NewPairFromStrings("BTC", "LTC")
_, err = GetTicker("bitfinex", btcltcPair, assets.AssetTypeSpot)
_, err = GetTicker("bitfinex", btcltcPair, asset.Spot)
if err == nil {
t.Fatal("Test Failed. TestGetTicker returned ticker for invalid second currency")
}
@@ -127,7 +127,7 @@ func TestGetTickerByExchange(t *testing.T) {
PriceATH: 1337,
}
anxTicker := CreateNewTicker("ANX", &priceStruct, assets.AssetTypeSpot)
anxTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
Tickers = append(Tickers, anxTicker)
tickerPtr, err := GetTickerByExchange("ANX")
@@ -152,7 +152,7 @@ func TestFirstCurrencyExists(t *testing.T) {
PriceATH: 1337,
}
alphaTicker := CreateNewTicker("alphapoint", &priceStruct, assets.AssetTypeSpot)
alphaTicker := CreateNewTicker("alphapoint", &priceStruct, asset.Spot)
Tickers = append(Tickers, alphaTicker)
if !FirstCurrencyExists("alphapoint", currency.BTC) {
@@ -178,7 +178,7 @@ func TestSecondCurrencyExists(t *testing.T) {
PriceATH: 1337,
}
bitstampTicker := CreateNewTicker("bitstamp", &priceStruct, assets.AssetTypeSpot)
bitstampTicker := CreateNewTicker("bitstamp", &priceStruct, asset.Spot)
Tickers = append(Tickers, bitstampTicker)
if !SecondCurrencyExists("bitstamp", newPair) {
@@ -205,7 +205,7 @@ func TestCreateNewTicker(t *testing.T) {
PriceATH: 1337,
}
newTicker := CreateNewTicker("ANX", &priceStruct, assets.AssetTypeSpot)
newTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
if reflect.ValueOf(newTicker).NumField() != 2 {
t.Error("Test Failed - ticker CreateNewTicker struct change/or updated")
@@ -217,31 +217,31 @@ func TestCreateNewTicker(t *testing.T) {
t.Error("Test Failed - ticker CreateNewTicker.ExchangeName value is not ANX")
}
if newTicker.Price[currency.BTC.Upper().String()][currency.USD.Upper().String()][assets.AssetTypeSpot.String()].Pair.String() != "BTCUSD" {
if newTicker.Price[currency.BTC.Upper().String()][currency.USD.Upper().String()][asset.Spot.String()].Pair.String() != "BTCUSD" {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Pair.Pair().String() value is not expected 'BTCUSD'")
}
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Ask).String() != float64Type {
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Ask).String() != float64Type {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Ask value is not a float64")
}
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Bid).String() != float64Type {
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Bid).String() != float64Type {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Bid value is not a float64")
}
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Pair).String() != "currency.Pair" {
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Pair).String() != "currency.Pair" {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].CurrencyPair value is not a currency.Pair")
}
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].High).String() != float64Type {
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].High).String() != float64Type {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].High value is not a float64")
}
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Last).String() != float64Type {
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Last).String() != float64Type {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Last value is not a float64")
}
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Low).String() != float64Type {
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Low).String() != float64Type {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Low value is not a float64")
}
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].PriceATH).String() != float64Type {
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].PriceATH).String() != float64Type {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].PriceATH value is not a float64")
}
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Volume).String() != float64Type {
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Volume).String() != float64Type {
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Volume value is not a float64")
}
}
@@ -261,17 +261,17 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
PriceATH: 1337,
}
err := ProcessTicker(exchName, &Price{}, assets.AssetTypeSpot)
err := ProcessTicker(exchName, &Price{}, asset.Spot)
if err == nil {
t.Fatal("Test failed. ProcessTicker error cannot be nil")
}
err = ProcessTicker(exchName, &priceStruct, assets.AssetTypeSpot)
err = ProcessTicker(exchName, &priceStruct, asset.Spot)
if err != nil {
t.Fatal("Test failed. ProcessTicker error", err)
}
result, err := GetTicker(exchName, newPair, assets.AssetTypeSpot)
result, err := GetTicker(exchName, newPair, asset.Spot)
if err != nil {
t.Fatal("Test failed. TestProcessTicker failed to create and return a new ticker")
}
@@ -282,17 +282,17 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
secondPair := currency.NewPairFromStrings("BTC", "AUD")
priceStruct.Pair = secondPair
err = ProcessTicker(exchName, &priceStruct, assets.AssetTypeSpot)
err = ProcessTicker(exchName, &priceStruct, asset.Spot)
if err != nil {
t.Fatal("Test failed. ProcessTicker error", err)
}
result, err = GetTicker(exchName, secondPair, assets.AssetTypeSpot)
result, err = GetTicker(exchName, secondPair, asset.Spot)
if err != nil {
t.Fatal("Test failed. TestProcessTicker failed to create and return a new ticker")
}
result, err = GetTicker(exchName, newPair, assets.AssetTypeSpot)
result, err = GetTicker(exchName, newPair, asset.Spot)
if err != nil {
t.Fatal("Test failed. TestProcessTicker failed to return an existing ticker")
}
@@ -328,7 +328,7 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
}
sm.Lock()
err = ProcessTicker(newName, &tp, assets.AssetTypeSpot)
err = ProcessTicker(newName, &tp, asset.Spot)
if err != nil {
log.Error(err)
catastrophicFailure = true
@@ -351,7 +351,7 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
wg.Add(1)
fatalErr := false
go func(test quick) {
result, err := GetTicker(test.Name, test.P, assets.AssetTypeSpot)
result, err := GetTicker(test.Name, test.P, asset.Spot)
if err != nil {
fatalErr = true
return

View File

@@ -9,7 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -429,7 +429,7 @@ func (w *Websocket) GetName() string {
func (w *WebsocketOrderbookLocal) Update(bidTargets, askTargets []orderbook.Item,
p currency.Pair,
updated time.Time,
exchName string, assetType assets.AssetType) error {
exchName string, assetType asset.Item) error {
if bidTargets == nil && askTargets == nil {
return errors.New("exchange.go websocket orderbook cache Update() error - cannot have bids and ask targets both nil")
}
@@ -556,7 +556,7 @@ func (w *WebsocketOrderbookLocal) LoadSnapshot(newOrderbook *orderbook.Base, exc
// UpdateUsingID updates orderbooks using specified ID
func (w *WebsocketOrderbookLocal) UpdateUsingID(bidTargets, askTargets []orderbook.Item,
p currency.Pair,
exchName string, assetType assets.AssetType, action string) error {
exchName string, assetType asset.Item, action string) error {
w.m.Lock()
defer w.m.Unlock()

View File

@@ -7,7 +7,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
)
@@ -161,7 +161,7 @@ func TestInsertingSnapShots(t *testing.T) {
snapShot1.Asks = asks
snapShot1.Bids = bids
snapShot1.AssetType = assets.AssetTypeSpot
snapShot1.AssetType = asset.Spot
snapShot1.Pair = currency.NewPairFromString("BTCUSD")
wsTest.Websocket.Orderbook.LoadSnapshot(&snapShot1, "ExchangeTest", false)
@@ -197,7 +197,7 @@ func TestInsertingSnapShots(t *testing.T) {
snapShot2.Asks = asks
snapShot2.Bids = bids
snapShot2.AssetType = assets.AssetTypeSpot
snapShot2.AssetType = asset.Spot
snapShot2.Pair = currency.NewPairFromString("LTCUSD")
wsTest.Websocket.Orderbook.LoadSnapshot(&snapShot2, "ExchangeTest", false)
@@ -265,7 +265,7 @@ func TestUpdate(t *testing.T) {
LTCUSDPAIR,
time.Now(),
"ExchangeTest",
assets.AssetTypeSpot)
asset.Spot)
if err != nil {
t.Error("test failed - OrderbookUpdate error", err)
@@ -301,7 +301,7 @@ func TestUpdate(t *testing.T) {
BTCUSDPAIR,
time.Now(),
"ExchangeTest",
assets.AssetTypeSpot)
asset.Spot)
if err != nil {
t.Error("test failed - OrderbookUpdate error", err)

View File

@@ -5,7 +5,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
)
@@ -118,7 +118,7 @@ type WebsocketResponse struct {
// has been updated in the orderbook package
type WebsocketOrderbookUpdate struct {
Pair currency.Pair
Asset assets.AssetType
Asset asset.Item
Exchange string
}
@@ -126,7 +126,7 @@ type WebsocketOrderbookUpdate struct {
type TradeData struct {
Timestamp time.Time
CurrencyPair currency.Pair
AssetType assets.AssetType
AssetType asset.Item
Exchange string
EventType string
EventTime int64
@@ -139,7 +139,7 @@ type TradeData struct {
type TickerData struct {
Timestamp time.Time
Pair currency.Pair
AssetType assets.AssetType
AssetType asset.Item
Exchange string
ClosePrice float64
Quantity float64
@@ -152,7 +152,7 @@ type TickerData struct {
type KlineData struct {
Timestamp time.Time
Pair currency.Pair
AssetType assets.AssetType
AssetType asset.Item
Exchange string
StartTime time.Time
CloseTime time.Time
@@ -168,6 +168,6 @@ type KlineData struct {
type WebsocketPositionUpdated struct {
Timestamp time.Time
Pair currency.Pair
AssetType assets.AssetType
AssetType asset.Item
Exchange string
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
)
var y Yobit
@@ -41,7 +41,7 @@ func TestSetup(t *testing.T) {
func TestFetchTradablePairs(t *testing.T) {
t.Parallel()
_, err := y.FetchTradablePairs(assets.AssetTypeSpot)
_, err := y.FetchTradablePairs(asset.Spot)
if err != nil {
t.Errorf("Test failed. FetchTradablePairs err: %s", err)
}

View File

@@ -13,7 +13,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -52,8 +52,8 @@ func (y *Yobit) SetDefaults() {
y.API.CredentialsValidator.RequiresSecret = true
y.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
RequestFormat: &currency.PairFormat{
@@ -130,7 +130,7 @@ func (y *Yobit) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (y *Yobit) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (y *Yobit) FetchTradablePairs(asset asset.Item) ([]string, error) {
info, err := y.GetInfo()
if err != nil {
return nil, err
@@ -147,16 +147,16 @@ func (y *Yobit) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (y *Yobit) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := y.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := y.FetchTradablePairs(asset.Spot)
if err != nil {
return err
}
return y.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return y.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (y *Yobit) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (y *Yobit) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
pairsCollated, err := y.FormatExchangeCurrencies(y.GetEnabledPairs(assetType), assetType)
if err != nil {
@@ -188,7 +188,7 @@ func (y *Yobit) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticke
}
// FetchTicker returns the ticker for a currency pair
func (y *Yobit) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (y *Yobit) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tick, err := ticker.GetTicker(y.GetName(), p, assetType)
if err != nil {
return y.UpdateTicker(p, assetType)
@@ -197,7 +197,7 @@ func (y *Yobit) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker
}
// FetchOrderbook returns the orderbook for a currency pair
func (y *Yobit) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (y *Yobit) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(y.GetName(), p, assetType)
if err != nil {
return y.UpdateOrderbook(p, assetType)
@@ -206,7 +206,7 @@ func (y *Yobit) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (ord
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (y *Yobit) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (y *Yobit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := y.GetDepth(y.FormatExchangeCurrency(p, assetType).String())
if err != nil {
@@ -275,7 +275,7 @@ func (y *Yobit) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (y *Yobit) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (y *Yobit) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -330,9 +330,9 @@ func (y *Yobit) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelA
}
var allActiveOrders []map[string]ActiveOrders
for _, pair := range y.GetEnabledPairs(assets.AssetTypeSpot) {
for _, pair := range y.GetEnabledPairs(asset.Spot) {
activeOrdersForPair, err := y.GetOpenOrders(y.FormatExchangeCurrency(pair,
assets.AssetTypeSpot).String())
asset.Spot).String())
if err != nil {
return cancelAllOrdersResponse, err
}
@@ -418,14 +418,14 @@ func (y *Yobit) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
var orders []exchange.OrderDetail
for _, c := range getOrdersRequest.Currencies {
resp, err := y.GetOpenOrders(y.FormatExchangeCurrency(c,
assets.AssetTypeSpot).String())
asset.Spot).String())
if err != nil {
return nil, err
}
for ID, order := range resp {
symbol := currency.NewPairDelimiter(order.Pair,
y.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
y.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(int64(order.TimestampCreated), 0)
side := exchange.OrderSide(strings.ToUpper(order.Type))
orders = append(orders, exchange.OrderDetail{
@@ -457,7 +457,7 @@ func (y *Yobit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
getOrdersRequest.StartTicks.Unix(),
getOrdersRequest.EndTicks.Unix(),
"DESC",
y.FormatExchangeCurrency(currency, assets.AssetTypeSpot).String())
y.FormatExchangeCurrency(currency, asset.Spot).String())
if err != nil {
return nil, err
}
@@ -470,7 +470,7 @@ func (y *Yobit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
var orders []exchange.OrderDetail
for _, order := range allOrders {
symbol := currency.NewPairDelimiter(order.Pair,
y.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
y.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(int64(order.Timestamp), 0)
side := exchange.OrderSide(strings.ToUpper(order.Type))
orders = append(orders, exchange.OrderDetail{

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -117,7 +117,7 @@ func (z *ZB) WsHandleData() {
z.Websocket.DataHandler <- exchange.TickerData{
Timestamp: time.Unix(0, ticker.Date),
Pair: currency.NewPairFromString(cPair[0]),
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: z.GetName(),
ClosePrice: ticker.Data.Last,
HighPrice: ticker.Data.High,
@@ -156,7 +156,7 @@ func (z *ZB) WsHandleData() {
var newOrderBook orderbook.Base
newOrderBook.Asks = asks
newOrderBook.Bids = bids
newOrderBook.AssetType = assets.AssetTypeSpot
newOrderBook.AssetType = asset.Spot
newOrderBook.Pair = cPair
err = z.Websocket.Orderbook.LoadSnapshot(&newOrderBook,
@@ -169,7 +169,7 @@ func (z *ZB) WsHandleData() {
z.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: cPair,
Asset: assets.AssetTypeSpot,
Asset: asset.Spot,
Exchange: z.GetName(),
}
@@ -190,7 +190,7 @@ func (z *ZB) WsHandleData() {
z.Websocket.DataHandler <- exchange.TradeData{
Timestamp: time.Unix(0, t.Date),
CurrencyPair: cPair,
AssetType: assets.AssetTypeSpot,
AssetType: asset.Spot,
Exchange: z.GetName(),
EventTime: t.Date,
Price: t.Price,
@@ -248,7 +248,7 @@ func (z *ZB) GenerateDefaultSubscriptions() {
Channel: "markets",
})
channels := []string{"%s_ticker", "%s_depth", "%s_trades"}
enabledCurrencies := z.GetEnabledPairs(assets.AssetTypeSpot)
enabledCurrencies := z.GetEnabledPairs(asset.Spot)
for i := range channels {
for j := range enabledCurrencies {
enabledCurrencies[j].Delimiter = ""

View File

@@ -12,7 +12,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/asset"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -51,8 +51,8 @@ func (z *ZB) SetDefaults() {
z.API.CredentialsValidator.RequiresSecret = true
z.CurrencyPairs = currency.PairsManager{
AssetTypes: assets.AssetTypes{
assets.AssetTypeSpot,
AssetTypes: asset.Items{
asset.Spot,
},
UseGlobalFormat: true,
@@ -145,7 +145,7 @@ func (z *ZB) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (z *ZB) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
func (z *ZB) FetchTradablePairs(asset asset.Item) ([]string, error) {
markets, err := z.GetMarkets()
if err != nil {
return nil, err
@@ -162,16 +162,16 @@ func (z *ZB) FetchTradablePairs(asset assets.AssetType) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (z *ZB) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := z.FetchTradablePairs(assets.AssetTypeSpot)
pairs, err := z.FetchTradablePairs(asset.Spot)
if err != nil {
return nil
}
return z.UpdatePairs(currency.NewPairsFromStrings(pairs), assets.AssetTypeSpot, false, forceUpdate)
return z.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
}
// UpdateTicker updates and returns the ticker for a currency pair
func (z *ZB) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (z *ZB) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
result, err := z.GetTickers()
@@ -202,7 +202,7 @@ func (z *ZB) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.P
}
// FetchTicker returns the ticker for a currency pair
func (z *ZB) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Price, error) {
func (z *ZB) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(z.GetName(), p, assetType)
if err != nil {
return z.UpdateTicker(p, assetType)
@@ -211,7 +211,7 @@ func (z *ZB) FetchTicker(p currency.Pair, assetType assets.AssetType) (ticker.Pr
}
// FetchOrderbook returns orderbook base on the currency pair
func (z *ZB) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (z *ZB) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
ob, err := orderbook.Get(z.GetName(), p, assetType)
if err != nil {
return z.UpdateOrderbook(p, assetType)
@@ -220,7 +220,7 @@ func (z *ZB) FetchOrderbook(p currency.Pair, assetType assets.AssetType) (orderb
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (z *ZB) UpdateOrderbook(p currency.Pair, assetType assets.AssetType) (orderbook.Base, error) {
func (z *ZB) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
currency := z.FormatExchangeCurrency(p, assetType).String()
@@ -295,7 +295,7 @@ func (z *ZB) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (z *ZB) GetExchangeHistory(p currency.Pair, assetType assets.AssetType) ([]exchange.TradeHistory, error) {
func (z *ZB) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -357,10 +357,10 @@ func (z *ZB) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllO
OrderStatus: make(map[string]string),
}
var allOpenOrders []Order
for _, currency := range z.GetEnabledPairs(assets.AssetTypeSpot) {
for _, currency := range z.GetEnabledPairs(asset.Spot) {
// Limiting to 10 pages
for i := 0; i < 10; i++ {
openOrders, err := z.GetUnfinishedOrdersIgnoreTradeType(z.FormatExchangeCurrency(currency, assets.AssetTypeSpot).String(), 1, 10)
openOrders, err := z.GetUnfinishedOrdersIgnoreTradeType(z.FormatExchangeCurrency(currency, asset.Spot).String(), 1, 10)
if err != nil {
return cancelAllOrdersResponse, err
}
@@ -439,7 +439,7 @@ func (z *ZB) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exc
var pageNumber int64
// Limiting to 10 pages
for i := 0; i < 10; i++ {
resp, err := z.GetUnfinishedOrdersIgnoreTradeType(z.FormatExchangeCurrency(currency, assets.AssetTypeSpot).String(), pageNumber, 10)
resp, err := z.GetUnfinishedOrdersIgnoreTradeType(z.FormatExchangeCurrency(currency, asset.Spot).String(), pageNumber, 10)
if err != nil {
return nil, err
}
@@ -455,7 +455,7 @@ func (z *ZB) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exc
var orders []exchange.OrderDetail
for _, order := range allOrders {
symbol := currency.NewPairDelimiter(order.Currency,
z.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
z.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(int64(order.TradeDate), 0)
orderSide := orderSideMap[order.Type]
orders = append(orders, exchange.OrderDetail{
@@ -494,7 +494,7 @@ func (z *ZB) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exc
var pageNumber int64
// Limiting to 10 pages
for i := 0; i < 10; i++ {
resp, err := z.GetOrders(z.FormatExchangeCurrency(currency, assets.AssetTypeSpot).String(), pageNumber, side)
resp, err := z.GetOrders(z.FormatExchangeCurrency(currency, asset.Spot).String(), pageNumber, side)
if err != nil {
return nil, err
}
@@ -511,7 +511,7 @@ func (z *ZB) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exc
var orders []exchange.OrderDetail
for _, order := range allOrders {
symbol := currency.NewPairDelimiter(order.Currency,
z.CurrencyPairs.Get(assets.AssetTypeSpot).ConfigFormat.Delimiter)
z.CurrencyPairs.Get(asset.Spot).ConfigFormat.Delimiter)
orderDate := time.Unix(int64(order.TradeDate), 0)
orderSide := orderSideMap[order.Type]
orders = append(orders, exchange.OrderDetail{