mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 07:26:48 +00:00
* tag optional sonic and allow full library conversion * Add workflow and disallow arm and darwin usage * Add basic hotswap benchmark * linter: fix * use bash * linter: fix? * Fix whoopsie, add to make file, also add mention in features list. * test enforcement * actually read documentation see if this works * linter: fix * linter: fix * sonic: bump tagged version * encoding/json: drop build tag arch and os filters * encoding/json: consolidate tests * encoding/json: log build tag usage * rm superfluous builds * glorious/nits: add template change and regen docs * glorious/nits: update commentary on nolint directive * glorious/nits: rm init func and log results in main.go * Test to actually pull flag in * linter: fix * thrasher: nits * gk: nits 4 goflags goooooooooo! * gk: nits rn * make sonic default json implementation * screen 386 * linter: fix * Add commentary * glorious: nits Makefile not working * gk: nits * gk: nits whoops * whoopsirino * mention 32bit systems won't be sonic * gk: super-duper nit of extremes --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package alphapoint
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/websocket"
|
|
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
|
"github.com/thrasher-corp/gocryptotrader/log"
|
|
)
|
|
|
|
const (
|
|
alphapointDefaultWebsocketURL = "wss://sim3.alphapoint.com:8401/v1/GetTicker/"
|
|
)
|
|
|
|
// WebsocketClient starts a new webstocket connection
|
|
func (a *Alphapoint) WebsocketClient() {
|
|
for a.Enabled {
|
|
var dialer websocket.Dialer
|
|
var err error
|
|
var httpResp *http.Response
|
|
endpoint, err := a.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
|
if err != nil {
|
|
log.Errorln(log.WebsocketMgr, err)
|
|
}
|
|
a.WebsocketConn, httpResp, err = dialer.Dial(endpoint, http.Header{})
|
|
httpResp.Body.Close() // not used, so safely free the body
|
|
|
|
if err != nil {
|
|
log.Errorf(log.ExchangeSys, "%s Unable to connect to Websocket. Error: %s\n", a.Name, err)
|
|
continue
|
|
}
|
|
|
|
if a.Verbose {
|
|
log.Debugf(log.ExchangeSys, "%s Connected to Websocket.\n", a.Name)
|
|
}
|
|
|
|
err = a.WebsocketConn.WriteMessage(websocket.TextMessage, []byte(`{"messageType": "logon"}`))
|
|
|
|
if err != nil {
|
|
log.Errorln(log.ExchangeSys, err)
|
|
return
|
|
}
|
|
|
|
for a.Enabled {
|
|
msgType, resp, err := a.WebsocketConn.ReadMessage()
|
|
if err != nil {
|
|
log.Errorln(log.ExchangeSys, err)
|
|
break
|
|
}
|
|
|
|
if msgType == websocket.TextMessage {
|
|
type MsgType struct {
|
|
MessageType string `json:"messageType"`
|
|
}
|
|
|
|
msgType := MsgType{}
|
|
err := json.Unmarshal(resp, &msgType)
|
|
if err != nil {
|
|
log.Errorln(log.ExchangeSys, err)
|
|
continue
|
|
}
|
|
|
|
if msgType.MessageType == "Ticker" {
|
|
ticker := WebsocketTicker{}
|
|
err = json.Unmarshal(resp, &ticker)
|
|
if err != nil {
|
|
log.Errorln(log.ExchangeSys, err)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
a.WebsocketConn.Close()
|
|
log.Debugf(log.ExchangeSys, "%s Websocket client disconnected.", a.Name)
|
|
}
|
|
}
|