mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 23:16:53 +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"
|
||||
@@ -41,7 +41,13 @@ func (z *ZB) Run() {
|
||||
currencies = append(currencies, x)
|
||||
}
|
||||
|
||||
err = z.UpdateCurrencies(currencies, false, false)
|
||||
var newCurrencies currency.Pairs
|
||||
for _, p := range currencies {
|
||||
newCurrencies = append(newCurrencies,
|
||||
currency.NewPairFromString(p))
|
||||
}
|
||||
|
||||
err = z.UpdateCurrencies(newCurrencies, false, false)
|
||||
if err != nil {
|
||||
log.Errorf("%s Failed to update available currencies.\n", z.GetName())
|
||||
}
|
||||
@@ -49,7 +55,7 @@ func (z *ZB) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (z *ZB) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (z *ZB) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
|
||||
result, err := z.GetTickers()
|
||||
@@ -69,14 +75,18 @@ func (z *ZB) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price,
|
||||
tp.Last = result[currency].Last
|
||||
tp.Low = result[currency].Low
|
||||
tp.Volume = result[currency].Vol
|
||||
ticker.ProcessTicker(z.Name, x, tp, assetType)
|
||||
|
||||
err = ticker.ProcessTicker(z.Name, tp, assetType)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
}
|
||||
|
||||
return ticker.GetTicker(z.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (z *ZB) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (z *ZB) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(z.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return z.UpdateTicker(p, assetType)
|
||||
@@ -85,8 +95,8 @@ func (z *ZB) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns orderbook base on the currency pair
|
||||
func (z *ZB) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook(z.GetName(), currency, assetType)
|
||||
func (z *ZB) GetOrderbookEx(currency currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(z.GetName(), currency, assetType)
|
||||
if err != nil {
|
||||
return z.UpdateOrderbook(currency, assetType)
|
||||
}
|
||||
@@ -94,7 +104,7 @@ func (z *ZB) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (order
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (z *ZB) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
func (z *ZB) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
currency := exchange.FormatExchangeCurrency(z.Name, p).String()
|
||||
|
||||
@@ -113,8 +123,16 @@ func (z *ZB) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.B
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data[1], Price: data[0]})
|
||||
}
|
||||
|
||||
orderbook.ProcessOrderbook(z.GetName(), p, orderBook, assetType)
|
||||
return orderbook.GetOrderbook(z.Name, p, assetType)
|
||||
orderBook.Pair = p
|
||||
orderBook.AssetType = assetType
|
||||
orderBook.ExchangeName = z.GetName()
|
||||
|
||||
err = orderBook.Process()
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
return orderbook.Get(z.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetAccountInfo retrieves balances for all enabled currencies for the
|
||||
@@ -139,7 +157,7 @@ func (z *ZB) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: data.EnName,
|
||||
CurrencyName: currency.NewCode(data.EnName),
|
||||
TotalValue: hold + avail,
|
||||
Hold: hold,
|
||||
})
|
||||
@@ -161,14 +179,14 @@ func (z *ZB) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
}
|
||||
|
||||
// GetExchangeHistory returns historic trade data since exchange opening.
|
||||
func (z *ZB) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
func (z *ZB) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
var resp []exchange.TradeHistory
|
||||
|
||||
return resp, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (z *ZB) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
func (z *ZB) SubmitOrder(p currency.Pair, side exchange.OrderSide, _ exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
var oT SpotNewOrderRequestParamsType
|
||||
|
||||
@@ -181,7 +199,7 @@ func (z *ZB) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ exchang
|
||||
var params = SpotNewOrderRequestParams{
|
||||
Amount: amount,
|
||||
Price: price,
|
||||
Symbol: common.StringToLower(p.Pair().String()),
|
||||
Symbol: common.StringToLower(p.String()),
|
||||
Type: oT,
|
||||
}
|
||||
response, err := z.SpotNewOrder(params)
|
||||
@@ -255,7 +273,7 @@ func (z *ZB) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (z *ZB) GetDepositAddress(cryptocurrency pair.CurrencyItem, _ string) (string, error) {
|
||||
func (z *ZB) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
address, err := z.GetCryptoAddress(cryptocurrency)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -315,7 +333,8 @@ func (z *ZB) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]exch
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range allOrders {
|
||||
symbol := pair.NewCurrencyPairDelimiter(order.Currency, z.ConfigCurrencyPairFormat.Delimiter)
|
||||
symbol := currency.NewPairDelimiter(order.Currency,
|
||||
z.ConfigCurrencyPairFormat.Delimiter)
|
||||
orderDate := time.Unix(int64(order.TradeDate), 0)
|
||||
orderSide := orderSideMap[order.Type]
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
@@ -329,7 +348,8 @@ func (z *ZB) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]exch
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
@@ -370,7 +390,8 @@ func (z *ZB) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]exch
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range allOrders {
|
||||
symbol := pair.NewCurrencyPairDelimiter(order.Currency, z.ConfigCurrencyPairFormat.Delimiter)
|
||||
symbol := currency.NewPairDelimiter(order.Currency,
|
||||
z.ConfigCurrencyPairFormat.Delimiter)
|
||||
orderDate := time.Unix(int64(order.TradeDate), 0)
|
||||
orderSide := orderSideMap[order.Type]
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
|
||||
Reference in New Issue
Block a user