mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 15:11:07 +00:00
Calculating each exchange's fees (#188)
* Adds some constants for fee types Adds some fee calculation in an attempt to be generic Adds fee stuff to Bittrex Adds fee stuff to bitstamp * Fixes bitstamp fee calculation * Tests Tests all scenarios for GetFeeByType * Adds method to wrapper Adds err to response Checks for err * Adds support for Bittrex fees * Adds maker/taker dynamic to fees Updates tests Adds bitmex fee support Removes unused switch case scenarios to not waste space * Adds bithumb support for fee calculation * Adds Bitfinex fee support Adds list of currencies as const strings Sets up bitflyer * Fixes arguments * Greatly expands symbols Adds Binance fee calculation support Cleans up previous exchanges * Fixes errors for fee calculations * Adds ANX fee support * Adds btcc fee support Adds alphapoint fee wrapper support Renames method to match "enum" Uses symbols in tests, not inline strings * Adds support for BTCMarkets fee calculation Adds new method to retrieve fee amount from BTCMarkets Adds new fee type struct: FeeBuilder Updates ANX and BTCMarkets to use new FeeBuilder type struct Standardises the tests to run when it comes to fee calculation * Migrates all existing exchange fee to use new feebuilder type struct Uses standard testing model * Fixes unit tests * Updates maker taker fees in test config * Removes parallel from fee testing * Removes more parallel from tests * Adds coinbasepro fee support * Adds Coinut fee support * Adds Exmo fee support Adds maker fee support to coinut Introduces a type for fees and bank transfers to prevent random strings being used * Adds partial bitflyer support Moves bitflyer to feeBuilder struct * Adds gateio fee support * Adds Gemini fee support * Adds hitbtc fee support * Adds huobi fee support * Adds HuobiHadax fee support * Adds itbit fee support * Adds partial kraken fee support with trading fees * Finishes basic Kraken fee support * Adds basic LakeBTC fee support * Adds basic liqui fee support * Adds localbitcoins fee support....... * Adds basic okcoin fee support * Adds simple OKEX fee support Adds many new currency symbols Fixes liqui's fees * Adds poloniex fee support * Adds fee support for Yobit * Adds WEX fee support * Adds ZB fee support * Removes bad reference * Improves accuracy of variable name * trading fee method names are now consistent (cherry picked from commit 21c82e8b90cae590cfd73d365d7be39e1a00e973) * Fixes rebasing issues * Fixes issues from rebase Removes "IsTaker" as IsMaker bool can imply taker Updates tests to actually work. * Adds a zero to the test * Fixes bitfinex api endpoints and fixes fee calculations * Updates btcmarkets trading fee calculation * Verifies tests with apis for all exchanges except coinbasepro, itbit and bitflyer Removes taker fee test as taker is default * Removes redundant all exchange wrapper error checks due to the error checks being redundant * Addresses review comments: - Renames variables - Changes how functions return data - Fixes typo
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
@@ -54,65 +55,65 @@ type HitBTC struct {
|
||||
}
|
||||
|
||||
// SetDefaults sets default settings for hitbtc
|
||||
func (p *HitBTC) SetDefaults() {
|
||||
p.Name = "HitBTC"
|
||||
p.Enabled = false
|
||||
p.Fee = 0
|
||||
p.Verbose = false
|
||||
p.RESTPollingDelay = 10
|
||||
p.RequestCurrencyPairFormat.Delimiter = ""
|
||||
p.RequestCurrencyPairFormat.Uppercase = true
|
||||
p.ConfigCurrencyPairFormat.Delimiter = "-"
|
||||
p.ConfigCurrencyPairFormat.Uppercase = true
|
||||
p.AssetTypes = []string{ticker.Spot}
|
||||
p.SupportsAutoPairUpdating = true
|
||||
p.SupportsRESTTickerBatching = true
|
||||
p.Requester = request.New(p.Name,
|
||||
func (h *HitBTC) SetDefaults() {
|
||||
h.Name = "HitBTC"
|
||||
h.Enabled = false
|
||||
h.Fee = 0
|
||||
h.Verbose = false
|
||||
h.RESTPollingDelay = 10
|
||||
h.RequestCurrencyPairFormat.Delimiter = ""
|
||||
h.RequestCurrencyPairFormat.Uppercase = true
|
||||
h.ConfigCurrencyPairFormat.Delimiter = "-"
|
||||
h.ConfigCurrencyPairFormat.Uppercase = true
|
||||
h.AssetTypes = []string{ticker.Spot}
|
||||
h.SupportsAutoPairUpdating = true
|
||||
h.SupportsRESTTickerBatching = true
|
||||
h.Requester = request.New(h.Name,
|
||||
request.NewRateLimit(time.Second, hitbtcAuthRate),
|
||||
request.NewRateLimit(time.Second, hitbtcUnauthRate),
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
||||
p.APIUrlDefault = apiURL
|
||||
p.APIUrl = p.APIUrlDefault
|
||||
p.WebsocketInit()
|
||||
h.APIUrlDefault = apiURL
|
||||
h.APIUrl = h.APIUrlDefault
|
||||
h.WebsocketInit()
|
||||
}
|
||||
|
||||
// Setup sets user exchange configuration settings
|
||||
func (p *HitBTC) Setup(exch config.ExchangeConfig) {
|
||||
func (h *HitBTC) Setup(exch config.ExchangeConfig) {
|
||||
if !exch.Enabled {
|
||||
p.SetEnabled(false)
|
||||
h.SetEnabled(false)
|
||||
} else {
|
||||
p.Enabled = true
|
||||
p.AuthenticatedAPISupport = exch.AuthenticatedAPISupport
|
||||
p.SetAPIKeys(exch.APIKey, exch.APISecret, "", false)
|
||||
p.SetHTTPClientTimeout(exch.HTTPTimeout)
|
||||
p.SetHTTPClientUserAgent(exch.HTTPUserAgent)
|
||||
p.RESTPollingDelay = exch.RESTPollingDelay // Max 60000ms
|
||||
p.Verbose = exch.Verbose
|
||||
p.Websocket.SetEnabled(exch.Websocket)
|
||||
p.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
|
||||
p.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
p.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
|
||||
err := p.SetCurrencyPairFormat()
|
||||
h.Enabled = true
|
||||
h.AuthenticatedAPISupport = exch.AuthenticatedAPISupport
|
||||
h.SetAPIKeys(exch.APIKey, exch.APISecret, "", false)
|
||||
h.SetHTTPClientTimeout(exch.HTTPTimeout)
|
||||
h.SetHTTPClientUserAgent(exch.HTTPUserAgent)
|
||||
h.RESTPollingDelay = exch.RESTPollingDelay // Max 60000ms
|
||||
h.Verbose = exch.Verbose
|
||||
h.Websocket.SetEnabled(exch.Websocket)
|
||||
h.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
|
||||
h.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
h.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
|
||||
err := h.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = p.SetAssetTypes()
|
||||
err = h.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = p.SetAutoPairDefaults()
|
||||
err = h.SetAutoPairDefaults()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = p.SetAPIURL(exch)
|
||||
err = h.SetAPIURL(exch)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = p.SetClientProxyAddress(exch.ProxyAddress)
|
||||
err = h.SetClientProxyAddress(exch.ProxyAddress)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = p.WebsocketSetup(p.WsConnect,
|
||||
err = h.WebsocketSetup(h.WsConnect,
|
||||
exch.Name,
|
||||
exch.Websocket,
|
||||
hitbtcWebsocketAddress,
|
||||
@@ -123,25 +124,20 @@ func (p *HitBTC) Setup(exch config.ExchangeConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetFee returns the fee for hitbtc
|
||||
func (p *HitBTC) GetFee() float64 {
|
||||
return p.Fee
|
||||
}
|
||||
|
||||
// Public Market Data
|
||||
// https://api.hitbtc.com/?python#market-data
|
||||
|
||||
// GetCurrencies returns the actual list of available currencies, tokens, ICO
|
||||
// etc.
|
||||
func (p *HitBTC) GetCurrencies(currency string) (map[string]Currencies, error) {
|
||||
func (h *HitBTC) GetCurrencies() (map[string]Currencies, error) {
|
||||
type Response struct {
|
||||
Data []Currencies
|
||||
}
|
||||
resp := Response{}
|
||||
path := fmt.Sprintf("%s/%s/%s", p.APIUrl, apiV2Currency, currency)
|
||||
path := fmt.Sprintf("%s/%s", h.APIUrl, apiV2Currency)
|
||||
|
||||
ret := make(map[string]Currencies)
|
||||
err := p.SendHTTPRequest(path, &resp.Data)
|
||||
err := h.SendHTTPRequest(path, &resp.Data)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
@@ -152,17 +148,29 @@ func (p *HitBTC) GetCurrencies(currency string) (map[string]Currencies, error) {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// GetCurrency returns the actual list of available currencies, tokens, ICO
|
||||
// etc.
|
||||
func (h *HitBTC) GetCurrency(currency string) (Currencies, error) {
|
||||
type Response struct {
|
||||
Data Currencies
|
||||
}
|
||||
resp := Response{}
|
||||
path := fmt.Sprintf("%s/%s/%s", h.APIUrl, apiV2Currency, currency)
|
||||
|
||||
return resp.Data, h.SendHTTPRequest(path, &resp.Data)
|
||||
}
|
||||
|
||||
// GetSymbols Return the actual list of currency symbols (currency pairs) traded
|
||||
// on HitBTC exchange. The first listed currency of a symbol is called the base
|
||||
// currency, and the second currency is called the quote currency. The currency
|
||||
// pair indicates how much of the quote currency is needed to purchase one unit
|
||||
// of the base currency.
|
||||
func (p *HitBTC) GetSymbols(symbol string) ([]string, error) {
|
||||
func (h *HitBTC) GetSymbols(symbol string) ([]string, error) {
|
||||
resp := []Symbol{}
|
||||
path := fmt.Sprintf("%s/%s/%s", p.APIUrl, apiV2Symbol, symbol)
|
||||
path := fmt.Sprintf("%s/%s/%s", h.APIUrl, apiV2Symbol, symbol)
|
||||
|
||||
ret := make([]string, 0, len(resp))
|
||||
err := p.SendHTTPRequest(path, &resp)
|
||||
err := h.SendHTTPRequest(path, &resp)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
@@ -175,24 +183,24 @@ func (p *HitBTC) GetSymbols(symbol string) ([]string, error) {
|
||||
|
||||
// GetSymbolsDetailed is the same as above but returns an array of symbols with
|
||||
// all their details.
|
||||
func (p *HitBTC) GetSymbolsDetailed() ([]Symbol, error) {
|
||||
func (h *HitBTC) GetSymbolsDetailed() ([]Symbol, error) {
|
||||
resp := []Symbol{}
|
||||
path := fmt.Sprintf("%s/%s", p.APIUrl, apiV2Symbol)
|
||||
path := fmt.Sprintf("%s/%s", h.APIUrl, apiV2Symbol)
|
||||
|
||||
return resp, p.SendHTTPRequest(path, &resp)
|
||||
return resp, h.SendHTTPRequest(path, &resp)
|
||||
}
|
||||
|
||||
// GetTicker returns ticker information
|
||||
func (p *HitBTC) GetTicker(symbol string) (map[string]Ticker, error) {
|
||||
func (h *HitBTC) GetTicker(symbol string) (map[string]Ticker, error) {
|
||||
resp1 := []TickerResponse{}
|
||||
resp2 := TickerResponse{}
|
||||
ret := make(map[string]TickerResponse)
|
||||
result := make(map[string]Ticker)
|
||||
path := fmt.Sprintf("%s/%s/%s", p.APIUrl, apiV2Ticker, symbol)
|
||||
path := fmt.Sprintf("%s/%s/%s", h.APIUrl, apiV2Ticker, symbol)
|
||||
var err error
|
||||
|
||||
if symbol == "" {
|
||||
err = p.SendHTTPRequest(path, &resp1)
|
||||
err = h.SendHTTPRequest(path, &resp1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -203,7 +211,7 @@ func (p *HitBTC) GetTicker(symbol string) (map[string]Ticker, error) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = p.SendHTTPRequest(path, &resp2)
|
||||
err = h.SendHTTPRequest(path, &resp2)
|
||||
ret[resp2.Symbol] = resp2
|
||||
}
|
||||
|
||||
@@ -245,12 +253,12 @@ func (p *HitBTC) GetTicker(symbol string) (map[string]Ticker, error) {
|
||||
}
|
||||
|
||||
// GetTrades returns trades from hitbtc
|
||||
func (p *HitBTC) GetTrades(currencyPair, from, till, limit, offset, by, sort string) ([]TradeHistory, error) {
|
||||
func (h *HitBTC) GetTrades(currencyPair, from, till, limit, offset, by, sort string) ([]TradeHistory, error) {
|
||||
// start Number or Datetime
|
||||
// end Number or Datetime
|
||||
// limit Number
|
||||
// offset Number
|
||||
// by Filtration definition. Accepted values: id, timestamp. Default timestamp
|
||||
// by Filtration definition. Accepted values: id, timestamh. Default timestamp
|
||||
// sort Default DESC
|
||||
vals := url.Values{}
|
||||
|
||||
@@ -279,14 +287,14 @@ func (p *HitBTC) GetTrades(currencyPair, from, till, limit, offset, by, sort str
|
||||
}
|
||||
|
||||
resp := []TradeHistory{}
|
||||
path := fmt.Sprintf("%s/%s/%s?%s", p.APIUrl, apiV2Trades, currencyPair, vals.Encode())
|
||||
path := fmt.Sprintf("%s/%s/%s?%s", h.APIUrl, apiV2Trades, currencyPair, vals.Encode())
|
||||
|
||||
return resp, p.SendHTTPRequest(path, &resp)
|
||||
return resp, h.SendHTTPRequest(path, &resp)
|
||||
}
|
||||
|
||||
// GetOrderbook an order book is an electronic list of buy and sell orders for a
|
||||
// specific symbol, organized by price level.
|
||||
func (p *HitBTC) GetOrderbook(currencyPair string, limit int) (Orderbook, error) {
|
||||
func (h *HitBTC) GetOrderbook(currencyPair string, limit int) (Orderbook, error) {
|
||||
// limit Limit of orderbook levels, default 100. Set 0 to view full orderbook levels
|
||||
vals := url.Values{}
|
||||
|
||||
@@ -295,9 +303,9 @@ func (p *HitBTC) GetOrderbook(currencyPair string, limit int) (Orderbook, error)
|
||||
}
|
||||
|
||||
resp := OrderbookResponse{}
|
||||
path := fmt.Sprintf("%s/%s/%s?%s", p.APIUrl, apiV2Orderbook, currencyPair, vals.Encode())
|
||||
path := fmt.Sprintf("%s/%s/%s?%s", h.APIUrl, apiV2Orderbook, currencyPair, vals.Encode())
|
||||
|
||||
err := p.SendHTTPRequest(path, &resp)
|
||||
err := h.SendHTTPRequest(path, &resp)
|
||||
if err != nil {
|
||||
return Orderbook{}, err
|
||||
}
|
||||
@@ -315,7 +323,7 @@ func (p *HitBTC) GetOrderbook(currencyPair string, limit int) (Orderbook, error)
|
||||
|
||||
// GetCandles returns candles which is used for OHLC a specific symbol.
|
||||
// Note: Result contain candles only with non zero volume.
|
||||
func (p *HitBTC) GetCandles(currencyPair, limit, period string) ([]ChartData, error) {
|
||||
func (h *HitBTC) GetCandles(currencyPair, limit, period string) ([]ChartData, error) {
|
||||
// limit Limit of candles, default 100.
|
||||
// period One of: M1 (one minute), M3, M5, M15, M30, H1, H4, D1, D7, 1M (one month). Default is M30 (30 minutes).
|
||||
vals := url.Values{}
|
||||
@@ -329,18 +337,18 @@ func (p *HitBTC) GetCandles(currencyPair, limit, period string) ([]ChartData, er
|
||||
}
|
||||
|
||||
resp := []ChartData{}
|
||||
path := fmt.Sprintf("%s/%s/%s?%s", p.APIUrl, apiV2Candles, currencyPair, vals.Encode())
|
||||
path := fmt.Sprintf("%s/%s/%s?%s", h.APIUrl, apiV2Candles, currencyPair, vals.Encode())
|
||||
|
||||
return resp, p.SendHTTPRequest(path, &resp)
|
||||
return resp, h.SendHTTPRequest(path, &resp)
|
||||
}
|
||||
|
||||
// Authenticated Market Data
|
||||
// https://api.hitbtc.com/?python#market-data
|
||||
|
||||
// GetBalances returns full balance for your account
|
||||
func (p *HitBTC) GetBalances() (map[string]Balance, error) {
|
||||
func (h *HitBTC) GetBalances() (map[string]Balance, error) {
|
||||
result := []Balance{}
|
||||
err := p.SendAuthenticatedHTTPRequest("GET", apiV2Balance, url.Values{}, &result)
|
||||
err := h.SendAuthenticatedHTTPRequest("GET", apiV2Balance, url.Values{}, &result)
|
||||
ret := make(map[string]Balance)
|
||||
|
||||
if err != nil {
|
||||
@@ -355,31 +363,31 @@ func (p *HitBTC) GetBalances() (map[string]Balance, error) {
|
||||
}
|
||||
|
||||
// GetDepositAddresses returns a deposit address for a specific currency
|
||||
func (p *HitBTC) GetDepositAddresses(currency string) (DepositCryptoAddresses, error) {
|
||||
func (h *HitBTC) GetDepositAddresses(currency string) (DepositCryptoAddresses, error) {
|
||||
resp := DepositCryptoAddresses{}
|
||||
err := p.SendAuthenticatedHTTPRequest("GET", apiV2CryptoAddress+"/"+currency, url.Values{}, &resp)
|
||||
err := h.SendAuthenticatedHTTPRequest("GET", apiV2CryptoAddress+"/"+currency, url.Values{}, &resp)
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GenerateNewAddress generates a new deposit address for a currency
|
||||
func (p *HitBTC) GenerateNewAddress(currency string) (DepositCryptoAddresses, error) {
|
||||
func (h *HitBTC) GenerateNewAddress(currency string) (DepositCryptoAddresses, error) {
|
||||
resp := DepositCryptoAddresses{}
|
||||
err := p.SendAuthenticatedHTTPRequest("POST", apiV2CryptoAddress+"/"+currency, url.Values{}, &resp)
|
||||
err := h.SendAuthenticatedHTTPRequest("POST", apiV2CryptoAddress+"/"+currency, url.Values{}, &resp)
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GetActiveorders returns all your active orders
|
||||
func (p *HitBTC) GetActiveorders(currency string) ([]Order, error) {
|
||||
func (h *HitBTC) GetActiveorders(currency string) ([]Order, error) {
|
||||
resp := []Order{}
|
||||
err := p.SendAuthenticatedHTTPRequest("GET", orders+"?symbol="+currency, url.Values{}, &resp)
|
||||
err := h.SendAuthenticatedHTTPRequest("GET", orders+"?symbol="+currency, url.Values{}, &resp)
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GetAuthenticatedTradeHistory returns your trade history
|
||||
func (p *HitBTC) GetAuthenticatedTradeHistory(currency, start, end string) (interface{}, error) {
|
||||
func (h *HitBTC) GetAuthenticatedTradeHistory(currency, start, end string) (interface{}, error) {
|
||||
values := url.Values{}
|
||||
|
||||
if start != "" {
|
||||
@@ -394,17 +402,17 @@ func (p *HitBTC) GetAuthenticatedTradeHistory(currency, start, end string) (inte
|
||||
values.Set("currencyPair", currency)
|
||||
result := AuthenticatedTradeHistoryResponse{}
|
||||
|
||||
return result, p.SendAuthenticatedHTTPRequest("POST", apiV2TradeHistory, values, &result.Data)
|
||||
return result, h.SendAuthenticatedHTTPRequest("POST", apiV2TradeHistory, values, &result.Data)
|
||||
}
|
||||
|
||||
values.Set("currencyPair", "all")
|
||||
result := AuthenticatedTradeHistoryAll{}
|
||||
|
||||
return result, p.SendAuthenticatedHTTPRequest("POST", apiV2TradeHistory, values, &result.Data)
|
||||
return result, h.SendAuthenticatedHTTPRequest("POST", apiV2TradeHistory, values, &result.Data)
|
||||
}
|
||||
|
||||
// PlaceOrder places an order on the exchange
|
||||
func (p *HitBTC) PlaceOrder(currency string, rate, amount float64, immediate, fillOrKill, buy bool) (OrderResponse, error) {
|
||||
func (h *HitBTC) PlaceOrder(currency string, rate, amount float64, immediate, fillOrKill, buy bool) (OrderResponse, error) {
|
||||
result := OrderResponse{}
|
||||
values := url.Values{}
|
||||
|
||||
@@ -427,7 +435,7 @@ func (p *HitBTC) PlaceOrder(currency string, rate, amount float64, immediate, fi
|
||||
values.Set("fillOrKill", "1")
|
||||
}
|
||||
|
||||
err := p.SendAuthenticatedHTTPRequest("POST", orderType, values, &result)
|
||||
err := h.SendAuthenticatedHTTPRequest("POST", orderType, values, &result)
|
||||
|
||||
if err != nil {
|
||||
return result, err
|
||||
@@ -437,12 +445,12 @@ func (p *HitBTC) PlaceOrder(currency string, rate, amount float64, immediate, fi
|
||||
}
|
||||
|
||||
// CancelOrder cancels a specific order by OrderID
|
||||
func (p *HitBTC) CancelOrder(orderID int64) (bool, error) {
|
||||
func (h *HitBTC) CancelOrder(orderID int64) (bool, error) {
|
||||
result := GenericResponse{}
|
||||
values := url.Values{}
|
||||
values.Set("orderNumber", strconv.FormatInt(orderID, 10))
|
||||
|
||||
err := p.SendAuthenticatedHTTPRequest("POST", orderCancel, values, &result)
|
||||
err := h.SendAuthenticatedHTTPRequest("POST", orderCancel, values, &result)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -456,7 +464,7 @@ func (p *HitBTC) CancelOrder(orderID int64) (bool, error) {
|
||||
}
|
||||
|
||||
// MoveOrder generates a new move order
|
||||
func (p *HitBTC) MoveOrder(orderID int64, rate, amount float64) (MoveOrderResponse, error) {
|
||||
func (h *HitBTC) MoveOrder(orderID int64, rate, amount float64) (MoveOrderResponse, error) {
|
||||
result := MoveOrderResponse{}
|
||||
values := url.Values{}
|
||||
values.Set("orderNumber", strconv.FormatInt(orderID, 10))
|
||||
@@ -466,7 +474,7 @@ func (p *HitBTC) MoveOrder(orderID int64, rate, amount float64) (MoveOrderRespon
|
||||
values.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
}
|
||||
|
||||
err := p.SendAuthenticatedHTTPRequest("POST", orderMove, values, &result)
|
||||
err := h.SendAuthenticatedHTTPRequest("POST", orderMove, values, &result)
|
||||
|
||||
if err != nil {
|
||||
return result, err
|
||||
@@ -480,7 +488,7 @@ func (p *HitBTC) MoveOrder(orderID int64, rate, amount float64) (MoveOrderRespon
|
||||
}
|
||||
|
||||
// Withdraw allows for the withdrawal to a specific address
|
||||
func (p *HitBTC) Withdraw(currency, address string, amount float64) (bool, error) {
|
||||
func (h *HitBTC) Withdraw(currency, address string, amount float64) (bool, error) {
|
||||
result := Withdraw{}
|
||||
values := url.Values{}
|
||||
|
||||
@@ -488,7 +496,7 @@ func (p *HitBTC) Withdraw(currency, address string, amount float64) (bool, error
|
||||
values.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
values.Set("address", address)
|
||||
|
||||
err := p.SendAuthenticatedHTTPRequest("POST", apiV2CryptoWithdraw, values, &result)
|
||||
err := h.SendAuthenticatedHTTPRequest("POST", apiV2CryptoWithdraw, values, &result)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -502,21 +510,21 @@ func (p *HitBTC) Withdraw(currency, address string, amount float64) (bool, error
|
||||
}
|
||||
|
||||
// GetFeeInfo returns current fee information
|
||||
func (p *HitBTC) GetFeeInfo(currencyPair string) (Fee, error) {
|
||||
func (h *HitBTC) GetFeeInfo(currencyPair string) (Fee, error) {
|
||||
result := Fee{}
|
||||
err := p.SendAuthenticatedHTTPRequest("GET", apiV2FeeInfo+"/"+currencyPair, url.Values{}, &result)
|
||||
err := h.SendAuthenticatedHTTPRequest("GET", apiV2FeeInfo+"/"+currencyPair, url.Values{}, &result)
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
// GetTradableBalances returns current tradable balances
|
||||
func (p *HitBTC) GetTradableBalances() (map[string]map[string]float64, error) {
|
||||
func (h *HitBTC) GetTradableBalances() (map[string]map[string]float64, error) {
|
||||
type Response struct {
|
||||
Data map[string]map[string]interface{}
|
||||
}
|
||||
result := Response{}
|
||||
|
||||
err := p.SendAuthenticatedHTTPRequest("POST", tradableBalances, url.Values{}, &result.Data)
|
||||
err := h.SendAuthenticatedHTTPRequest("POST", tradableBalances, url.Values{}, &result.Data)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -535,7 +543,7 @@ func (p *HitBTC) GetTradableBalances() (map[string]map[string]float64, error) {
|
||||
}
|
||||
|
||||
// TransferBalance transfers a balance
|
||||
func (p *HitBTC) TransferBalance(currency, from, to string, amount float64) (bool, error) {
|
||||
func (h *HitBTC) TransferBalance(currency, from, to string, amount float64) (bool, error) {
|
||||
values := url.Values{}
|
||||
result := GenericResponse{}
|
||||
|
||||
@@ -544,7 +552,7 @@ func (p *HitBTC) TransferBalance(currency, from, to string, amount float64) (boo
|
||||
values.Set("fromAccount", from)
|
||||
values.Set("toAccount", to)
|
||||
|
||||
err := p.SendAuthenticatedHTTPRequest("POST", transferBalance, values, &result)
|
||||
err := h.SendAuthenticatedHTTPRequest("POST", transferBalance, values, &result)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -558,19 +566,64 @@ func (p *HitBTC) TransferBalance(currency, from, to string, amount float64) (boo
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (p *HitBTC) SendHTTPRequest(path string, result interface{}) error {
|
||||
return p.SendPayload("GET", path, nil, nil, result, false, p.Verbose)
|
||||
func (h *HitBTC) SendHTTPRequest(path string, result interface{}) error {
|
||||
return h.SendPayload("GET", path, nil, nil, result, false, h.Verbose)
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated http request
|
||||
func (p *HitBTC) SendAuthenticatedHTTPRequest(method, endpoint string, values url.Values, result interface{}) error {
|
||||
if !p.AuthenticatedAPISupport {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, p.Name)
|
||||
func (h *HitBTC) SendAuthenticatedHTTPRequest(method, endpoint string, values url.Values, result interface{}) error {
|
||||
if !h.AuthenticatedAPISupport {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, h.Name)
|
||||
}
|
||||
headers := make(map[string]string)
|
||||
headers["Authorization"] = "Basic " + common.Base64Encode([]byte(p.APIKey+":"+p.APISecret))
|
||||
headers["Authorization"] = "Basic " + common.Base64Encode([]byte(h.APIKey+":"+h.APISecret))
|
||||
|
||||
path := fmt.Sprintf("%s/%s", p.APIUrl, endpoint)
|
||||
path := fmt.Sprintf("%s/%s", h.APIUrl, endpoint)
|
||||
|
||||
return p.SendPayload(method, path, headers, bytes.NewBufferString(values.Encode()), result, true, p.Verbose)
|
||||
return h.SendPayload(method, path, headers, bytes.NewBufferString(values.Encode()), result, true, h.Verbose)
|
||||
}
|
||||
|
||||
// GetFee returns an estimate of fee based on type of transaction
|
||||
func (h *HitBTC) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
|
||||
var fee float64
|
||||
switch feeBuilder.FeeType {
|
||||
case exchange.CryptocurrencyTradeFee:
|
||||
feeInfo, err := h.GetFeeInfo(feeBuilder.FirstCurrency + feeBuilder.Delimiter + feeBuilder.SecondCurrency)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
fee = calculateTradingFee(feeInfo, feeBuilder.PurchasePrice, feeBuilder.Amount, feeBuilder.IsMaker)
|
||||
case exchange.CryptocurrencyWithdrawalFee:
|
||||
currencyInfo, err := h.GetCurrency(feeBuilder.FirstCurrency)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
fee, err = strconv.ParseFloat(currencyInfo.PayoutFee, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
case exchange.CyptocurrencyDepositFee:
|
||||
fee = calculateCryptocurrencyDepositFee(feeBuilder.FirstCurrency, feeBuilder.Amount)
|
||||
}
|
||||
|
||||
return fee, nil
|
||||
}
|
||||
|
||||
func calculateCryptocurrencyDepositFee(currency string, amount float64) float64 {
|
||||
var fee float64
|
||||
if currency == symbol.BTC {
|
||||
fee = 0.0006
|
||||
}
|
||||
return fee * amount
|
||||
}
|
||||
|
||||
func calculateTradingFee(feeInfo Fee, purchasePrice, amount float64, isMaker bool) float64 {
|
||||
var volumeFee float64
|
||||
if isMaker {
|
||||
volumeFee = feeInfo.ProvideLiquidityRate
|
||||
} else {
|
||||
volumeFee = feeInfo.TakeLiquidityRate
|
||||
}
|
||||
|
||||
return volumeFee * amount * purchasePrice
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
)
|
||||
|
||||
var p HitBTC
|
||||
var h HitBTC
|
||||
|
||||
// Please supply your own APIKEYS here for due diligence testing
|
||||
|
||||
@@ -16,7 +18,7 @@ const (
|
||||
)
|
||||
|
||||
func TestSetDefaults(t *testing.T) {
|
||||
p.SetDefaults()
|
||||
h.SetDefaults()
|
||||
}
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
@@ -31,39 +33,130 @@ func TestSetup(t *testing.T) {
|
||||
hitbtcConfig.APIKey = apiKey
|
||||
hitbtcConfig.APISecret = apiSecret
|
||||
|
||||
p.Setup(hitbtcConfig)
|
||||
}
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
if p.GetFee() != 0 {
|
||||
t.Error("Test faild - HitBTC GetFee() error")
|
||||
}
|
||||
h.Setup(hitbtcConfig)
|
||||
}
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
_, err := p.GetOrderbook("BTCUSD", 50)
|
||||
_, err := h.GetOrderbook("BTCUSD", 50)
|
||||
if err != nil {
|
||||
t.Error("Test faild - HitBTC GetOrderbook() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTrades(t *testing.T) {
|
||||
_, err := p.GetTrades("BTCUSD", "", "", "", "", "", "")
|
||||
_, err := h.GetTrades("BTCUSD", "", "", "", "", "", "")
|
||||
if err != nil {
|
||||
t.Error("Test faild - HitBTC GetTradeHistory() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetChartCandles(t *testing.T) {
|
||||
_, err := p.GetCandles("BTCUSD", "", "")
|
||||
_, err := h.GetCandles("BTCUSD", "", "")
|
||||
if err != nil {
|
||||
t.Error("Test faild - HitBTC GetChartData() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCurrencies(t *testing.T) {
|
||||
_, err := p.GetCurrencies("")
|
||||
_, err := h.GetCurrencies()
|
||||
if err != nil {
|
||||
t.Error("Test faild - HitBTC GetCurrencies() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func setFeeBuilder() exchange.FeeBuilder {
|
||||
return exchange.FeeBuilder{
|
||||
Amount: 1,
|
||||
Delimiter: "",
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
FirstCurrency: symbol.ETH,
|
||||
SecondCurrency: symbol.BTC,
|
||||
IsMaker: false,
|
||||
PurchasePrice: 1,
|
||||
CurrencyItem: symbol.USD,
|
||||
BankTransactionType: exchange.WireTransfer,
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
h.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var feeBuilder = setFeeBuilder()
|
||||
if apiKey != "" && apiSecret != "" {
|
||||
// CryptocurrencyTradeFee Basic
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(0.001) || err != nil {
|
||||
t.Error(err)
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(0.001), resp)
|
||||
}
|
||||
|
||||
// CryptocurrencyTradeFee High quantity
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.Amount = 1000
|
||||
feeBuilder.PurchasePrice = 1000
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(1000) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(1000), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyTradeFee IsMaker
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.IsMaker = true
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(-0.0001) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(-0.0001), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyTradeFee Negative purchase price
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.PurchasePrice = -1000
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(-1) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(-1), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyWithdrawalFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(0.009580) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(0.009580), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyWithdrawalFee Invalid currency
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FirstCurrency = "hello"
|
||||
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err == nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// CyptocurrencyDepositFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.CyptocurrencyDepositFee
|
||||
feeBuilder.FirstCurrency = symbol.BTC
|
||||
feeBuilder.SecondCurrency = symbol.LTC
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(0.0006) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(0.0006), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// InternationalBankDepositFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.InternationalBankDepositFee
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// InternationalBankWithdrawalFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
|
||||
feeBuilder.CurrencyItem = symbol.USD
|
||||
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Recieved: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,8 @@ type Currencies struct {
|
||||
PayoutEnabled bool `json:"payoutEnabled"` // Is allowed for withdraw (false for ICO)
|
||||
PayoutIsPaymentID bool `json:"payoutIsPaymentId"` // Is allowed to provide additional information for withdraw
|
||||
TransferEnabled bool `json:"transferEnabled"` // Is allowed to transfer between trading and account (may be disabled on maintain)
|
||||
Delisted bool `json:"delisted"` // True if currency delisted (stopped deposit and trading)
|
||||
PayoutFee string `json:"payoutFee"` // Default withdraw fee
|
||||
}
|
||||
|
||||
// LoanOrder contains information about your loans
|
||||
|
||||
@@ -208,3 +208,8 @@ func (h *HitBTC) WithdrawFiatExchangeFundsToInternationalBank(currency pair.Curr
|
||||
func (h *HitBTC) GetWebsocket() (*exchange.Websocket, error) {
|
||||
return h.Websocket, nil
|
||||
}
|
||||
|
||||
// GetFeeByType returns an estimate of fee based on type of transaction
|
||||
func (h *HitBTC) GetFeeByType(feeBuilder exchange.FeeBuilder) (float64, error) {
|
||||
return h.GetFee(feeBuilder)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user