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:
Ryan O'Hara-Reid
2019-03-19 11:49:05 +11:00
committed by Adrian Gallagher
parent ed760e184e
commit 0990f9d118
189 changed files with 11982 additions and 8055 deletions

View File

@@ -11,7 +11,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency/symbol"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -88,9 +88,9 @@ func (e *EXMO) Setup(exch config.ExchangeConfig) {
e.SetHTTPClientUserAgent(exch.HTTPUserAgent)
e.RESTPollingDelay = exch.RESTPollingDelay
e.Verbose = exch.Verbose
e.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
e.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
e.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
e.BaseCurrencies = exch.BaseCurrencies
e.AvailablePairs = exch.AvailablePairs
e.EnabledPairs = exch.EnabledPairs
err := e.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
@@ -377,7 +377,8 @@ func (e *EXMO) SendHTTPRequest(path string, result interface{}) error {
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request
func (e *EXMO) SendAuthenticatedHTTPRequest(method, endpoint string, vals url.Values, result interface{}) error {
if !e.AuthenticatedAPISupport {
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, e.Name)
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet,
e.Name)
}
if e.Nonce.Get() == 0 {
@@ -388,10 +389,15 @@ func (e *EXMO) SendAuthenticatedHTTPRequest(method, endpoint string, vals url.Va
vals.Set("nonce", e.Nonce.String())
payload := vals.Encode()
hash := common.GetHMAC(common.HashSHA512, []byte(payload), []byte(e.APISecret))
hash := common.GetHMAC(common.HashSHA512,
[]byte(payload),
[]byte(e.APISecret))
if e.Verbose {
log.Debugf("Sending %s request to %s with params %s\n", method, endpoint, payload)
log.Debugf("Sending %s request to %s with params %s\n",
method,
endpoint,
payload)
}
headers := make(map[string]string)
@@ -401,7 +407,13 @@ func (e *EXMO) SendAuthenticatedHTTPRequest(method, endpoint string, vals url.Va
path := fmt.Sprintf("%s/v%s/%s", e.APIUrl, exmoAPIVersion, endpoint)
return e.SendPayload(method, path, headers, strings.NewReader(payload), result, true, e.Verbose)
return e.SendPayload(method,
path,
headers,
strings.NewReader(payload),
result,
true,
e.Verbose)
}
// GetFee returns an estimate of fee based on type of transaction
@@ -411,11 +423,15 @@ func (e *EXMO) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
case exchange.CryptocurrencyTradeFee:
fee = e.calculateTradingFee(feeBuilder.PurchasePrice, feeBuilder.Amount)
case exchange.CryptocurrencyWithdrawalFee:
fee = getCryptocurrencyWithdrawalFee(feeBuilder.FirstCurrency)
fee = getCryptocurrencyWithdrawalFee(feeBuilder.Pair.Base)
case exchange.InternationalBankWithdrawalFee:
fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem, feeBuilder.Amount, feeBuilder.BankTransactionType)
fee = getInternationalBankWithdrawalFee(feeBuilder.FiatCurrency,
feeBuilder.Amount,
feeBuilder.BankTransactionType)
case exchange.InternationalBankDepositFee:
fee = getInternationalBankDepositFee(feeBuilder.CurrencyItem, feeBuilder.Amount, feeBuilder.BankTransactionType)
fee = getInternationalBankDepositFee(feeBuilder.FiatCurrency,
feeBuilder.Amount,
feeBuilder.BankTransactionType)
}
if fee < 0 {
@@ -425,8 +441,8 @@ func (e *EXMO) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
return fee, nil
}
func getCryptocurrencyWithdrawalFee(currency string) float64 {
return WithdrawalFees[currency]
func getCryptocurrencyWithdrawalFee(c currency.Code) float64 {
return WithdrawalFees[c]
}
func (e *EXMO) calculateTradingFee(purchasePrice, amount float64) float64 {
@@ -439,69 +455,69 @@ func calculateTradingFee(purchasePrice, amount float64) float64 {
return fee * amount * purchasePrice
}
func getInternationalBankWithdrawalFee(currency string, amount float64, bankTransactionType exchange.InternationalBankTransactionType) float64 {
func getInternationalBankWithdrawalFee(c currency.Code, amount float64, bankTransactionType exchange.InternationalBankTransactionType) float64 {
var fee float64
switch bankTransactionType {
case exchange.WireTransfer:
switch currency {
case symbol.RUB:
switch c {
case currency.RUB:
fee = 3200
case symbol.PLN:
case currency.PLN:
fee = 125
case symbol.TRY:
case currency.TRY:
fee = 0
}
case exchange.PerfectMoney:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = 0.01 * amount
case symbol.EUR:
case currency.EUR:
fee = 0.0195 * amount
}
case exchange.Neteller:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = 0.0195 * amount
case symbol.EUR:
case currency.EUR:
fee = 0.0195 * amount
}
case exchange.AdvCash:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = 0.0295 * amount
case symbol.EUR:
case currency.EUR:
fee = 0.03 * amount
case symbol.RUB:
case currency.RUB:
fee = 0.0195 * amount
case symbol.UAH:
case currency.UAH:
fee = 0.0495 * amount
}
case exchange.Payeer:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = 0.0395 * amount
case symbol.EUR:
case currency.EUR:
fee = 0.01 * amount
case symbol.RUB:
case currency.RUB:
fee = 0.0595 * amount
}
case exchange.Skrill:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = 0.0145 * amount
case symbol.EUR:
case currency.EUR:
fee = 0.03 * amount
case symbol.TRY:
case currency.TRY:
fee = 0
}
case exchange.VisaMastercard:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = 0.06 * amount
case symbol.EUR:
case currency.EUR:
fee = 0.06 * amount
case symbol.PLN:
case currency.PLN:
fee = 0.06 * amount
}
}
@@ -509,54 +525,54 @@ func getInternationalBankWithdrawalFee(currency string, amount float64, bankTran
return fee
}
func getInternationalBankDepositFee(currency string, amount float64, bankTransactionType exchange.InternationalBankTransactionType) float64 {
func getInternationalBankDepositFee(c currency.Code, amount float64, bankTransactionType exchange.InternationalBankTransactionType) float64 {
var fee float64
switch bankTransactionType {
case exchange.WireTransfer:
switch currency {
case symbol.RUB:
switch c {
case currency.RUB:
fee = 1600
case symbol.PLN:
case currency.PLN:
fee = 30
case symbol.TRY:
case currency.TRY:
fee = 0
}
case exchange.Neteller:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = (0.035 * amount) + 0.29
case symbol.EUR:
case currency.EUR:
fee = (0.035 * amount) + 0.25
}
case exchange.AdvCash:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = 0.0295 * amount
case symbol.EUR:
case currency.EUR:
fee = 0.01 * amount
case symbol.RUB:
case currency.RUB:
fee = 0.0495 * amount
case symbol.UAH:
case currency.UAH:
fee = 0.01 * amount
}
case exchange.Payeer:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = 0.0195 * amount
case symbol.EUR:
case currency.EUR:
fee = 0.0295 * amount
case symbol.RUB:
case currency.RUB:
fee = 0.0345 * amount
}
case exchange.Skrill:
switch currency {
case symbol.USD:
switch c {
case currency.USD:
fee = (0.0495 * amount) + 0.36
case symbol.EUR:
case currency.EUR:
fee = (0.0295 * amount) + 0.29
case symbol.PLN:
case currency.PLN:
fee = (0.035 * amount) + 1.21
case symbol.TRY:
case currency.TRY:
fee = 0
}
}