Offline worst case trade fees (#274)

* Really basic getSimulated fee function everywhere

* Worst case fees for all exchanges

* Adds tests, fixes comment spacing. Adds wrapper logic. Makes test api key var name consistent. Removes some okcoin ETT tests

* Removes redundant functions

* linting issues. Fixes introduces huobi issues

* More linting

* Stops trying to hide ETT problems, uses iota

* Skips ETT tests for now
This commit is contained in:
Scott
2019-04-09 19:38:31 +10:00
committed by Adrian Gallagher
parent eeda97bbaf
commit e56fc26d93
83 changed files with 814 additions and 136 deletions

View File

@@ -1086,6 +1086,8 @@ func (b *Bitfinex) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error) {
fee = getInternationalBankDepositFee(feeBuilder.Amount)
case exchange.InternationalBankWithdrawalFee:
fee = getInternationalBankWithdrawalFee(feeBuilder.Amount)
case exchange.OfflineTradeFee:
fee = getOfflineTradeFee(feeBuilder.PurchasePrice, feeBuilder.Amount)
}
if fee < 0 {
fee = 0
@@ -1093,6 +1095,12 @@ func (b *Bitfinex) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error) {
return fee, nil
}
// getOfflineTradeFee calculates the worst case-scenario trading fee
// does not require an API request, requires manual updating
func getOfflineTradeFee(price, amount float64) float64 {
return 0.001 * price * amount
}
// GetCryptocurrencyWithdrawalFee returns an estimate of fee based on type of transaction
func (b *Bitfinex) GetCryptocurrencyWithdrawalFee(c currency.Code, accountFees AccountFees) (fee float64, err error) {
switch result := accountFees.Withdraw[c.String()].(type) {

View File

@@ -14,8 +14,8 @@ import (
// Please supply your own keys here to do better tests
const (
testAPIKey = ""
testAPISecret = ""
apiKey = ""
apiSecret = ""
canManipulateRealOrders = false
)
@@ -30,8 +30,8 @@ func TestSetup(t *testing.T) {
t.Error("Test Failed - Bitfinex Setup() init error")
}
b.Setup(&bfxConfig)
b.APIKey = testAPIKey
b.APISecret = testAPISecret
b.APIKey = apiKey
b.APISecret = apiSecret
if !b.Enabled || b.AuthenticatedAPISupport || b.RESTPollingDelay != time.Duration(10) ||
b.Verbose || b.Websocket.IsEnabled() || len(b.BaseCurrencies) < 1 ||
len(b.AvailablePairs) < 1 || len(b.EnabledPairs) < 1 {
@@ -619,12 +619,27 @@ func setFeeBuilder() *exchange.FeeBuilder {
}
}
// TestGetFeeByTypeOfflineTradeFee logic test
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
var feeBuilder = setFeeBuilder()
b.GetFeeByType(feeBuilder)
if apiKey == "" || apiSecret == "" {
if feeBuilder.FeeType != exchange.OfflineTradeFee {
t.Errorf("Expected %v, received %v", exchange.OfflineTradeFee, feeBuilder.FeeType)
}
} else {
if feeBuilder.FeeType != exchange.CryptocurrencyTradeFee {
t.Errorf("Expected %v, received %v", exchange.CryptocurrencyTradeFee, feeBuilder.FeeType)
}
}
}
func TestGetFee(t *testing.T) {
b.SetDefaults()
TestSetup(t)
var feeBuilder = setFeeBuilder()
if testAPIKey != "" || testAPISecret != "" {
if apiKey != "" || apiSecret != "" {
// CryptocurrencyTradeFee Basic
if resp, err := b.GetFee(feeBuilder); resp != float64(0.002) || err != nil {
t.Error(err)

View File

@@ -329,6 +329,10 @@ func (b *Bitfinex) GetWebsocket() (*exchange.Websocket, error) {
// GetFeeByType returns an estimate of fee based on type of transaction
func (b *Bitfinex) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
if (b.APIKey == "" || b.APISecret == "") && // Todo check connection status
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
feeBuilder.FeeType = exchange.OfflineTradeFee
}
return b.GetFee(feeBuilder)
}