mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 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
@@ -149,9 +149,9 @@ func (l *LocalBitcoins) Setup(exch config.ExchangeConfig) {
|
||||
l.SetHTTPClientUserAgent(exch.HTTPUserAgent)
|
||||
l.RESTPollingDelay = exch.RESTPollingDelay
|
||||
l.Verbose = exch.Verbose
|
||||
l.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
|
||||
l.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
l.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
|
||||
l.BaseCurrencies = exch.BaseCurrencies
|
||||
l.AvailablePairs = exch.AvailablePairs
|
||||
l.EnabledPairs = exch.EnabledPairs
|
||||
err := l.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
)
|
||||
|
||||
@@ -98,14 +97,13 @@ func TestEditAd(t *testing.T) {
|
||||
|
||||
func setFeeBuilder() exchange.FeeBuilder {
|
||||
return exchange.FeeBuilder{
|
||||
Amount: 1,
|
||||
Delimiter: "-",
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
FirstCurrency: symbol.LTC,
|
||||
SecondCurrency: symbol.BTC,
|
||||
IsMaker: false,
|
||||
Amount: 1,
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
Pair: currency.NewPairWithDelimiter(currency.LTC.String(),
|
||||
currency.BTC.String(),
|
||||
"-"),
|
||||
PurchasePrice: 1,
|
||||
CurrencyItem: symbol.USD,
|
||||
FiatCurrency: currency.USD,
|
||||
BankTransactionType: exchange.WireTransfer,
|
||||
}
|
||||
}
|
||||
@@ -153,7 +151,7 @@ func TestGetFee(t *testing.T) {
|
||||
|
||||
// CryptocurrencyWithdrawalFee Invalid currency
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FirstCurrency = "hello"
|
||||
feeBuilder.Pair.Base = currency.NewCode("hello")
|
||||
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
|
||||
if resp, err := l.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
@@ -179,7 +177,7 @@ func TestGetFee(t *testing.T) {
|
||||
// InternationalBankWithdrawalFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
|
||||
feeBuilder.CurrencyItem = symbol.USD
|
||||
feeBuilder.FiatCurrency = currency.USD
|
||||
if resp, err := l.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
@@ -247,10 +245,10 @@ func TestSubmitOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var p = pair.CurrencyPair{
|
||||
Delimiter: "",
|
||||
FirstCurrency: symbol.BTC,
|
||||
SecondCurrency: symbol.EUR,
|
||||
var p = currency.Pair{
|
||||
Delimiter: "",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.EUR,
|
||||
}
|
||||
response, err := l.SubmitOrder(p, exchange.BuyOrderSide, exchange.MarketOrderType, 1, 10, "hi")
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
@@ -268,7 +266,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
OrderID: "1",
|
||||
@@ -294,7 +292,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
OrderID: "1",
|
||||
@@ -329,7 +327,7 @@ func TestWithdraw(t *testing.T) {
|
||||
TestSetup(t)
|
||||
var withdrawCryptoRequest = exchange.WithdrawRequest{
|
||||
Amount: 100,
|
||||
Currency: symbol.LTC,
|
||||
Currency: currency.LTC,
|
||||
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
@@ -381,12 +379,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
if apiKey != "" || apiSecret != "" {
|
||||
_, err := l.GetDepositAddress(symbol.BTC, "")
|
||||
_, err := l.GetDepositAddress(currency.BTC, "")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - GetDepositAddress() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := l.GetDepositAddress(symbol.BTC, "")
|
||||
_, err := l.GetDepositAddress(currency.BTC, "")
|
||||
if err == nil {
|
||||
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
|
||||
}
|
||||
|
||||
@@ -9,10 +9,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
|
||||
"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"
|
||||
@@ -46,7 +44,13 @@ func (l *LocalBitcoins) Run() {
|
||||
pairs = append(pairs, "BTC"+currencies[x])
|
||||
}
|
||||
|
||||
err = l.UpdateCurrencies(pairs, false, false)
|
||||
var newExchangeProducts currency.Pairs
|
||||
for _, p := range pairs {
|
||||
newExchangeProducts = append(newExchangeProducts,
|
||||
currency.NewPairFromString(p))
|
||||
}
|
||||
|
||||
err = l.UpdateCurrencies(newExchangeProducts, false, false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update available currencies. Err %s", l.Name, err)
|
||||
}
|
||||
@@ -54,7 +58,7 @@ func (l *LocalBitcoins) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (l *LocalBitcoins) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (l *LocalBitcoins) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := l.GetTicker()
|
||||
if err != nil {
|
||||
@@ -62,19 +66,23 @@ func (l *LocalBitcoins) UpdateTicker(p pair.CurrencyPair, assetType string) (tic
|
||||
}
|
||||
|
||||
for _, x := range l.GetEnabledCurrencies() {
|
||||
currency := x.SecondCurrency.String()
|
||||
currency := x.Quote.String()
|
||||
var tp ticker.Price
|
||||
tp.Pair = x
|
||||
tp.Last = tick[currency].Avg24h
|
||||
tp.Volume = tick[currency].VolumeBTC
|
||||
ticker.ProcessTicker(l.GetName(), x, tp, assetType)
|
||||
|
||||
err = ticker.ProcessTicker(l.GetName(), tp, assetType)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
}
|
||||
|
||||
return ticker.GetTicker(l.GetName(), p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (l *LocalBitcoins) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (l *LocalBitcoins) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(l.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return l.UpdateTicker(p, assetType)
|
||||
@@ -83,8 +91,8 @@ func (l *LocalBitcoins) GetTickerPrice(p pair.CurrencyPair, assetType string) (t
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns orderbook base on the currency pair
|
||||
func (l *LocalBitcoins) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook(l.GetName(), p, assetType)
|
||||
func (l *LocalBitcoins) GetOrderbookEx(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(l.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return l.UpdateOrderbook(p, assetType)
|
||||
}
|
||||
@@ -92,9 +100,9 @@ func (l *LocalBitcoins) GetOrderbookEx(p pair.CurrencyPair, assetType string) (o
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (l *LocalBitcoins) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
func (l *LocalBitcoins) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
orderbookNew, err := l.GetOrderbook(p.SecondCurrency.String())
|
||||
orderbookNew, err := l.GetOrderbook(p.Quote.String())
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
@@ -109,8 +117,16 @@ func (l *LocalBitcoins) UpdateOrderbook(p pair.CurrencyPair, assetType string) (
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data.Amount / data.Price, Price: data.Price})
|
||||
}
|
||||
|
||||
orderbook.ProcessOrderbook(l.GetName(), p, orderBook, assetType)
|
||||
return orderbook.GetOrderbook(l.Name, p, assetType)
|
||||
orderBook.Pair = p
|
||||
orderBook.ExchangeName = l.GetName()
|
||||
orderBook.AssetType = assetType
|
||||
|
||||
err = orderBook.Process()
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
return orderbook.Get(l.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetAccountInfo retrieves balances for all enabled currencies for the
|
||||
@@ -123,7 +139,7 @@ func (l *LocalBitcoins) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
return response, err
|
||||
}
|
||||
var exchangeCurrency exchange.AccountCurrencyInfo
|
||||
exchangeCurrency.CurrencyName = "BTC"
|
||||
exchangeCurrency.CurrencyName = currency.BTC
|
||||
exchangeCurrency.TotalValue = accountBalance.Total.Balance
|
||||
|
||||
response.Accounts = append(response.Accounts, exchange.Account{
|
||||
@@ -140,14 +156,14 @@ func (l *LocalBitcoins) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
}
|
||||
|
||||
// GetExchangeHistory returns historic trade data since exchange opening.
|
||||
func (l *LocalBitcoins) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
func (l *LocalBitcoins) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
var resp []exchange.TradeHistory
|
||||
|
||||
return resp, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (l *LocalBitcoins) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ exchange.OrderType, amount, _ float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
func (l *LocalBitcoins) SubmitOrder(p currency.Pair, side exchange.OrderSide, _ exchange.OrderType, amount, _ float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
// These are placeholder details
|
||||
// TODO store a user's localbitcoin details to use here
|
||||
@@ -158,7 +174,7 @@ func (l *LocalBitcoins) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide
|
||||
City: "City",
|
||||
Location: "Location",
|
||||
CountryCode: "US",
|
||||
Currency: p.SecondCurrency.String(),
|
||||
Currency: p.Quote.String(),
|
||||
AccountInfo: "-",
|
||||
BankName: "Bank",
|
||||
MSG: side.ToString(),
|
||||
@@ -252,10 +268,10 @@ func (l *LocalBitcoins) GetOrderInfo(orderID string) (exchange.OrderDetail, erro
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (l *LocalBitcoins) GetDepositAddress(cryptocurrency pair.CurrencyItem, _ string) (string, error) {
|
||||
if !strings.EqualFold(symbol.BTC, cryptocurrency.String()) {
|
||||
func (l *LocalBitcoins) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
if !strings.EqualFold(currency.BTC.String(), cryptocurrency.String()) {
|
||||
return "", fmt.Errorf("%s does not have support for currency %s, it only supports bitcoin",
|
||||
l.Name, cryptocurrency.String())
|
||||
l.Name, cryptocurrency)
|
||||
}
|
||||
|
||||
return l.GetWalletAddress()
|
||||
@@ -302,7 +318,10 @@ func (l *LocalBitcoins) GetActiveOrders(getOrdersRequest exchange.GetOrdersReque
|
||||
orderDate, err := time.Parse(time.RFC3339, trade.Data.CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
l.Name, "GetActiveOrders", trade.Data.Advertisement.ID, trade.Data.CreatedAt)
|
||||
l.Name,
|
||||
"GetActiveOrders",
|
||||
trade.Data.Advertisement.ID,
|
||||
trade.Data.CreatedAt)
|
||||
}
|
||||
|
||||
var side exchange.OrderSide
|
||||
@@ -313,18 +332,21 @@ func (l *LocalBitcoins) GetActiveOrders(getOrdersRequest exchange.GetOrdersReque
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
Amount: trade.Data.AmountBTC,
|
||||
Price: trade.Data.Amount,
|
||||
ID: fmt.Sprintf("%v", trade.Data.Advertisement.ID),
|
||||
OrderDate: orderDate,
|
||||
Fee: trade.Data.FeeBTC,
|
||||
OrderSide: side,
|
||||
CurrencyPair: pair.NewCurrencyPairWithDelimiter(symbol.BTC, trade.Data.Currency, l.ConfigCurrencyPairFormat.Delimiter),
|
||||
Exchange: l.Name,
|
||||
Amount: trade.Data.AmountBTC,
|
||||
Price: trade.Data.Amount,
|
||||
ID: fmt.Sprintf("%v", trade.Data.Advertisement.ID),
|
||||
OrderDate: orderDate,
|
||||
Fee: trade.Data.FeeBTC,
|
||||
OrderSide: side,
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
trade.Data.Currency,
|
||||
l.ConfigCurrencyPairFormat.Delimiter),
|
||||
Exchange: l.Name,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
@@ -357,7 +379,10 @@ func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest exchange.GetOrdersReque
|
||||
orderDate, err := time.Parse(time.RFC3339, trade.Data.CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
l.Name, "GetActiveOrders", trade.Data.Advertisement.ID, trade.Data.CreatedAt)
|
||||
l.Name,
|
||||
"GetActiveOrders",
|
||||
trade.Data.Advertisement.ID,
|
||||
trade.Data.CreatedAt)
|
||||
}
|
||||
|
||||
var side exchange.OrderSide
|
||||
@@ -379,19 +404,22 @@ func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest exchange.GetOrdersReque
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
Amount: trade.Data.AmountBTC,
|
||||
Price: trade.Data.Amount,
|
||||
ID: fmt.Sprintf("%v", trade.Data.Advertisement.ID),
|
||||
OrderDate: orderDate,
|
||||
Fee: trade.Data.FeeBTC,
|
||||
OrderSide: side,
|
||||
Status: status,
|
||||
CurrencyPair: pair.NewCurrencyPairWithDelimiter(symbol.BTC, trade.Data.Currency, l.ConfigCurrencyPairFormat.Delimiter),
|
||||
Exchange: l.Name,
|
||||
Amount: trade.Data.AmountBTC,
|
||||
Price: trade.Data.Amount,
|
||||
ID: fmt.Sprintf("%v", trade.Data.Advertisement.ID),
|
||||
OrderDate: orderDate,
|
||||
Fee: trade.Data.FeeBTC,
|
||||
OrderSide: side,
|
||||
Status: status,
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
trade.Data.Currency,
|
||||
l.ConfigCurrencyPairFormat.Delimiter),
|
||||
Exchange: l.Name,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
|
||||
Reference in New Issue
Block a user