mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-25 07:26: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
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
@@ -93,9 +94,9 @@ func (g *Gateio) Setup(exch config.ExchangeConfig) {
|
||||
g.SetHTTPClientUserAgent(exch.HTTPUserAgent)
|
||||
g.RESTPollingDelay = exch.RESTPollingDelay
|
||||
g.Verbose = exch.Verbose
|
||||
g.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
|
||||
g.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
g.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
|
||||
g.BaseCurrencies = exch.BaseCurrencies
|
||||
g.AvailablePairs = exch.AvailablePairs
|
||||
g.EnabledPairs = exch.EnabledPairs
|
||||
err := g.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -462,7 +463,8 @@ func (g *Gateio) GetTradeHistory(symbol string) (TradHistoryResponse, error) {
|
||||
// To use this you must setup an APIKey and APISecret from the exchange
|
||||
func (g *Gateio) SendAuthenticatedHTTPRequest(method, endpoint, param string, result interface{}) error {
|
||||
if !g.AuthenticatedAPISupport {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, g.Name)
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet,
|
||||
g.Name)
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
@@ -476,7 +478,13 @@ func (g *Gateio) SendAuthenticatedHTTPRequest(method, endpoint, param string, re
|
||||
|
||||
var intermidiary json.RawMessage
|
||||
|
||||
err := g.SendPayload(method, urlPath, headers, strings.NewReader(param), &intermidiary, true, g.Verbose)
|
||||
err := g.SendPayload(method,
|
||||
urlPath,
|
||||
headers,
|
||||
strings.NewReader(param),
|
||||
&intermidiary,
|
||||
true,
|
||||
g.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -507,19 +515,29 @@ func (g *Gateio) GetFee(feeBuilder exchange.FeeBuilder) (fee float64, err error)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
currencyPair := feeBuilder.FirstCurrency + feeBuilder.Delimiter + feeBuilder.SecondCurrency
|
||||
|
||||
currencyPair := feeBuilder.Pair.Base.String() +
|
||||
feeBuilder.Pair.Delimiter +
|
||||
feeBuilder.Pair.Quote.String()
|
||||
|
||||
var feeForPair float64
|
||||
for _, i := range feePairs.Pairs {
|
||||
if strings.EqualFold(currencyPair, i.Symbol) {
|
||||
feeForPair = i.Fee
|
||||
}
|
||||
}
|
||||
|
||||
if feeForPair == 0 {
|
||||
return 0, fmt.Errorf("currency '%s' failed to find fee data", currencyPair)
|
||||
return 0, fmt.Errorf("currency '%s' failed to find fee data",
|
||||
currencyPair)
|
||||
}
|
||||
fee = calculateTradingFee(feeForPair, feeBuilder.PurchasePrice, feeBuilder.Amount)
|
||||
|
||||
fee = calculateTradingFee(feeForPair,
|
||||
feeBuilder.PurchasePrice,
|
||||
feeBuilder.Amount)
|
||||
|
||||
case exchange.CryptocurrencyWithdrawalFee:
|
||||
fee = getCryptocurrencyWithdrawalFee(feeBuilder.FirstCurrency)
|
||||
fee = getCryptocurrencyWithdrawalFee(feeBuilder.Pair.Base)
|
||||
}
|
||||
|
||||
if fee < 0 {
|
||||
@@ -533,8 +551,8 @@ func calculateTradingFee(feeForPair, purchasePrice, amount float64) float64 {
|
||||
return (feeForPair / 100) * purchasePrice * amount
|
||||
}
|
||||
|
||||
func getCryptocurrencyWithdrawalFee(currency string) float64 {
|
||||
return WithdrawalFees[currency]
|
||||
func getCryptocurrencyWithdrawalFee(c currency.Code) float64 {
|
||||
return WithdrawalFees[c]
|
||||
}
|
||||
|
||||
// WithdrawCrypto withdraws cryptocurrency to your selected wallet
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -146,14 +145,13 @@ func TestGetSpotKline(t *testing.T) {
|
||||
|
||||
func setFeeBuilder() exchange.FeeBuilder {
|
||||
return exchange.FeeBuilder{
|
||||
Amount: 1,
|
||||
Delimiter: "_",
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
FirstCurrency: symbol.BTC,
|
||||
SecondCurrency: symbol.USDT,
|
||||
Amount: 1,
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
Pair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
currency.USDT.String(), "_"),
|
||||
IsMaker: false,
|
||||
PurchasePrice: 1,
|
||||
CurrencyItem: symbol.USD,
|
||||
FiatCurrency: currency.USD,
|
||||
BankTransactionType: exchange.WireTransfer,
|
||||
}
|
||||
}
|
||||
@@ -205,7 +203,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 := g.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
@@ -231,7 +229,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 := g.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
@@ -273,9 +271,9 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
OrderType: exchange.AnyOrderType,
|
||||
}
|
||||
|
||||
currPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
|
||||
currPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
currPair.Delimiter = "_"
|
||||
getOrdersRequest.Currencies = []pair.CurrencyPair{currPair}
|
||||
getOrdersRequest.Currencies = []currency.Pair{currPair}
|
||||
|
||||
_, err := g.GetOrderHistory(getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
@@ -303,10 +301,10 @@ func TestSubmitOrder(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var p = pair.CurrencyPair{
|
||||
Delimiter: "_",
|
||||
FirstCurrency: symbol.LTC,
|
||||
SecondCurrency: symbol.BTC,
|
||||
var p = currency.Pair{
|
||||
Delimiter: "_",
|
||||
Base: currency.LTC,
|
||||
Quote: currency.BTC,
|
||||
}
|
||||
response, err := g.SubmitOrder(p, exchange.BuyOrderSide, exchange.MarketOrderType, 1, 10, "1234234")
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
@@ -324,7 +322,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
OrderID: "1",
|
||||
@@ -350,7 +348,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
OrderID: "1",
|
||||
@@ -399,7 +397,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",
|
||||
}
|
||||
@@ -451,12 +449,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := g.GetDepositAddress(symbol.ETC, "")
|
||||
_, err := g.GetDepositAddress(currency.ETC, "")
|
||||
if err != nil {
|
||||
t.Error("Test Fail - GetDepositAddress error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := g.GetDepositAddress(symbol.ETC, "")
|
||||
_, err := g.GetDepositAddress(currency.ETC, "")
|
||||
if err == nil {
|
||||
t.Error("Test Fail - GetDepositAddress error cannot be nil")
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
// SpotNewOrderRequestParamsType order type (buy or sell)
|
||||
@@ -179,211 +179,211 @@ type TradesResponse struct {
|
||||
|
||||
// WithdrawalFees the large list of predefined withdrawal fees
|
||||
// Prone to change
|
||||
var WithdrawalFees = map[string]float64{
|
||||
symbol.USDT: 10,
|
||||
symbol.USDT_ETH: 10,
|
||||
symbol.BTC: 0.001,
|
||||
symbol.BCH: 0.0006,
|
||||
symbol.BTG: 0.002,
|
||||
symbol.LTC: 0.002,
|
||||
symbol.ZEC: 0.001,
|
||||
symbol.ETH: 0.003,
|
||||
symbol.ETC: 0.01,
|
||||
symbol.DASH: 0.02,
|
||||
symbol.QTUM: 0.1,
|
||||
symbol.QTUM_ETH: 0.1,
|
||||
symbol.DOGE: 50,
|
||||
symbol.REP: 0.1,
|
||||
symbol.BAT: 10,
|
||||
symbol.SNT: 30,
|
||||
symbol.BTM: 10,
|
||||
symbol.BTM_ETH: 10,
|
||||
symbol.CVC: 5,
|
||||
symbol.REQ: 20,
|
||||
symbol.RDN: 1,
|
||||
symbol.STX: 3,
|
||||
symbol.KNC: 1,
|
||||
symbol.LINK: 8,
|
||||
symbol.FIL: 0.1,
|
||||
symbol.CDT: 20,
|
||||
symbol.AE: 1,
|
||||
symbol.INK: 10,
|
||||
symbol.BOT: 5,
|
||||
symbol.POWR: 5,
|
||||
symbol.WTC: 0.2,
|
||||
symbol.VET: 10,
|
||||
symbol.RCN: 5,
|
||||
symbol.PPT: 0.1,
|
||||
symbol.ARN: 2,
|
||||
symbol.BNT: 0.5,
|
||||
symbol.VERI: 0.005,
|
||||
symbol.MCO: 0.1,
|
||||
symbol.MDA: 0.5,
|
||||
symbol.FUN: 50,
|
||||
symbol.DATA: 10,
|
||||
symbol.RLC: 1,
|
||||
symbol.ZSC: 20,
|
||||
symbol.WINGS: 2,
|
||||
symbol.GVT: 0.2,
|
||||
symbol.KICK: 5,
|
||||
symbol.CTR: 1,
|
||||
symbol.HC: 0.2,
|
||||
symbol.QBT: 5,
|
||||
symbol.QSP: 5,
|
||||
symbol.BCD: 0.02,
|
||||
symbol.MED: 100,
|
||||
symbol.QASH: 1,
|
||||
symbol.DGD: 0.05,
|
||||
symbol.GNT: 10,
|
||||
symbol.MDS: 20,
|
||||
symbol.SBTC: 0.05,
|
||||
symbol.MANA: 50,
|
||||
symbol.GOD: 0.1,
|
||||
symbol.BCX: 30,
|
||||
symbol.SMT: 50,
|
||||
symbol.BTF: 0.1,
|
||||
symbol.IOTA: 0.1,
|
||||
symbol.NAS: 0.5,
|
||||
symbol.NAS_ETH: 0.5,
|
||||
symbol.TSL: 10,
|
||||
symbol.ADA: 1,
|
||||
symbol.LSK: 0.1,
|
||||
symbol.WAVES: 0.1,
|
||||
symbol.BIFI: 0.2,
|
||||
symbol.XTZ: 0.1,
|
||||
symbol.BNTY: 10,
|
||||
symbol.ICX: 0.5,
|
||||
symbol.LEND: 20,
|
||||
symbol.LUN: 0.2,
|
||||
symbol.ELF: 2,
|
||||
symbol.SALT: 0.2,
|
||||
symbol.FUEL: 2,
|
||||
symbol.DRGN: 2,
|
||||
symbol.GTC: 2,
|
||||
symbol.MDT: 2,
|
||||
symbol.QUN: 2,
|
||||
symbol.GNX: 2,
|
||||
symbol.DDD: 10,
|
||||
symbol.OST: 4,
|
||||
symbol.BTO: 10,
|
||||
symbol.TIO: 10,
|
||||
symbol.THETA: 10,
|
||||
symbol.SNET: 10,
|
||||
symbol.OCN: 10,
|
||||
symbol.ZIL: 10,
|
||||
symbol.RUFF: 10,
|
||||
symbol.TNC: 10,
|
||||
symbol.COFI: 10,
|
||||
symbol.ZPT: 0.1,
|
||||
symbol.JNT: 10,
|
||||
symbol.GXS: 1,
|
||||
symbol.MTN: 10,
|
||||
symbol.BLZ: 2,
|
||||
symbol.GEM: 2,
|
||||
symbol.DADI: 2,
|
||||
symbol.ABT: 2,
|
||||
symbol.LEDU: 10,
|
||||
symbol.RFR: 10,
|
||||
symbol.XLM: 1,
|
||||
symbol.MOBI: 1,
|
||||
symbol.ONT: 1,
|
||||
symbol.NEO: 0,
|
||||
symbol.GAS: 0.02,
|
||||
symbol.DBC: 10,
|
||||
symbol.QLC: 10,
|
||||
symbol.MKR: 0.003,
|
||||
symbol.MKR_OLD: 0.003,
|
||||
symbol.DAI: 2,
|
||||
symbol.LRC: 10,
|
||||
symbol.OAX: 10,
|
||||
symbol.ZRX: 10,
|
||||
symbol.PST: 5,
|
||||
symbol.TNT: 20,
|
||||
symbol.LLT: 10,
|
||||
symbol.DNT: 1,
|
||||
symbol.DPY: 2,
|
||||
symbol.BCDN: 20,
|
||||
symbol.STORJ: 3,
|
||||
symbol.OMG: 0.2,
|
||||
symbol.PAY: 1,
|
||||
symbol.EOS: 0.1,
|
||||
symbol.EON: 20,
|
||||
symbol.IQ: 20,
|
||||
symbol.EOSDAC: 20,
|
||||
symbol.TIPS: 100,
|
||||
symbol.XRP: 1,
|
||||
symbol.CNC: 0.1,
|
||||
symbol.TIX: 0.1,
|
||||
symbol.XMR: 0.05,
|
||||
symbol.BTS: 1,
|
||||
symbol.XTC: 10,
|
||||
symbol.BU: 0.1,
|
||||
symbol.DCR: 0.02,
|
||||
symbol.BCN: 10,
|
||||
symbol.XMC: 0.05,
|
||||
symbol.PPS: 0.01,
|
||||
symbol.BOE: 5,
|
||||
symbol.PLY: 10,
|
||||
symbol.MEDX: 100,
|
||||
symbol.TRX: 0.1,
|
||||
symbol.SMT_ETH: 50,
|
||||
symbol.CS: 10,
|
||||
symbol.MAN: 10,
|
||||
symbol.REM: 10,
|
||||
symbol.LYM: 10,
|
||||
symbol.INSTAR: 10,
|
||||
symbol.BFT: 10,
|
||||
symbol.IHT: 10,
|
||||
symbol.SENC: 10,
|
||||
symbol.TOMO: 10,
|
||||
symbol.ELEC: 10,
|
||||
symbol.SHIP: 10,
|
||||
symbol.TFD: 10,
|
||||
symbol.HAV: 10,
|
||||
symbol.HUR: 10,
|
||||
symbol.LST: 10,
|
||||
symbol.LINO: 10,
|
||||
symbol.SWTH: 5,
|
||||
symbol.NKN: 5,
|
||||
symbol.SOUL: 5,
|
||||
symbol.GALA_NEO: 5,
|
||||
symbol.LRN: 5,
|
||||
symbol.ADD: 20,
|
||||
symbol.MEETONE: 5,
|
||||
symbol.DOCK: 20,
|
||||
symbol.GSE: 20,
|
||||
symbol.RATING: 20,
|
||||
symbol.HSC: 100,
|
||||
symbol.HIT: 100,
|
||||
symbol.DX: 100,
|
||||
symbol.BXC: 100,
|
||||
symbol.PAX: 5,
|
||||
symbol.GARD: 100,
|
||||
symbol.FTI: 100,
|
||||
symbol.SOP: 100,
|
||||
symbol.LEMO: 20,
|
||||
symbol.NPXS: 40,
|
||||
symbol.QKC: 20,
|
||||
symbol.IOTX: 20,
|
||||
symbol.RED: 20,
|
||||
symbol.LBA: 20,
|
||||
symbol.KAN: 20,
|
||||
symbol.OPEN: 20,
|
||||
symbol.MITH: 20,
|
||||
symbol.SKM: 20,
|
||||
symbol.XVG: 20,
|
||||
symbol.NANO: 20,
|
||||
symbol.NBAI: 20,
|
||||
symbol.UPP: 20,
|
||||
symbol.ATMI: 20,
|
||||
symbol.TMT: 20,
|
||||
symbol.HT: 1,
|
||||
symbol.BNB: 0.3,
|
||||
symbol.BBK: 20,
|
||||
symbol.EDR: 20,
|
||||
symbol.MET: 0.3,
|
||||
symbol.TCT: 20,
|
||||
symbol.EXC: 10,
|
||||
var WithdrawalFees = map[currency.Code]float64{
|
||||
currency.USDT: 10,
|
||||
currency.USDT_ETH: 10,
|
||||
currency.BTC: 0.001,
|
||||
currency.BCH: 0.0006,
|
||||
currency.BTG: 0.002,
|
||||
currency.LTC: 0.002,
|
||||
currency.ZEC: 0.001,
|
||||
currency.ETH: 0.003,
|
||||
currency.ETC: 0.01,
|
||||
currency.DASH: 0.02,
|
||||
currency.QTUM: 0.1,
|
||||
currency.QTUM_ETH: 0.1,
|
||||
currency.DOGE: 50,
|
||||
currency.REP: 0.1,
|
||||
currency.BAT: 10,
|
||||
currency.SNT: 30,
|
||||
currency.BTM: 10,
|
||||
currency.BTM_ETH: 10,
|
||||
currency.CVC: 5,
|
||||
currency.REQ: 20,
|
||||
currency.RDN: 1,
|
||||
currency.STX: 3,
|
||||
currency.KNC: 1,
|
||||
currency.LINK: 8,
|
||||
currency.FIL: 0.1,
|
||||
currency.CDT: 20,
|
||||
currency.AE: 1,
|
||||
currency.INK: 10,
|
||||
currency.BOT: 5,
|
||||
currency.POWR: 5,
|
||||
currency.WTC: 0.2,
|
||||
currency.VET: 10,
|
||||
currency.RCN: 5,
|
||||
currency.PPT: 0.1,
|
||||
currency.ARN: 2,
|
||||
currency.BNT: 0.5,
|
||||
currency.VERI: 0.005,
|
||||
currency.MCO: 0.1,
|
||||
currency.MDA: 0.5,
|
||||
currency.FUN: 50,
|
||||
currency.DATA: 10,
|
||||
currency.RLC: 1,
|
||||
currency.ZSC: 20,
|
||||
currency.WINGS: 2,
|
||||
currency.GVT: 0.2,
|
||||
currency.KICK: 5,
|
||||
currency.CTR: 1,
|
||||
currency.HC: 0.2,
|
||||
currency.QBT: 5,
|
||||
currency.QSP: 5,
|
||||
currency.BCD: 0.02,
|
||||
currency.MED: 100,
|
||||
currency.QASH: 1,
|
||||
currency.DGD: 0.05,
|
||||
currency.GNT: 10,
|
||||
currency.MDS: 20,
|
||||
currency.SBTC: 0.05,
|
||||
currency.MANA: 50,
|
||||
currency.GOD: 0.1,
|
||||
currency.BCX: 30,
|
||||
currency.SMT: 50,
|
||||
currency.BTF: 0.1,
|
||||
currency.IOTA: 0.1,
|
||||
currency.NAS: 0.5,
|
||||
currency.NAS_ETH: 0.5,
|
||||
currency.TSL: 10,
|
||||
currency.ADA: 1,
|
||||
currency.LSK: 0.1,
|
||||
currency.WAVES: 0.1,
|
||||
currency.BIFI: 0.2,
|
||||
currency.XTZ: 0.1,
|
||||
currency.BNTY: 10,
|
||||
currency.ICX: 0.5,
|
||||
currency.LEND: 20,
|
||||
currency.LUN: 0.2,
|
||||
currency.ELF: 2,
|
||||
currency.SALT: 0.2,
|
||||
currency.FUEL: 2,
|
||||
currency.DRGN: 2,
|
||||
currency.GTC: 2,
|
||||
currency.MDT: 2,
|
||||
currency.QUN: 2,
|
||||
currency.GNX: 2,
|
||||
currency.DDD: 10,
|
||||
currency.OST: 4,
|
||||
currency.BTO: 10,
|
||||
currency.TIO: 10,
|
||||
currency.THETA: 10,
|
||||
currency.SNET: 10,
|
||||
currency.OCN: 10,
|
||||
currency.ZIL: 10,
|
||||
currency.RUFF: 10,
|
||||
currency.TNC: 10,
|
||||
currency.COFI: 10,
|
||||
currency.ZPT: 0.1,
|
||||
currency.JNT: 10,
|
||||
currency.GXS: 1,
|
||||
currency.MTN: 10,
|
||||
currency.BLZ: 2,
|
||||
currency.GEM: 2,
|
||||
currency.DADI: 2,
|
||||
currency.ABT: 2,
|
||||
currency.LEDU: 10,
|
||||
currency.RFR: 10,
|
||||
currency.XLM: 1,
|
||||
currency.MOBI: 1,
|
||||
currency.ONT: 1,
|
||||
currency.NEO: 0,
|
||||
currency.GAS: 0.02,
|
||||
currency.DBC: 10,
|
||||
currency.QLC: 10,
|
||||
currency.MKR: 0.003,
|
||||
currency.MKR_OLD: 0.003,
|
||||
currency.DAI: 2,
|
||||
currency.LRC: 10,
|
||||
currency.OAX: 10,
|
||||
currency.ZRX: 10,
|
||||
currency.PST: 5,
|
||||
currency.TNT: 20,
|
||||
currency.LLT: 10,
|
||||
currency.DNT: 1,
|
||||
currency.DPY: 2,
|
||||
currency.BCDN: 20,
|
||||
currency.STORJ: 3,
|
||||
currency.OMG: 0.2,
|
||||
currency.PAY: 1,
|
||||
currency.EOS: 0.1,
|
||||
currency.EON: 20,
|
||||
currency.IQ: 20,
|
||||
currency.EOSDAC: 20,
|
||||
currency.TIPS: 100,
|
||||
currency.XRP: 1,
|
||||
currency.CNC: 0.1,
|
||||
currency.TIX: 0.1,
|
||||
currency.XMR: 0.05,
|
||||
currency.BTS: 1,
|
||||
currency.XTC: 10,
|
||||
currency.BU: 0.1,
|
||||
currency.DCR: 0.02,
|
||||
currency.BCN: 10,
|
||||
currency.XMC: 0.05,
|
||||
currency.PPS: 0.01,
|
||||
currency.BOE: 5,
|
||||
currency.PLY: 10,
|
||||
currency.MEDX: 100,
|
||||
currency.TRX: 0.1,
|
||||
currency.SMT_ETH: 50,
|
||||
currency.CS: 10,
|
||||
currency.MAN: 10,
|
||||
currency.REM: 10,
|
||||
currency.LYM: 10,
|
||||
currency.INSTAR: 10,
|
||||
currency.BFT: 10,
|
||||
currency.IHT: 10,
|
||||
currency.SENC: 10,
|
||||
currency.TOMO: 10,
|
||||
currency.ELEC: 10,
|
||||
currency.SHIP: 10,
|
||||
currency.TFD: 10,
|
||||
currency.HAV: 10,
|
||||
currency.HUR: 10,
|
||||
currency.LST: 10,
|
||||
currency.LINO: 10,
|
||||
currency.SWTH: 5,
|
||||
currency.NKN: 5,
|
||||
currency.SOUL: 5,
|
||||
currency.GALA_NEO: 5,
|
||||
currency.LRN: 5,
|
||||
currency.ADD: 20,
|
||||
currency.MEETONE: 5,
|
||||
currency.DOCK: 20,
|
||||
currency.GSE: 20,
|
||||
currency.RATING: 20,
|
||||
currency.HSC: 100,
|
||||
currency.HIT: 100,
|
||||
currency.DX: 100,
|
||||
currency.BXC: 100,
|
||||
currency.PAX: 5,
|
||||
currency.GARD: 100,
|
||||
currency.FTI: 100,
|
||||
currency.SOP: 100,
|
||||
currency.LEMO: 20,
|
||||
currency.NPXS: 40,
|
||||
currency.QKC: 20,
|
||||
currency.IOTX: 20,
|
||||
currency.RED: 20,
|
||||
currency.LBA: 20,
|
||||
currency.KAN: 20,
|
||||
currency.OPEN: 20,
|
||||
currency.MITH: 20,
|
||||
currency.SKM: 20,
|
||||
currency.XVG: 20,
|
||||
currency.NANO: 20,
|
||||
currency.NBAI: 20,
|
||||
currency.UPP: 20,
|
||||
currency.ATMI: 20,
|
||||
currency.TMT: 20,
|
||||
currency.HT: 1,
|
||||
currency.BNB: 0.3,
|
||||
currency.BBK: 20,
|
||||
currency.EDR: 20,
|
||||
currency.MET: 0.3,
|
||||
currency.TCT: 20,
|
||||
currency.EXC: 10,
|
||||
}
|
||||
|
||||
// WebsocketRequest defines the initial request in JSON
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"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"
|
||||
)
|
||||
@@ -56,7 +56,7 @@ func (g *Gateio) WsSubscribe() error {
|
||||
ticker := WebsocketRequest{
|
||||
ID: 1337,
|
||||
Method: "ticker.subscribe",
|
||||
Params: []interface{}{c.Pair().String()},
|
||||
Params: []interface{}{c.String()},
|
||||
}
|
||||
|
||||
err := g.WebsocketConn.WriteJSON(ticker)
|
||||
@@ -67,7 +67,7 @@ func (g *Gateio) WsSubscribe() error {
|
||||
trade := WebsocketRequest{
|
||||
ID: 1337,
|
||||
Method: "trades.subscribe",
|
||||
Params: []interface{}{c.Pair().String()},
|
||||
Params: []interface{}{c.String()},
|
||||
}
|
||||
|
||||
err = g.WebsocketConn.WriteJSON(trade)
|
||||
@@ -78,7 +78,7 @@ func (g *Gateio) WsSubscribe() error {
|
||||
depth := WebsocketRequest{
|
||||
ID: 1337,
|
||||
Method: "depth.subscribe",
|
||||
Params: []interface{}{c.Pair().String(), 30, "0.1"},
|
||||
Params: []interface{}{c.String(), 30, "0.1"},
|
||||
}
|
||||
|
||||
err = g.WebsocketConn.WriteJSON(depth)
|
||||
@@ -89,7 +89,7 @@ func (g *Gateio) WsSubscribe() error {
|
||||
kline := WebsocketRequest{
|
||||
ID: 1337,
|
||||
Method: "kline.subscribe",
|
||||
Params: []interface{}{c.Pair().String(), 1800},
|
||||
Params: []interface{}{c.String(), 1800},
|
||||
}
|
||||
|
||||
err = g.WebsocketConn.WriteJSON(kline)
|
||||
@@ -170,7 +170,7 @@ func (g *Gateio) WsHandleData() {
|
||||
|
||||
g.Websocket.DataHandler <- exchange.TickerData{
|
||||
Timestamp: time.Now(),
|
||||
Pair: pair.NewCurrencyPairFromString(c),
|
||||
Pair: currency.NewPairFromString(c),
|
||||
AssetType: "SPOT",
|
||||
Exchange: g.GetName(),
|
||||
ClosePrice: ticker.Close,
|
||||
@@ -198,7 +198,7 @@ func (g *Gateio) WsHandleData() {
|
||||
for _, trade := range trades {
|
||||
g.Websocket.DataHandler <- exchange.TradeData{
|
||||
Timestamp: time.Now(),
|
||||
CurrencyPair: pair.NewCurrencyPairFromString(c),
|
||||
CurrencyPair: currency.NewPairFromString(c),
|
||||
AssetType: "SPOT",
|
||||
Exchange: g.GetName(),
|
||||
Price: trade.Price,
|
||||
@@ -268,9 +268,7 @@ func (g *Gateio) WsHandleData() {
|
||||
newOrderbook.Asks = asks
|
||||
newOrderbook.Bids = bids
|
||||
newOrderbook.AssetType = "SPOT"
|
||||
newOrderbook.CurrencyPair = c
|
||||
newOrderbook.LastUpdated = time.Now()
|
||||
newOrderbook.Pair = pair.NewCurrencyPairFromString(c)
|
||||
newOrderbook.Pair = currency.NewPairFromString(c)
|
||||
|
||||
err = g.Websocket.Orderbook.LoadSnapshot(newOrderbook,
|
||||
g.GetName(),
|
||||
@@ -281,7 +279,7 @@ func (g *Gateio) WsHandleData() {
|
||||
} else {
|
||||
err = g.Websocket.Orderbook.Update(asks,
|
||||
bids,
|
||||
pair.NewCurrencyPairFromString(c),
|
||||
currency.NewPairFromString(c),
|
||||
time.Now(),
|
||||
g.GetName(),
|
||||
"SPOT")
|
||||
@@ -291,7 +289,7 @@ func (g *Gateio) WsHandleData() {
|
||||
}
|
||||
|
||||
g.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
||||
Pair: pair.NewCurrencyPairFromString(c),
|
||||
Pair: currency.NewPairFromString(c),
|
||||
Asset: "SPOT",
|
||||
Exchange: g.GetName(),
|
||||
}
|
||||
@@ -312,7 +310,7 @@ func (g *Gateio) WsHandleData() {
|
||||
|
||||
g.Websocket.DataHandler <- exchange.KlineData{
|
||||
Timestamp: time.Now(),
|
||||
Pair: pair.NewCurrencyPairFromString(data[7].(string)),
|
||||
Pair: currency.NewPairFromString(data[7].(string)),
|
||||
AssetType: "SPOT",
|
||||
Exchange: g.GetName(),
|
||||
OpenPrice: open,
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"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"
|
||||
@@ -37,7 +37,13 @@ func (g *Gateio) Run() {
|
||||
if err != nil {
|
||||
log.Errorf("%s Unable to fetch symbols.\n", g.GetName())
|
||||
} else {
|
||||
err = g.UpdateCurrencies(symbols, false, false)
|
||||
var newCurrencies currency.Pairs
|
||||
for _, p := range symbols {
|
||||
newCurrencies = append(newCurrencies,
|
||||
currency.NewPairFromString(p))
|
||||
}
|
||||
|
||||
err = g.UpdateCurrencies(newCurrencies, false, false)
|
||||
if err != nil {
|
||||
log.Errorf("%s Failed to update available currencies.\n", g.GetName())
|
||||
}
|
||||
@@ -45,7 +51,7 @@ func (g *Gateio) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (g *Gateio) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (g *Gateio) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
result, err := g.GetTickers()
|
||||
if err != nil {
|
||||
@@ -61,14 +67,18 @@ func (g *Gateio) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pri
|
||||
tp.Last = result[currency].Last
|
||||
tp.Low = result[currency].Low
|
||||
tp.Volume = result[currency].Volume
|
||||
ticker.ProcessTicker(g.Name, x, tp, assetType)
|
||||
|
||||
err = ticker.ProcessTicker(g.Name, tp, assetType)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
}
|
||||
|
||||
return ticker.GetTicker(g.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (g *Gateio) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (g *Gateio) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(g.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return g.UpdateTicker(p, assetType)
|
||||
@@ -77,8 +87,8 @@ func (g *Gateio) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.P
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns orderbook base on the currency pair
|
||||
func (g *Gateio) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook(g.GetName(), currency, assetType)
|
||||
func (g *Gateio) GetOrderbookEx(currency currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(g.GetName(), currency, assetType)
|
||||
if err != nil {
|
||||
return g.UpdateOrderbook(currency, assetType)
|
||||
}
|
||||
@@ -86,7 +96,7 @@ func (g *Gateio) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (o
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (g *Gateio) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
func (g *Gateio) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
currency := exchange.FormatExchangeCurrency(g.Name, p).String()
|
||||
|
||||
@@ -105,8 +115,16 @@ func (g *Gateio) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbo
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data.Amount, Price: data.Price})
|
||||
}
|
||||
|
||||
orderbook.ProcessOrderbook(g.GetName(), p, orderBook, assetType)
|
||||
return orderbook.GetOrderbook(g.Name, p, assetType)
|
||||
orderBook.Pair = p
|
||||
orderBook.ExchangeName = g.GetName()
|
||||
orderBook.AssetType = assetType
|
||||
|
||||
err = orderBook.Process()
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
return orderbook.Get(g.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetAccountInfo retrieves balances for all enabled currencies for the
|
||||
@@ -133,7 +151,7 @@ func (g *Gateio) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: key,
|
||||
CurrencyName: currency.NewCode(key),
|
||||
Hold: lockedF,
|
||||
})
|
||||
}
|
||||
@@ -146,7 +164,7 @@ func (g *Gateio) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
|
||||
var updated bool
|
||||
for i := range balances {
|
||||
if balances[i].CurrencyName == key {
|
||||
if balances[i].CurrencyName == currency.NewCode(key) {
|
||||
balances[i].TotalValue = balances[i].Hold + availAmount
|
||||
updated = true
|
||||
break
|
||||
@@ -155,7 +173,7 @@ func (g *Gateio) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
|
||||
if !updated {
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: key,
|
||||
CurrencyName: currency.NewCode(key),
|
||||
TotalValue: availAmount,
|
||||
})
|
||||
}
|
||||
@@ -178,7 +196,7 @@ func (g *Gateio) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
}
|
||||
|
||||
// GetExchangeHistory returns historic trade data since exchange opening.
|
||||
func (g *Gateio) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
func (g *Gateio) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
var resp []exchange.TradeHistory
|
||||
|
||||
return resp, common.ErrNotYetImplemented
|
||||
@@ -186,7 +204,7 @@ func (g *Gateio) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]ex
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
// TODO: support multiple order types (IOC)
|
||||
func (g *Gateio) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
func (g *Gateio) SubmitOrder(p currency.Pair, side exchange.OrderSide, _ exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
var orderTypeFormat SpotNewOrderRequestParamsType
|
||||
|
||||
@@ -199,7 +217,7 @@ func (g *Gateio) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ exc
|
||||
var spotNewOrderRequestParams = SpotNewOrderRequestParams{
|
||||
Amount: amount,
|
||||
Price: price,
|
||||
Symbol: p.Pair().String(),
|
||||
Symbol: p.String(),
|
||||
Type: orderTypeFormat,
|
||||
}
|
||||
|
||||
@@ -266,7 +284,7 @@ func (g *Gateio) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (g *Gateio) GetDepositAddress(cryptocurrency pair.CurrencyItem, _ string) (string, error) {
|
||||
func (g *Gateio) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
addr, err := g.GetCryptoDepositAddress(cryptocurrency.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -321,7 +339,7 @@ func (g *Gateio) GetFeeByType(feeBuilder exchange.FeeBuilder) (float64, error) {
|
||||
func (g *Gateio) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].Pair().String()
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := g.GetOpenOrders(currPair)
|
||||
@@ -335,7 +353,8 @@ func (g *Gateio) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]
|
||||
continue
|
||||
}
|
||||
|
||||
symbol := pair.NewCurrencyPairDelimiter(order.CurrencyPair, g.ConfigCurrencyPairFormat.Delimiter)
|
||||
symbol := currency.NewPairDelimiter(order.CurrencyPair,
|
||||
g.ConfigCurrencyPairFormat.Delimiter)
|
||||
side := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orderDate := time.Unix(order.Timestamp, 0)
|
||||
|
||||
@@ -362,7 +381,7 @@ func (g *Gateio) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]
|
||||
func (g *Gateio) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var trades []TradesResponse
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
resp, err := g.GetTradeHistory(currency.Pair().String())
|
||||
resp, err := g.GetTradeHistory(currency.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -371,7 +390,8 @@ func (g *Gateio) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, trade := range trades {
|
||||
symbol := pair.NewCurrencyPairDelimiter(trade.Pair, g.ConfigCurrencyPairFormat.Delimiter)
|
||||
symbol := currency.NewPairDelimiter(trade.Pair,
|
||||
g.ConfigCurrencyPairFormat.Delimiter)
|
||||
side := exchange.OrderSide(strings.ToUpper(trade.Type))
|
||||
orderDate := time.Unix(trade.TimeUnix, 0)
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
@@ -385,7 +405,8 @@ func (g *Gateio) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]
|
||||
})
|
||||
}
|
||||
|
||||
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