mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
Finish off websocket ticker demo, update config files and fix tests
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -49,6 +50,7 @@ type Alphapoint struct {
|
||||
func (a *Alphapoint) SetDefaults() {
|
||||
a.APIUrl = alphapointDefaultAPIURL
|
||||
a.WebsocketURL = alphapointDefaultWebsocketURL
|
||||
a.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
// GetTicker returns current ticker information from Alphapoint for a selected
|
||||
|
||||
@@ -29,8 +29,8 @@ func (a *Alphapoint) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (a *Alphapoint) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (a *Alphapoint) UpdateTicker(p pair.CurrencyPair) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := a.GetTicker(p.Pair().String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -43,13 +43,13 @@ func (a *Alphapoint) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, erro
|
||||
tickerPrice.High = tick.High
|
||||
tickerPrice.Volume = tick.Volume
|
||||
tickerPrice.Last = tick.Last
|
||||
ticker.ProcessTicker(a.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(a.GetName(), p, tickerPrice, ticker.Spot)
|
||||
return ticker.GetTicker(a.Name, p, ticker.Spot)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (a *Alphapoint) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tick, err := ticker.GetTicker(a.GetName(), p)
|
||||
func (a *Alphapoint) GetTickerPrice(p pair.CurrencyPair) (ticker.Price, error) {
|
||||
tick, err := ticker.GetTicker(a.GetName(), p, ticker.Spot)
|
||||
if err != nil {
|
||||
return a.UpdateTicker(p)
|
||||
}
|
||||
@@ -74,9 +74,8 @@ func (a *Alphapoint) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBa
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Quantity, Price: data.Price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(a.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(a.Name, p)
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns the orderbook for a currency pair
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -45,6 +46,7 @@ func (a *ANX) SetDefaults() {
|
||||
a.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
a.ConfigCurrencyPairFormat.Uppercase = true
|
||||
a.ConfigCurrencyPairFormat.Index = "BTC"
|
||||
a.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
//Setup is run on startup to setup exchange with config values
|
||||
@@ -65,6 +67,10 @@ func (a *ANX) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = a.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,10 @@ package anx
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
@@ -23,29 +21,12 @@ func (a *ANX) Run() {
|
||||
log.Printf("%s polling delay: %ds.\n", a.GetName(), a.RESTPollingDelay)
|
||||
log.Printf("%s %d currencies enabled: %s.\n", a.GetName(), len(a.EnabledPairs), a.EnabledPairs)
|
||||
}
|
||||
|
||||
for a.Enabled {
|
||||
pairs := a.GetEnabledCurrencies()
|
||||
for x := range pairs {
|
||||
currency := pairs[x]
|
||||
go func() {
|
||||
ticker, err := a.UpdateTicker(currency)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
log.Printf("ANX %s: Last %f High %f Low %f Volume %f\n", exchange.FormatCurrency(currency).String(), ticker.Last, ticker.High, ticker.Low, ticker.Volume)
|
||||
stats.AddExchangeInfo(a.GetName(), currency.GetFirstCurrency().String(), currency.GetSecondCurrency().String(), ticker.Last, ticker.Volume)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * a.RESTPollingDelay)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (a *ANX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
tick, err := a.GetTicker(p.Pair().String())
|
||||
func (a *ANX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := a.GetTicker(exchange.FormatExchangeCurrency(a.GetName(), p).String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
@@ -105,15 +86,15 @@ func (a *ANX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
} else {
|
||||
tickerPrice.High = 0
|
||||
}
|
||||
ticker.ProcessTicker(a.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(a.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(a.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (a *ANX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(a.GetName(), p)
|
||||
func (a *ANX) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(a.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return a.UpdateTicker(p)
|
||||
return a.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -85,6 +86,7 @@ func (b *Bitfinex) SetDefaults() {
|
||||
b.RequestCurrencyPairFormat.Uppercase = true
|
||||
b.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
b.ConfigCurrencyPairFormat.Uppercase = true
|
||||
b.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
// Setup takes in the supplied exchange configuration details and sets params
|
||||
@@ -105,6 +107,10 @@ func (b *Bitfinex) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = b.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ func (b *Bitfinex) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bitfinex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (b *Bitfinex) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tickerNew, err := b.GetTicker(p.Pair().String(), nil)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -53,15 +53,15 @@ func (b *Bitfinex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error)
|
||||
tickerPrice.Last = tickerNew.Last
|
||||
tickerPrice.Volume = tickerNew.Volume
|
||||
tickerPrice.High = tickerNew.High
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (b *Bitfinex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p)
|
||||
func (b *Bitfinex) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p, ticker.Spot)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p)
|
||||
return b.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tick, nil
|
||||
}
|
||||
@@ -91,9 +91,8 @@ func (b *Bitfinex) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase
|
||||
orderBook.Bids = append(orderBook.Bids, orderbook.OrderbookItem{Price: orderbookNew.Bids[x].Price, Amount: orderbookNew.Bids[x].Amount})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(b.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(b.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies on the
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
@@ -18,7 +19,7 @@ func TestRun(t *testing.T) {
|
||||
|
||||
func TestGetTickerPrice(t *testing.T) {
|
||||
getTickerPrice := Bitfinex{}
|
||||
_, err := getTickerPrice.GetTickerPrice(pair.NewCurrencyPair("BTC", "USD"))
|
||||
_, err := getTickerPrice.GetTickerPrice(pair.NewCurrencyPair("BTC", "USD"), ticker.Spot)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Bitfinex GetTickerPrice() error: %s", err)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -64,6 +65,7 @@ func (b *Bitstamp) SetDefaults() {
|
||||
b.RequestCurrencyPairFormat.Uppercase = true
|
||||
b.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
b.ConfigCurrencyPairFormat.Uppercase = true
|
||||
b.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
// Setup sets configuration values to bitstamp
|
||||
@@ -84,6 +86,10 @@ func (b *Bitstamp) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = b.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ func (b *Bitstamp) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := b.GetTicker(p.Pair().String(), false)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -43,15 +43,15 @@ func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error)
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Volume
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (b *Bitstamp) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p)
|
||||
func (b *Bitstamp) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p)
|
||||
return b.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tick, nil
|
||||
}
|
||||
@@ -83,9 +83,8 @@ func (b *Bitstamp) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Amount, Price: data.Price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(b.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(b.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -70,6 +71,7 @@ func (b *Bittrex) SetDefaults() {
|
||||
b.RequestCurrencyPairFormat.Uppercase = true
|
||||
b.ConfigCurrencyPairFormat.Delimiter = "-"
|
||||
b.ConfigCurrencyPairFormat.Uppercase = true
|
||||
b.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
// Setup method sets current configuration details if enabled
|
||||
@@ -90,6 +92,10 @@ func (b *Bittrex) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = b.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ func (b *Bittrex) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bittrex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (b *Bittrex) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := b.GetMarketSummary(exchange.FormatExchangeCurrency(b.GetName(), p).String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -86,15 +86,15 @@ func (b *Bittrex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error)
|
||||
tickerPrice.Bid = tick[0].Bid
|
||||
tickerPrice.Last = tick[0].Last
|
||||
tickerPrice.Volume = tick[0].Volume
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (b *Bittrex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p)
|
||||
func (b *Bittrex) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p, ticker.Spot)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p)
|
||||
return b.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tick, nil
|
||||
}
|
||||
@@ -134,7 +134,6 @@ func (b *Bittrex) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase,
|
||||
)
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(b.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(b.Name, p)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -59,6 +60,7 @@ func (b *BTCC) SetDefaults() {
|
||||
b.RequestCurrencyPairFormat.Uppercase = false
|
||||
b.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
b.ConfigCurrencyPairFormat.Uppercase = true
|
||||
b.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
// Setup is run on startup to setup exchange with config values
|
||||
@@ -79,6 +81,10 @@ func (b *BTCC) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = b.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ func (b *BTCC) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *BTCC) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (b *BTCC) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := b.GetTicker(exchange.FormatExchangeCurrency(b.GetName(), p).String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -42,15 +42,15 @@ func (b *BTCC) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Vol
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (b *BTCC) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(b.GetName(), p)
|
||||
func (b *BTCC) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p)
|
||||
return b.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -82,9 +82,8 @@ func (b *BTCC) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, er
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Price: data[0], Amount: data[1]})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(b.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(b.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo : Retrieves balances for all enabled currencies for
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -53,6 +54,7 @@ func (b *BTCE) SetDefaults() {
|
||||
b.RequestCurrencyPairFormat.Separator = "-"
|
||||
b.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
b.ConfigCurrencyPairFormat.Uppercase = true
|
||||
b.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (b *BTCE) Setup(exch config.ExchangeConfig) {
|
||||
@@ -72,6 +74,10 @@ func (b *BTCE) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = b.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ func (b *BTCE) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *BTCE) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (b *BTCE) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
result, err := b.GetTicker(p.Pair().String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -71,15 +71,15 @@ func (b *BTCE) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Vol_cur
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (b *BTCE) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p)
|
||||
func (b *BTCE) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tick, err := ticker.GetTicker(b.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p)
|
||||
return b.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tick, nil
|
||||
}
|
||||
@@ -111,9 +111,8 @@ func (b *BTCE) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, er
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Price: data[0], Amount: data[1]})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(b.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(b.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -56,6 +57,7 @@ func (b *BTCMarkets) SetDefaults() {
|
||||
b.RequestCurrencyPairFormat.Uppercase = true
|
||||
b.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
b.ConfigCurrencyPairFormat.Uppercase = true
|
||||
b.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
// Setup takes in an exchange configuration and sets all paramaters
|
||||
@@ -76,6 +78,10 @@ func (b *BTCMarkets) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = b.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ func (b *BTCMarkets) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := b.GetTicker(p.GetFirstCurrency().String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -61,15 +61,15 @@ func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, erro
|
||||
tickerPrice.Ask = tick.BestAsk
|
||||
tickerPrice.Bid = tick.BestBID
|
||||
tickerPrice.Last = tick.LastPrice
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (b *BTCMarkets) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(b.GetName(), p)
|
||||
func (b *BTCMarkets) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p)
|
||||
return b.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -101,9 +101,8 @@ func (b *BTCMarkets) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBa
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(b.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(b.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -52,6 +53,7 @@ func (c *COINUT) SetDefaults() {
|
||||
c.RequestCurrencyPairFormat.Uppercase = true
|
||||
c.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
c.ConfigCurrencyPairFormat.Uppercase = true
|
||||
c.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (c *COINUT) Setup(exch config.ExchangeConfig) {
|
||||
@@ -71,6 +73,10 @@ func (c *COINUT) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = c.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ type CoinutTicker struct {
|
||||
type CoinutOrderbookBase struct {
|
||||
Count int `json:"count"`
|
||||
Price float64 `json:"price,string"`
|
||||
Quantity float64 `json:"quantity,string"`
|
||||
Quantity float64 `json:"qty,string"`
|
||||
}
|
||||
|
||||
type CoinutOrderbook struct {
|
||||
|
||||
@@ -69,11 +69,11 @@ func (c *COINUT) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (c *COINUT) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (c *COINUT) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := c.GetInstrumentTicker(c.InstrumentMap[p.Pair().String()])
|
||||
if err != nil {
|
||||
return ticker.TickerPrice{}, err
|
||||
return ticker.Price{}, err
|
||||
}
|
||||
|
||||
tickerPrice.Pair = p
|
||||
@@ -81,16 +81,16 @@ func (c *COINUT) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.High = tick.HighestBuy
|
||||
tickerPrice.Low = tick.LowestSell
|
||||
ticker.ProcessTicker(c.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(c.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(c.Name, p, assetType)
|
||||
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (c *COINUT) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(c.GetName(), p)
|
||||
func (c *COINUT) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(c.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return c.UpdateTicker(p)
|
||||
return c.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -120,7 +120,6 @@ func (c *COINUT) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase,
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: orderbookNew.Sell[x].Quantity, Price: orderbookNew.Sell[x].Price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(c.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(c.Name, p)
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ type Base struct {
|
||||
BaseCurrencies []string
|
||||
AvailablePairs []string
|
||||
EnabledPairs []string
|
||||
AssetTypes []string
|
||||
WebsocketURL string
|
||||
APIUrl string
|
||||
RequestCurrencyPairFormat config.CurrencyPairFormatConfig
|
||||
@@ -63,8 +64,8 @@ type IBotExchange interface {
|
||||
SetDefaults()
|
||||
GetName() string
|
||||
IsEnabled() bool
|
||||
GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice, error)
|
||||
UpdateTicker(currency pair.CurrencyPair) (ticker.TickerPrice, error)
|
||||
GetTickerPrice(currency pair.CurrencyPair, assetType string) (ticker.Price, error)
|
||||
UpdateTicker(currency pair.CurrencyPair, assetType string) (ticker.Price, error)
|
||||
GetOrderbookEx(currency pair.CurrencyPair) (orderbook.OrderbookBase, error)
|
||||
UpdateOrderbook(currency pair.CurrencyPair) (orderbook.OrderbookBase, error)
|
||||
GetEnabledCurrencies() []pair.CurrencyPair
|
||||
@@ -72,6 +73,42 @@ type IBotExchange interface {
|
||||
GetAuthenticatedAPISupport() bool
|
||||
}
|
||||
|
||||
// SetAssetTypes checks the exchange asset types (whether it supports SPOT,
|
||||
// Binary or Futures) and sets it to a default setting if it doesn't exist
|
||||
func (e *Base) SetAssetTypes() error {
|
||||
cfg := config.GetConfig()
|
||||
exch, err := cfg.GetExchangeConfig(e.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
update := false
|
||||
if exch.AssetTypes == "" {
|
||||
exch.AssetTypes = common.JoinStrings(e.AssetTypes, ",")
|
||||
update = true
|
||||
} else {
|
||||
e.AssetTypes = common.SplitStrings(exch.AssetTypes, ",")
|
||||
}
|
||||
|
||||
if update {
|
||||
return cfg.UpdateExchangeConfig(exch)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetExchangeAssetTypes returns the asset types the exchange supports (SPOT,
|
||||
// binary, futures)
|
||||
func GetExchangeAssetTypes(exchName string) ([]string, error) {
|
||||
cfg := config.GetConfig()
|
||||
exch, err := cfg.GetExchangeConfig(exchName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return common.SplitStrings(exch.AssetTypes, ","), nil
|
||||
}
|
||||
|
||||
// SetCurrencyPairFormat checks the exchange request and config currency pair
|
||||
// formats and sets it to a default setting if it doesn't exist
|
||||
func (e *Base) SetCurrencyPairFormat() error {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -50,6 +51,7 @@ func (g *GDAX) SetDefaults() {
|
||||
g.RequestCurrencyPairFormat.Uppercase = true
|
||||
g.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
g.ConfigCurrencyPairFormat.Uppercase = true
|
||||
g.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (g *GDAX) Setup(exch config.ExchangeConfig) {
|
||||
@@ -69,6 +71,10 @@ func (g *GDAX) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = g.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,17 +65,17 @@ func (g *GDAX) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (g *GDAX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (g *GDAX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := g.GetTicker(exchange.FormatExchangeCurrency(g.Name, p).String())
|
||||
if err != nil {
|
||||
return ticker.TickerPrice{}, err
|
||||
return ticker.Price{}, err
|
||||
}
|
||||
|
||||
stats, err := g.GetStats(exchange.FormatExchangeCurrency(g.Name, p).String())
|
||||
|
||||
if err != nil {
|
||||
return ticker.TickerPrice{}, err
|
||||
return ticker.Price{}, err
|
||||
}
|
||||
|
||||
tickerPrice.Pair = p
|
||||
@@ -83,15 +83,15 @@ func (g *GDAX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerPrice.Last = tick.Price
|
||||
tickerPrice.High = stats.High
|
||||
tickerPrice.Low = stats.Low
|
||||
ticker.ProcessTicker(g.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(g.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(g.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (g *GDAX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(g.GetName(), p)
|
||||
func (g *GDAX) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(g.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return g.UpdateTicker(p)
|
||||
return g.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (g *GDAX) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, err
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (g *GDAX) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
|
||||
var orderBook orderbook.OrderbookBase
|
||||
orderbookNew, err := g.GetOrderbook(p.Pair().String(), 2)
|
||||
orderbookNew, err := g.GetOrderbook(exchange.FormatExchangeCurrency(g.Name, p).String(), 2)
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
@@ -123,7 +123,6 @@ func (g *GDAX) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, er
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: obNew.Bids[x].Amount, Price: obNew.Bids[x].Price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(g.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(g.Name, p)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -49,6 +50,7 @@ func (g *Gemini) SetDefaults() {
|
||||
g.RequestCurrencyPairFormat.Uppercase = true
|
||||
g.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
g.ConfigCurrencyPairFormat.Uppercase = true
|
||||
g.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (g *Gemini) Setup(exch config.ExchangeConfig) {
|
||||
@@ -68,6 +70,10 @@ func (g *Gemini) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = g.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ func (g *Gemini) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (g *Gemini) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (g *Gemini) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := g.GetTicker(p.Pair().String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -64,15 +64,15 @@ func (g *Gemini) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerPrice.Bid = tick.Bid
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Volume.USD
|
||||
ticker.ProcessTicker(g.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(g.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(g.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (g *Gemini) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(g.GetName(), p)
|
||||
func (g *Gemini) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(g.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return g.UpdateTicker(p)
|
||||
return g.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -102,7 +102,6 @@ func (g *Gemini) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase,
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: orderbookNew.Asks[x].Amount, Price: orderbookNew.Asks[x].Price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(g.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(g.Name, p)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -33,6 +34,7 @@ func (h *HUOBI) SetDefaults() {
|
||||
h.RequestCurrencyPairFormat.Uppercase = false
|
||||
h.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
h.ConfigCurrencyPairFormat.Uppercase = true
|
||||
h.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (h *HUOBI) Setup(exch config.ExchangeConfig) {
|
||||
@@ -52,6 +54,10 @@ func (h *HUOBI) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = h.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ func (h *HUOBI) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (h *HUOBI) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (h *HUOBI) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := h.GetTicker(p.GetFirstCurrency().Lower().String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
@@ -42,15 +42,15 @@ func (h *HUOBI) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Vol
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(h.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(h.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(h.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (h *HUOBI) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(h.GetName(), p)
|
||||
func (h *HUOBI) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(h.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return h.UpdateTicker(p)
|
||||
return h.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -82,9 +82,8 @@ func (h *HUOBI) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, e
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(h.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(h.Name, p)
|
||||
}
|
||||
|
||||
//GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,6 +36,7 @@ func (i *ItBit) SetDefaults() {
|
||||
i.RequestCurrencyPairFormat.Uppercase = true
|
||||
i.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
i.ConfigCurrencyPairFormat.Uppercase = true
|
||||
i.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (i *ItBit) Setup(exch config.ExchangeConfig) {
|
||||
@@ -54,6 +56,10 @@ func (i *ItBit) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = i.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,10 @@ func (i *ItBit) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (i *ItBit) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
tick, err := i.GetTicker(p.Pair().String())
|
||||
func (i *ItBit) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := i.GetTicker(exchange.FormatExchangeCurrency(i.Name,
|
||||
p).String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
@@ -38,15 +39,15 @@ func (i *ItBit) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerPrice.High = tick.High24h
|
||||
tickerPrice.Low = tick.Low24h
|
||||
tickerPrice.Volume = tick.Volume24h
|
||||
ticker.ProcessTicker(i.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
ticker.ProcessTicker(i.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(i.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (i *ItBit) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(i.GetName(), p)
|
||||
func (i *ItBit) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(i.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return i.UpdateTicker(p)
|
||||
return i.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -63,7 +64,8 @@ func (i *ItBit) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (i *ItBit) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
|
||||
var orderBook orderbook.OrderbookBase
|
||||
orderbookNew, err := i.GetOrderbook(p.Pair().String())
|
||||
orderbookNew, err := i.GetOrderbook(exchange.FormatExchangeCurrency(i.Name,
|
||||
p).String())
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
@@ -94,9 +96,8 @@ func (i *ItBit) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, e
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: amount, Price: price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(i.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(i.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -60,6 +61,7 @@ func (k *Kraken) SetDefaults() {
|
||||
k.RequestCurrencyPairFormat.Separator = ","
|
||||
k.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
k.ConfigCurrencyPairFormat.Uppercase = true
|
||||
k.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (k *Kraken) Setup(exch config.ExchangeConfig) {
|
||||
@@ -79,6 +81,10 @@ func (k *Kraken) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = k.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ func (k *Kraken) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (k *Kraken) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (k *Kraken) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
pairs := k.GetEnabledCurrencies()
|
||||
pairsCollated, err := exchange.GetAndFormatExchangeCurrencies(k.Name, pairs)
|
||||
if err != nil {
|
||||
@@ -50,7 +50,7 @@ func (k *Kraken) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
}
|
||||
|
||||
for _, x := range pairs {
|
||||
var tp ticker.TickerPrice
|
||||
var tp ticker.Price
|
||||
tick, ok := k.Ticker[x.Pair().String()]
|
||||
if !ok {
|
||||
continue
|
||||
@@ -63,16 +63,16 @@ func (k *Kraken) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tp.High = tick.High
|
||||
tp.Low = tick.Low
|
||||
tp.Volume = tick.Volume
|
||||
ticker.ProcessTicker(k.GetName(), x, tp)
|
||||
ticker.ProcessTicker(k.GetName(), x, tp, assetType)
|
||||
}
|
||||
return ticker.GetTicker(k.GetName(), p)
|
||||
return ticker.GetTicker(k.GetName(), p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (k *Kraken) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(k.GetName(), p)
|
||||
func (k *Kraken) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(k.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return k.UpdateTicker(p)
|
||||
return k.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -102,9 +102,8 @@ func (k *Kraken) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase,
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: orderbookNew.Asks[x].Amount, Price: orderbookNew.Asks[x].Price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(k.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(k.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -46,6 +47,7 @@ func (l *LakeBTC) SetDefaults() {
|
||||
l.RequestCurrencyPairFormat.Uppercase = true
|
||||
l.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
l.ConfigCurrencyPairFormat.Uppercase = true
|
||||
l.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (l *LakeBTC) Setup(exch config.ExchangeConfig) {
|
||||
@@ -65,6 +67,10 @@ func (l *LakeBTC) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = l.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,34 +25,32 @@ func (l *LakeBTC) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (l *LakeBTC) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
func (l *LakeBTC) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tick, err := l.GetTicker()
|
||||
if err != nil {
|
||||
return ticker.TickerPrice{}, err
|
||||
return ticker.Price{}, err
|
||||
}
|
||||
|
||||
result, ok := tick[p.Pair().String()]
|
||||
if !ok {
|
||||
return ticker.TickerPrice{}, err
|
||||
for _, x := range l.GetEnabledCurrencies() {
|
||||
currency := exchange.FormatExchangeCurrency(l.Name, x).String()
|
||||
var tickerPrice ticker.Price
|
||||
tickerPrice.Pair = x
|
||||
tickerPrice.Ask = tick[currency].Ask
|
||||
tickerPrice.Bid = tick[currency].Bid
|
||||
tickerPrice.Volume = tick[currency].Volume
|
||||
tickerPrice.High = tick[currency].High
|
||||
tickerPrice.Low = tick[currency].Low
|
||||
tickerPrice.Last = tick[currency].Last
|
||||
ticker.ProcessTicker(l.GetName(), x, tickerPrice, assetType)
|
||||
}
|
||||
|
||||
var tickerPrice ticker.TickerPrice
|
||||
tickerPrice.Pair = p
|
||||
tickerPrice.Ask = result.Ask
|
||||
tickerPrice.Bid = result.Bid
|
||||
tickerPrice.Volume = result.Volume
|
||||
tickerPrice.High = result.High
|
||||
tickerPrice.Low = result.Low
|
||||
tickerPrice.Last = result.Last
|
||||
ticker.ProcessTicker(l.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
return ticker.GetTicker(l.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (l *LakeBTC) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(l.GetName(), p)
|
||||
func (l *LakeBTC) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(l.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return l.UpdateTicker(p)
|
||||
return l.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -82,9 +80,8 @@ func (l *LakeBTC) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase,
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: orderbookNew.Asks[x].Amount, Price: orderbookNew.Asks[x].Price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(l.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(l.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -51,6 +52,7 @@ func (l *Liqui) SetDefaults() {
|
||||
l.RequestCurrencyPairFormat.Separator = "-"
|
||||
l.ConfigCurrencyPairFormat.Delimiter = "_"
|
||||
l.ConfigCurrencyPairFormat.Uppercase = true
|
||||
l.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (l *Liqui) Setup(exch config.ExchangeConfig) {
|
||||
@@ -70,6 +72,10 @@ func (l *Liqui) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = l.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ func (l *Liqui) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (l *Liqui) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (l *Liqui) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
pairsString, err := exchange.GetAndFormatExchangeCurrencies(l.Name,
|
||||
l.GetEnabledCurrencies())
|
||||
if err != nil {
|
||||
@@ -49,34 +49,34 @@ func (l *Liqui) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
return tickerPrice, err
|
||||
}
|
||||
|
||||
for x, y := range result {
|
||||
var tp ticker.TickerPrice
|
||||
currency := pair.NewCurrencyPairDelimiter(common.StringToUpper(x), "_")
|
||||
tp.Pair = currency
|
||||
tp.Last = y.Last
|
||||
tp.Ask = y.Sell
|
||||
tp.Bid = y.Buy
|
||||
tp.Last = y.Last
|
||||
tp.Low = y.Low
|
||||
tp.Volume = y.Vol_cur
|
||||
ticker.ProcessTicker(l.GetName(), currency, tp)
|
||||
for _, x := range l.GetEnabledCurrencies() {
|
||||
currency := exchange.FormatExchangeCurrency(l.Name, x).String()
|
||||
var tp ticker.Price
|
||||
tp.Pair = x
|
||||
tp.Last = result[currency].Last
|
||||
tp.Ask = result[currency].Sell
|
||||
tp.Bid = result[currency].Buy
|
||||
tp.Last = result[currency].Last
|
||||
tp.Low = result[currency].Low
|
||||
tp.Volume = result[currency].Vol_cur
|
||||
ticker.ProcessTicker(l.Name, x, tp, assetType)
|
||||
}
|
||||
|
||||
return ticker.GetTicker(l.GetName(), p)
|
||||
return ticker.GetTicker(l.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (l *Liqui) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(l.GetName(), p)
|
||||
func (l *Liqui) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(l.Name, p, assetType)
|
||||
if err != nil {
|
||||
return l.UpdateTicker(p)
|
||||
return l.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns orderbook base on the currency pair
|
||||
func (l *Liqui) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
|
||||
ob, err := orderbook.GetOrderbook(l.GetName(), p)
|
||||
ob, err := orderbook.GetOrderbook(l.Name, p)
|
||||
if err == nil {
|
||||
return l.UpdateOrderbook(p)
|
||||
}
|
||||
@@ -101,9 +101,8 @@ func (l *Liqui) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, e
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(l.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
orderbook.ProcessOrderbook(l.Name, p, orderBook)
|
||||
return orderbook.GetOrderbook(l.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -42,6 +43,7 @@ func (l *LocalBitcoins) SetDefaults() {
|
||||
l.RequestCurrencyPairFormat.Uppercase = true
|
||||
l.ConfigCurrencyPairFormat.Delimiter = ""
|
||||
l.ConfigCurrencyPairFormat.Uppercase = true
|
||||
l.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (l *LocalBitcoins) Setup(exch config.ExchangeConfig) {
|
||||
@@ -61,6 +63,10 @@ func (l *LocalBitcoins) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = l.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ package localbitcoins
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
@@ -25,30 +23,30 @@ func (l *LocalBitcoins) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (l *LocalBitcoins) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (l *LocalBitcoins) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := l.GetTicker()
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
|
||||
for key, value := range tick {
|
||||
currency := pair.NewCurrencyPair("BTC", common.StringToUpper(key))
|
||||
var tp ticker.TickerPrice
|
||||
tp.Pair = currency
|
||||
tp.Last = value.Rates.Last
|
||||
tp.Volume = value.VolumeBTC
|
||||
ticker.ProcessTicker(l.GetName(), currency, tp)
|
||||
for _, x := range l.GetEnabledCurrencies() {
|
||||
currency := x.SecondCurrency.String()
|
||||
var tp ticker.Price
|
||||
tp.Pair = x
|
||||
tp.Last = tick[currency].Rates.Last
|
||||
tp.Volume = tick[currency].VolumeBTC
|
||||
ticker.ProcessTicker(l.GetName(), x, tp, assetType)
|
||||
}
|
||||
|
||||
return ticker.GetTicker(l.GetName(), p)
|
||||
return ticker.GetTicker(l.GetName(), p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (l *LocalBitcoins) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(l.GetName(), p)
|
||||
func (l *LocalBitcoins) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(l.GetName(), p, assetType)
|
||||
if err == nil {
|
||||
return l.UpdateTicker(p)
|
||||
return l.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -77,12 +75,11 @@ func (l *LocalBitcoins) UpdateOrderbook(p pair.CurrencyPair) (orderbook.Orderboo
|
||||
|
||||
for x := range orderbookNew.Asks {
|
||||
data := orderbookNew.Asks[x]
|
||||
orderBook.Bids = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Amount, Price: data.Price})
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Amount, Price: data.Price})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(l.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(l.Name, p)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -93,8 +94,10 @@ func (o *OKCoin) SetDefaults() {
|
||||
o.Websocket = false
|
||||
o.RESTPollingDelay = 10
|
||||
o.FuturesValues = []string{"this_week", "next_week", "quarter"}
|
||||
o.AssetTypes = []string{ticker.Spot}
|
||||
|
||||
if !okcoinDefaultsSet {
|
||||
o.AssetTypes = append(o.AssetTypes, o.FuturesValues...)
|
||||
o.APIUrl = OKCOIN_API_URL
|
||||
o.Name = "OKCOIN International"
|
||||
o.WebsocketURL = OKCOIN_WEBSOCKET_URL
|
||||
@@ -125,6 +128,10 @@ func (o *OKCoin) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = o.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,11 @@ package okcoin
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
@@ -28,53 +26,49 @@ func (o *OKCoin) Run() {
|
||||
if o.Websocket {
|
||||
go o.WebsocketClient()
|
||||
}
|
||||
|
||||
for o.Enabled {
|
||||
pairs := o.GetEnabledCurrencies()
|
||||
for x := range pairs {
|
||||
curr := pairs[x]
|
||||
if o.APIUrl == OKCOIN_API_URL {
|
||||
for _, y := range o.FuturesValues {
|
||||
futuresValue := y
|
||||
go func() {
|
||||
ticker, err := o.GetFuturesTicker(exchange.FormatExchangeCurrency(o.Name, curr).String(), futuresValue)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
log.Printf("OKCoin Intl Futures %s (%s): Last %f High %f Low %f Volume %f\n", exchange.FormatCurrency(curr).String(), futuresValue, ticker.Last, ticker.High, ticker.Low, ticker.Vol)
|
||||
stats.AddExchangeInfo(o.GetName(), curr.GetFirstCurrency().String(), curr.GetSecondCurrency().String(), ticker.Last, ticker.Vol)
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second * o.RESTPollingDelay)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (o *OKCoin) UpdateTicker(currency pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
var tickerPrice ticker.TickerPrice
|
||||
tick, err := o.GetTicker(exchange.FormatExchangeCurrency(o.Name, currency).String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
func (o *OKCoin) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
currency := exchange.FormatExchangeCurrency(o.Name, p).String()
|
||||
var tickerPrice ticker.Price
|
||||
|
||||
if assetType != ticker.Spot && o.APIUrl == OKCOIN_API_URL {
|
||||
tick, err := o.GetFuturesTicker(currency, assetType)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
tickerPrice.Pair = p
|
||||
tickerPrice.Ask = tick.Sell
|
||||
tickerPrice.Bid = tick.Buy
|
||||
tickerPrice.Low = tick.Low
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Vol
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(o.GetName(), p, tickerPrice, assetType)
|
||||
} else {
|
||||
tick, err := o.GetTicker(currency)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
tickerPrice.Pair = p
|
||||
tickerPrice.Ask = tick.Sell
|
||||
tickerPrice.Bid = tick.Buy
|
||||
tickerPrice.Low = tick.Low
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Vol
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(o.GetName(), p, tickerPrice, ticker.Spot)
|
||||
|
||||
}
|
||||
tickerPrice.Pair = currency
|
||||
tickerPrice.Ask = tick.Sell
|
||||
tickerPrice.Bid = tick.Buy
|
||||
tickerPrice.Low = tick.Low
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Vol
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(o.GetName(), currency, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
return ticker.GetTicker(o.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (o *OKCoin) GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(o.GetName(), currency)
|
||||
func (o *OKCoin) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(o.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return o.UpdateTicker(currency)
|
||||
return o.UpdateTicker(p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -106,9 +100,8 @@ func (o *OKCoin) UpdateOrderbook(currency pair.CurrencyPair) (orderbook.Orderboo
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]})
|
||||
}
|
||||
|
||||
orderBook.Pair = currency
|
||||
orderbook.ProcessOrderbook(o.GetName(), currency, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(o.Name, currency)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -122,6 +122,7 @@ func CreateNewOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew O
|
||||
|
||||
func ProcessOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew OrderbookBase) {
|
||||
orderbookNew.CurrencyPair = p.Pair().String()
|
||||
orderbookNew.LastUpdated = time.Now()
|
||||
if len(Orderbooks) == 0 {
|
||||
CreateNewOrderbook(exchangeName, p, orderbookNew)
|
||||
return
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -62,6 +63,7 @@ func (p *Poloniex) SetDefaults() {
|
||||
p.RequestCurrencyPairFormat.Uppercase = true
|
||||
p.ConfigCurrencyPairFormat.Delimiter = "_"
|
||||
p.ConfigCurrencyPairFormat.Uppercase = true
|
||||
p.AssetTypes = []string{ticker.Spot}
|
||||
}
|
||||
|
||||
func (p *Poloniex) Setup(exch config.ExchangeConfig) {
|
||||
@@ -81,6 +83,10 @@ func (p *Poloniex) Setup(exch config.ExchangeConfig) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = p.SetAssetTypes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,14 +139,20 @@ func (p *Poloniex) GetOrderbook(currencyPair string, depth int) (PoloniexOrderbo
|
||||
ob := PoloniexOrderbook{}
|
||||
for x := range resp.Asks {
|
||||
data := resp.Asks[x]
|
||||
price, _ := strconv.ParseFloat(data[0].(string), 64)
|
||||
price, err := strconv.ParseFloat(data[0].(string), 64)
|
||||
if err != nil {
|
||||
return ob, err
|
||||
}
|
||||
amount := data[1].(float64)
|
||||
ob.Asks = append(ob.Asks, PoloniexOrderbookItem{Price: price, Amount: amount})
|
||||
}
|
||||
|
||||
for x := range resp.Bids {
|
||||
data := resp.Bids[x]
|
||||
price, _ := strconv.ParseFloat(data[0].(string), 64)
|
||||
price, err := strconv.ParseFloat(data[0].(string), 64)
|
||||
if err != nil {
|
||||
return ob, err
|
||||
}
|
||||
amount := data[1].(float64)
|
||||
ob.Bids = append(ob.Bids, PoloniexOrderbookItem{Price: price, Amount: amount})
|
||||
}
|
||||
|
||||
@@ -29,30 +29,33 @@ func (p *Poloniex) Run() {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (p *Poloniex) UpdateTicker(currencyPair pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
currency := exchange.FormatCurrency(currencyPair).String()
|
||||
var tickerPrice ticker.TickerPrice
|
||||
func (p *Poloniex) UpdateTicker(currencyPair pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
tick, err := p.GetTicker()
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
|
||||
tickerPrice.Pair = currencyPair
|
||||
tickerPrice.Ask = tick[currency].Last
|
||||
tickerPrice.Bid = tick[currency].HighestBid
|
||||
tickerPrice.High = tick[currency].HighestBid
|
||||
tickerPrice.Last = tick[currency].Last
|
||||
tickerPrice.Low = tick[currency].LowestAsk
|
||||
tickerPrice.Volume = tick[currency].BaseVolume
|
||||
ticker.ProcessTicker(p.GetName(), currencyPair, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
for _, x := range p.GetEnabledCurrencies() {
|
||||
var tp ticker.Price
|
||||
curr := exchange.FormatExchangeCurrency(p.GetName(), x).String()
|
||||
tp.Pair = x
|
||||
tp.Ask = tick[curr].LowestAsk
|
||||
tp.Bid = tick[curr].HighestBid
|
||||
tp.High = tick[curr].High24Hr
|
||||
tp.Last = tick[curr].Last
|
||||
tp.Low = tick[curr].Low24Hr
|
||||
tp.Volume = tick[curr].BaseVolume
|
||||
ticker.ProcessTicker(p.GetName(), x, tp, assetType)
|
||||
}
|
||||
return ticker.GetTicker(p.Name, currencyPair, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (p *Poloniex) GetTickerPrice(currencyPair pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(p.GetName(), currencyPair)
|
||||
func (p *Poloniex) GetTickerPrice(currencyPair pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(p.GetName(), currencyPair, assetType)
|
||||
if err != nil {
|
||||
return p.UpdateTicker(currencyPair)
|
||||
return p.UpdateTicker(currencyPair, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
@@ -69,7 +72,7 @@ func (p *Poloniex) GetOrderbookEx(currencyPair pair.CurrencyPair) (orderbook.Ord
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (p *Poloniex) UpdateOrderbook(currencyPair pair.CurrencyPair) (orderbook.OrderbookBase, error) {
|
||||
var orderBook orderbook.OrderbookBase
|
||||
orderbookNew, err := p.GetOrderbook(exchange.FormatCurrency(currencyPair).String(), 1000)
|
||||
orderbookNew, err := p.GetOrderbook(exchange.FormatExchangeCurrency(p.GetName(), currencyPair).String(), 1000)
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
@@ -83,9 +86,9 @@ func (p *Poloniex) UpdateOrderbook(currencyPair pair.CurrencyPair) (orderbook.Or
|
||||
data := orderbookNew.Asks[x]
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Amount, Price: data.Price})
|
||||
}
|
||||
orderBook.Pair = currencyPair
|
||||
|
||||
orderbook.ProcessOrderbook(p.GetName(), currencyPair, orderBook)
|
||||
return orderBook, nil
|
||||
return orderbook.GetOrderbook(p.Name, currencyPair)
|
||||
}
|
||||
|
||||
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
@@ -8,15 +8,22 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
)
|
||||
|
||||
var (
|
||||
// Const values for the ticker package
|
||||
const (
|
||||
ErrTickerForExchangeNotFound = "Ticker for exchange does not exist."
|
||||
ErrPrimaryCurrencyNotFound = "Error primary currency for ticker not found."
|
||||
ErrSecondaryCurrencyNotFound = "Error secondary currency for ticker not found."
|
||||
|
||||
Spot = "SPOT"
|
||||
)
|
||||
|
||||
// Vars for the ticker package
|
||||
var (
|
||||
Tickers []Ticker
|
||||
)
|
||||
|
||||
type TickerPrice struct {
|
||||
// Price struct stores the currency pair and pricing information
|
||||
type Price struct {
|
||||
Pair pair.CurrencyPair `json:"Pair"`
|
||||
CurrencyPair string `json:"CurrencyPair"`
|
||||
Last float64 `json:"Last"`
|
||||
@@ -28,50 +35,55 @@ type TickerPrice struct {
|
||||
PriceATH float64 `json:"PriceATH"`
|
||||
}
|
||||
|
||||
// Ticker struct holds the ticker information for a currency pair and type
|
||||
type Ticker struct {
|
||||
Price map[pair.CurrencyItem]map[pair.CurrencyItem]TickerPrice
|
||||
Price map[pair.CurrencyItem]map[pair.CurrencyItem]map[string]Price
|
||||
ExchangeName string
|
||||
}
|
||||
|
||||
func (t *Ticker) PriceToString(p pair.CurrencyPair, priceType string) string {
|
||||
// PriceToString returns the string version of a stored price field
|
||||
func (t *Ticker) PriceToString(p pair.CurrencyPair, priceType, tickerType string) string {
|
||||
priceType = common.StringToLower(priceType)
|
||||
|
||||
switch priceType {
|
||||
case "last":
|
||||
return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Last, 'f', -1, 64)
|
||||
return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Last, 'f', -1, 64)
|
||||
case "high":
|
||||
return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].High, 'f', -1, 64)
|
||||
return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].High, 'f', -1, 64)
|
||||
case "low":
|
||||
return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Low, 'f', -1, 64)
|
||||
return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Low, 'f', -1, 64)
|
||||
case "bid":
|
||||
return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Bid, 'f', -1, 64)
|
||||
return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Bid, 'f', -1, 64)
|
||||
case "ask":
|
||||
return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Ask, 'f', -1, 64)
|
||||
return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Ask, 'f', -1, 64)
|
||||
case "volume":
|
||||
return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Volume, 'f', -1, 64)
|
||||
return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Volume, 'f', -1, 64)
|
||||
case "ath":
|
||||
return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].PriceATH, 'f', -1, 64)
|
||||
return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].PriceATH, 'f', -1, 64)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func GetTicker(exchange string, p pair.CurrencyPair) (TickerPrice, error) {
|
||||
// GetTicker checks and returns a requested ticker if it exists
|
||||
func GetTicker(exchange string, p pair.CurrencyPair, tickerType string) (Price, error) {
|
||||
ticker, err := GetTickerByExchange(exchange)
|
||||
if err != nil {
|
||||
return TickerPrice{}, err
|
||||
return Price{}, err
|
||||
}
|
||||
|
||||
if !FirstCurrencyExists(exchange, p.GetFirstCurrency()) {
|
||||
return TickerPrice{}, errors.New(ErrPrimaryCurrencyNotFound)
|
||||
if !FirstCurrencyExists(exchange, p.FirstCurrency) {
|
||||
return Price{}, errors.New(ErrPrimaryCurrencyNotFound)
|
||||
}
|
||||
|
||||
if !SecondCurrencyExists(exchange, p) {
|
||||
return TickerPrice{}, errors.New(ErrSecondaryCurrencyNotFound)
|
||||
return Price{}, errors.New(ErrSecondaryCurrencyNotFound)
|
||||
}
|
||||
|
||||
return ticker.Price[p.GetFirstCurrency()][p.GetSecondCurrency()], nil
|
||||
return ticker.Price[p.FirstCurrency][p.SecondCurrency][tickerType], nil
|
||||
}
|
||||
|
||||
// GetTickerByExchange returns an exchange Ticker
|
||||
func GetTickerByExchange(exchange string) (*Ticker, error) {
|
||||
for _, y := range Tickers {
|
||||
if y.ExchangeName == exchange {
|
||||
@@ -81,6 +93,8 @@ func GetTickerByExchange(exchange string) (*Ticker, error) {
|
||||
return nil, errors.New(ErrTickerForExchangeNotFound)
|
||||
}
|
||||
|
||||
// FirstCurrencyExists checks to see if the first currency of the Price map
|
||||
// exists
|
||||
func FirstCurrencyExists(exchange string, currency pair.CurrencyItem) bool {
|
||||
for _, y := range Tickers {
|
||||
if y.ExchangeName == exchange {
|
||||
@@ -92,6 +106,8 @@ func FirstCurrencyExists(exchange string, currency pair.CurrencyItem) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// SecondCurrencyExists checks to see if the second currency of the Price map
|
||||
// exists
|
||||
func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool {
|
||||
for _, y := range Tickers {
|
||||
if y.ExchangeName == exchange {
|
||||
@@ -105,40 +121,49 @@ func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func CreateNewTicker(exchangeName string, p pair.CurrencyPair, tickerNew TickerPrice) Ticker {
|
||||
// CreateNewTicker creates a new Ticker
|
||||
func CreateNewTicker(exchangeName string, p pair.CurrencyPair, tickerNew Price, tickerType string) Ticker {
|
||||
ticker := Ticker{}
|
||||
ticker.ExchangeName = exchangeName
|
||||
ticker.Price = make(map[pair.CurrencyItem]map[pair.CurrencyItem]TickerPrice)
|
||||
sMap := make(map[pair.CurrencyItem]TickerPrice)
|
||||
sMap[p.GetSecondCurrency()] = tickerNew
|
||||
ticker.Price[p.GetFirstCurrency()] = sMap
|
||||
ticker.Price = make(map[pair.CurrencyItem]map[pair.CurrencyItem]map[string]Price)
|
||||
a := make(map[pair.CurrencyItem]map[string]Price)
|
||||
b := make(map[string]Price)
|
||||
b[tickerType] = tickerNew
|
||||
a[p.SecondCurrency] = b
|
||||
ticker.Price[p.FirstCurrency] = a
|
||||
Tickers = append(Tickers, ticker)
|
||||
return ticker
|
||||
}
|
||||
|
||||
func ProcessTicker(exchangeName string, p pair.CurrencyPair, tickerNew TickerPrice) {
|
||||
// ProcessTicker processes incoming tickers, creating or updating the Tickers
|
||||
// list
|
||||
func ProcessTicker(exchangeName string, p pair.CurrencyPair, tickerNew Price, tickerType string) {
|
||||
tickerNew.CurrencyPair = p.Pair().String()
|
||||
if len(Tickers) == 0 {
|
||||
CreateNewTicker(exchangeName, p, tickerNew)
|
||||
//issue - not appending
|
||||
CreateNewTicker(exchangeName, p, tickerNew, tickerType)
|
||||
return
|
||||
} else {
|
||||
ticker, err := GetTickerByExchange(exchangeName)
|
||||
if err != nil {
|
||||
CreateNewTicker(exchangeName, p, tickerNew)
|
||||
}
|
||||
|
||||
ticker, err := GetTickerByExchange(exchangeName)
|
||||
if err != nil {
|
||||
CreateNewTicker(exchangeName, p, tickerNew, tickerType)
|
||||
return
|
||||
}
|
||||
|
||||
if FirstCurrencyExists(exchangeName, p.FirstCurrency) {
|
||||
if !SecondCurrencyExists(exchangeName, p) {
|
||||
a := ticker.Price[p.FirstCurrency]
|
||||
b := make(map[string]Price)
|
||||
b[tickerType] = tickerNew
|
||||
a[p.SecondCurrency] = b
|
||||
ticker.Price[p.FirstCurrency] = a
|
||||
return
|
||||
}
|
||||
|
||||
if FirstCurrencyExists(exchangeName, p.GetFirstCurrency()) {
|
||||
if !SecondCurrencyExists(exchangeName, p) {
|
||||
second := ticker.Price[p.GetFirstCurrency()]
|
||||
second[p.GetSecondCurrency()] = tickerNew
|
||||
ticker.Price[p.GetFirstCurrency()] = second
|
||||
return
|
||||
}
|
||||
}
|
||||
sMap := make(map[pair.CurrencyItem]TickerPrice)
|
||||
sMap[p.GetSecondCurrency()] = tickerNew
|
||||
ticker.Price[p.GetFirstCurrency()] = sMap
|
||||
}
|
||||
|
||||
a := make(map[pair.CurrencyItem]map[string]Price)
|
||||
b := make(map[string]Price)
|
||||
b[tickerType] = tickerNew
|
||||
a[p.SecondCurrency] = b
|
||||
ticker.Price[p.FirstCurrency] = a
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func TestPriceToString(t *testing.T) {
|
||||
newPair := pair.NewCurrencyPair("BTC", "USD")
|
||||
priceStruct := TickerPrice{
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
CurrencyPair: newPair.Pair().String(),
|
||||
Last: 1200,
|
||||
@@ -21,37 +21,37 @@ func TestPriceToString(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
newTicker := CreateNewTicker("ANX", newPair, priceStruct)
|
||||
newTicker := CreateNewTicker("ANX", newPair, priceStruct, Spot)
|
||||
|
||||
if newTicker.PriceToString(newPair, "last") != "1200" {
|
||||
if newTicker.PriceToString(newPair, "last", Spot) != "1200" {
|
||||
t.Error("Test Failed - ticker PriceToString last value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "high") != "1298" {
|
||||
if newTicker.PriceToString(newPair, "high", Spot) != "1298" {
|
||||
t.Error("Test Failed - ticker PriceToString high value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "low") != "1148" {
|
||||
if newTicker.PriceToString(newPair, "low", Spot) != "1148" {
|
||||
t.Error("Test Failed - ticker PriceToString low value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "bid") != "1195" {
|
||||
if newTicker.PriceToString(newPair, "bid", Spot) != "1195" {
|
||||
t.Error("Test Failed - ticker PriceToString bid value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "ask") != "1220" {
|
||||
if newTicker.PriceToString(newPair, "ask", Spot) != "1220" {
|
||||
t.Error("Test Failed - ticker PriceToString ask value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "volume") != "5" {
|
||||
if newTicker.PriceToString(newPair, "volume", Spot) != "5" {
|
||||
t.Error("Test Failed - ticker PriceToString volume value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "ath") != "1337" {
|
||||
if newTicker.PriceToString(newPair, "ath", Spot) != "1337" {
|
||||
t.Error("Test Failed - ticker PriceToString ath value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "obtuse") != "" {
|
||||
if newTicker.PriceToString(newPair, "obtuse", Spot) != "" {
|
||||
t.Error("Test Failed - ticker PriceToString obtuse value is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
newPair := pair.NewCurrencyPair("BTC", "USD")
|
||||
priceStruct := TickerPrice{
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
CurrencyPair: newPair.Pair().String(),
|
||||
Last: 1200,
|
||||
@@ -63,21 +63,30 @@ func TestGetTicker(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
bitfinexTicker := CreateNewTicker("bitfinex", newPair, priceStruct)
|
||||
Tickers = append(Tickers, bitfinexTicker)
|
||||
|
||||
tickerPrice, err := GetTicker("bitfinex", newPair)
|
||||
ProcessTicker("bitfinex", newPair, priceStruct, Spot)
|
||||
tickerPrice, err := GetTicker("bitfinex", newPair, Spot)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Ticker GetTicker init error: %s", err)
|
||||
}
|
||||
if tickerPrice.CurrencyPair != "BTCUSD" {
|
||||
t.Error("Test Failed - ticker tickerPrice.CurrencyPair value is incorrect")
|
||||
}
|
||||
|
||||
priceStruct.PriceATH = 9001
|
||||
ProcessTicker("bitfinex", newPair, priceStruct, "futures_3m")
|
||||
tickerPrice, err = GetTicker("bitfinex", newPair, "futures_3m")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Ticker GetTicker init error: %s", err)
|
||||
}
|
||||
|
||||
if tickerPrice.PriceATH != 9001 {
|
||||
t.Error("Test Failed - ticker tickerPrice.PriceATH value is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTickerByExchange(t *testing.T) {
|
||||
newPair := pair.NewCurrencyPair("BTC", "USD")
|
||||
priceStruct := TickerPrice{
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
CurrencyPair: newPair.Pair().String(),
|
||||
Last: 1200,
|
||||
@@ -89,7 +98,7 @@ func TestGetTickerByExchange(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
anxTicker := CreateNewTicker("ANX", newPair, priceStruct)
|
||||
anxTicker := CreateNewTicker("ANX", newPair, priceStruct, Spot)
|
||||
Tickers = append(Tickers, anxTicker)
|
||||
|
||||
tickerPtr, err := GetTickerByExchange("ANX")
|
||||
@@ -103,7 +112,7 @@ func TestGetTickerByExchange(t *testing.T) {
|
||||
|
||||
func TestFirstCurrencyExists(t *testing.T) {
|
||||
newPair := pair.NewCurrencyPair("BTC", "USD")
|
||||
priceStruct := TickerPrice{
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
CurrencyPair: newPair.Pair().String(),
|
||||
Last: 1200,
|
||||
@@ -115,7 +124,7 @@ func TestFirstCurrencyExists(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
alphaTicker := CreateNewTicker("alphapoint", newPair, priceStruct)
|
||||
alphaTicker := CreateNewTicker("alphapoint", newPair, priceStruct, Spot)
|
||||
Tickers = append(Tickers, alphaTicker)
|
||||
|
||||
if !FirstCurrencyExists("alphapoint", "BTC") {
|
||||
@@ -130,7 +139,7 @@ func TestSecondCurrencyExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
newPair := pair.NewCurrencyPair("BTC", "USD")
|
||||
priceStruct := TickerPrice{
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
CurrencyPair: newPair.Pair().String(),
|
||||
Last: 1200,
|
||||
@@ -142,7 +151,7 @@ func TestSecondCurrencyExists(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
bitstampTicker := CreateNewTicker("bitstamp", newPair, priceStruct)
|
||||
bitstampTicker := CreateNewTicker("bitstamp", newPair, priceStruct, "SPOT")
|
||||
Tickers = append(Tickers, bitstampTicker)
|
||||
|
||||
if !SecondCurrencyExists("bitstamp", newPair) {
|
||||
@@ -157,7 +166,7 @@ func TestSecondCurrencyExists(t *testing.T) {
|
||||
|
||||
func TestCreateNewTicker(t *testing.T) {
|
||||
newPair := pair.NewCurrencyPair("BTC", "USD")
|
||||
priceStruct := TickerPrice{
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
CurrencyPair: newPair.Pair().String(),
|
||||
Last: 1200,
|
||||
@@ -169,7 +178,7 @@ func TestCreateNewTicker(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
newTicker := CreateNewTicker("ANX", newPair, priceStruct)
|
||||
newTicker := CreateNewTicker("ANX", newPair, priceStruct, Spot)
|
||||
|
||||
if reflect.ValueOf(newTicker).NumField() != 2 {
|
||||
t.Error("Test Failed - ticker CreateNewTicker struct change/or updated")
|
||||
@@ -181,38 +190,38 @@ func TestCreateNewTicker(t *testing.T) {
|
||||
t.Error("Test Failed - ticker CreateNewTicker.ExchangeName value is not ANX")
|
||||
}
|
||||
|
||||
if newTicker.Price["BTC"]["USD"].Pair.Pair().String() != "BTCUSD" {
|
||||
if newTicker.Price["BTC"]["USD"][Spot].Pair.Pair().String() != "BTCUSD" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Pair.Pair().String() value is not expected 'BTCUSD'")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Ask).String() != "float64" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Ask).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Ask value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Bid).String() != "float64" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Bid).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Bid value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].CurrencyPair).String() != "string" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].CurrencyPair).String() != "string" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].CurrencyPair value is not a string")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].High).String() != "float64" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].High).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].High value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Last).String() != "float64" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Last).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Last value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Low).String() != "float64" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Low).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Low value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].PriceATH).String() != "float64" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].PriceATH).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].PriceATH value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Volume).String() != "float64" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Volume).String() != "float64" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Volume value is not a float64")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessTicker(t *testing.T) { //non-appending function to tickers
|
||||
newPair := pair.NewCurrencyPair("BTC", "USD")
|
||||
priceStruct := TickerPrice{
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
CurrencyPair: newPair.Pair().String(),
|
||||
Last: 1200,
|
||||
@@ -224,5 +233,5 @@ func TestProcessTicker(t *testing.T) { //non-appending function to tickers
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
ProcessTicker("btcc", newPair, priceStruct)
|
||||
ProcessTicker("btcc", newPair, priceStruct, Spot)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user