Move gdax message/request to new package

This commit is contained in:
Kevin Cotugno 2017-09-21 14:03:35 -07:00
parent a70168ce7e
commit f1a4e5730c
3 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,4 @@
package tacitus package gdax
import ( import (
"github.com/shopspring/decimal" "github.com/shopspring/decimal"

View File

@ -1,4 +1,4 @@
package tacitus package gdax
const Subscribe = RequestType("subscribe") const Subscribe = RequestType("subscribe")
const Unsubscribe = RequestType("unsubscribe") const Unsubscribe = RequestType("unsubscribe")

View File

@ -1,7 +1,7 @@
package websocket package websocket
import ( import (
"github.com/kcotugno/tacitus" "github.com/kcotugno/tacitus/gdax"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
@ -9,9 +9,9 @@ import (
const ENDPOINT = "wss://ws-feed.gdax.com" const ENDPOINT = "wss://ws-feed.gdax.com"
type Client struct { type Client struct {
msgs chan tacitus.Message msgs chan gdax.Message
err chan error err chan error
writer chan tacitus.Request writer chan gdax.Request
conn *websocket.Conn conn *websocket.Conn
connected bool connected bool
@ -20,9 +20,9 @@ type Client struct {
func NewClient() *Client { func NewClient() *Client {
c := Client{} c := Client{}
c.msgs = make(chan tacitus.Message, 1024) c.msgs = make(chan gdax.Message, 1024)
c.err = make(chan error) c.err = make(chan error)
c.writer = make(chan tacitus.Request) c.writer = make(chan gdax.Request)
c.close = make(chan bool) c.close = make(chan bool)
return &c return &c
@ -42,7 +42,7 @@ func (c *Client) Open() error {
select { select {
case <- c.close: case <- c.close:
default: default:
var msg tacitus.Message var msg gdax.Message
err := c.conn.ReadJSON(&msg) err := c.conn.ReadJSON(&msg)
if err != nil { if err != nil {
@ -78,13 +78,13 @@ func (c *Client) Close() {
c.conn.Close() c.conn.Close()
} }
func (c *Client) Send(msg tacitus.Request) { func (c *Client) Send(msg gdax.Request) {
if c.connected { if c.connected {
c.writer <- msg c.writer <- msg
} }
} }
func (c *Client) MessageStream() <- chan tacitus.Message { func (c *Client) MessageStream() <- chan gdax.Message {
return c.msgs return c.msgs
} }