Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/thrasher-/gocryptotrader:
  Fixes theme picker reference error after changes in https://github.com/thrasher-/gocryptotrader/pull/154
  Improved code quality (thrasher-corp#154)
  Improve request package and adjust bitfinex rate limiter
  Bump Travis golang version
  Update exchange wrapper template file
  Binance websocket (thrasher-corp#143)
  Adds support for new Huobi authorised requests and a tool for ecdsa keys
  Use WebsocketEvent in ws client and add timestamp to Tickers
  Fix race condition in request
  Bithumb replace deprecated API to new one
  Improve Bithumb API error handling
  Add bank details support
  Update README.md
  Skip BTCC tests as REST API is not available after infrastructure update
  Rename GDAX -> CoinbasePro
  Hotfix/web dependencies (thrasher-corp#149)
  Fixed some typos in binance types and updated binance trading symbols in config example (thrasher-corp#148)
  • Loading branch information
vyloy committed Jul 18, 2018
2 parents f7ded2a + 322b67e commit 68193dd
Show file tree
Hide file tree
Showing 109 changed files with 8,547 additions and 4,358 deletions.
51 changes: 30 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
language: go
matrix:
include:
- language: node_js
node_js:
- '10'
- '8'
- '6'
before_install:
- cd web/
install:
- npm install
script:
- npm run lint
- npm run build

go:
- 1.8.x
#- master

before_install:
- go get -t -v ./...

script:
- ./testdata/test.sh

install:
- go get github.com/gorilla/websocket
- go get github.com/toorop/go-pusher
- go get github.com/thrasher-/socketio
- go get github.com/beatgammit/turnpike
- go get github.com/gorilla/mux
- go get golang.org/x/crypto/scrypt

after_success:
- bash <(curl -s https://codecov.io/bash)
- language: go
go:
- 1.10.x
before_install:
- go get -t -v ./...
script:
- ./testdata/test.sh
install:
- go get github.com/gorilla/websocket
- go get github.com/toorop/go-pusher
- go get github.com/thrasher-/socketio
- go get github.com/beatgammit/turnpike
- go get github.com/gorilla/mux
- go get golang.org/x/crypto/scrypt
after_success:
- bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ tongxiaofeng | https://github.com/tongxiaofeng
idealhack | https://github.com/idealhack
askew- | https://github.com/askew-
snipesjr | https://github.com/snipesjr

marcofranssen | https://github.com/marcofranssen
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
FROM golang:1.9.4 as build
WORKDIR /go/src/github.com/thrasher-/gocryptotrader
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
WORKDIR /go/src/gocryptotrader
COPY Gopkg.* ./
RUN dep ensure -vendor-only
COPY . .
RUN mv -vn config_example.json config.json \
&& go get -v -d \
&& GOARCH=386 GOOS=linux CGO_ENABLED=0 go install -v \
&& mv /go/bin/linux_386 /go/bin/gocryptotrader

FROM alpine:latest
RUN apk update && apk add --no-cache ca-certificates
COPY --from=build /go/bin/gocryptotrader /app/
COPY --from=build /go/src/github.com/thrasher-/gocryptotrader/config.json /app/
COPY --from=build /go/src/gocryptotrader/config.json /app/
EXPOSE 9050
CMD ["/app/gocryptotrader"]
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
|----------|------|-----------|-----|
| Alphapoint | Yes | Yes | NA |
| ANXPRO | Yes | No | NA |
| Binance| Yes | No | NA |
| Binance| Yes | Yes | NA |
| Bitfinex | Yes | Yes | NA |
| Bitflyer | Yes | No | NA |
| Bithumb | Yes | NA | NA |
Expand All @@ -30,7 +30,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
| BTCMarkets | Yes | No | NA |
| COINUT | Yes | No | NA |
| Exmo | Yes | NA | NA |
| GDAX(Coinbase) | Yes | Yes | No|
| CoinbasePro | Yes | Yes | No|
| Gemini | Yes | No | No |
| HitBTC | Yes | Yes | No |
| Huobi.Pro | Yes | No |No |
Expand All @@ -53,13 +53,15 @@ We are aiming to support the top 20 highest volume exchanges based off the [Coin
## Current Features

+ Support for all Exchange fiat and digital currencies, with the ability to individually toggle them on/off.
+ AES encrypted config file.
+ AES256 encrypted config file.
+ REST API support for all exchanges.
+ Websocket support for applicable exchanges.
+ Ability to turn off/on certain exchanges.
+ Ability to adjust manual polling timer for exchanges.
+ SMS notification support via SMS Gateway.
+ Packages for handling currency pairs, ticker/orderbook fetching and currency conversion.
+ Communication packages (Slack, SMS via SMSGlobal, Telegram and SMTP)
+ HTTP rate limiter package.
+ Forex currency converter packages (CurrencyConverterAPI, CurrencyLayer, Fixer.io, OpenExchangeRates)
+ Packages for handling currency pairs, tickers and orderbooks.
+ Portfolio management tool; fetches balances from supported exchanges and allows for custom address tracking.
+ Basic event trigger system.
+ WebGUI.
Expand Down Expand Up @@ -142,19 +144,23 @@ Binaries will be published once the codebase reaches a stable condition.

|User|Github|Contribution Amount|
|--|--|--|
| thrasher- | https://github.com/thrasher- | 434 |
| shazbert | https://github.com/shazbert | 132 |
| gloriousCode | https://github.com/gloriousCode | 116 |
| thrasher- | https://github.com/thrasher- | 442 |
| shazbert | https://github.com/shazbert | 139 |
| gloriousCode | https://github.com/gloriousCode | 121 |
| 140am | https://github.com/140am | 8 |
| Betazoid | https://github.com/Betazoid | 4 |
| marcofranssen | https://github.com/marcofranssen | 3 |
| crackcomm | https://github.com/crackcomm | 3 |
| bretep | https://github.com/bretep | 2 |
| ermalguni | https://github.com/ermalguni | 2 |
| gam-phon | https://github.com/gam-phon | 2 |
| cornelk | https://github.com/cornelk | 2 |
| if1live | https://github.com/if1live | 2 |
| daniel-cohen | https://github.com/daniel-cohen | 1 |
| frankzougc | https://github.com/frankzougc | 1 |
| starit | https://github.com/starit | 1 |
| Jimexist | https://github.com/Jimexist | 1 |
| lookfirst | https://github.com/lookfirst | 1 |
| zeldrinn | https://github.com/zeldrinn | 1 |
| mattkanwisher | https://github.com/mattkanwisher | 1 |
| mKurrels | https://github.com/mKurrels | 1 |
Expand All @@ -163,6 +169,7 @@ Binaries will be published once the codebase reaches a stable condition.
| tongxiaofeng | https://github.com/tongxiaofeng | 1 |
| idealhack | https://github.com/idealhack | 1 |
| askew- | https://github.com/askew- | 1 |
| whilei | https://github.com/whilei | 1 |
| snipesjr | https://github.com/snipesjr | 1 |


Expand Down
2 changes: 1 addition & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func initialiseHTTPClient() {
}
}

// NewHTTPClientWithTimeout initalises a new HTTP client with the specified
// NewHTTPClientWithTimeout initialises a new HTTP client with the specified
// timeout duration
func NewHTTPClientWithTimeout(t time.Duration) *http.Client {
h := &http.Client{Timeout: t}
Expand Down
6 changes: 3 additions & 3 deletions common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,9 @@ func TestGetURIPath(t *testing.T) {
t.Parallel()
// mapping of input vs expected result
testTable := map[string]string{
"https://api.gdax.com/accounts": "/accounts",
"https://api.gdax.com/accounts?a=1&b=2": "/accounts?a=1&b=2",
"http://www.google.com/accounts?!@#$%;^^": "",
"https://api.pro.coinbase.com/accounts": "/accounts",
"https://api.pro.coinbase.com/accounts?a=1&b=2": "/accounts?a=1&b=2",
"http://www.google.com/accounts?!@#$%;^^": "",
}
for testInput, expectedOutput := range testTable {
actualOutput := GetURIPath(testInput)
Expand Down
133 changes: 82 additions & 51 deletions communications/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type Slack struct {
}

// Setup takes in a slack configuration, sets bots target channel and
// sets verfication token to access workspace
// sets verification token to access workspace
func (s *Slack) Setup(config config.CommunicationsConfig) {
s.Name = config.SlackConfig.Name
s.Enabled = config.SlackConfig.Enabled
Expand Down Expand Up @@ -213,82 +213,113 @@ func (s *Slack) WebsocketReader() {
switch data.Type {

case "error":
if data.Error.Msg == "Socket URL has expired" {
if s.Verbose {
log.Println("Slack websocket URL has expired.. Reconnecting")
}
if err = s.WebsocketConn.Close(); err != nil {
log.Println(err)
}
s.ReconnectURL = ""
s.Connected = false
if err := s.NewConnection(); err != nil {
log.Fatal(err)
}
return
}
s.handleErrorResponse(data)

case "hello":
if s.Verbose {
log.Println("Websocket connected successfully.")
}
s.Connected = true
go s.WebsocketKeepAlive()
s.handleHelloResponse(data)

case "reconnect_url":
type reconnectResponse struct {
URL string `json:"url"`
}
var recURL reconnectResponse
err = common.JSONDecode(resp, &recURL)
err = s.handleReconnectResponse(resp)
if err != nil {
continue
}
s.ReconnectURL = recURL.URL
if s.Verbose {
log.Printf("Reconnect URL set to %s\n", s.ReconnectURL)
}

case "presence_change":
var pres PresenceChange
err = common.JSONDecode(resp, &pres)
err = s.handlePresenceChange(resp)
if err != nil {
continue
}
if s.Verbose {
log.Printf("Presence change. User %s [%s] changed status to %s\n",
s.GetUsernameByID(pres.User),
pres.User, pres.Presence)
}

case "message":
if data.ReplyTo != 0 {
continue
}
var msg Message
err = common.JSONDecode(resp, &msg)
err = s.handleMessageResponse(resp, data)
if err != nil {
continue
}
if s.Verbose {
log.Printf("Msg received by %s [%s] with text: %s\n",
s.GetUsernameByID(msg.User),
msg.User, msg.Text)
}
if string(msg.Text[0]) == "!" {
s.HandleMessage(msg)
}

case "pong":
if s.Verbose {
log.Println("Pong recieved from server")
log.Println("Pong received from server")
}
default:
log.Println(string(resp))
}
}
}

func (s *Slack) handlePresenceChange(resp []byte) error {
var pres PresenceChange
err := common.JSONDecode(resp, &pres)
if err != nil {
return err
}
if s.Verbose {
log.Printf("Presence change. User %s [%s] changed status to %s\n",
s.GetUsernameByID(pres.User),
pres.User, pres.Presence)
}
return nil
}

func (s *Slack) handleMessageResponse(resp []byte, data WebsocketResponse) error {
if data.ReplyTo != 0 {
return fmt.Errorf("ReplyTo != 0")
}
var msg Message
err := common.JSONDecode(resp, &msg)
if err != nil {
return err
}
if s.Verbose {
log.Printf("Msg received by %s [%s] with text: %s\n",
s.GetUsernameByID(msg.User),
msg.User, msg.Text)
}
if string(msg.Text[0]) == "!" {
s.HandleMessage(msg)
}
return nil
}
func (s *Slack) handleErrorResponse(data WebsocketResponse) {
if data.Error.Msg == "Socket URL has expired" {
if s.Verbose {
log.Println("Slack websocket URL has expired.. Reconnecting")
}
if err := s.WebsocketConn.Close(); err != nil {
log.Println(err)
}
s.ReconnectURL = ""
s.Connected = false
if err := s.NewConnection(); err != nil {
log.Fatal(err)
}
return
}
}

func (s *Slack) handleHelloResponse(data WebsocketResponse) {
if s.Verbose {
log.Println("Websocket connected successfully.")
}
s.Connected = true
go s.WebsocketKeepAlive()
}

func (s *Slack) handleReconnectResponse(resp []byte) error {
type reconnectResponse struct {
URL string `json:"url"`
}
var recURL reconnectResponse
err := common.JSONDecode(resp, &recURL)
if err != nil {
return err
}
s.ReconnectURL = recURL.URL
if s.Verbose {
log.Printf("Reconnect URL set to %s\n", s.ReconnectURL)
}
return nil
}

// WebsocketKeepAlive sends a ping every 5 minutes to keep connection alive
func (s *Slack) WebsocketKeepAlive() {
ticker := time.NewTicker(5 * time.Minute)
Expand Down Expand Up @@ -319,7 +350,7 @@ func (s *Slack) WebsocketSend(eventType, text string) error {
}

// HandleMessage handles incoming messages and/or commands from slack
func (s Slack) HandleMessage(msg Message) {
func (s *Slack) HandleMessage(msg Message) {
switch {
case common.StringContains(msg.Text, cmdStatus):
s.WebsocketSend("message", s.GetStatus())
Expand Down
Loading

0 comments on commit 68193dd

Please sign in to comment.