This commit is contained in:
Kevin Cotugno 2017-09-24 20:46:21 -07:00
parent 9102e5e34e
commit 406fb75d56

View File

@ -2,26 +2,44 @@ package main
import (
"github.com/kcotugno/tacitus"
"github.com/kcotugno/tacitus/websocket"
"github.com/kcotugno/tacitus/osutil"
"github.com/kcotugno/tacitus/postgres"
"github.com/kcotugno/tacitus/gdax"
"github.com/kcotugno/tacitus/gdax/websocket"
"log"
"time"
)
func main() {
logger := osutil.NewLogger()
c := websocket.NewClient()
err := c.Open()
ls := gdax.ListenerService{}
ls.Client = c
ls.Logger = logger
db := postgres.NewClient()
db.Name = "gdax"
db.User = "gdax"
db.SetLogger(logger)
err := db.Open()
if err != nil {
log.Panic(err)
}
err = ls.Open()
if err != nil {
log.Print(err)
}
req := tacitus.Request{Type: tacitus.Subscribe,
ProductIds: []string{"ETH-USD"}}
ls.Subscribe("ETH-USD", "BTC-USD")
time.Sleep(2 * time.Second)
c.Send(req)
time.Sleep(30 * time.Second)
for t := range ls.Stream() {
go func (trade tacitus.Trade) {
_, err := db.TradeService().CreateTrade(trade)
if err != nil {
logger.Info("Error inserting trade: %v", err)
}
}(t)
}
}