mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-25 15:10:24 +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
@@ -10,10 +10,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
@@ -94,9 +95,9 @@ func (z *ZB) Setup(exch config.ExchangeConfig) {
|
||||
z.RESTPollingDelay = exch.RESTPollingDelay
|
||||
z.Verbose = exch.Verbose
|
||||
z.Websocket.SetWsStatusAndConnection(exch.Websocket)
|
||||
z.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
|
||||
z.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
z.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
|
||||
z.BaseCurrencies = exch.BaseCurrencies
|
||||
z.AvailablePairs = exch.AvailablePairs
|
||||
z.EnabledPairs = exch.EnabledPairs
|
||||
err := z.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -347,7 +348,7 @@ func (z *ZB) GetSpotKline(arg KlinesRequestParams) (KLineResponse, error) {
|
||||
// NOTE - PLEASE BE AWARE THAT YOU NEED TO GENERATE A DEPOSIT ADDRESS VIA
|
||||
// LOGGING IN AND NOT BY USING THIS ENDPOINT OTHERWISE THIS WILL GIVE YOU A
|
||||
// GENERAL ERROR RESPONSE.
|
||||
func (z *ZB) GetCryptoAddress(currency pair.CurrencyItem) (UserAddress, error) {
|
||||
func (z *ZB) GetCryptoAddress(currency currency.Code) (UserAddress, error) {
|
||||
var resp UserAddress
|
||||
|
||||
vals := url.Values{}
|
||||
@@ -420,7 +421,7 @@ func (z *ZB) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
|
||||
case exchange.CryptocurrencyTradeFee:
|
||||
fee = calculateTradingFee(feeBuilder.PurchasePrice, feeBuilder.Amount)
|
||||
case exchange.CryptocurrencyWithdrawalFee:
|
||||
fee = getWithdrawalFee(feeBuilder.FirstCurrency)
|
||||
fee = getWithdrawalFee(feeBuilder.Pair.Base)
|
||||
}
|
||||
if fee < 0 {
|
||||
fee = 0
|
||||
@@ -434,8 +435,8 @@ func calculateTradingFee(purchasePrice, amount float64) (fee float64) {
|
||||
return fee * amount * purchasePrice
|
||||
}
|
||||
|
||||
func getWithdrawalFee(currency string) float64 {
|
||||
return WithdrawalFees[currency]
|
||||
func getWithdrawalFee(c currency.Code) float64 {
|
||||
return WithdrawalFees[c]
|
||||
}
|
||||
|
||||
var errorCode = map[int64]string{
|
||||
|
||||
@@ -6,8 +6,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"
|
||||
)
|
||||
|
||||
@@ -128,14 +127,13 @@ func TestGetSpotKline(t *testing.T) {
|
||||
|
||||
func setFeeBuilder() exchange.FeeBuilder {
|
||||
return exchange.FeeBuilder{
|
||||
Amount: 1,
|
||||
Delimiter: "-",
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
FirstCurrency: symbol.LTC,
|
||||
SecondCurrency: symbol.BTC,
|
||||
IsMaker: false,
|
||||
Amount: 1,
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
Pair: currency.NewPairWithDelimiter(currency.LTC.String(),
|
||||
currency.BTC.String(),
|
||||
"-"),
|
||||
PurchasePrice: 1,
|
||||
CurrencyItem: symbol.USD,
|
||||
FiatCurrency: currency.USD,
|
||||
BankTransactionType: exchange.WireTransfer,
|
||||
}
|
||||
}
|
||||
@@ -185,7 +183,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 := z.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
@@ -211,7 +209,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 := z.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
@@ -234,8 +232,9 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
Currencies: []pair.CurrencyPair{pair.NewCurrencyPair(symbol.LTC, symbol.BTC)},
|
||||
OrderType: exchange.AnyOrderType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.LTC,
|
||||
currency.BTC)},
|
||||
}
|
||||
|
||||
_, err := z.GetActiveOrders(getOrdersRequest)
|
||||
@@ -251,9 +250,10 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
Currencies: []pair.CurrencyPair{pair.NewCurrencyPair(symbol.LTC, symbol.BTC)},
|
||||
OrderType: exchange.AnyOrderType,
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.LTC,
|
||||
currency.BTC)},
|
||||
}
|
||||
|
||||
_, err := z.GetOrderHistory(getOrdersRequest)
|
||||
@@ -279,15 +279,23 @@ func TestSubmitOrder(t *testing.T) {
|
||||
TestSetup(t)
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip(fmt.Sprintf("ApiKey: %s. Can place orders: %v", z.APIKey, canManipulateRealOrders))
|
||||
t.Skip(fmt.Sprintf("ApiKey: %s. Can place orders: %v",
|
||||
z.APIKey,
|
||||
canManipulateRealOrders))
|
||||
}
|
||||
var currencyPair = pair.CurrencyPair{
|
||||
Delimiter: "_",
|
||||
FirstCurrency: symbol.QTUM,
|
||||
SecondCurrency: symbol.USDT,
|
||||
var pair = currency.Pair{
|
||||
Delimiter: "_",
|
||||
Base: currency.QTUM,
|
||||
Quote: currency.USDT,
|
||||
}
|
||||
|
||||
response, err := z.SubmitOrder(currencyPair, exchange.BuyOrderSide, exchange.MarketOrderType, 1, 10, "hi")
|
||||
response, err := z.SubmitOrder(pair,
|
||||
exchange.BuyOrderSide,
|
||||
exchange.MarketOrderType,
|
||||
1,
|
||||
10,
|
||||
"hi")
|
||||
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
@@ -303,7 +311,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
OrderID: "1",
|
||||
@@ -329,7 +337,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
OrderID: "1",
|
||||
@@ -378,7 +386,7 @@ func TestWithdraw(t *testing.T) {
|
||||
TestSetup(t)
|
||||
var withdrawCryptoRequest = exchange.WithdrawRequest{
|
||||
Amount: 100,
|
||||
Currency: symbol.BTC,
|
||||
Currency: currency.BTC,
|
||||
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
Description: "WITHDRAW IT ALL",
|
||||
FeeAmount: 1,
|
||||
@@ -431,13 +439,13 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
if apiKey != "" || apiSecret != "" {
|
||||
_, err := z.GetDepositAddress(symbol.BTC, "")
|
||||
_, err := z.GetDepositAddress(currency.BTC, "")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - GetDepositAddress() error PLEASE MAKE SURE YOU CREATE DEPOSIT ADDRESSES VIA ZB.COM",
|
||||
err)
|
||||
}
|
||||
} else {
|
||||
_, err := z.GetDepositAddress(symbol.BTC, "")
|
||||
_, err := z.GetDepositAddress(currency.BTC, "")
|
||||
if err == nil {
|
||||
t.Error("Test Failed - GetDepositAddress() error")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package zb
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
)
|
||||
|
||||
@@ -168,76 +168,76 @@ var (
|
||||
|
||||
// WithdrawalFees the large list of predefined withdrawal fees
|
||||
// Prone to change, using highest value
|
||||
var WithdrawalFees = map[string]float64{
|
||||
symbol.ZB: 5,
|
||||
symbol.BTC: 0.001,
|
||||
symbol.BCH: 0.0006,
|
||||
symbol.LTC: 0.005,
|
||||
symbol.ETH: 0.01,
|
||||
symbol.ETC: 0.01,
|
||||
symbol.BTS: 3,
|
||||
symbol.EOS: 0.1,
|
||||
symbol.QTUM: 0.01,
|
||||
symbol.HC: 0.001,
|
||||
symbol.XRP: 0.1,
|
||||
symbol.QC: 5,
|
||||
symbol.DASH: 0.002,
|
||||
symbol.BCD: 0,
|
||||
symbol.UBTC: 0.001,
|
||||
symbol.SBTC: 0,
|
||||
symbol.INK: 60,
|
||||
symbol.BTH: 0.01,
|
||||
symbol.LBTC: 0.01,
|
||||
symbol.CHAT: 20,
|
||||
symbol.BITCNY: 20,
|
||||
symbol.HLC: 100,
|
||||
symbol.BTP: 0.001,
|
||||
symbol.TOPC: 200,
|
||||
symbol.ENT: 50,
|
||||
symbol.BAT: 40,
|
||||
symbol.FIRST: 30,
|
||||
symbol.SAFE: 0.001,
|
||||
symbol.QUN: 200,
|
||||
symbol.BTN: 0.005,
|
||||
symbol.TRUE: 5,
|
||||
symbol.CDC: 1,
|
||||
symbol.DDM: 1,
|
||||
symbol.HOTC: 150,
|
||||
symbol.USDT: 5,
|
||||
symbol.XUC: 1,
|
||||
symbol.EPC: 40,
|
||||
symbol.BDS: 3,
|
||||
symbol.GRAM: 5,
|
||||
symbol.DOGE: 20,
|
||||
symbol.NEO: 0,
|
||||
symbol.OMG: 0.5,
|
||||
symbol.BTM: 4,
|
||||
symbol.SNT: 60,
|
||||
symbol.AE: 3,
|
||||
symbol.ICX: 3,
|
||||
symbol.ZRX: 10,
|
||||
symbol.EDO: 4,
|
||||
symbol.FUN: 250,
|
||||
symbol.MANA: 70,
|
||||
symbol.RCN: 70,
|
||||
symbol.MCO: 0.6,
|
||||
symbol.MITH: 10,
|
||||
symbol.KNC: 5,
|
||||
symbol.XLM: 0.1,
|
||||
symbol.GNT: 20,
|
||||
symbol.MTL: 3,
|
||||
symbol.SUB: 20,
|
||||
symbol.XEM: 4,
|
||||
symbol.EOSDAC: 0,
|
||||
symbol.KAN: 350,
|
||||
symbol.AAA: 1,
|
||||
symbol.XWC: 1,
|
||||
symbol.PDX: 1,
|
||||
symbol.SLT: 100,
|
||||
symbol.ADA: 1,
|
||||
symbol.HPY: 100,
|
||||
symbol.PAX: 5,
|
||||
symbol.XTZ: 0.1,
|
||||
var WithdrawalFees = map[currency.Code]float64{
|
||||
currency.ZB: 5,
|
||||
currency.BTC: 0.001,
|
||||
currency.BCH: 0.0006,
|
||||
currency.LTC: 0.005,
|
||||
currency.ETH: 0.01,
|
||||
currency.ETC: 0.01,
|
||||
currency.BTS: 3,
|
||||
currency.EOS: 0.1,
|
||||
currency.QTUM: 0.01,
|
||||
currency.HC: 0.001,
|
||||
currency.XRP: 0.1,
|
||||
currency.QC: 5,
|
||||
currency.DASH: 0.002,
|
||||
currency.BCD: 0,
|
||||
currency.UBTC: 0.001,
|
||||
currency.SBTC: 0,
|
||||
currency.INK: 60,
|
||||
currency.BTH: 0.01,
|
||||
currency.LBTC: 0.01,
|
||||
currency.CHAT: 20,
|
||||
currency.BITCNY: 20,
|
||||
currency.HLC: 100,
|
||||
currency.BTP: 0.001,
|
||||
currency.TOPC: 200,
|
||||
currency.ENT: 50,
|
||||
currency.BAT: 40,
|
||||
currency.FIRST: 30,
|
||||
currency.SAFE: 0.001,
|
||||
currency.QUN: 200,
|
||||
currency.BTN: 0.005,
|
||||
currency.TRUE: 5,
|
||||
currency.CDC: 1,
|
||||
currency.DDM: 1,
|
||||
currency.HOTC: 150,
|
||||
currency.USDT: 5,
|
||||
currency.XUC: 1,
|
||||
currency.EPC: 40,
|
||||
currency.BDS: 3,
|
||||
currency.GRAM: 5,
|
||||
currency.DOGE: 20,
|
||||
currency.NEO: 0,
|
||||
currency.OMG: 0.5,
|
||||
currency.BTM: 4,
|
||||
currency.SNT: 60,
|
||||
currency.AE: 3,
|
||||
currency.ICX: 3,
|
||||
currency.ZRX: 10,
|
||||
currency.EDO: 4,
|
||||
currency.FUN: 250,
|
||||
currency.MANA: 70,
|
||||
currency.RCN: 70,
|
||||
currency.MCO: 0.6,
|
||||
currency.MITH: 10,
|
||||
currency.KNC: 5,
|
||||
currency.XLM: 0.1,
|
||||
currency.GNT: 20,
|
||||
currency.MTL: 3,
|
||||
currency.SUB: 20,
|
||||
currency.XEM: 4,
|
||||
currency.EOSDAC: 0,
|
||||
currency.KAN: 350,
|
||||
currency.AAA: 1,
|
||||
currency.XWC: 1,
|
||||
currency.PDX: 1,
|
||||
currency.SLT: 100,
|
||||
currency.ADA: 1,
|
||||
currency.HPY: 100,
|
||||
currency.PAX: 5,
|
||||
currency.XTZ: 0.1,
|
||||
}
|
||||
|
||||
// orderSideMap holds order type info based on Alphapoint data
|
||||
|
||||
@@ -9,7 +9,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"
|
||||
)
|
||||
@@ -64,7 +64,7 @@ func (z *ZB) WsSubscribe() error {
|
||||
}
|
||||
|
||||
for _, c := range z.GetEnabledCurrencies() {
|
||||
cPair := c.FirstCurrency.Lower() + c.SecondCurrency.Lower()
|
||||
cPair := c.Base.Lower().String() + c.Quote.Lower().String()
|
||||
|
||||
ticker := Subscription{
|
||||
Event: "addChannel",
|
||||
@@ -186,7 +186,7 @@ func (z *ZB) WsHandleData() {
|
||||
|
||||
z.Websocket.DataHandler <- exchange.TickerData{
|
||||
Timestamp: time.Unix(0, ticker.Date),
|
||||
Pair: pair.NewCurrencyPairFromString(cPair[0]),
|
||||
Pair: currency.NewPairFromString(cPair[0]),
|
||||
AssetType: "SPOT",
|
||||
Exchange: z.GetName(),
|
||||
ClosePrice: ticker.Data.Last,
|
||||
@@ -221,17 +221,17 @@ func (z *ZB) WsHandleData() {
|
||||
}
|
||||
|
||||
channelInfo := common.SplitStrings(result.Channel, "_")
|
||||
cPair := pair.NewCurrencyPairFromString(channelInfo[0])
|
||||
cPair := currency.NewPairFromString(channelInfo[0])
|
||||
|
||||
var newOrderbook orderbook.Base
|
||||
newOrderbook.Asks = asks
|
||||
newOrderbook.Bids = bids
|
||||
newOrderbook.AssetType = "SPOT"
|
||||
newOrderbook.Pair = cPair
|
||||
newOrderbook.CurrencyPair = channelInfo[0]
|
||||
newOrderbook.LastUpdated = time.Now()
|
||||
|
||||
err = z.Websocket.Orderbook.LoadSnapshot(newOrderbook, z.GetName(), true)
|
||||
err = z.Websocket.Orderbook.LoadSnapshot(newOrderbook,
|
||||
z.GetName(),
|
||||
true)
|
||||
if err != nil {
|
||||
z.Websocket.DataHandler <- err
|
||||
continue
|
||||
@@ -255,7 +255,7 @@ func (z *ZB) WsHandleData() {
|
||||
t := trades.Data[len(trades.Data)-1]
|
||||
|
||||
channelInfo := common.SplitStrings(result.Channel, "_")
|
||||
cPair := pair.NewCurrencyPairFromString(channelInfo[0])
|
||||
cPair := currency.NewPairFromString(channelInfo[0])
|
||||
|
||||
z.Websocket.DataHandler <- exchange.TradeData{
|
||||
Timestamp: time.Unix(0, t.Date),
|
||||
|
||||
@@ -8,7 +8,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"
|
||||
@@ -41,7 +41,13 @@ func (z *ZB) Run() {
|
||||
currencies = append(currencies, x)
|
||||
}
|
||||
|
||||
err = z.UpdateCurrencies(currencies, false, false)
|
||||
var newCurrencies currency.Pairs
|
||||
for _, p := range currencies {
|
||||
newCurrencies = append(newCurrencies,
|
||||
currency.NewPairFromString(p))
|
||||
}
|
||||
|
||||
err = z.UpdateCurrencies(newCurrencies, false, false)
|
||||
if err != nil {
|
||||
log.Errorf("%s Failed to update available currencies.\n", z.GetName())
|
||||
}
|
||||
@@ -49,7 +55,7 @@ func (z *ZB) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (z *ZB) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (z *ZB) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
|
||||
result, err := z.GetTickers()
|
||||
@@ -69,14 +75,18 @@ func (z *ZB) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price,
|
||||
tp.Last = result[currency].Last
|
||||
tp.Low = result[currency].Low
|
||||
tp.Volume = result[currency].Vol
|
||||
ticker.ProcessTicker(z.Name, x, tp, assetType)
|
||||
|
||||
err = ticker.ProcessTicker(z.Name, tp, assetType)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
}
|
||||
|
||||
return ticker.GetTicker(z.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (z *ZB) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (z *ZB) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(z.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return z.UpdateTicker(p, assetType)
|
||||
@@ -85,8 +95,8 @@ func (z *ZB) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns orderbook base on the currency pair
|
||||
func (z *ZB) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook(z.GetName(), currency, assetType)
|
||||
func (z *ZB) GetOrderbookEx(currency currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(z.GetName(), currency, assetType)
|
||||
if err != nil {
|
||||
return z.UpdateOrderbook(currency, assetType)
|
||||
}
|
||||
@@ -94,7 +104,7 @@ func (z *ZB) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (order
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (z *ZB) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
func (z *ZB) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
currency := exchange.FormatExchangeCurrency(z.Name, p).String()
|
||||
|
||||
@@ -113,8 +123,16 @@ func (z *ZB) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.B
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data[1], Price: data[0]})
|
||||
}
|
||||
|
||||
orderbook.ProcessOrderbook(z.GetName(), p, orderBook, assetType)
|
||||
return orderbook.GetOrderbook(z.Name, p, assetType)
|
||||
orderBook.Pair = p
|
||||
orderBook.AssetType = assetType
|
||||
orderBook.ExchangeName = z.GetName()
|
||||
|
||||
err = orderBook.Process()
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
return orderbook.Get(z.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetAccountInfo retrieves balances for all enabled currencies for the
|
||||
@@ -139,7 +157,7 @@ func (z *ZB) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: data.EnName,
|
||||
CurrencyName: currency.NewCode(data.EnName),
|
||||
TotalValue: hold + avail,
|
||||
Hold: hold,
|
||||
})
|
||||
@@ -161,14 +179,14 @@ func (z *ZB) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
}
|
||||
|
||||
// GetExchangeHistory returns historic trade data since exchange opening.
|
||||
func (z *ZB) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
func (z *ZB) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
var resp []exchange.TradeHistory
|
||||
|
||||
return resp, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (z *ZB) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
func (z *ZB) SubmitOrder(p currency.Pair, side exchange.OrderSide, _ exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
var oT SpotNewOrderRequestParamsType
|
||||
|
||||
@@ -181,7 +199,7 @@ func (z *ZB) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ exchang
|
||||
var params = SpotNewOrderRequestParams{
|
||||
Amount: amount,
|
||||
Price: price,
|
||||
Symbol: common.StringToLower(p.Pair().String()),
|
||||
Symbol: common.StringToLower(p.String()),
|
||||
Type: oT,
|
||||
}
|
||||
response, err := z.SpotNewOrder(params)
|
||||
@@ -255,7 +273,7 @@ func (z *ZB) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (z *ZB) GetDepositAddress(cryptocurrency pair.CurrencyItem, _ string) (string, error) {
|
||||
func (z *ZB) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
address, err := z.GetCryptoAddress(cryptocurrency)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -315,7 +333,8 @@ func (z *ZB) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]exch
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range allOrders {
|
||||
symbol := pair.NewCurrencyPairDelimiter(order.Currency, z.ConfigCurrencyPairFormat.Delimiter)
|
||||
symbol := currency.NewPairDelimiter(order.Currency,
|
||||
z.ConfigCurrencyPairFormat.Delimiter)
|
||||
orderDate := time.Unix(int64(order.TradeDate), 0)
|
||||
orderSide := orderSideMap[order.Type]
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
@@ -329,7 +348,8 @@ func (z *ZB) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]exch
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
@@ -370,7 +390,8 @@ func (z *ZB) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]exch
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range allOrders {
|
||||
symbol := pair.NewCurrencyPairDelimiter(order.Currency, z.ConfigCurrencyPairFormat.Delimiter)
|
||||
symbol := currency.NewPairDelimiter(order.Currency,
|
||||
z.ConfigCurrencyPairFormat.Delimiter)
|
||||
orderDate := time.Unix(int64(order.TradeDate), 0)
|
||||
orderSide := orderSideMap[order.Type]
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
|
||||
Reference in New Issue
Block a user