Skip to content

Commit f777918

Browse files
buck54321chappjc
authored andcommitted
exchanges: add bittrex websocket support
Bittrex uses a SignalR wrapper for its websocket, so a library is used for the SignalR connection. Much of the websocket implementation from Poloniex exchange is re-used, including some types and methods being elevated to a common type or CommonExchange method.
1 parent 4ee1782 commit f777918

8 files changed

Lines changed: 894 additions & 162 deletions

File tree

‎dcrrates/rateserver/go.sum‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
33
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
44
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
5+
github.com/carterjones/go-cloudflare-scraper v0.1.2 h1:GNmlJEfhIVPVXaEItnPSDtwOpuJo6rFH2SFWuAjeEuM=
6+
github.com/carterjones/go-cloudflare-scraper v0.1.2/go.mod h1:maO/ygX7QWbdh/TzHqr5uR42b2BW81g/05QRx7fpw38=
7+
github.com/carterjones/signalr v0.3.5 h1:kJSw+6a9XmsOb/+9HWTnY8SjTrVOdpzCSPV/9IVS2nI=
8+
github.com/carterjones/signalr v0.3.5/go.mod h1:SOGIwr/0/4GGNjHWSSginY66OVSaOeM85yWCNytdEwE=
59
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
610
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
711
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -35,6 +39,7 @@ github.com/decred/dcrd/wire v1.2.0 h1:HqJVB7vcklIguzFWgRXw/WYCQ9cD3bUC5TKj53i1Hn
3539
github.com/decred/dcrd/wire v1.2.0/go.mod h1:/JKOsLInOJu6InN+/zH5AyCq3YDIOW/EqcffvU8fJHM=
3640
github.com/decred/slog v1.0.0 h1:Dl+W8O6/JH6n2xIFN2p3DNjCmjYwvrXsjlSJTQQ4MhE=
3741
github.com/decred/slog v1.0.0/go.mod h1:zR98rEZHSnbZ4WHZtO0iqmSZjDLKhkXfrPTZQKtAonQ=
42+
github.com/elazarl/goproxy v0.0.0-20181111060418-2ce16c963a8a/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
3843
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
3944
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
4045
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -51,6 +56,10 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS
5156
github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI=
5257
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
5358
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
59+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
60+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
61+
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d h1:1VUlQbCfkoSGv7qP7Y+ro3ap1P1pPZxgdGVqiTVy5C4=
62+
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY=
5463
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
5564
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
5665
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -96,4 +105,6 @@ google.golang.org/grpc v1.19.1 h1:TrBcJ1yqAl1G++wO39nD/qtgpsW9/1+QGrluyMGEYgM=
96105
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
97106
google.golang.org/grpc v1.20.0 h1:DlsSIrgEBuZAUFJcta2B5i/lzeHHbnfkNFAfFXLVFYQ=
98107
google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
108+
gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI=
109+
gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
99110
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

‎exchanges/bot.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ func (bot *ExchangeBot) StateBytes() []byte {
625625
return bot.currentStateBytes
626626
}
627627

628-
func (bot *ExchangeBot) jsonify(thing interface{}) ([]byte, error) {
628+
// Encodes the thing as JSON, with indentation if configured.
629+
func (bot *ExchangeBot) encodeJSON(thing interface{}) ([]byte, error) {
629630
if bot.config.Indent {
630631
return json.MarshalIndent(thing, "", " ")
631632
}
@@ -639,7 +640,7 @@ func (bot *ExchangeBot) ConvertedStateBytes(symbol string) ([]byte, error) {
639640
if err != nil {
640641
return nil, err
641642
}
642-
return bot.jsonify(state)
643+
return bot.encodeJSON(state)
643644
}
644645

645646
// AvailableIndices creates a fresh slice of all available index currency codes.
@@ -912,7 +913,7 @@ func (bot *ExchangeBot) QuickSticks(token string, rawBin string) ([]byte, error)
912913

913914
expiration := sticks[len(sticks)-1].Start.Add(2 * bin.duration())
914915

915-
chart, err := bot.jsonify(&candlestickResponse{
916+
chart, err := bot.encodeJSON(&candlestickResponse{
916917
BtcIndex: bot.BtcIndex,
917918
Price: bot.currentState.Price,
918919
Sticks: sticks,
@@ -1038,7 +1039,7 @@ func (bot *ExchangeBot) QuickDepth(token string) (chart []byte, err error) {
10381039
if agDepth == nil {
10391040
return nil, fmt.Errorf("Failed to find depth for %s", token)
10401041
}
1041-
chart, err = bot.jsonify(agDepth)
1042+
chart, err = bot.encodeJSON(agDepth)
10421043
} else {
10431044
bot.mtx.Lock()
10441045
defer bot.mtx.Unlock()
@@ -1049,7 +1050,7 @@ func (bot *ExchangeBot) QuickDepth(token string) (chart []byte, err error) {
10491050
if xcState.Depth == nil {
10501051
return nil, fmt.Errorf("Failed to find depth for %s", token)
10511052
}
1052-
chart, err = bot.jsonify(&depthResponse{
1053+
chart, err = bot.encodeJSON(&depthResponse{
10531054
BtcIndex: bot.BtcIndex,
10541055
Price: bot.currentState.Price,
10551056
Data: xcState.Depth,

0 commit comments

Comments
 (0)
⌂ 换网址