engine: Ticker REST/Websocket improvements (#345)

* Adds extra properties to Websocket ticker. Adds new properties to binance and bitfinex, but doesn't test anything yet. Changes names and properties of ticker package to make more streamlined

* Adds support for coinbasepro, coinut, gateio, gitbtc, huobi, hadax, kraken, okex, okcoin. Adds quoteVolume

* Adds poloniex and ZB ticker datas

* Updates ANX, Binance, Bitfinex, Bistamp, Bittrex, BTCMarkets, BTSE, CoinbasePRo, Coinut, Exmo tickers. It looks like a whole bunch of stuff is wrong in how tickers are done though :/

* Updates tickers everywhere. Will revert batch ones

* Re-Preseves ticker batching

* Minor fixes to ticks and removal of comment

* Logging errors instead of returning mid loop. Adds bitfinex batch ticker processing. Fixes unrelated okgroup wallet bug

* Removes bad code I wrote preventing function from running if feature not enabled

* Fixes issue with bitmex and rebase issues

* Fixes bitmex iterator error, splits hitbtc ticker requests

* Fixes okgroup currency pair formatting. Updates okgroup to use ticker batching. Fixes okgroup ticker issues due to assetTypes. Fixes okgroup ws pinging. Fixes Kraken's currency pairs formatting. Reverts ANXs auto parsing back to strings because ANX json makes me cry. Minor property improvements for coinut, coinbasepro, btse, exmo. Protects wshandler manageSubscriptions() from running and returning an error when feature not supported

* Updates config example to reflect the underscore dash situation

* Fixes a config delimiter oopsie. Simplifies ANX wrapper ticker parsing. Fixes bittrex date parsing. Simplifies okcoin switch to if.

* Fixes super fun issue where kraken has updated their currency pair format and must add new delimiter support. Fixes super fun issue where okex has updated their currency pair format and must add new delimiter support. Fixes super fun issue where okcoin has updated their currency pair format and must add new delimiter support.

* Updates config example for kraken

* Adds lbank batch ticker support. Adds details to errors

* Updates FetchTradablePairs to use the config delimiter to prevent issues if the delimiter ever changes

* Fixes nil reference bug. Uses NAme not GetNAme

* Fixes hardcoded delimiter in Binance.  Expands bitfinex websocket ticker fields. Updates Bitstamp rate limits. Expands BTSE ticker data fields. Fixes typo in coibasepro. Expands Coinut ticker data. Renames currency to curr as it conflicts with package name. Expands GateIO websocket ticker data. Fixes ticker data implementation for huobi and huobi hadax. Reverts ticker map to string instead of assetType. Fixes real stupid bug I introduced which preveted subscriptions from running :glitch_crab: Adds Price ATH to ws ticker type. Adds quotevolume to yobit ticker. Uses delimiter in ZB rather than hardcoded field.

* Fixes bug in syncer where if the websocket is already connected, then UsingWebsocket is not set

* Updates broken tests

* Simplifies poloniex frozen check

* Updates configtest.json with new delimiters

* Renames shorthand properties of structs. Fixes delimiter referencing

* Fixes some bugs and nits around variable declaration, currency pairs and config upscaling

* Adds config upgrade path for okcoin and okex. Reverts configtest.json.

* Fixes okex futures currency formatting by no longer using global currency format. updates Run code to adapt. Removes BTSE value

* Adds ":" as a delimiter for when a delimiter only shows up SOMETIMES

* Adds support for optional delimiter
This commit is contained in:
Scott
2019-09-02 18:05:09 +10:00
committed by Adrian Gallagher
parent 833a866506
commit 74d5bca03b
86 changed files with 1575 additions and 1042 deletions

View File

@@ -74,48 +74,20 @@ func (g *Gemini) GetSymbols() ([]string, error) {
}
// GetTicker returns information about recent trading activity for the symbol
func (g *Gemini) GetTicker(currencyPair string) (Ticker, error) {
type TickerResponse struct {
Ask float64 `json:"ask,string"`
Bid float64 `json:"bid,string"`
Last float64 `json:"last,string"`
Volume map[string]interface{}
Message string `json:"message"`
}
ticker := Ticker{}
resp := TickerResponse{}
path := fmt.Sprintf("%s/v%s/%s/%s", g.API.Endpoints.URL, geminiAPIVersion, geminiTicker, currencyPair)
err := g.SendHTTPRequest(path, &resp)
func (g *Gemini) GetTicker(currencyPair string) (TickerV2, error) {
ticker := TickerV2{}
path := fmt.Sprintf("%s/v2/ticker/%s", g.API.Endpoints.URL, currencyPair)
err := g.SendHTTPRequest(path, &ticker)
if err != nil {
return ticker, err
}
if resp.Message != "" {
return ticker, errors.New(resp.Message)
if ticker.Result == "error" {
return ticker, fmt.Errorf("%v %v %v",
g.Name,
ticker.Reason,
ticker.Message)
}
ticker.Ask = resp.Ask
ticker.Bid = resp.Bid
ticker.Last = resp.Last
ticker.Volume.Currency, _ = strconv.ParseFloat(resp.Volume[currencyPair[0:3]].(string), 64)
if strings.Contains(currencyPair, "USD") {
ticker.Volume.USD, _ = strconv.ParseFloat(resp.Volume["USD"].(string), 64)
} else {
if resp.Volume["ETH"] != nil {
ticker.Volume.ETH, _ = strconv.ParseFloat(resp.Volume["ETH"].(string), 64)
}
if resp.Volume["BTC"] != nil {
ticker.Volume.BTC, _ = strconv.ParseFloat(resp.Volume["BTC"].(string), 64)
}
}
time, _ := resp.Volume["timestamp"].(float64)
ticker.Volume.Timestamp = int64(time)
return ticker, nil
}

View File

@@ -16,6 +16,21 @@ type Ticker struct {
}
}
// TickerV2 holds returned ticker data from the exchange
type TickerV2 struct {
Ask float64 `json:"ask,string"`
Bid float64 `json:"bid,string"`
Changes []string `json:"changes"`
Close float64 `json:"close,string"`
High float64 `json:"high,string"`
Low float64 `json:"low,string"`
Open float64 `json:"open,string"`
Message string `json:"message,omitempty"`
Reason string `json:"reason,omitempty"`
Result string `json:"result,omitempty"`
Symbol currency.Pair `json:"symbol"`
}
// Orderbook contains orderbook information for both bid and ask side
type Orderbook struct {
Bids []OrderbookEntry `json:"bids"`

View File

@@ -222,12 +222,15 @@ func (g *Gemini) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pri
if err != nil {
return tickerPrice, err
}
tickerPrice.Pair = p
tickerPrice.Ask = tick.Ask
tickerPrice.Bid = tick.Bid
tickerPrice.Last = tick.Last
tickerPrice.Volume = tick.Volume.USD
tickerPrice = ticker.Price{
High: tick.High,
Low: tick.Low,
Bid: tick.Bid,
Ask: tick.Ask,
Open: tick.Open,
Close: tick.Close,
Pair: p,
}
err = ticker.ProcessTicker(g.GetName(), &tickerPrice, assetType)
if err != nil {
return tickerPrice, err