mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-19 23:16:48 +00:00
Bugfixes: Bitfinex websocket, ZB market response and portfolio (#397)
* bug fix for websocket orderbook processing * Fix more panics * fix linter issue * kick panic can down the road * temp fix for issue with a 404 returned error as chainz.cryptoid dropped eth support * Address nits and fixed orderbook updating * Fix trade data, rm'd event time from struct * fix time conversion for huobi * Actually process kline data and fix time stamps * btse time conversion fix and RM log, as it seems that the gain is reflecting transaction side. Drop ticker fetching support because there does not seem to be support on docs. And added trade fetching support. * revert huobi println * Adressed suggestion * rm unnecessary assignment * rm unnecessary check and assign * fix conversion mishap * fix currency conversion bug * update websocket logging * RM websocket type which stops conversion and copy * fix linter issue, add in unknown side type
This commit is contained in:
committed by
Adrian Gallagher
parent
467d8d91a2
commit
98a277a4c3
@@ -67,11 +67,11 @@ type OrderbookItem struct {
|
||||
|
||||
// OrderBookData is resp data from orderbook endpoint
|
||||
type OrderBookData struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
LastUpdateID int64 `json:"lastUpdateId"`
|
||||
Bids [][]string `json:"bids"`
|
||||
Asks [][]string `json:"asks"`
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
LastUpdateID int64 `json:"lastUpdateId"`
|
||||
Bids [][2]string `json:"bids"`
|
||||
Asks [][2]string `json:"asks"`
|
||||
}
|
||||
|
||||
// OrderBook actual structured data that can be used for orderbook
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
)
|
||||
@@ -62,6 +63,8 @@ func (b *Binance) WsConnect() error {
|
||||
}
|
||||
|
||||
b.WebsocketConn.URL = wsurl
|
||||
b.WebsocketConn.Verbose = b.Verbose
|
||||
|
||||
err = b.WebsocketConn.Dial(&dialer, http.Header{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Unable to connect to Websocket. Error: %s",
|
||||
@@ -131,7 +134,7 @@ func (b *Binance) WsHandleData() {
|
||||
b.Websocket.DataHandler <- wshandler.TradeData{
|
||||
CurrencyPair: currency.NewPairFromFormattedPairs(trade.Symbol, b.GetEnabledPairs(asset.Spot),
|
||||
b.GetPairFormat(asset.Spot, true)),
|
||||
Timestamp: time.Unix(0, trade.TimeStamp),
|
||||
Timestamp: time.Unix(0, trade.TimeStamp*int64(time.Millisecond)),
|
||||
Price: price,
|
||||
Amount: amount,
|
||||
Exchange: b.Name,
|
||||
@@ -149,25 +152,25 @@ func (b *Binance) WsHandleData() {
|
||||
continue
|
||||
}
|
||||
|
||||
b.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: b.Name,
|
||||
Open: t.OpenPrice,
|
||||
Close: t.ClosePrice,
|
||||
Volume: t.TotalTradedVolume,
|
||||
QuoteVolume: t.TotalTradedQuoteVolume,
|
||||
High: t.HighPrice,
|
||||
Low: t.LowPrice,
|
||||
Bid: t.BestBidPrice,
|
||||
Ask: t.BestAskPrice,
|
||||
Last: t.LastPrice,
|
||||
Timestamp: time.Unix(0, t.EventTime),
|
||||
AssetType: asset.Spot,
|
||||
b.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: b.Name,
|
||||
Open: t.OpenPrice,
|
||||
Close: t.ClosePrice,
|
||||
Volume: t.TotalTradedVolume,
|
||||
QuoteVolume: t.TotalTradedQuoteVolume,
|
||||
High: t.HighPrice,
|
||||
Low: t.LowPrice,
|
||||
Bid: t.BestBidPrice,
|
||||
Ask: t.BestAskPrice,
|
||||
Last: t.LastPrice,
|
||||
LastUpdated: time.Unix(0, t.EventTime*int64(time.Millisecond)),
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromFormattedPairs(t.Symbol, b.GetEnabledPairs(asset.Spot),
|
||||
b.GetPairFormat(asset.Spot, true)),
|
||||
}
|
||||
|
||||
continue
|
||||
case "kline":
|
||||
case "kline_1m":
|
||||
kline := KlineStream{}
|
||||
err := json.Unmarshal(multiStreamData.Data, &kline)
|
||||
if err != nil {
|
||||
@@ -178,13 +181,13 @@ func (b *Binance) WsHandleData() {
|
||||
}
|
||||
|
||||
var wsKline wshandler.KlineData
|
||||
wsKline.Timestamp = time.Unix(0, kline.EventTime)
|
||||
wsKline.Timestamp = time.Unix(0, kline.EventTime*int64(time.Millisecond))
|
||||
wsKline.Pair = currency.NewPairFromFormattedPairs(kline.Symbol, b.GetEnabledPairs(asset.Spot),
|
||||
b.GetPairFormat(asset.Spot, true))
|
||||
wsKline.AssetType = asset.Spot
|
||||
wsKline.Exchange = b.Name
|
||||
wsKline.StartTime = time.Unix(0, kline.Kline.StartTime)
|
||||
wsKline.CloseTime = time.Unix(0, kline.Kline.CloseTime)
|
||||
wsKline.StartTime = time.Unix(0, kline.Kline.StartTime*int64(time.Millisecond))
|
||||
wsKline.CloseTime = time.Unix(0, kline.Kline.CloseTime*int64(time.Millisecond))
|
||||
wsKline.Interval = kline.Kline.Interval
|
||||
wsKline.OpenPrice, _ = strconv.ParseFloat(kline.Kline.OpenPrice, 64)
|
||||
wsKline.ClosePrice, _ = strconv.ParseFloat(kline.Kline.ClosePrice, 64)
|
||||
@@ -249,7 +252,6 @@ func (b *Binance) SeedLocalCache(p currency.Pair) error {
|
||||
})
|
||||
}
|
||||
|
||||
newOrderBook.LastUpdated = time.Unix(orderbookNew.LastUpdateID, 0)
|
||||
newOrderBook.Pair = p
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.ExchangeName = b.Name
|
||||
|
||||
@@ -385,7 +385,7 @@ type WebsocketChanInfo struct {
|
||||
// WebsocketBook holds booking information
|
||||
type WebsocketBook struct {
|
||||
Price float64
|
||||
ID int
|
||||
ID int64
|
||||
Amount float64
|
||||
}
|
||||
|
||||
@@ -395,6 +395,10 @@ type WebsocketTrade struct {
|
||||
Timestamp int64
|
||||
Price float64
|
||||
Amount float64
|
||||
// Funding rate of the trade
|
||||
Rate float64
|
||||
// Funding offer period in days
|
||||
Period int64
|
||||
}
|
||||
|
||||
// WebsocketCandle candle data
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -122,6 +123,12 @@ func (b *Bitfinex) WsDataHandler() {
|
||||
}
|
||||
case "[]interface {}":
|
||||
chanData := result.([]interface{})
|
||||
if hb, ok := chanData[1].(string); ok {
|
||||
// Capturing heart beat
|
||||
if hb == "hb" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
chanID := int(chanData[0].(float64))
|
||||
chanInfo, ok := b.WebsocketSubdChannels[chanID]
|
||||
if !ok && chanID != 0 {
|
||||
@@ -135,14 +142,14 @@ func (b *Bitfinex) WsDataHandler() {
|
||||
var newOrderbook []WebsocketBook
|
||||
curr := currency.NewPairFromString(chanInfo.Pair)
|
||||
if obSnapBundle, ok := chanData[1].([]interface{}); ok {
|
||||
switch snapshot := obSnapBundle[0].(type) {
|
||||
switch id := obSnapBundle[0].(type) {
|
||||
case []interface{}:
|
||||
for i := range snapshot {
|
||||
obSnap := snapshot[i].([]interface{})
|
||||
for i := range obSnapBundle {
|
||||
data := obSnapBundle[i].([]interface{})
|
||||
newOrderbook = append(newOrderbook, WebsocketBook{
|
||||
ID: int(obSnap[0].(float64)),
|
||||
Price: obSnap[1].(float64),
|
||||
Amount: obSnap[2].(float64)})
|
||||
ID: int64(data[0].(float64)),
|
||||
Price: data[1].(float64),
|
||||
Amount: data[2].(float64)})
|
||||
}
|
||||
err := b.WsInsertSnapshot(curr,
|
||||
asset.Spot,
|
||||
@@ -153,7 +160,7 @@ func (b *Bitfinex) WsDataHandler() {
|
||||
}
|
||||
case float64:
|
||||
newOrderbook = append(newOrderbook, WebsocketBook{
|
||||
ID: int(snapshot),
|
||||
ID: int64(id),
|
||||
Price: obSnapBundle[1].(float64),
|
||||
Amount: obSnapBundle[2].(float64)})
|
||||
err := b.WsUpdateOrderbook(curr,
|
||||
@@ -205,38 +212,50 @@ func (b *Bitfinex) WsDataHandler() {
|
||||
continue
|
||||
case wsTicker:
|
||||
tickerData := chanData[1].([]interface{})
|
||||
b.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: b.Name,
|
||||
Bid: tickerData[0].(float64),
|
||||
Ask: tickerData[2].(float64),
|
||||
Last: tickerData[6].(float64),
|
||||
Volume: tickerData[7].(float64),
|
||||
High: tickerData[8].(float64),
|
||||
Low: tickerData[9].(float64),
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromString(chanInfo.Pair),
|
||||
b.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: b.Name,
|
||||
Bid: tickerData[0].(float64),
|
||||
Ask: tickerData[2].(float64),
|
||||
Last: tickerData[6].(float64),
|
||||
Volume: tickerData[7].(float64),
|
||||
High: tickerData[8].(float64),
|
||||
Low: tickerData[9].(float64),
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromString(chanInfo.Pair),
|
||||
}
|
||||
continue
|
||||
case wsTrades:
|
||||
var trades []WebsocketTrade
|
||||
switch len(chanData) {
|
||||
case 2:
|
||||
data := chanData[1].([]interface{})
|
||||
for i := range data {
|
||||
y := data[i].([]interface{})
|
||||
if _, ok := y[0].(string); ok {
|
||||
snapshot := chanData[1].([]interface{})
|
||||
for i := range snapshot {
|
||||
elem := snapshot[i].([]interface{})
|
||||
if len(elem) == 5 {
|
||||
trades = append(trades,
|
||||
WebsocketTrade{
|
||||
ID: int64(elem[0].(float64)),
|
||||
Timestamp: int64(elem[1].(float64)),
|
||||
Amount: elem[3].(float64),
|
||||
Rate: elem[4].(float64),
|
||||
Period: int64(elem[4].(float64)),
|
||||
})
|
||||
continue
|
||||
}
|
||||
trades = append(trades,
|
||||
WebsocketTrade{
|
||||
ID: int64(y[0].(float64)),
|
||||
Timestamp: int64(y[1].(float64)),
|
||||
Price: y[3].(float64),
|
||||
Amount: y[2].(float64)})
|
||||
ID: int64(elem[0].(float64)),
|
||||
Timestamp: int64(elem[1].(float64)),
|
||||
Price: elem[3].(float64),
|
||||
Amount: elem[2].(float64),
|
||||
})
|
||||
}
|
||||
case 3:
|
||||
if chanData[1].(string) == wsTradeExecuted {
|
||||
// the te update contains less data then the "tu"
|
||||
if chanData[1].(string) == wsTradeExecutionUpdate ||
|
||||
chanData[1].(string) == wsFundingTradeUpdate {
|
||||
// "(f)te - trade executed" && "(f)tu - trade updated"
|
||||
// contain the same amount of data
|
||||
// "(f)te" gets sent first so we can drop "(f)tu"
|
||||
continue
|
||||
}
|
||||
data := chanData[2].([]interface{})
|
||||
@@ -246,27 +265,42 @@ func (b *Bitfinex) WsDataHandler() {
|
||||
Price: data[3].(float64),
|
||||
Amount: data[2].(float64)})
|
||||
}
|
||||
if len(trades) > 0 {
|
||||
for i := range trades {
|
||||
side := order.Buy.String()
|
||||
newAmount := trades[i].Amount
|
||||
if newAmount < 0 {
|
||||
side = order.Sell.String()
|
||||
newAmount *= -1
|
||||
}
|
||||
b.Websocket.DataHandler <- wshandler.TradeData{
|
||||
|
||||
for i := range trades {
|
||||
side := order.Buy.String()
|
||||
newAmount := trades[i].Amount
|
||||
if newAmount < 0 {
|
||||
side = order.Sell.String()
|
||||
newAmount *= -1
|
||||
}
|
||||
|
||||
if trades[i].Rate > 0 {
|
||||
b.Websocket.DataHandler <- wshandler.FundingData{
|
||||
CurrencyPair: currency.NewPairFromString(chanInfo.Pair),
|
||||
Timestamp: time.Unix(trades[i].Timestamp, 0),
|
||||
Price: trades[i].Price,
|
||||
Timestamp: time.Unix(0, trades[i].Timestamp*int64(time.Millisecond)),
|
||||
Amount: newAmount,
|
||||
Exchange: b.Name,
|
||||
AssetType: asset.Spot,
|
||||
Side: side,
|
||||
Rate: trades[i].Rate,
|
||||
Period: trades[i].Period,
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
b.Websocket.DataHandler <- wshandler.TradeData{
|
||||
CurrencyPair: currency.NewPairFromString(chanInfo.Pair),
|
||||
Timestamp: time.Unix(0, trades[i].Timestamp*int64(time.Millisecond)),
|
||||
Price: trades[i].Price,
|
||||
Amount: newAmount,
|
||||
Exchange: b.Name,
|
||||
AssetType: asset.Spot,
|
||||
Side: side,
|
||||
}
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if authResp, ok := chanData[1].(string); ok {
|
||||
switch authResp {
|
||||
case wsHeartbeat, pong:
|
||||
@@ -608,15 +642,19 @@ func (b *Bitfinex) WsInsertSnapshot(p currency.Pair, assetType asset.Item, books
|
||||
}
|
||||
var bid, ask []orderbook.Item
|
||||
for i := range books {
|
||||
if books[i].Amount >= 0 {
|
||||
bid = append(bid, orderbook.Item{Amount: books[i].Amount, Price: books[i].Price})
|
||||
if books[i].Amount > 0 {
|
||||
bid = append(bid, orderbook.Item{
|
||||
ID: books[i].ID,
|
||||
Amount: books[i].Amount,
|
||||
Price: books[i].Price})
|
||||
} else {
|
||||
ask = append(ask, orderbook.Item{Amount: books[i].Amount * -1, Price: books[i].Price})
|
||||
ask = append(ask, orderbook.Item{
|
||||
ID: books[i].ID,
|
||||
Amount: books[i].Amount * -1,
|
||||
Price: books[i].Price})
|
||||
}
|
||||
}
|
||||
if len(bid) == 0 && len(ask) == 0 {
|
||||
return errors.New("bitfinex.go error - no orderbooks in item lists")
|
||||
}
|
||||
|
||||
var newOrderBook orderbook.Base
|
||||
newOrderBook.Asks = ask
|
||||
newOrderBook.AssetType = assetType
|
||||
@@ -638,29 +676,41 @@ func (b *Bitfinex) WsInsertSnapshot(p currency.Pair, assetType asset.Item, books
|
||||
// orderbook sides
|
||||
func (b *Bitfinex) WsUpdateOrderbook(p currency.Pair, assetType asset.Item, book []WebsocketBook) error {
|
||||
orderbookUpdate := wsorderbook.WebsocketOrderbookUpdate{
|
||||
Asks: []orderbook.Item{},
|
||||
Bids: []orderbook.Item{},
|
||||
Asset: assetType,
|
||||
Pair: p,
|
||||
}
|
||||
|
||||
for i := 0; i < len(book); i++ {
|
||||
for i := range book {
|
||||
switch {
|
||||
case book[i].Price > 0:
|
||||
orderbookUpdate.Action = "update/insert"
|
||||
if book[i].Amount > 0 {
|
||||
// update bid
|
||||
orderbookUpdate.Bids = append(orderbookUpdate.Bids, orderbook.Item{Amount: book[i].Amount, Price: book[i].Price})
|
||||
orderbookUpdate.Bids = append(orderbookUpdate.Bids,
|
||||
orderbook.Item{
|
||||
ID: book[i].ID,
|
||||
Amount: book[i].Amount,
|
||||
Price: book[i].Price})
|
||||
} else if book[i].Amount < 0 {
|
||||
// update ask
|
||||
orderbookUpdate.Asks = append(orderbookUpdate.Asks, orderbook.Item{Amount: book[i].Amount * -1, Price: book[i].Price})
|
||||
orderbookUpdate.Asks = append(orderbookUpdate.Asks,
|
||||
orderbook.Item{
|
||||
ID: book[i].ID,
|
||||
Amount: book[i].Amount * -1,
|
||||
Price: book[i].Price})
|
||||
}
|
||||
case book[i].Price == 0:
|
||||
orderbookUpdate.Action = "delete"
|
||||
if book[i].Amount == 1 {
|
||||
// delete bid
|
||||
orderbookUpdate.Bids = append(orderbookUpdate.Bids, orderbook.Item{Amount: 0, Price: book[i].Price})
|
||||
orderbookUpdate.Bids = append(orderbookUpdate.Bids,
|
||||
orderbook.Item{
|
||||
ID: book[i].ID})
|
||||
} else if book[i].Amount == -1 {
|
||||
// delete ask
|
||||
orderbookUpdate.Asks = append(orderbookUpdate.Asks, orderbook.Item{Amount: 0, Price: book[i].Price})
|
||||
orderbookUpdate.Asks = append(orderbookUpdate.Asks,
|
||||
orderbook.Item{
|
||||
ID: book[i].ID})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -716,6 +766,7 @@ func (b *Bitfinex) Subscribe(channelToSubscribe wshandler.WebsocketChannelSubscr
|
||||
req := make(map[string]interface{})
|
||||
req["event"] = "subscribe"
|
||||
req["channel"] = channelToSubscribe.Channel
|
||||
|
||||
if channelToSubscribe.Currency.String() != "" {
|
||||
if channelToSubscribe.Channel == wsCandles {
|
||||
// TODO: Add ability to select timescale
|
||||
@@ -726,11 +777,13 @@ func (b *Bitfinex) Subscribe(channelToSubscribe wshandler.WebsocketChannelSubscr
|
||||
asset.Spot).String()
|
||||
}
|
||||
}
|
||||
|
||||
if len(channelToSubscribe.Params) > 0 {
|
||||
for k, v := range channelToSubscribe.Params {
|
||||
req[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return b.WebsocketConn.SendMessage(req)
|
||||
}
|
||||
|
||||
@@ -775,14 +828,6 @@ func (b *Bitfinex) WsSendAuth() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WsSendUnauth sends an unauthenticated payload
|
||||
func (b *Bitfinex) WsSendUnauth() error {
|
||||
req := make(map[string]string)
|
||||
req["event"] = "unauth"
|
||||
|
||||
return b.WebsocketConn.SendMessage(req)
|
||||
}
|
||||
|
||||
// WsAddSubscriptionChannel adds a new subscription channel to the
|
||||
// WebsocketSubdChannels map in bitfinex.go (Bitfinex struct)
|
||||
func (b *Bitfinex) WsAddSubscriptionChannel(chanID int, channel, pair string) {
|
||||
|
||||
@@ -185,10 +185,10 @@ func (b *Bitfinex) Setup(exch *config.ExchangeConfig) error {
|
||||
|
||||
b.Websocket.Orderbook.Setup(
|
||||
exch.WebsocketOrderbookBufferLimit,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
exch.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -153,6 +155,8 @@ func (b *BTCMarkets) WsHandleData() {
|
||||
Exchange: b.Name,
|
||||
Price: trade.Price,
|
||||
Amount: trade.Volume,
|
||||
Side: order.SideUnknown.String(),
|
||||
EventType: order.Unknown.String(),
|
||||
}
|
||||
case tick:
|
||||
var tick WsTick
|
||||
@@ -163,17 +167,18 @@ func (b *BTCMarkets) WsHandleData() {
|
||||
}
|
||||
|
||||
p := currency.NewPairFromString(tick.Currency)
|
||||
b.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: b.Name,
|
||||
Volume: tick.Volume,
|
||||
High: tick.High24,
|
||||
Low: tick.Low24h,
|
||||
Bid: tick.Bid,
|
||||
Ask: tick.Ask,
|
||||
Last: tick.Last,
|
||||
Timestamp: tick.Timestamp,
|
||||
AssetType: asset.Spot,
|
||||
Pair: p,
|
||||
|
||||
b.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: b.Name,
|
||||
Volume: tick.Volume,
|
||||
High: tick.High24,
|
||||
Low: tick.Low24h,
|
||||
Bid: tick.Bid,
|
||||
Ask: tick.Ask,
|
||||
Last: tick.Last,
|
||||
LastUpdated: tick.Timestamp,
|
||||
AssetType: asset.Spot,
|
||||
Pair: p,
|
||||
}
|
||||
case fundChange:
|
||||
var transferData WsFundTransfer
|
||||
|
||||
@@ -70,11 +70,6 @@ func (b *BTSE) WsHandleData() {
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(result["topic"].(string), "tradeHistory"):
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"%s: Buy/Sell side functionality is broken for this exchange "+
|
||||
"currently! 'gain' has no correlation with buy side or "+
|
||||
"sell side",
|
||||
b.Name)
|
||||
var tradeHistory wsTradeHistory
|
||||
err = json.Unmarshal(resp.Raw, &tradeHistory)
|
||||
if err != nil {
|
||||
@@ -87,8 +82,8 @@ func (b *BTSE) WsHandleData() {
|
||||
side = order.Sell.String()
|
||||
}
|
||||
b.Websocket.DataHandler <- wshandler.TradeData{
|
||||
Timestamp: time.Unix(tradeHistory.Data[x].TransactionTime, 0),
|
||||
CurrencyPair: currency.NewPairFromString(strings.Replace(tradeHistory.Topic, "tradeHistory", "", 1)),
|
||||
Timestamp: time.Unix(0, tradeHistory.Data[x].TransactionTime*int64(time.Millisecond)),
|
||||
CurrencyPair: currency.NewPairFromString(strings.Replace(tradeHistory.Topic, "tradeHistory:", "", 1)),
|
||||
AssetType: asset.Spot,
|
||||
Exchange: b.Name,
|
||||
Price: tradeHistory.Data[x].Price,
|
||||
|
||||
@@ -91,12 +91,10 @@ func (b *BTSE) SetDefaults() {
|
||||
CryptoWithdrawalFee: true,
|
||||
},
|
||||
WebsocketCapabilities: protocol.Features{
|
||||
TickerFetching: true,
|
||||
OrderbookFetching: true,
|
||||
TradeFetching: true,
|
||||
Subscribe: true,
|
||||
Unsubscribe: true,
|
||||
// TradeHistory is supported but it is currently broken on BTSE's
|
||||
// API so it has been left as unsupported
|
||||
},
|
||||
WithdrawPermissions: exchange.NoAPIWithdrawalMethods,
|
||||
},
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
)
|
||||
@@ -81,25 +82,25 @@ func (c *CoinbasePro) WsHandleData() {
|
||||
c.Websocket.DataHandler <- errors.New(string(resp.Raw))
|
||||
|
||||
case "ticker":
|
||||
ticker := WebsocketTicker{}
|
||||
err := json.Unmarshal(resp.Raw, &ticker)
|
||||
wsTicker := WebsocketTicker{}
|
||||
err := json.Unmarshal(resp.Raw, &wsTicker)
|
||||
if err != nil {
|
||||
c.Websocket.DataHandler <- err
|
||||
continue
|
||||
}
|
||||
|
||||
c.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Timestamp: ticker.Time,
|
||||
Pair: ticker.ProductID,
|
||||
AssetType: asset.Spot,
|
||||
Exchange: c.Name,
|
||||
Open: ticker.Open24H,
|
||||
High: ticker.High24H,
|
||||
Low: ticker.Low24H,
|
||||
Last: ticker.Price,
|
||||
Volume: ticker.Volume24H,
|
||||
Bid: ticker.BestBid,
|
||||
Ask: ticker.BestAsk,
|
||||
c.Websocket.DataHandler <- &ticker.Price{
|
||||
LastUpdated: wsTicker.Time,
|
||||
Pair: wsTicker.ProductID,
|
||||
AssetType: asset.Spot,
|
||||
ExchangeName: c.Name,
|
||||
Open: wsTicker.Open24H,
|
||||
High: wsTicker.High24H,
|
||||
Low: wsTicker.Low24H,
|
||||
Last: wsTicker.Price,
|
||||
Volume: wsTicker.Volume24H,
|
||||
Bid: wsTicker.BestBid,
|
||||
Ask: wsTicker.BestAsk,
|
||||
}
|
||||
|
||||
case "snapshot":
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
)
|
||||
@@ -126,26 +127,26 @@ func (c *Coinbene) WsDataHandler() {
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(result[topic].(string), "ticker"):
|
||||
var ticker WsTicker
|
||||
err = json.Unmarshal(stream.Raw, &ticker)
|
||||
var wsTicker WsTicker
|
||||
err = json.Unmarshal(stream.Raw, &wsTicker)
|
||||
if err != nil {
|
||||
c.Websocket.DataHandler <- err
|
||||
continue
|
||||
}
|
||||
for x := range ticker.Data {
|
||||
c.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Volume: ticker.Data[x].Volume24h,
|
||||
Last: ticker.Data[x].LastPrice,
|
||||
High: ticker.Data[x].High24h,
|
||||
Low: ticker.Data[x].Low24h,
|
||||
Bid: ticker.Data[x].BestBidPrice,
|
||||
Ask: ticker.Data[x].BestAskPrice,
|
||||
Pair: currency.NewPairFromFormattedPairs(ticker.Data[x].Symbol,
|
||||
for x := range wsTicker.Data {
|
||||
c.Websocket.DataHandler <- &ticker.Price{
|
||||
Volume: wsTicker.Data[x].Volume24h,
|
||||
Last: wsTicker.Data[x].LastPrice,
|
||||
High: wsTicker.Data[x].High24h,
|
||||
Low: wsTicker.Data[x].Low24h,
|
||||
Bid: wsTicker.Data[x].BestBidPrice,
|
||||
Ask: wsTicker.Data[x].BestAskPrice,
|
||||
Pair: currency.NewPairFromFormattedPairs(wsTicker.Data[x].Symbol,
|
||||
c.GetEnabledPairs(asset.PerpetualSwap),
|
||||
c.GetPairFormat(asset.PerpetualSwap, true)),
|
||||
Exchange: c.Name,
|
||||
AssetType: asset.PerpetualSwap,
|
||||
Timestamp: ticker.Data[x].Timestamp,
|
||||
ExchangeName: c.Name,
|
||||
AssetType: asset.PerpetualSwap,
|
||||
LastUpdated: wsTicker.Data[x].Timestamp,
|
||||
}
|
||||
}
|
||||
case strings.Contains(result[topic].(string), "tradeList"):
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -133,25 +134,25 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
|
||||
case "hb":
|
||||
channels["hb"] <- resp
|
||||
case "inst_tick":
|
||||
var ticker WsTicker
|
||||
err := json.Unmarshal(resp, &ticker)
|
||||
var wsTicker WsTicker
|
||||
err := json.Unmarshal(resp, &wsTicker)
|
||||
if err != nil {
|
||||
c.Websocket.DataHandler <- err
|
||||
return
|
||||
}
|
||||
|
||||
currencyPair := c.instrumentMap.LookupInstrument(ticker.InstID)
|
||||
c.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: c.Name,
|
||||
Volume: ticker.Volume24,
|
||||
QuoteVolume: ticker.Volume24Quote,
|
||||
Bid: ticker.HighestBuy,
|
||||
Ask: ticker.LowestSell,
|
||||
High: ticker.High24,
|
||||
Low: ticker.Low24,
|
||||
Last: ticker.Last,
|
||||
Timestamp: time.Unix(0, ticker.Timestamp),
|
||||
AssetType: asset.Spot,
|
||||
currencyPair := c.instrumentMap.LookupInstrument(wsTicker.InstID)
|
||||
c.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: c.Name,
|
||||
Volume: wsTicker.Volume24,
|
||||
QuoteVolume: wsTicker.Volume24Quote,
|
||||
Bid: wsTicker.HighestBuy,
|
||||
Ask: wsTicker.LowestSell,
|
||||
High: wsTicker.High24,
|
||||
Low: wsTicker.Low24,
|
||||
Last: wsTicker.Last,
|
||||
LastUpdated: time.Unix(0, wsTicker.Timestamp),
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromFormattedPairs(currencyPair,
|
||||
c.GetEnabledPairs(asset.Spot),
|
||||
c.GetPairFormat(asset.Spot, true)),
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -122,9 +123,9 @@ func (g *Gateio) WsHandleData() {
|
||||
|
||||
switch {
|
||||
case strings.Contains(result.Method, "ticker"):
|
||||
var ticker WebsocketTicker
|
||||
var wsTicker WebsocketTicker
|
||||
var c string
|
||||
err = json.Unmarshal(result.Params[1], &ticker)
|
||||
err = json.Unmarshal(result.Params[1], &wsTicker)
|
||||
if err != nil {
|
||||
g.Websocket.DataHandler <- err
|
||||
continue
|
||||
@@ -136,17 +137,17 @@ func (g *Gateio) WsHandleData() {
|
||||
continue
|
||||
}
|
||||
|
||||
g.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: g.Name,
|
||||
Open: ticker.Open,
|
||||
Close: ticker.Close,
|
||||
Volume: ticker.BaseVolume,
|
||||
QuoteVolume: ticker.QuoteVolume,
|
||||
High: ticker.High,
|
||||
Low: ticker.Low,
|
||||
Last: ticker.Last,
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromString(c),
|
||||
g.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: g.Name,
|
||||
Open: wsTicker.Open,
|
||||
Close: wsTicker.Close,
|
||||
Volume: wsTicker.BaseVolume,
|
||||
QuoteVolume: wsTicker.QuoteVolume,
|
||||
High: wsTicker.High,
|
||||
Low: wsTicker.Low,
|
||||
Last: wsTicker.Last,
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromString(c),
|
||||
}
|
||||
|
||||
case strings.Contains(result.Method, "trades"):
|
||||
|
||||
@@ -297,11 +297,10 @@ func (g *Gemini) wsProcessUpdate(result WsMarketUpdateResponse, pair currency.Pa
|
||||
for i := 0; i < len(result.Events); i++ {
|
||||
if result.Events[i].Type == "trade" {
|
||||
g.Websocket.DataHandler <- wshandler.TradeData{
|
||||
Timestamp: time.Now(),
|
||||
Timestamp: time.Unix(0, result.Timestamp),
|
||||
CurrencyPair: pair,
|
||||
AssetType: asset.Spot,
|
||||
Exchange: g.Name,
|
||||
EventTime: result.Timestamp,
|
||||
Price: result.Events[i].Price,
|
||||
Amount: result.Events[i].Amount,
|
||||
Side: result.Events[i].MakerSide,
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/nonce"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -105,30 +106,30 @@ func (h *HitBTC) WsHandleData() {
|
||||
func (h *HitBTC) handleSubscriptionUpdates(resp wshandler.WebsocketResponse, init capture) {
|
||||
switch init.Method {
|
||||
case "ticker":
|
||||
var ticker WsTicker
|
||||
err := json.Unmarshal(resp.Raw, &ticker)
|
||||
var wsTicker WsTicker
|
||||
err := json.Unmarshal(resp.Raw, &wsTicker)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
}
|
||||
ts, err := time.Parse(time.RFC3339, ticker.Params.Timestamp)
|
||||
ts, err := time.Parse(time.RFC3339, wsTicker.Params.Timestamp)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
}
|
||||
h.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: h.Name,
|
||||
Open: ticker.Params.Open,
|
||||
Volume: ticker.Params.Volume,
|
||||
QuoteVolume: ticker.Params.VolumeQuote,
|
||||
High: ticker.Params.High,
|
||||
Low: ticker.Params.Low,
|
||||
Bid: ticker.Params.Bid,
|
||||
Ask: ticker.Params.Ask,
|
||||
Last: ticker.Params.Last,
|
||||
Timestamp: ts,
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromFormattedPairs(ticker.Params.Symbol,
|
||||
h.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: h.Name,
|
||||
Open: wsTicker.Params.Open,
|
||||
Volume: wsTicker.Params.Volume,
|
||||
QuoteVolume: wsTicker.Params.VolumeQuote,
|
||||
High: wsTicker.Params.High,
|
||||
Low: wsTicker.Params.Low,
|
||||
Bid: wsTicker.Params.Bid,
|
||||
Ask: wsTicker.Params.Ask,
|
||||
Last: wsTicker.Params.Last,
|
||||
LastUpdated: ts,
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromFormattedPairs(wsTicker.Params.Symbol,
|
||||
h.GetEnabledPairs(asset.Spot), h.GetPairFormat(asset.Spot, true)),
|
||||
}
|
||||
case "snapshotOrderbook":
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -250,7 +251,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||
}
|
||||
data := strings.Split(kline.Channel, ".")
|
||||
h.Websocket.DataHandler <- wshandler.KlineData{
|
||||
Timestamp: time.Unix(0, kline.Timestamp),
|
||||
Timestamp: time.Unix(0, kline.Timestamp*int64(time.Millisecond)),
|
||||
Exchange: h.Name,
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromFormattedPairs(data[1],
|
||||
@@ -274,26 +275,26 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||
AssetType: asset.Spot,
|
||||
CurrencyPair: currency.NewPairFromFormattedPairs(data[1],
|
||||
h.GetEnabledPairs(asset.Spot), h.GetPairFormat(asset.Spot, true)),
|
||||
Timestamp: time.Unix(0, trade.Tick.Timestamp),
|
||||
Timestamp: time.Unix(0, trade.Tick.Timestamp*int64(time.Millisecond)),
|
||||
}
|
||||
case strings.Contains(init.Channel, "detail"):
|
||||
var ticker WsTick
|
||||
err := json.Unmarshal(resp.Raw, &ticker)
|
||||
var wsTicker WsTick
|
||||
err := json.Unmarshal(resp.Raw, &wsTicker)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
}
|
||||
data := strings.Split(ticker.Channel, ".")
|
||||
h.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: h.Name,
|
||||
Open: ticker.Tick.Open,
|
||||
Close: ticker.Tick.Close,
|
||||
Volume: ticker.Tick.Amount,
|
||||
QuoteVolume: ticker.Tick.Volume,
|
||||
High: ticker.Tick.High,
|
||||
Low: ticker.Tick.Low,
|
||||
Timestamp: time.Unix(0, ticker.Timestamp),
|
||||
AssetType: asset.Spot,
|
||||
data := strings.Split(wsTicker.Channel, ".")
|
||||
h.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: h.Name,
|
||||
Open: wsTicker.Tick.Open,
|
||||
Close: wsTicker.Tick.Close,
|
||||
Volume: wsTicker.Tick.Amount,
|
||||
QuoteVolume: wsTicker.Tick.Volume,
|
||||
High: wsTicker.Tick.High,
|
||||
Low: wsTicker.Tick.Low,
|
||||
LastUpdated: time.Unix(0, wsTicker.Timestamp*int64(time.Millisecond)),
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromFormattedPairs(data[1],
|
||||
h.GetEnabledPairs(asset.Spot), h.GetPairFormat(asset.Spot, true)),
|
||||
}
|
||||
|
||||
@@ -623,7 +623,7 @@ func (h *HUOBI) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
CurrencyPair: currency.NewPairFromString(respData.Symbol),
|
||||
OrderType: orderType,
|
||||
OrderSide: orderSide,
|
||||
OrderDate: time.Unix(respData.CreatedAt, 0),
|
||||
OrderDate: time.Unix(0, respData.CreatedAt*int64(time.Millisecond)),
|
||||
Status: orderStatus,
|
||||
Price: respData.Price,
|
||||
Amount: respData.Amount,
|
||||
@@ -714,7 +714,7 @@ func (h *HUOBI) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, er
|
||||
CurrencyPair: req.Currencies[i],
|
||||
OrderType: orderType,
|
||||
OrderSide: orderSide,
|
||||
OrderDate: time.Unix(resp.Data[j].CreatedAt, 0),
|
||||
OrderDate: time.Unix(0, resp.Data[j].CreatedAt*int64(time.Millisecond)),
|
||||
Status: orderStatus,
|
||||
Price: resp.Data[j].Price,
|
||||
Amount: resp.Data[j].OrderAmount,
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -507,18 +508,17 @@ func (k *Kraken) wsProcessTickers(channelData *WebsocketChannelData, data map[st
|
||||
return
|
||||
}
|
||||
|
||||
k.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: k.Name,
|
||||
Open: openPrice,
|
||||
Close: closePrice,
|
||||
Volume: quantity,
|
||||
High: highPrice,
|
||||
Low: lowPrice,
|
||||
Bid: bid,
|
||||
Ask: ask,
|
||||
Timestamp: time.Now(),
|
||||
AssetType: asset.Spot,
|
||||
Pair: channelData.Pair,
|
||||
k.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: k.Name,
|
||||
Open: openPrice,
|
||||
Close: closePrice,
|
||||
Volume: quantity,
|
||||
High: highPrice,
|
||||
Low: lowPrice,
|
||||
Bid: bid,
|
||||
Ask: ask,
|
||||
AssetType: asset.Spot,
|
||||
Pair: channelData.Pair,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,7 +576,6 @@ func (k *Kraken) wsProcessTrades(channelData *WebsocketChannelData, data []inter
|
||||
k.Websocket.DataHandler <- wshandler.TradeData{
|
||||
AssetType: asset.Spot,
|
||||
CurrencyPair: channelData.Pair,
|
||||
EventTime: time.Now().Unix(),
|
||||
Exchange: k.Name,
|
||||
Price: price,
|
||||
Amount: amount,
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
"github.com/toorop/go-pusher"
|
||||
@@ -152,7 +153,6 @@ func (l *LakeBTC) processTrades(data, channel string) error {
|
||||
AssetType: asset.Spot,
|
||||
Exchange: l.Name,
|
||||
EventType: asset.Spot.String(),
|
||||
EventTime: tradeData.Trades[i].Date,
|
||||
Price: tradeData.Trades[i].Price,
|
||||
Amount: tradeData.Trades[i].Amount,
|
||||
Side: tradeData.Trades[i].Type,
|
||||
@@ -233,9 +233,9 @@ func (l *LakeBTC) getCurrencyFromChannel(channel string) currency.Pair {
|
||||
return currency.NewPairFromString(curr)
|
||||
}
|
||||
|
||||
func (l *LakeBTC) processTicker(ticker string) error {
|
||||
func (l *LakeBTC) processTicker(wsTicker string) error {
|
||||
var tUpdate map[string]interface{}
|
||||
err := json.Unmarshal([]byte(ticker), &tUpdate)
|
||||
err := json.Unmarshal([]byte(wsTicker), &tUpdate)
|
||||
if err != nil {
|
||||
l.Websocket.DataHandler <- err
|
||||
return err
|
||||
@@ -266,16 +266,16 @@ func (l *LakeBTC) processTicker(ticker string) error {
|
||||
return p
|
||||
}
|
||||
|
||||
l.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: l.Name,
|
||||
Bid: processTickerItem(tickerData, order.Buy.Lower()),
|
||||
High: processTickerItem(tickerData, tickerHighString),
|
||||
Last: processTickerItem(tickerData, tickerLastString),
|
||||
Low: processTickerItem(tickerData, tickerLowString),
|
||||
Ask: processTickerItem(tickerData, order.Sell.Lower()),
|
||||
Volume: processTickerItem(tickerData, tickerVolumeString),
|
||||
AssetType: asset.Spot,
|
||||
Pair: returnCurrency,
|
||||
l.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: l.Name,
|
||||
Bid: processTickerItem(tickerData, order.Buy.Lower()),
|
||||
High: processTickerItem(tickerData, tickerHighString),
|
||||
Last: processTickerItem(tickerData, tickerLastString),
|
||||
Low: processTickerItem(tickerData, tickerLowString),
|
||||
Ask: processTickerItem(tickerData, order.Sell.Lower()),
|
||||
Volume: processTickerItem(tickerData, tickerVolumeString),
|
||||
AssetType: asset.Spot,
|
||||
Pair: returnCurrency,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -410,20 +411,20 @@ func (o *OKGroup) wsProcessTickers(response *WebsocketDataResponse) {
|
||||
c = currency.NewPairWithDelimiter(f[0], f[1], delimiterDash)
|
||||
}
|
||||
|
||||
o.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: o.Name,
|
||||
Open: response.Data[i].Open24h,
|
||||
Close: response.Data[i].Last,
|
||||
Volume: response.Data[i].BaseVolume24h,
|
||||
QuoteVolume: response.Data[i].QuoteVolume24h,
|
||||
High: response.Data[i].High24h,
|
||||
Low: response.Data[i].Low24h,
|
||||
Bid: response.Data[i].BestBid,
|
||||
Ask: response.Data[i].BestAsk,
|
||||
Last: response.Data[i].Last,
|
||||
Timestamp: response.Data[i].Timestamp,
|
||||
AssetType: o.GetAssetTypeFromTableName(response.Table),
|
||||
Pair: c,
|
||||
o.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: o.Name,
|
||||
Open: response.Data[i].Open24h,
|
||||
Close: response.Data[i].Last,
|
||||
Volume: response.Data[i].BaseVolume24h,
|
||||
QuoteVolume: response.Data[i].QuoteVolume24h,
|
||||
High: response.Data[i].High24h,
|
||||
Low: response.Data[i].Low24h,
|
||||
Bid: response.Data[i].BestBid,
|
||||
Ask: response.Data[i].BestAsk,
|
||||
Last: response.Data[i].Last,
|
||||
LastUpdated: response.Data[i].Timestamp,
|
||||
AssetType: o.GetAssetTypeFromTableName(response.Table),
|
||||
Pair: c,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,7 +447,6 @@ func (o *OKGroup) wsProcessTrades(response *WebsocketDataResponse) {
|
||||
Amount: response.Data[i].Size,
|
||||
AssetType: o.GetAssetTypeFromTableName(response.Table),
|
||||
CurrencyPair: c,
|
||||
EventTime: time.Now().Unix(),
|
||||
Exchange: o.Name,
|
||||
Price: response.Data[i].WebsocketTradeResponse.Price,
|
||||
Side: response.Data[i].Side,
|
||||
|
||||
@@ -100,11 +100,12 @@ type Side string
|
||||
|
||||
// Order side types
|
||||
const (
|
||||
AnySide Side = "ANY"
|
||||
Buy Side = "BUY"
|
||||
Sell Side = "SELL"
|
||||
Bid Side = "BID"
|
||||
Ask Side = "ASK"
|
||||
AnySide Side = "ANY"
|
||||
Buy Side = "BUY"
|
||||
Sell Side = "SELL"
|
||||
Bid Side = "BID"
|
||||
Ask Side = "ASK"
|
||||
SideUnknown Side = "SIDEUNKNOWN"
|
||||
)
|
||||
|
||||
// Detail holds order detail data
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -278,18 +279,17 @@ func (p *Poloniex) wsHandleTickerData(data []interface{}) {
|
||||
return
|
||||
}
|
||||
|
||||
p.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: p.Name,
|
||||
Volume: t.BaseCurrencyVolume24H,
|
||||
QuoteVolume: t.QuoteCurrencyVolume24H,
|
||||
High: t.HighestBid,
|
||||
Low: t.LowestAsk,
|
||||
Bid: t.HighestBid,
|
||||
Ask: t.LowestAsk,
|
||||
Last: t.LastPrice,
|
||||
Timestamp: time.Now(),
|
||||
AssetType: asset.Spot,
|
||||
Pair: currencyPair,
|
||||
p.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: p.Name,
|
||||
Volume: t.BaseCurrencyVolume24H,
|
||||
QuoteVolume: t.QuoteCurrencyVolume24H,
|
||||
High: t.HighestBid,
|
||||
Low: t.LowestAsk,
|
||||
Bid: t.HighestBid,
|
||||
Ask: t.LowestAsk,
|
||||
Last: t.LastPrice,
|
||||
AssetType: asset.Spot,
|
||||
Pair: currencyPair,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ type Websocket struct {
|
||||
features *protocol.Features
|
||||
}
|
||||
|
||||
// WebsocketSetup defines variables for setting up a websocket connection
|
||||
type WebsocketSetup struct {
|
||||
Enabled bool
|
||||
Verbose bool
|
||||
@@ -103,28 +104,21 @@ type TradeData struct {
|
||||
AssetType asset.Item
|
||||
Exchange string
|
||||
EventType string
|
||||
EventTime int64
|
||||
Price float64
|
||||
Amount float64
|
||||
Side string
|
||||
}
|
||||
|
||||
// TickerData defines ticker feed
|
||||
type TickerData struct {
|
||||
Exchange string
|
||||
Open float64
|
||||
Close float64
|
||||
Volume float64
|
||||
QuoteVolume float64
|
||||
High float64
|
||||
Low float64
|
||||
Bid float64
|
||||
Ask float64
|
||||
Last float64
|
||||
PriceATH float64
|
||||
Timestamp time.Time
|
||||
AssetType asset.Item
|
||||
Pair currency.Pair
|
||||
// FundingData defines funding data
|
||||
type FundingData struct {
|
||||
Timestamp time.Time
|
||||
CurrencyPair currency.Pair
|
||||
AssetType asset.Item
|
||||
Exchange string
|
||||
Amount float64
|
||||
Rate float64
|
||||
Period int64
|
||||
Side string
|
||||
}
|
||||
|
||||
// KlineData defines kline feed
|
||||
|
||||
@@ -196,6 +196,29 @@ func (w *WebsocketOrderbookLocal) updateByIDAndAction(o *orderbook.Base, u *Webs
|
||||
sort.Slice(o.Asks, func(i, j int) bool {
|
||||
return o.Asks[i].Price < o.Asks[j].Price
|
||||
})
|
||||
|
||||
case "update/insert":
|
||||
updateBids:
|
||||
for x := range u.Bids {
|
||||
for y := range o.Bids {
|
||||
if o.Bids[y].ID == u.Bids[x].ID {
|
||||
o.Bids[y].Amount = u.Bids[x].Amount
|
||||
continue updateBids
|
||||
}
|
||||
}
|
||||
o.Bids = append(o.Bids, u.Bids[x])
|
||||
}
|
||||
|
||||
updateAsks:
|
||||
for x := range u.Asks {
|
||||
for y := range o.Asks {
|
||||
if o.Asks[y].ID == u.Asks[x].ID {
|
||||
o.Asks[y].Amount = u.Asks[x].Amount
|
||||
continue updateAsks
|
||||
}
|
||||
}
|
||||
o.Asks = append(o.Asks, u.Asks[x])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,22 +141,13 @@ func (z *ZB) GetOrders(currency string, pageindex, side int64) ([]Order, error)
|
||||
func (z *ZB) GetMarkets() (map[string]MarketResponseItem, error) {
|
||||
endpoint := fmt.Sprintf("%s/%s/%s", z.API.Endpoints.URL, zbAPIVersion, zbMarkets)
|
||||
|
||||
var res interface{}
|
||||
var res map[string]MarketResponseItem
|
||||
err := z.SendHTTPRequest(endpoint, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := res.(map[string]interface{})
|
||||
result := map[string]MarketResponseItem{}
|
||||
for k, v := range list {
|
||||
item := v.(map[string]interface{})
|
||||
result[k] = MarketResponseItem{
|
||||
AmountScale: item["amountScale"].(float64),
|
||||
PriceScale: item["priceScale"].(float64),
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// GetLatestSpotPrice returns latest spot price of symbol
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -88,25 +89,25 @@ func (z *ZB) WsHandleData() {
|
||||
|
||||
case strings.Contains(result.Channel, "ticker"):
|
||||
cPair := strings.Split(result.Channel, "_")
|
||||
var ticker WsTicker
|
||||
err := json.Unmarshal(fixedJSON, &ticker)
|
||||
var wsTicker WsTicker
|
||||
err := json.Unmarshal(fixedJSON, &wsTicker)
|
||||
if err != nil {
|
||||
z.Websocket.DataHandler <- err
|
||||
continue
|
||||
}
|
||||
|
||||
z.Websocket.DataHandler <- wshandler.TickerData{
|
||||
Exchange: z.Name,
|
||||
Close: ticker.Data.Last,
|
||||
Volume: ticker.Data.Volume24Hr,
|
||||
High: ticker.Data.High,
|
||||
Low: ticker.Data.Low,
|
||||
Last: ticker.Data.Last,
|
||||
Bid: ticker.Data.Buy,
|
||||
Ask: ticker.Data.Sell,
|
||||
Timestamp: time.Unix(0, ticker.Date*int64(time.Millisecond)),
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromString(cPair[0]),
|
||||
z.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: z.Name,
|
||||
Close: wsTicker.Data.Last,
|
||||
Volume: wsTicker.Data.Volume24Hr,
|
||||
High: wsTicker.Data.High,
|
||||
Low: wsTicker.Data.Low,
|
||||
Last: wsTicker.Data.Last,
|
||||
Bid: wsTicker.Data.Buy,
|
||||
Ask: wsTicker.Data.Sell,
|
||||
LastUpdated: time.Unix(0, wsTicker.Date*int64(time.Millisecond)),
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPairFromString(cPair[0]),
|
||||
}
|
||||
|
||||
case strings.Contains(result.Channel, "depth"):
|
||||
@@ -170,11 +171,10 @@ func (z *ZB) WsHandleData() {
|
||||
channelInfo := strings.Split(result.Channel, "_")
|
||||
cPair := currency.NewPairFromString(channelInfo[0])
|
||||
z.Websocket.DataHandler <- wshandler.TradeData{
|
||||
Timestamp: time.Unix(0, t.Date*int64(time.Millisecond)),
|
||||
Timestamp: time.Unix(t.Date, 0),
|
||||
CurrencyPair: cPair,
|
||||
AssetType: asset.Spot,
|
||||
Exchange: z.Name,
|
||||
EventTime: t.Date,
|
||||
Price: t.Price,
|
||||
Amount: t.Amount,
|
||||
Side: t.TradeType,
|
||||
|
||||
Reference in New Issue
Block a user