mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-22 23:16: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
@@ -10,7 +10,7 @@
|
||||
import "github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
|
||||
// Create new pair
|
||||
newPair := pair.NewCurrencyPair("BTC", "USD")
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
|
||||
// Retrieve different parts of the pair
|
||||
bitcoinString := newPair.GetFirstCurrency
|
||||
|
||||
@@ -29,7 +29,7 @@ totalAsks, totalOrderbookVal := ob.CalculateTotalAsks()
|
||||
the package itself.
|
||||
|
||||
```go
|
||||
ob, err := orderbook.GetOrderbook(...)
|
||||
ob, err := orderbook.Get(...)
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func ({{.Variable}} *{{.CapitalName}}) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func ({{.Variable}} *{{.CapitalName}}) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) UpdateTicker(p currency.Pair, assetType string) (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 pair.CurrencyPair, assetTy
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker({{.Variable}}.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return {{.Variable}}.UpdateTicker(p, assetType)
|
||||
@@ -68,8 +68,8 @@ func ({{.Variable}} *{{.CapitalName}}) GetTickerPrice(p pair.CurrencyPair, asset
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns orderbook base on the currency pair
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook({{.Variable}}.GetName(), currency, assetType)
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetOrderbookEx(currency currency.Pair, assetType string) (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}}) GetOrderbookEx(currency pair.CurrencyPair
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
//NOTE UPDATE ORDERBOOK EXAMPLE
|
||||
//orderbookNew, err := {{.Variable}}.GetOrderBook(exchange.FormatExchangeCurrency({{.Variable}}.Name, p).String(), 1000)
|
||||
@@ -94,7 +94,7 @@ func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(p pair.CurrencyPair, asse
|
||||
//}
|
||||
|
||||
//orderbook.ProcessOrderbook(b.GetName(), p, orderBook, assetType)
|
||||
//return orderbook.GetOrderbook({{.Variable}}.Name, p, assetType)
|
||||
//return orderbook.Get({{.Variable}}.Name, p, assetType)
|
||||
return orderBook, nil // NOTE DO NOT USE AS RETURN
|
||||
}
|
||||
|
||||
@@ -111,12 +111,12 @@ func ({{.Variable}} *{{.CapitalName}}) GetFundingHistory() ([]exchange.FundHisto
|
||||
}
|
||||
|
||||
// GetExchangeHistory returns historic trade data since exchange opening.
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
|
||||
return exchange.SubmitOrderResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -3,40 +3,45 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/bitfinex"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
"github.com/thrasher-/gocryptotrader/portfolio"
|
||||
)
|
||||
|
||||
var (
|
||||
priceMap map[string]float64
|
||||
displayCurrency string
|
||||
priceMap map[currency.Code]float64
|
||||
displayCurrency currency.Code
|
||||
)
|
||||
|
||||
func printSummary(msg string, amount float64) {
|
||||
log.Println()
|
||||
log.Println(fmt.Sprintf("%s in USD: $%.2f", msg, amount))
|
||||
|
||||
if displayCurrency != "USD" {
|
||||
conv, err := currency.ConvertCurrency(amount, "USD", displayCurrency)
|
||||
if displayCurrency != currency.USD {
|
||||
conv, err := currency.ConvertCurrency(amount,
|
||||
currency.USD,
|
||||
displayCurrency)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err)
|
||||
} else {
|
||||
symb, err := symbol.GetSymbolByCurrencyName(displayCurrency)
|
||||
symb, err := currency.GetSymbolByCurrencyName(displayCurrency)
|
||||
if err != nil {
|
||||
log.Println(fmt.Sprintf("%s in %s: %.2f", msg, displayCurrency, conv))
|
||||
log.Println(fmt.Sprintf("%s in %s: %.2f",
|
||||
msg,
|
||||
displayCurrency,
|
||||
conv))
|
||||
} else {
|
||||
log.Println(fmt.Sprintf("%s in %s: %s%.2f", msg, displayCurrency, symb, conv))
|
||||
log.Println(fmt.Sprintf("%s in %s: %s%.2f",
|
||||
msg,
|
||||
displayCurrency,
|
||||
symb,
|
||||
conv))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
log.Println()
|
||||
}
|
||||
|
||||
func getOnlineOfflinePortfolio(coins []portfolio.Coin, online bool) {
|
||||
@@ -88,34 +93,34 @@ func main() {
|
||||
}
|
||||
|
||||
cfg.RetrieveConfigCurrencyPairs(true)
|
||||
portfolioMap := make(map[string]PortfolioTemp)
|
||||
portfolioMap := make(map[currency.Code]PortfolioTemp)
|
||||
total := float64(0)
|
||||
|
||||
log.Println("Fetching currency data..")
|
||||
var fiatCurrencies []string
|
||||
var fiatCurrencies []currency.Code
|
||||
for _, y := range result.Totals {
|
||||
if currency.IsFiatCurrency(y.Coin) {
|
||||
if y.Coin.IsFiatCurrency() {
|
||||
fiatCurrencies = append(fiatCurrencies, y.Coin)
|
||||
}
|
||||
}
|
||||
err = currency.SeedCurrencyData(common.JoinStrings(fiatCurrencies, ","))
|
||||
err = currency.SeedForeignExchangeData(fiatCurrencies)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Fetched currency data.")
|
||||
log.Println("Fetching ticker data and calculating totals..")
|
||||
priceMap = make(map[string]float64)
|
||||
priceMap["USD"] = 1
|
||||
priceMap = make(map[currency.Code]float64)
|
||||
priceMap[currency.USD] = 1
|
||||
|
||||
for _, y := range result.Totals {
|
||||
pf := PortfolioTemp{}
|
||||
pf.Balance = y.Balance
|
||||
pf.Subtotal = 0
|
||||
|
||||
if currency.IsDefaultCurrency(y.Coin) {
|
||||
if y.Coin != "USD" {
|
||||
conv, err := currency.ConvertCurrency(y.Balance, y.Coin, "USD")
|
||||
if y.Coin.IsDefaultFiatCurrency() {
|
||||
if y.Coin != currency.USD {
|
||||
conv, err := currency.ConvertCurrency(y.Balance, y.Coin, currency.USD)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
@@ -127,7 +132,7 @@ func main() {
|
||||
}
|
||||
} else {
|
||||
bf := bitfinex.Bitfinex{}
|
||||
ticker, errf := bf.GetTicker(y.Coin + "USD")
|
||||
ticker, errf := bf.GetTicker(y.Coin.String() + currency.USD.String())
|
||||
if errf != nil {
|
||||
log.Println(errf)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user