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

@@ -13,6 +13,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"
@@ -111,9 +112,9 @@ func (b *Binance) Setup(exch config.ExchangeConfig) {
b.SetHTTPClientUserAgent(exch.HTTPUserAgent)
b.RESTPollingDelay = exch.RESTPollingDelay
b.Verbose = exch.Verbose
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
b.BaseCurrencies = exch.BaseCurrencies
b.AvailablePairs = exch.AvailablePairs
b.EnabledPairs = exch.EnabledPairs
err := b.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
@@ -706,7 +707,7 @@ func (b *Binance) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
}
fee = calculateTradingFee(feeBuilder.PurchasePrice, feeBuilder.Amount, multiplier)
case exchange.CryptocurrencyWithdrawalFee:
fee = getCryptocurrencyWithdrawalFee(feeBuilder.FirstCurrency)
fee = getCryptocurrencyWithdrawalFee(feeBuilder.Pair.Base)
}
if fee < 0 {
fee = 0
@@ -735,8 +736,8 @@ func calculateTradingFee(purchasePrice, amount, multiplier float64) float64 {
}
// getCryptocurrencyWithdrawalFee returns the fee for withdrawing from the exchange
func getCryptocurrencyWithdrawalFee(currency string) float64 {
return WithdrawalFees[currency]
func getCryptocurrencyWithdrawalFee(c currency.Code) float64 {
return WithdrawalFees[c]
}
// WithdrawCrypto sends cryptocurrency to the address of your choosing

View File

@@ -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"
)
@@ -234,13 +233,10 @@ func TestGetAccount(t *testing.T) {
func setFeeBuilder() exchange.FeeBuilder {
return exchange.FeeBuilder{
Amount: 1,
Delimiter: "",
FeeType: exchange.CryptocurrencyTradeFee,
FirstCurrency: symbol.BTC,
SecondCurrency: symbol.LTC,
IsMaker: false,
PurchasePrice: 1,
Amount: 1,
FeeType: exchange.CryptocurrencyTradeFee,
Pair: currency.NewPair(currency.BTC, currency.LTC),
PurchasePrice: 1,
}
}
@@ -303,7 +299,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.CurrencyItem = symbol.HKD
feeBuilder.FiatCurrency = currency.HKD
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
@@ -312,7 +308,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.CurrencyItem = symbol.HKD
feeBuilder.FiatCurrency = currency.HKD
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
@@ -342,7 +338,9 @@ func TestGetActiveOrders(t *testing.T) {
t.Error("Expected: 'At least one currency is required to fetch order history'. received nil")
}
getOrdersRequest.Currencies = []pair.CurrencyPair{pair.NewCurrencyPair(symbol.LTC, symbol.BTC)}
getOrdersRequest.Currencies = []currency.Pair{
currency.NewPair(currency.LTC, currency.BTC),
}
_, err = b.GetActiveOrders(getOrdersRequest)
if areTestAPIKeysSet() && err != nil {
@@ -365,7 +363,9 @@ func TestGetOrderHistory(t *testing.T) {
t.Error("Expected: 'At least one currency is required to fetch order history'. received nil")
}
getOrdersRequest.Currencies = []pair.CurrencyPair{pair.NewCurrencyPair(symbol.LTC, symbol.BTC)}
getOrdersRequest.Currencies = []currency.Pair{
currency.NewPair(currency.LTC,
currency.BTC)}
_, err = b.GetOrderHistory(getOrdersRequest)
if areTestAPIKeysSet() && err != nil {
@@ -390,10 +390,10 @@ func TestSubmitOrder(t *testing.T) {
b.SetDefaults()
TestSetup(t)
var p = pair.CurrencyPair{
Delimiter: "",
FirstCurrency: symbol.LTC,
SecondCurrency: symbol.BTC,
var p = currency.Pair{
Delimiter: "",
Base: currency.LTC,
Quote: currency.BTC,
}
response, err := b.SubmitOrder(p, exchange.BuyOrderSide, exchange.MarketOrderType, 1, 1, "clientId")
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
@@ -407,7 +407,7 @@ func TestCancelExchangeOrder(t *testing.T) {
b.SetDefaults()
TestSetup(t)
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
@@ -429,7 +429,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
b.SetDefaults()
TestSetup(t)
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
@@ -482,7 +482,7 @@ func TestWithdraw(t *testing.T) {
var withdrawCryptoRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.BTC,
Currency: currency.BTC,
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
Description: "WITHDRAW IT ALL",
}
@@ -530,12 +530,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
func TestGetDepositAddress(t *testing.T) {
if areTestAPIKeysSet() {
_, err := b.GetDepositAddress(symbol.BTC, "")
_, err := b.GetDepositAddress(currency.BTC, "")
if err != nil {
t.Error("Test Failed - GetDepositAddress() error", err)
}
} else {
_, err := b.GetDepositAddress(symbol.BTC, "")
_, err := b.GetDepositAddress(currency.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
}

View File

@@ -3,7 +3,7 @@ package binance
import (
"encoding/json"
"github.com/thrasher-/gocryptotrader/currency/symbol"
"github.com/thrasher-/gocryptotrader/currency"
)
// Response holds basic binance api response data
@@ -450,171 +450,171 @@ var (
// WithdrawalFees the large list of predefined withdrawal fees
// Prone to change
var WithdrawalFees = map[string]float64{
symbol.BNB: 0.13,
symbol.BTC: 0.0005,
symbol.NEO: 0,
symbol.ETH: 0.01,
symbol.LTC: 0.001,
symbol.QTUM: 0.01,
symbol.EOS: 0.1,
symbol.SNT: 35,
symbol.BNT: 1,
symbol.GAS: 0,
symbol.BCC: 0.001,
symbol.BTM: 5,
symbol.USDT: 3.4,
symbol.HCC: 0.0005,
symbol.OAX: 6.5,
symbol.DNT: 54,
symbol.MCO: 0.31,
symbol.ICN: 3.5,
symbol.ZRX: 1.9,
symbol.OMG: 0.4,
symbol.WTC: 0.5,
symbol.LRC: 12.3,
symbol.LLT: 67.8,
symbol.YOYO: 1,
symbol.TRX: 1,
symbol.STRAT: 0.1,
symbol.SNGLS: 54,
symbol.BQX: 3.9,
symbol.KNC: 3.5,
symbol.SNM: 25,
symbol.FUN: 86,
symbol.LINK: 4,
symbol.XVG: 0.1,
symbol.CTR: 35,
symbol.SALT: 2.3,
symbol.MDA: 2.3,
symbol.IOTA: 0.5,
symbol.SUB: 11.4,
symbol.ETC: 0.01,
symbol.MTL: 2,
symbol.MTH: 45,
symbol.ENG: 2.2,
symbol.AST: 14.4,
symbol.DASH: 0.002,
symbol.BTG: 0.001,
symbol.EVX: 2.8,
symbol.REQ: 29.9,
symbol.VIB: 30,
symbol.POWR: 8.2,
symbol.ARK: 0.2,
symbol.XRP: 0.25,
symbol.MOD: 2,
symbol.ENJ: 26,
symbol.STORJ: 5.1,
symbol.KMD: 0.002,
symbol.RCN: 47,
symbol.NULS: 0.01,
symbol.RDN: 2.5,
symbol.XMR: 0.04,
symbol.DLT: 19.8,
symbol.AMB: 8.9,
symbol.BAT: 8,
symbol.ZEC: 0.005,
symbol.BCPT: 14.5,
symbol.ARN: 3,
symbol.GVT: 0.13,
symbol.CDT: 81,
symbol.GXS: 0.3,
symbol.POE: 134,
symbol.QSP: 36,
symbol.BTS: 1,
symbol.XZC: 0.02,
symbol.LSK: 0.1,
symbol.TNT: 47,
symbol.FUEL: 79,
symbol.MANA: 18,
symbol.BCD: 0.01,
symbol.DGD: 0.04,
symbol.ADX: 6.3,
symbol.ADA: 1,
symbol.PPT: 0.41,
symbol.CMT: 12,
symbol.XLM: 0.01,
symbol.CND: 58,
symbol.LEND: 84,
symbol.WABI: 6.6,
symbol.SBTC: 0.0005,
symbol.BCX: 0.5,
symbol.WAVES: 0.002,
symbol.TNB: 139,
symbol.GTO: 20,
symbol.ICX: 0.02,
symbol.OST: 32,
symbol.ELF: 3.9,
symbol.AION: 3.2,
symbol.CVC: 10.9,
symbol.REP: 0.2,
symbol.GNT: 8.9,
symbol.DATA: 37,
symbol.ETF: 1,
symbol.BRD: 3.8,
symbol.NEBL: 0.01,
symbol.VIBE: 17.3,
symbol.LUN: 0.36,
symbol.CHAT: 60.7,
symbol.RLC: 3.4,
symbol.INS: 3.5,
symbol.IOST: 105.6,
symbol.STEEM: 0.01,
symbol.NANO: 0.01,
symbol.AE: 1.3,
symbol.VIA: 0.01,
symbol.BLZ: 10.3,
symbol.SYS: 1,
symbol.NCASH: 247.6,
symbol.POA: 0.01,
symbol.ONT: 1,
symbol.ZIL: 37.2,
symbol.STORM: 152,
symbol.XEM: 4,
symbol.WAN: 0.1,
symbol.WPR: 43.4,
symbol.QLC: 1,
symbol.GRS: 0.2,
symbol.CLOAK: 0.02,
symbol.LOOM: 11.9,
symbol.BCN: 1,
symbol.TUSD: 1.35,
symbol.ZEN: 0.002,
symbol.SKY: 0.01,
symbol.THETA: 24,
symbol.IOTX: 90.5,
symbol.QKC: 24.6,
symbol.AGI: 29.81,
symbol.NXS: 0.02,
symbol.SC: 0.1,
symbol.EON: 10,
symbol.NPXS: 897,
symbol.KEY: 223,
symbol.NAS: 0.1,
symbol.ADD: 100,
symbol.MEETONE: 300,
symbol.ATD: 100,
symbol.MFT: 175,
symbol.EOP: 5,
symbol.DENT: 596,
symbol.IQ: 50,
symbol.ARDR: 2,
symbol.HOT: 1210,
symbol.VET: 100,
symbol.DOCK: 68,
symbol.POLY: 7,
symbol.VTHO: 21,
symbol.ONG: 0.1,
symbol.PHX: 1,
symbol.HC: 0.005,
symbol.GO: 0.01,
symbol.PAX: 1.4,
symbol.EDO: 1.3,
symbol.WINGS: 8.9,
symbol.NAV: 0.2,
symbol.TRIG: 49.1,
symbol.APPC: 12.4,
symbol.PIVX: 0.02,
var WithdrawalFees = map[currency.Code]float64{
currency.BNB: 0.13,
currency.BTC: 0.0005,
currency.NEO: 0,
currency.ETH: 0.01,
currency.LTC: 0.001,
currency.QTUM: 0.01,
currency.EOS: 0.1,
currency.SNT: 35,
currency.BNT: 1,
currency.GAS: 0,
currency.BCC: 0.001,
currency.BTM: 5,
currency.USDT: 3.4,
currency.HCC: 0.0005,
currency.OAX: 6.5,
currency.DNT: 54,
currency.MCO: 0.31,
currency.ICN: 3.5,
currency.ZRX: 1.9,
currency.OMG: 0.4,
currency.WTC: 0.5,
currency.LRC: 12.3,
currency.LLT: 67.8,
currency.YOYO: 1,
currency.TRX: 1,
currency.STRAT: 0.1,
currency.SNGLS: 54,
currency.BQX: 3.9,
currency.KNC: 3.5,
currency.SNM: 25,
currency.FUN: 86,
currency.LINK: 4,
currency.XVG: 0.1,
currency.CTR: 35,
currency.SALT: 2.3,
currency.MDA: 2.3,
currency.IOTA: 0.5,
currency.SUB: 11.4,
currency.ETC: 0.01,
currency.MTL: 2,
currency.MTH: 45,
currency.ENG: 2.2,
currency.AST: 14.4,
currency.DASH: 0.002,
currency.BTG: 0.001,
currency.EVX: 2.8,
currency.REQ: 29.9,
currency.VIB: 30,
currency.POWR: 8.2,
currency.ARK: 0.2,
currency.XRP: 0.25,
currency.MOD: 2,
currency.ENJ: 26,
currency.STORJ: 5.1,
currency.KMD: 0.002,
currency.RCN: 47,
currency.NULS: 0.01,
currency.RDN: 2.5,
currency.XMR: 0.04,
currency.DLT: 19.8,
currency.AMB: 8.9,
currency.BAT: 8,
currency.ZEC: 0.005,
currency.BCPT: 14.5,
currency.ARN: 3,
currency.GVT: 0.13,
currency.CDT: 81,
currency.GXS: 0.3,
currency.POE: 134,
currency.QSP: 36,
currency.BTS: 1,
currency.XZC: 0.02,
currency.LSK: 0.1,
currency.TNT: 47,
currency.FUEL: 79,
currency.MANA: 18,
currency.BCD: 0.01,
currency.DGD: 0.04,
currency.ADX: 6.3,
currency.ADA: 1,
currency.PPT: 0.41,
currency.CMT: 12,
currency.XLM: 0.01,
currency.CND: 58,
currency.LEND: 84,
currency.WABI: 6.6,
currency.SBTC: 0.0005,
currency.BCX: 0.5,
currency.WAVES: 0.002,
currency.TNB: 139,
currency.GTO: 20,
currency.ICX: 0.02,
currency.OST: 32,
currency.ELF: 3.9,
currency.AION: 3.2,
currency.CVC: 10.9,
currency.REP: 0.2,
currency.GNT: 8.9,
currency.DATA: 37,
currency.ETF: 1,
currency.BRD: 3.8,
currency.NEBL: 0.01,
currency.VIBE: 17.3,
currency.LUN: 0.36,
currency.CHAT: 60.7,
currency.RLC: 3.4,
currency.INS: 3.5,
currency.IOST: 105.6,
currency.STEEM: 0.01,
currency.NANO: 0.01,
currency.AE: 1.3,
currency.VIA: 0.01,
currency.BLZ: 10.3,
currency.SYS: 1,
currency.NCASH: 247.6,
currency.POA: 0.01,
currency.ONT: 1,
currency.ZIL: 37.2,
currency.STORM: 152,
currency.XEM: 4,
currency.WAN: 0.1,
currency.WPR: 43.4,
currency.QLC: 1,
currency.GRS: 0.2,
currency.CLOAK: 0.02,
currency.LOOM: 11.9,
currency.BCN: 1,
currency.TUSD: 1.35,
currency.ZEN: 0.002,
currency.SKY: 0.01,
currency.THETA: 24,
currency.IOTX: 90.5,
currency.QKC: 24.6,
currency.AGI: 29.81,
currency.NXS: 0.02,
currency.SC: 0.1,
currency.EON: 10,
currency.NPXS: 897,
currency.KEY: 223,
currency.NAS: 0.1,
currency.ADD: 100,
currency.MEETONE: 300,
currency.ATD: 100,
currency.MFT: 175,
currency.EOP: 5,
currency.DENT: 596,
currency.IQ: 50,
currency.ARDR: 2,
currency.HOT: 1210,
currency.VET: 100,
currency.DOCK: 68,
currency.POLY: 7,
currency.VTHO: 21,
currency.ONG: 0.1,
currency.PHX: 1,
currency.HC: 0.005,
currency.GO: 0.01,
currency.PAX: 1.4,
currency.EDO: 1.3,
currency.WINGS: 8.9,
currency.NAV: 0.2,
currency.TRIG: 49.1,
currency.APPC: 12.4,
currency.PIVX: 0.02,
}
// WithdrawResponse contains status of withdrawal request

View File

@@ -12,7 +12,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"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -26,7 +26,7 @@ var lastUpdateID map[string]int64
var m sync.Mutex
// SeedLocalCache seeds depth data
func (b *Binance) SeedLocalCache(p pair.CurrencyPair) error {
func (b *Binance) SeedLocalCache(p currency.Pair) error {
var newOrderBook orderbook.Base
formattedPair := exchange.FormatExchangeCurrency(b.Name, p)
@@ -58,9 +58,7 @@ func (b *Binance) SeedLocalCache(p pair.CurrencyPair) error {
orderbook.Item{Amount: Asks.Quantity, Price: Asks.Price})
}
newOrderBook.Pair = pair.NewCurrencyPairFromString(formattedPair.String())
newOrderBook.CurrencyPair = formattedPair.String()
newOrderBook.LastUpdated = time.Now()
newOrderBook.Pair = currency.NewPairFromString(formattedPair.String())
newOrderBook.AssetType = ticker.Spot
return b.Websocket.Orderbook.LoadSnapshot(newOrderBook, b.GetName(), false)
@@ -113,7 +111,7 @@ func (b *Binance) UpdateLocalCache(ob WebsocketDepthStream) error {
}
updatedTime := time.Unix(ob.Timestamp, 0)
currencyPair := pair.NewCurrencyPairFromString(ob.Pair)
currencyPair := currency.NewPairFromString(ob.Pair)
return b.Websocket.Orderbook.Update(updateBid,
updateAsk,
@@ -134,16 +132,16 @@ func (b *Binance) WSConnect() error {
tick := strings.ToLower(
strings.Replace(
strings.Join(b.EnabledPairs, "@ticker/"), "-", "", -1)) + "@ticker"
strings.Join(b.EnabledPairs.Strings(), "@ticker/"), "-", "", -1)) + "@ticker"
trade := strings.ToLower(
strings.Replace(
strings.Join(b.EnabledPairs, "@trade/"), "-", "", -1)) + "@trade"
strings.Join(b.EnabledPairs.Strings(), "@trade/"), "-", "", -1)) + "@trade"
kline := strings.ToLower(
strings.Replace(
strings.Join(b.EnabledPairs, "@kline_1m/"), "-", "", -1)) + "@kline_1m"
strings.Join(b.EnabledPairs.Strings(), "@kline_1m/"), "-", "", -1)) + "@kline_1m"
depth := strings.ToLower(
strings.Replace(
strings.Join(b.EnabledPairs, "@depth/"), "-", "", -1)) + "@depth"
strings.Join(b.EnabledPairs.Strings(), "@depth/"), "-", "", -1)) + "@depth"
wsurl := b.Websocket.GetWebsocketURL() +
"/stream?streams=" +
@@ -255,7 +253,7 @@ func (b *Binance) WsHandleData() {
}
b.Websocket.DataHandler <- exchange.TradeData{
CurrencyPair: pair.NewCurrencyPairFromString(trade.Symbol),
CurrencyPair: currency.NewPairFromString(trade.Symbol),
Timestamp: time.Unix(0, trade.TimeStamp),
Price: price,
Amount: amount,
@@ -277,7 +275,7 @@ func (b *Binance) WsHandleData() {
var wsTicker exchange.TickerData
wsTicker.Timestamp = time.Unix(0, t.EventTime)
wsTicker.Pair = pair.NewCurrencyPairFromString(t.Symbol)
wsTicker.Pair = currency.NewPairFromString(t.Symbol)
wsTicker.AssetType = ticker.Spot
wsTicker.Exchange = b.GetName()
wsTicker.ClosePrice, _ = strconv.ParseFloat(t.CurrDayClose, 64)
@@ -301,7 +299,7 @@ func (b *Binance) WsHandleData() {
var wsKline exchange.KlineData
wsKline.Timestamp = time.Unix(0, kline.EventTime)
wsKline.Pair = pair.NewCurrencyPairFromString(kline.Symbol)
wsKline.Pair = currency.NewPairFromString(kline.Symbol)
wsKline.AssetType = ticker.Spot
wsKline.Exchange = b.GetName()
wsKline.StartTime = time.Unix(0, kline.Kline.StartTime)
@@ -332,7 +330,7 @@ func (b *Binance) WsHandleData() {
continue
}
currencyPair := pair.NewCurrencyPairFromString(depth.Pair)
currencyPair := currency.NewPairFromString(depth.Pair)
b.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: currencyPair,

View File

@@ -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"
@@ -44,13 +44,18 @@ func (b *Binance) Run() {
log.Errorf("%s Failed to get exchange info.\n", b.GetName())
} else {
forceUpgrade := false
if !common.StringDataContains(b.EnabledPairs, "-") ||
!common.StringDataContains(b.AvailablePairs, "-") {
if !common.StringDataContains(b.EnabledPairs.Strings(), "-") ||
!common.StringDataContains(b.AvailablePairs.Strings(), "-") {
forceUpgrade = true
}
if forceUpgrade {
enabledPairs := []string{"BTC-USDT"}
enabledPairs := currency.Pairs{currency.Pair{
Base: currency.BTC,
Quote: currency.USDT,
Delimiter: "-",
}}
log.Warn("Available pairs for Binance reset due to config upgrade, please enable the ones you would like again")
err = b.UpdateCurrencies(enabledPairs, true, true)
@@ -58,7 +63,14 @@ func (b *Binance) Run() {
log.Errorf("%s Failed to get config.\n", b.GetName())
}
}
err = b.UpdateCurrencies(symbols, false, forceUpgrade)
var newSymbols currency.Pairs
for _, p := range symbols {
newSymbols = append(newSymbols,
currency.NewPairFromString(p))
}
err = b.UpdateCurrencies(newSymbols, false, forceUpgrade)
if err != nil {
log.Errorf("%s Failed to get config.\n", b.GetName())
}
@@ -66,7 +78,7 @@ func (b *Binance) Run() {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Binance) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
func (b *Binance) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := b.GetTickers()
if err != nil {
@@ -86,14 +98,14 @@ func (b *Binance) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pr
tickerPrice.Last = tick[y].LastPrice
tickerPrice.Low = tick[y].LowPrice
tickerPrice.Volume = tick[y].Volume
ticker.ProcessTicker(b.Name, x, tickerPrice, assetType)
ticker.ProcessTicker(b.Name, tickerPrice, assetType)
}
}
return ticker.GetTicker(b.Name, p, assetType)
}
// GetTickerPrice returns the ticker for a currency pair
func (b *Binance) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
func (b *Binance) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -102,8 +114,8 @@ func (b *Binance) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.
}
// GetOrderbookEx returns orderbook base on the currency pair
func (b *Binance) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.GetOrderbook(b.GetName(), currency, assetType)
func (b *Binance) GetOrderbookEx(currency currency.Pair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), currency, assetType)
if err != nil {
return b.UpdateOrderbook(currency, assetType)
}
@@ -111,7 +123,7 @@ func (b *Binance) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Binance) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
func (b *Binance) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderBook(OrderBookDataRequestParams{Symbol: exchange.FormatExchangeCurrency(b.Name, p).String(), Limit: 1000})
if err != nil {
@@ -128,8 +140,16 @@ func (b *Binance) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderb
orderbook.Item{Amount: asks.Quantity, Price: asks.Price})
}
orderbook.ProcessOrderbook(b.GetName(), p, orderBook, assetType)
return orderbook.GetOrderbook(b.Name, p, assetType)
orderBook.Pair = p
orderBook.ExchangeName = b.GetName()
orderBook.AssetType = assetType
err = orderBook.Process()
if err != nil {
return orderBook, err
}
return orderbook.Get(b.Name, p, assetType)
}
// GetAccountInfo retrieves balances for all enabled currencies for the
@@ -154,7 +174,7 @@ func (b *Binance) GetAccountInfo() (exchange.AccountInfo, error) {
}
currencyBalance = append(currencyBalance, exchange.AccountCurrencyInfo{
CurrencyName: balance.Asset,
CurrencyName: currency.NewCode(balance.Asset),
TotalValue: freeCurrency + lockedCurrency,
Hold: freeCurrency,
})
@@ -176,13 +196,13 @@ func (b *Binance) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Binance) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
func (b *Binance) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
var resp []exchange.TradeHistory
return resp, common.ErrNotYetImplemented
}
// SubmitOrder submits a new order
func (b *Binance) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
func (b *Binance) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
var submitOrderResponse exchange.SubmitOrderResponse
var sideType RequestParamsSideType
@@ -204,7 +224,7 @@ func (b *Binance) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orde
}
var orderRequest = NewOrderRequest{
Symbol: p.FirstCurrency.String() + p.SecondCurrency.String(),
Symbol: p.Base.String() + p.Quote.String(),
Side: sideType,
Price: price,
Quantity: amount,
@@ -271,7 +291,7 @@ func (b *Binance) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
}
// GetDepositAddress returns a deposit address for a specified currency
func (b *Binance) GetDepositAddress(cryptocurrency pair.CurrencyItem, _ string) (string, error) {
func (b *Binance) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
return b.GetDepositAddressForCurrency(cryptocurrency.String())
}
@@ -313,8 +333,8 @@ func (b *Binance) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([
}
var orders []exchange.OrderDetail
for _, currency := range getOrdersRequest.Currencies {
resp, err := b.OpenOrders(exchange.FormatExchangeCurrency(b.Name, currency).String())
for _, c := range getOrdersRequest.Currencies {
resp, err := b.OpenOrders(exchange.FormatExchangeCurrency(b.Name, c).String())
if err != nil {
return nil, err
}
@@ -333,7 +353,7 @@ func (b *Binance) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([
OrderType: orderType,
Price: order.Price,
Status: order.Status,
CurrencyPair: pair.NewCurrencyPairFromString(order.Symbol),
CurrencyPair: currency.NewPairFromString(order.Symbol),
})
}
}
@@ -353,8 +373,8 @@ func (b *Binance) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([
}
var orders []exchange.OrderDetail
for _, currency := range getOrdersRequest.Currencies {
resp, err := b.AllOrders(exchange.FormatExchangeCurrency(b.Name, currency).String(), "", "1000")
for _, c := range getOrdersRequest.Currencies {
resp, err := b.AllOrders(exchange.FormatExchangeCurrency(b.Name, c).String(), "", "1000")
if err != nil {
return nil, err
}
@@ -376,7 +396,7 @@ func (b *Binance) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([
OrderSide: orderSide,
OrderType: orderType,
Price: order.Price,
CurrencyPair: pair.NewCurrencyPairFromString(order.Symbol),
CurrencyPair: currency.NewPairFromString(order.Symbol),
Status: order.Status,
})
}