mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-25 07:26:48 +00:00
Currency package update (#247)
* Initial currency overhaul before service system implementation * Remove redundant currency string in orderbook.Base Unexport lastupdated field in orderbook.Base as it was being instantiated multiple times Add error handling for process orderbook * Remove redundant currency string in ticker.Price Unexport lastupdated field in ticker.Price Add error handling for process ticker function and fix tests * Phase Two Update * Update translations to use map type - thankyou to kempeng for spotting this * Change pair method name from Display -> Format for better readability * Fixes misspelling and tests * Implement requested changes from GloriousCode * Remove reduntant function and streamlined return in currency_translation.go * Revert pair method naming conventions * Change currency naming conventions * Changed code type to exported Item type with underlying string to reduce complexity * Added interim orderbook process method to orderbook.Base type * Changed feebuilder struct field to currency.Pair * Adds fall over system for backup fx providers * deprecate function and children and fix linter issue with btcmarkets * Fixed requested changes * Fix bug and move mtx for rates * Fixed after rebase oopsies * Fix linter issues * Fixes race conditions in testing functions * Final phase coinmarketcap update * fix linter issues * Implement requested changes * Adds configuration variables to increase/decrease time durations between updating currency file and fetching new currency rates * Add a collection of tests to improve codecov * After rebase oopsy fixes for btse * Fix requested changes * fix after rebase oopsies and add more efficient comparison checks within currency pair * Fix linter issues
This commit is contained in:
committed by
Adrian Gallagher
parent
ed760e184e
commit
0990f9d118
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
@@ -36,19 +36,23 @@ func (b *Bittrex) Run() {
|
||||
log.Errorf("%s Failed to get available symbols.\n", b.GetName())
|
||||
} else {
|
||||
forceUpgrade := false
|
||||
if !common.StringDataContains(b.EnabledPairs, "-") || !common.StringDataContains(b.AvailablePairs, "-") {
|
||||
if !common.StringDataContains(b.EnabledPairs.Strings(), "-") ||
|
||||
!common.StringDataContains(b.AvailablePairs.Strings(), "-") {
|
||||
forceUpgrade = true
|
||||
}
|
||||
var currencies []string
|
||||
for x := range exchangeProducts.Result {
|
||||
if !exchangeProducts.Result[x].IsActive || exchangeProducts.Result[x].MarketName == "" {
|
||||
if !exchangeProducts.Result[x].IsActive ||
|
||||
exchangeProducts.Result[x].MarketName == "" {
|
||||
continue
|
||||
}
|
||||
currencies = append(currencies, exchangeProducts.Result[x].MarketName)
|
||||
}
|
||||
|
||||
if forceUpgrade {
|
||||
enabledPairs := []string{"USDT-BTC"}
|
||||
enabledPairs := currency.Pairs{currency.Pair{Base: currency.USDT,
|
||||
Quote: currency.BTC, Delimiter: "-"}}
|
||||
|
||||
log.Warn("Available pairs for Bittrex reset due to config upgrade, please enable the ones you would like again")
|
||||
|
||||
err = b.UpdateCurrencies(enabledPairs, true, true)
|
||||
@@ -56,7 +60,14 @@ func (b *Bittrex) Run() {
|
||||
log.Errorf("%s Failed to get config.", b.GetName())
|
||||
}
|
||||
}
|
||||
err = b.UpdateCurrencies(currencies, false, forceUpgrade)
|
||||
|
||||
var newCurrencies currency.Pairs
|
||||
for _, p := range currencies {
|
||||
newCurrencies = append(newCurrencies,
|
||||
currency.NewPairFromString(p))
|
||||
}
|
||||
|
||||
err = b.UpdateCurrencies(newCurrencies, false, forceUpgrade)
|
||||
if err != nil {
|
||||
log.Errorf("%s Failed to get config.", b.GetName())
|
||||
}
|
||||
@@ -76,7 +87,7 @@ func (b *Bittrex) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
var currencies []exchange.AccountCurrencyInfo
|
||||
for i := 0; i < len(accountBalance.Result); i++ {
|
||||
var exchangeCurrency exchange.AccountCurrencyInfo
|
||||
exchangeCurrency.CurrencyName = accountBalance.Result[i].Currency
|
||||
exchangeCurrency.CurrencyName = currency.NewCode(accountBalance.Result[i].Currency)
|
||||
exchangeCurrency.TotalValue = accountBalance.Result[i].Balance
|
||||
exchangeCurrency.Hold = accountBalance.Result[i].Balance - accountBalance.Result[i].Available
|
||||
currencies = append(currencies, exchangeCurrency)
|
||||
@@ -90,7 +101,7 @@ func (b *Bittrex) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bittrex) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (b *Bittrex) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := b.GetMarketSummaries()
|
||||
if err != nil {
|
||||
@@ -110,14 +121,14 @@ func (b *Bittrex) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pr
|
||||
tickerPrice.Bid = tick.Result[y].Bid
|
||||
tickerPrice.Last = tick.Result[y].Last
|
||||
tickerPrice.Volume = tick.Result[y].Volume
|
||||
ticker.ProcessTicker(b.GetName(), x, tickerPrice, assetType)
|
||||
ticker.ProcessTicker(b.GetName(), tickerPrice, assetType)
|
||||
}
|
||||
}
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (b *Bittrex) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (b *Bittrex) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p, ticker.Spot)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p, assetType)
|
||||
@@ -126,8 +137,8 @@ func (b *Bittrex) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns the orderbook for a currency pair
|
||||
func (b *Bittrex) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook(b.GetName(), p, assetType)
|
||||
func (b *Bittrex) GetOrderbookEx(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(b.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateOrderbook(p, assetType)
|
||||
}
|
||||
@@ -135,7 +146,7 @@ func (b *Bittrex) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderbo
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (b *Bittrex) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
func (b *Bittrex) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
orderbookNew, err := b.GetOrderbook(exchange.FormatExchangeCurrency(b.GetName(), p).String())
|
||||
if err != nil {
|
||||
@@ -160,8 +171,16 @@ func (b *Bittrex) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderb
|
||||
)
|
||||
}
|
||||
|
||||
orderbook.ProcessOrderbook(b.GetName(), p, orderBook, assetType)
|
||||
return orderbook.GetOrderbook(b.Name, p, assetType)
|
||||
orderBook.Pair = p
|
||||
orderBook.ExchangeName = b.GetName()
|
||||
orderBook.AssetType = assetType
|
||||
|
||||
err = orderBook.Process()
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
return orderbook.Get(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetFundingHistory returns funding history, deposits and
|
||||
@@ -172,14 +191,14 @@ func (b *Bittrex) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
}
|
||||
|
||||
// GetExchangeHistory returns historic trade data since exchange opening.
|
||||
func (b *Bittrex) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
func (b *Bittrex) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
var resp []exchange.TradeHistory
|
||||
|
||||
return resp, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bittrex) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
func (b *Bittrex) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
buy := side == exchange.BuyOrderSide
|
||||
var response UUID
|
||||
@@ -190,9 +209,9 @@ func (b *Bittrex) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orde
|
||||
}
|
||||
|
||||
if buy {
|
||||
response, err = b.PlaceBuyLimit(p.Pair().String(), amount, price)
|
||||
response, err = b.PlaceBuyLimit(p.String(), amount, price)
|
||||
} else {
|
||||
response, err = b.PlaceSellLimit(p.Pair().String(), amount, price)
|
||||
response, err = b.PlaceSellLimit(p.String(), amount, price)
|
||||
}
|
||||
|
||||
if response.Result.ID != "" {
|
||||
@@ -246,7 +265,7 @@ func (b *Bittrex) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (b *Bittrex) GetDepositAddress(cryptocurrency pair.CurrencyItem, _ string) (string, error) {
|
||||
func (b *Bittrex) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
depositAddr, err := b.GetCryptoDepositAddress(cryptocurrency.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -289,7 +308,7 @@ func (b *Bittrex) GetFeeByType(feeBuilder exchange.FeeBuilder) (float64, error)
|
||||
func (b *Bittrex) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].Pair().String()
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := b.GetOpenOrders(currPair)
|
||||
@@ -305,7 +324,8 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
b.Name, "GetActiveOrders", order.OrderUUID, order.Opened)
|
||||
}
|
||||
|
||||
currency := pair.NewCurrencyPairDelimiter(order.Exchange, b.ConfigCurrencyPairFormat.Delimiter)
|
||||
pair := currency.NewPairDelimiter(order.Exchange,
|
||||
b.ConfigCurrencyPairFormat.Delimiter)
|
||||
orderType := exchange.OrderType(strings.ToUpper(order.Type))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
@@ -316,12 +336,13 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
ID: order.OrderUUID,
|
||||
Exchange: b.Name,
|
||||
OrderType: orderType,
|
||||
CurrencyPair: currency,
|
||||
CurrencyPair: pair,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
|
||||
return orders, nil
|
||||
@@ -332,7 +353,7 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
func (b *Bittrex) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].Pair().String()
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := b.GetOrderHistoryForCurrency(currPair)
|
||||
@@ -348,7 +369,8 @@ func (b *Bittrex) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
b.Name, "GetActiveOrders", order.OrderUUID, order.Opened)
|
||||
}
|
||||
|
||||
currency := pair.NewCurrencyPairDelimiter(order.Exchange, b.ConfigCurrencyPairFormat.Delimiter)
|
||||
pair := currency.NewPairDelimiter(order.Exchange,
|
||||
b.ConfigCurrencyPairFormat.Delimiter)
|
||||
orderType := exchange.OrderType(strings.ToUpper(order.Type))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
@@ -360,12 +382,13 @@ func (b *Bittrex) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
Exchange: b.Name,
|
||||
OrderType: orderType,
|
||||
Fee: order.Commission,
|
||||
CurrencyPair: currency,
|
||||
CurrencyPair: pair,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
|
||||
return orders, nil
|
||||
|
||||
Reference in New Issue
Block a user