Skip to content

Commit

Permalink
Websocket update increasing exchange coverage and bug fixes (thrasher…
Browse files Browse the repository at this point in the history
…-corp#233)

Websocket update increasing exchange coverage and bug fixes
  • Loading branch information
shazbert authored and thrasher- committed Jan 23, 2019
1 parent b62a9c7 commit 41415ca
Show file tree
Hide file tree
Showing 72 changed files with 1,978 additions and 435 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ ermalguni | https://github.com/ermalguni
marcofranssen | https://github.com/marcofranssen
cranktakular | https://github.com/cranktakular
crackcomm | https://github.com/crackcomm
xtda | https://github.com/xtda
andreygrehov | https://github.com/andreygrehov
bretep | https://github.com/bretep
gam-phon | https://github.com/gam-phon
cornelk | https://github.com/cornelk
if1live | https://github.com/if1live
soxipy | https://github.com/soxipy
herenow | https://github.com/herenow
xtda | https://github.com/xtda
blombard | https://github.com/blombard
CodeLingoBot | https://github.com/CodeLingoBot
Daanikus | https://github.com/Daanikus
daniel-cohen | https://github.com/daniel-cohen
frankzougc | https://github.com/frankzougc
woshidama323 | https://github.com/woshidama323
starit | https://github.com/starit
Jimexist | https://github.com/Jimexist
lookfirst | https://github.com/lookfirst
Expand All @@ -28,6 +30,4 @@ mattkanwisher | https://github.com/mattkanwisher
mKurrels | https://github.com/mKurrels
m1kola | https://github.com/m1kola
cavapoo2 | https://github.com/cavapoo2
tongxiaofeng | https://github.com/tongxiaofeng
idealhack | https://github.com/idealhack

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2018 The GoCryptoTrader Developers
Copyright (c) 2014-2019 The GoCryptoTrader Developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
| Bitfinex | Yes | Yes | NA |
| Bitflyer | Yes | No | NA |
| Bithumb | Yes | NA | NA |
| BitMEX | Yes | No | NA |
| BitMEX | Yes | Yes | NA |
| Bitstamp | Yes | Yes | No |
| Bittrex | Yes | No | NA |
| BTCC | Yes | Yes | No |
| BTCMarkets | Yes | No | NA |
| COINUT | Yes | No | NA |
| COINUT | Yes | Yes | NA |
| Exmo | Yes | NA | NA |
| CoinbasePro | Yes | Yes | No|
| GateIO | Yes | No | NA |
| Gemini | Yes | No | No |
| GateIO | Yes | Yes | NA |
| Gemini | Yes | Yes | No |
| HitBTC | Yes | Yes | No |
| Huobi.Pro | Yes | No | NA |
| Huobi.Hadax | Yes | No | NA |
| Huobi.Pro | Yes | Yes | NA |
| Huobi.Hadax | Yes | Yes | NA |
| ItBit | Yes | NA | No |
| Kraken | Yes | NA | NA |
| LakeBTC | Yes | No | NA |
| Liqui | Yes | No | NA |
| LocalBitcoins | Yes | NA | NA |
| OKCoin China | Yes | Yes | No |
| OKCoin International | Yes | Yes | No |
| OKEX | Yes | No | No |
| OKEX | Yes | Yes | No |
| Poloniex | Yes | Yes | NA |
| WEX | Yes | NA | NA |
| Yobit | Yes | NA | NA |
| ZB.COM | Yes | No | NA |
| ZB.COM | Yes | Yes | NA |

We are aiming to support the top 20 highest volume exchanges based off the [CoinMarketCap exchange data](https://coinmarketcap.com/exchanges/volume/24-hour/).

Expand Down Expand Up @@ -133,26 +133,28 @@ Binaries will be published once the codebase reaches a stable condition.

|User|Github|Contribution Amount|
|--|--|--|
| thrasher- | https://github.com/thrasher- | 489 |
| shazbert | https://github.com/shazbert | 156 |
| gloriousCode | https://github.com/gloriousCode | 139 |
| thrasher- | https://github.com/thrasher- | 496 |
| shazbert | https://github.com/shazbert | 158 |
| gloriousCode | https://github.com/gloriousCode | 141 |
| ermalguni | https://github.com/ermalguni | 14 |
| 140am | https://github.com/140am | 8 |
| marcofranssen | https://github.com/marcofranssen | 8 |
| cranktakular | https://github.com/cranktakular | 5 |
| crackcomm | https://github.com/crackcomm | 3 |
| xtda | https://github.com/xtda | 2 |
| andreygrehov | https://github.com/andreygrehov | 2 |
| bretep | https://github.com/bretep | 2 |
| gam-phon | https://github.com/gam-phon | 2 |
| cornelk | https://github.com/cornelk | 2 |
| if1live | https://github.com/if1live | 2 |
| soxipy | https://github.com/soxipy | 2 |
| herenow | https://github.com/herenow | 2 |
| xtda | https://github.com/xtda | 1 |
| blombard | https://github.com/blombard | 1 |
| CodeLingoBot | https://github.com/CodeLingoBot | 1 |
| Daanikus | https://github.com/Daanikus | 1 |
| daniel-cohen | https://github.com/daniel-cohen | 1 |
| frankzougc | https://github.com/frankzougc | 1 |
| woshidama323 | https://github.com/woshidama323 | 1 |
| starit | https://github.com/starit | 1 |
| Jimexist | https://github.com/Jimexist | 1 |
| lookfirst | https://github.com/lookfirst | 1 |
Expand All @@ -161,8 +163,6 @@ Binaries will be published once the codebase reaches a stable condition.
| mKurrels | https://github.com/mKurrels | 1 |
| m1kola | https://github.com/m1kola | 1 |
| cavapoo2 | https://github.com/cavapoo2 | 1 |
| tongxiaofeng | https://github.com/tongxiaofeng | 1 |
| idealhack | https://github.com/idealhack | 1 |



2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ func (c *Config) CheckExchangeConfigValues() error {
lastUpdated := common.UnixTimestampToTime(exch.PairsLastUpdated)
lastUpdated = lastUpdated.AddDate(0, 0, configPairsLastUpdatedWarningThreshold)
if lastUpdated.Unix() <= time.Now().Unix() {
log.Warn(WarningPairsLastUpdatedThresholdExceeded, exch.Name, configPairsLastUpdatedWarningThreshold)
log.Warnf(WarningPairsLastUpdatedThresholdExceeded, exch.Name, configPairsLastUpdatedWarningThreshold)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,11 @@ func (c *CurrencyConverter) SendHTTPRequest(endPoint string, values url.Values,
}
path = path + values.Encode()

return common.SendHTTPGetRequest(path, true, c.Verbose, &result)
err := common.SendHTTPGetRequest(path, true, c.Verbose, &result)
if err != nil {
return fmt.Errorf("Currency converter API SendHTTPRequest error %s with path %s",
err,
path)
}
return nil
}
4 changes: 3 additions & 1 deletion exchanges/alphapoint/alphapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func (a *Alphapoint) SetDefaults() {
a.AssetTypes = []string{ticker.Spot}
a.SupportsAutoPairUpdating = false
a.SupportsRESTTickerBatching = false
a.APIWithdrawPermissions = exchange.WithdrawCryptoWith2FA | exchange.AutoWithdrawCryptoWithAPIPermission | exchange.NoFiatWithdrawals
a.APIWithdrawPermissions = exchange.WithdrawCryptoWith2FA |
exchange.AutoWithdrawCryptoWithAPIPermission |
exchange.NoFiatWithdrawals
a.Requester = request.New(a.Name,
request.NewRateLimit(time.Minute*10, alphapointAuthRate),
request.NewRateLimit(time.Minute*10, alphapointUnauthRate),
Expand Down
2 changes: 1 addition & 1 deletion exchanges/alphapoint/alphapoint_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (a *Alphapoint) GetWebsocket() (*exchange.Websocket, error) {

// GetFeeByType returns an estimate of fee based on type of transaction
func (a *Alphapoint) GetFeeByType(feeBuilder exchange.FeeBuilder) (float64, error) {
return 0, common.ErrNotYetImplemented
return 0, common.ErrFunctionNotSupported
}

// GetWithdrawCapabilities returns the types of withdrawal methods permitted by the exchange
Expand Down
6 changes: 4 additions & 2 deletions exchanges/anx/anx.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ func (a *ANX) SetDefaults() {
a.ConfigCurrencyPairFormat.Delimiter = "_"
a.ConfigCurrencyPairFormat.Uppercase = true
a.ConfigCurrencyPairFormat.Index = ""
a.APIWithdrawPermissions = exchange.WithdrawCryptoWithEmail | exchange.AutoWithdrawCryptoWithSetup |
exchange.WithdrawCryptoWith2FA | exchange.WithdrawFiatViaWebsiteOnly
a.APIWithdrawPermissions = exchange.WithdrawCryptoWithEmail |
exchange.AutoWithdrawCryptoWithSetup |
exchange.WithdrawCryptoWith2FA |
exchange.WithdrawFiatViaWebsiteOnly
a.AssetTypes = []string{ticker.Spot}
a.SupportsAutoPairUpdating = true
a.SupportsRESTTickerBatching = false
Expand Down
7 changes: 6 additions & 1 deletion exchanges/binance/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (b *Binance) SetDefaults() {
b.AssetTypes = []string{ticker.Spot}
b.SupportsAutoPairUpdating = true
b.SupportsRESTTickerBatching = true
b.APIWithdrawPermissions = exchange.AutoWithdrawCrypto | exchange.NoFiatWithdrawals
b.APIWithdrawPermissions = exchange.AutoWithdrawCrypto |
exchange.NoFiatWithdrawals
b.SetValues()
b.Requester = request.New(b.Name,
request.NewRateLimit(time.Second, binanceAuthRate),
Expand All @@ -91,6 +92,10 @@ func (b *Binance) SetDefaults() {
b.APIUrlDefault = apiURL
b.APIUrl = b.APIUrlDefault
b.WebsocketInit()
b.Websocket.Functionality = exchange.WebsocketTradeDataSupported |
exchange.WebsocketTickerSupported |
exchange.WebsocketKlineSupported |
exchange.WebsocketOrderbookSupported
}

// Setup takes in the supplied exchange configuration details and sets params
Expand Down
44 changes: 17 additions & 27 deletions exchanges/binance/binance_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (b *Binance) SeedLocalCache(p pair.CurrencyPair) error {
newOrderBook.LastUpdated = time.Now()
newOrderBook.AssetType = "SPOT"

return b.Websocket.Orderbook.LoadSnapshot(newOrderBook, b.GetName())
return b.Websocket.Orderbook.LoadSnapshot(newOrderBook, b.GetName(), false)
}

// UpdateLocalCache updates and returns the most recent iteration of the orderbook
Expand Down Expand Up @@ -182,8 +182,19 @@ func (b *Binance) WSConnect() error {
return nil
}

// WSReadData reads from the websocket connection
func (b *Binance) WSReadData() {
// WSReadData reads from the websocket connection and returns the response
func (b *Binance) WSReadData() (exchange.WebsocketResponse, error) {
msgType, resp, err := b.WebsocketConn.ReadMessage()
if err != nil {
return exchange.WebsocketResponse{}, err
}

b.Websocket.TrafficAlert <- struct{}{}
return exchange.WebsocketResponse{Type: msgType, Raw: resp}, nil
}

// WsHandleData handles websocket data from WsReadData
func (b *Binance) WsHandleData() {
b.Websocket.Wg.Add(1)

defer func() {
Expand All @@ -201,37 +212,16 @@ func (b *Binance) WSReadData() {
return

default:
msgType, resp, err := b.WebsocketConn.ReadMessage()
read, err := b.WSReadData()
if err != nil {
b.Websocket.DataHandler <- fmt.Errorf("binance_websocket.go - Websocket Read Data. Error: %s",
err)
b.Websocket.DataHandler <- err
return
}

b.Websocket.TrafficAlert <- struct{}{}
b.Websocket.Intercomm <- exchange.WebsocketResponse{Type: msgType, Raw: resp}
}
}
}

// WsHandleData handles websocket data from WsReadData
func (b *Binance) WsHandleData() {
b.Websocket.Wg.Add(1)
defer b.Websocket.Wg.Done()

go b.WSReadData()

for {
select {
case <-b.Websocket.ShutdownC:
return

case read := <-b.Websocket.Intercomm:
switch read.Type {
case websocket.TextMessage:
multiStreamData := MultiStreamData{}

err := common.JSONDecode(read.Raw, &multiStreamData)
err = common.JSONDecode(read.Raw, &multiStreamData)
if err != nil {
b.Websocket.DataHandler <- fmt.Errorf("binance_websocket.go - Could not load multi stream data: %s",
string(read.Raw))
Expand Down
6 changes: 5 additions & 1 deletion exchanges/bitfinex/bitfinex.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (b *Bitfinex) SetDefaults() {
b.Verbose = false
b.RESTPollingDelay = 10
b.WebsocketSubdChannels = make(map[int]WebsocketChanInfo)
b.APIWithdrawPermissions = exchange.AutoWithdrawCryptoWithAPIPermission | exchange.AutoWithdrawFiatWithAPIPermission
b.APIWithdrawPermissions = exchange.AutoWithdrawCryptoWithAPIPermission |
exchange.AutoWithdrawFiatWithAPIPermission
b.RequestCurrencyPairFormat.Delimiter = ""
b.RequestCurrencyPairFormat.Uppercase = true
b.ConfigCurrencyPairFormat.Delimiter = ""
Expand All @@ -109,6 +110,9 @@ func (b *Bitfinex) SetDefaults() {
b.APIUrlDefault = bitfinexAPIURLBase
b.APIUrl = b.APIUrlDefault
b.WebsocketInit()
b.Websocket.Functionality = exchange.WebsocketTickerSupported |
exchange.WebsocketTradeDataSupported |
exchange.WebsocketOrderbookSupported
}

// Setup takes in the supplied exchange configuration details and sets params
Expand Down
47 changes: 20 additions & 27 deletions exchanges/bitfinex/bitfinex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,29 @@ func (b *Bitfinex) WsConnect() error {

pongReceive = make(chan struct{}, 1)

go b.WsReadData()
go b.WsDataHandler()

return nil
}

// WsReadData reads and handles websocket stream data
func (b *Bitfinex) WsReadData() {
func (b *Bitfinex) WsReadData() (exchange.WebsocketResponse, error) {
msgType, resp, err := b.WebsocketConn.ReadMessage()
if err != nil {
return exchange.WebsocketResponse{}, err
}

b.Websocket.TrafficAlert <- struct{}{}

return exchange.WebsocketResponse{
Type: msgType,
Raw: resp,
}, nil

}

// WsDataHandler handles data from WsReadData
func (b *Bitfinex) WsDataHandler() {
b.Websocket.Wg.Add(1)

defer func() {
Expand All @@ -210,35 +225,14 @@ func (b *Bitfinex) WsReadData() {
select {
case <-b.Websocket.ShutdownC:
return

default:
msgType, resp, err := b.WebsocketConn.ReadMessage()
stream, err := b.WsReadData()
if err != nil {
b.Websocket.DataHandler <- err
return
}

b.Websocket.TrafficAlert <- struct{}{}

b.Websocket.Intercomm <- exchange.WebsocketResponse{
Type: msgType,
Raw: resp,
}
}
}
}

// WsDataHandler handles data from WsReadData
func (b *Bitfinex) WsDataHandler() {
b.Websocket.Wg.Add(1)
defer b.Websocket.Wg.Done()

for {
select {
case <-b.Websocket.ShutdownC:
return

case stream := <-b.Websocket.Intercomm:

switch stream.Type {
case websocket.TextMessage:
var result interface{}
Expand Down Expand Up @@ -320,7 +314,6 @@ func (b *Bitfinex) WsDataHandler() {
b.Websocket.DataHandler <- fmt.Errorf("bitfinex_websocket.go inserting snapshot error: %s",
err)
}

continue
}

Expand Down Expand Up @@ -537,7 +530,7 @@ func (b *Bitfinex) WsInsertSnapshot(p pair.CurrencyPair, assetType string, books
newOrderbook.LastUpdated = time.Now()
newOrderbook.Pair = p

err := b.Websocket.Orderbook.LoadSnapshot(newOrderbook, b.GetName())
err := b.Websocket.Orderbook.LoadSnapshot(newOrderbook, b.GetName(), false)
if err != nil {
return fmt.Errorf("bitfinex.go error - %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion exchanges/bitflyer/bitflyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func (b *Bitflyer) SetDefaults() {
b.Enabled = false
b.Verbose = false
b.RESTPollingDelay = 10
b.APIWithdrawPermissions = exchange.WithdrawCryptoViaWebsiteOnly | exchange.AutoWithdrawFiat
b.APIWithdrawPermissions = exchange.WithdrawCryptoViaWebsiteOnly |
exchange.AutoWithdrawFiat
b.RequestCurrencyPairFormat.Delimiter = "_"
b.RequestCurrencyPairFormat.Uppercase = true
b.ConfigCurrencyPairFormat.Delimiter = "_"
Expand Down
3 changes: 2 additions & 1 deletion exchanges/bithumb/bithumb.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func (b *Bithumb) SetDefaults() {
b.Enabled = false
b.Verbose = false
b.RESTPollingDelay = 10
b.APIWithdrawPermissions = exchange.AutoWithdrawCrypto | exchange.AutoWithdrawFiat
b.APIWithdrawPermissions = exchange.AutoWithdrawCrypto |
exchange.AutoWithdrawFiat
b.RequestCurrencyPairFormat.Delimiter = ""
b.RequestCurrencyPairFormat.Uppercase = true
b.ConfigCurrencyPairFormat.Delimiter = ""
Expand Down
Loading

0 comments on commit 41415ca

Please sign in to comment.