mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +00:00
Asset update to fix minor stutter (#316)
This commit is contained in:
committed by
Adrian Gallagher
parent
b901c4b670
commit
20c24601fb
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user