mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-18 07:26:50 +00:00
Engine: Dispatch service (#346)
* Added dispatch service * Added orderbook streaming capabilities * Assigned correct orderbook.base exchange name * Fixed Requested niterinos Add in cli orderbook QA tool to gctcli Add exchange orderbook streaming * Add ticker streaming support through dispatch package * Added in some more info on error returns for orderbook.go * fix linter issues * Fix some issues * Update * Fix requested * move dispatch out of exchanges folder to its own independant folder * Fix requested * change orderbook string to tickers * Limit orderbooks to 50 and made dispatch system more stateless in operation * lower cases for update/retrieve/sub exchange name * Adds in asset validation and lower case conversion on cli * Remove comment * Moved timer to a higher scope so its not constantly initialised just reset per instance and removed returning unused channel on error * Rm unused release function in dispatch.go Reset timer and bleed buffered timer chan if needed in dispatch.go Added in ticker.Stop() and timer.Stop() functions for worker routine return in dispatch.go Index aggregated bid and ask functions for orderbook.go Added in dummy slice for wsorderbook_test.go * Moved drain to above Reset so potential race would not occur in dispatch.go Fix various linter issues dispatch.go * Fix some issues * change to start/stop service, added in service state change via cli, updated logger * fix requested * Add worker amount init spawning * fix linter issues * Fix more linter issues * More fixes * Fix race issue on releasing pipe channel on a close after shutting down dispatcher system * Moved all types to dispatch_types.go && remove panic * Moved types into serperate file && improve test coverage * RM unnecessary select case for draining channel && fixed error string * Added orderbook_types file and improved code coverage * gofmt file * reinstated select cases on drain because I am silly * Remove error for drop worker * Added more test cases * not checking error issue fix * remove func causing race in test, this has required protection via an exported function * set Gemini websocket orderbook exchange name
This commit is contained in:
committed by
Adrian Gallagher
parent
4a0fcc7f0f
commit
db317a2447
@@ -4,7 +4,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
@@ -544,6 +548,11 @@ func getTicker(c *cli.Context) error {
|
||||
assetType = c.Args().Get(2)
|
||||
}
|
||||
|
||||
assetType = strings.ToLower(assetType)
|
||||
if !validAsset(assetType) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -652,6 +661,11 @@ func getOrderbook(c *cli.Context) error {
|
||||
assetType = c.Args().Get(2)
|
||||
}
|
||||
|
||||
assetType = strings.ToLower(assetType)
|
||||
if !validAsset(assetType) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1066,6 +1080,11 @@ func getOrders(c *cli.Context) error {
|
||||
assetType = c.Args().Get(1)
|
||||
}
|
||||
|
||||
assetType = strings.ToLower(assetType)
|
||||
if !validAsset(assetType) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
if c.IsSet("pair") {
|
||||
currencyPair = c.String("pair")
|
||||
} else {
|
||||
@@ -1559,6 +1578,11 @@ func cancelOrder(c *cli.Context) error {
|
||||
assetType = c.String("asset_type")
|
||||
}
|
||||
|
||||
assetType = strings.ToLower(assetType)
|
||||
if !validAsset(assetType) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
if c.IsSet("wallet_address") {
|
||||
walletAddress = c.String("wallet_address")
|
||||
}
|
||||
@@ -1782,6 +1806,11 @@ func addEvent(c *cli.Context) error {
|
||||
assetType = c.String("asset_type")
|
||||
}
|
||||
|
||||
assetType = strings.ToLower(assetType)
|
||||
if !validAsset(assetType) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
if c.IsSet("action") {
|
||||
action = c.String("action")
|
||||
} else {
|
||||
@@ -2172,6 +2201,11 @@ func getExchangePairs(c *cli.Context) error {
|
||||
asset = c.Args().Get(1)
|
||||
}
|
||||
|
||||
asset = strings.ToLower(asset)
|
||||
if !validAsset(asset) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -2249,6 +2283,11 @@ func enableExchangePair(c *cli.Context) error {
|
||||
asset = c.Args().Get(2)
|
||||
}
|
||||
|
||||
asset = strings.ToLower(asset)
|
||||
if !validAsset(asset) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -2332,6 +2371,11 @@ func disableExchangePair(c *cli.Context) error {
|
||||
asset = c.Args().Get(2)
|
||||
}
|
||||
|
||||
asset = strings.ToLower(asset)
|
||||
if !validAsset(asset) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -2357,3 +2401,407 @@ func disableExchangePair(c *cli.Context) error {
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
var getOrderbookStreamCommand = cli.Command{
|
||||
Name: "getorderbookstream",
|
||||
Usage: "gets the orderbook stream for a specific currency pair and exchange",
|
||||
ArgsUsage: "<exchange> <currencyPair> <asset>",
|
||||
Action: getOrderbookStream,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "the exchange to get the orderbook from",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "pair",
|
||||
Usage: "currency pair",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "asset",
|
||||
Usage: "the asset type of the currency pair",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func getOrderbookStream(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowCommandHelp(c, "getorderbookstream")
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchangeName string
|
||||
var pair string
|
||||
var assetType string
|
||||
|
||||
if c.IsSet("exchange") {
|
||||
exchangeName = c.String("exchange")
|
||||
} else {
|
||||
exchangeName = c.Args().First()
|
||||
}
|
||||
|
||||
if !validExchange(exchangeName) {
|
||||
return errInvalidExchange
|
||||
}
|
||||
|
||||
if c.IsSet("pair") {
|
||||
pair = c.String("pair")
|
||||
} else {
|
||||
pair = c.Args().Get(1)
|
||||
}
|
||||
|
||||
if !validPair(pair) {
|
||||
return errInvalidPair
|
||||
}
|
||||
|
||||
if c.IsSet("asset") {
|
||||
assetType = c.String("asset")
|
||||
} else {
|
||||
assetType = c.Args().Get(2)
|
||||
}
|
||||
|
||||
assetType = strings.ToLower(assetType)
|
||||
|
||||
if !validAsset(assetType) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
p := currency.NewPairDelimiter(pair, pairDelimiter)
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.GetOrderbookStream(context.Background(),
|
||||
&gctrpc.GetOrderbookStreamRequest{
|
||||
Exchange: exchangeName,
|
||||
Pair: &gctrpc.CurrencyPair{
|
||||
Base: p.Base.String(),
|
||||
Quote: p.Quote.String(),
|
||||
Delimiter: p.Delimiter,
|
||||
},
|
||||
AssetType: assetType,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
resp, err := result.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = clearScreen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Orderbook stream for %s %s:\n\n", exchangeName,
|
||||
resp.Pair.String())
|
||||
fmt.Println("\t\tBids\t\t\t\tAsks")
|
||||
fmt.Println()
|
||||
|
||||
bidLen := len(resp.Bids) - 1
|
||||
askLen := len(resp.Asks) - 1
|
||||
|
||||
var maxLen int
|
||||
if bidLen >= askLen {
|
||||
maxLen = bidLen
|
||||
} else {
|
||||
maxLen = askLen
|
||||
}
|
||||
|
||||
for i := 0; i < maxLen; i++ {
|
||||
var bidAmount, bidPrice float64
|
||||
if i <= bidLen {
|
||||
bidAmount = resp.Bids[i].Amount
|
||||
bidPrice = resp.Bids[i].Price
|
||||
}
|
||||
|
||||
var askAmount, askPrice float64
|
||||
if i <= askLen {
|
||||
askAmount = resp.Asks[i].Amount
|
||||
askPrice = resp.Asks[i].Price
|
||||
}
|
||||
|
||||
fmt.Printf("%f %s @ %f %s\t\t%f %s @ %f %s\n",
|
||||
bidAmount,
|
||||
resp.Pair.Base,
|
||||
bidPrice,
|
||||
resp.Pair.Quote,
|
||||
askAmount,
|
||||
resp.Pair.Base,
|
||||
askPrice,
|
||||
resp.Pair.Quote)
|
||||
|
||||
if i >= 49 {
|
||||
// limits orderbook display output
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var getExchangeOrderbookStreamCommand = cli.Command{
|
||||
Name: "getexchangeorderbookstream",
|
||||
Usage: "gets a stream for all orderbooks associated with an exchange",
|
||||
ArgsUsage: "<exchange>",
|
||||
Action: getExchangeOrderbookStream,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "the exchange to get the orderbook from",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func getExchangeOrderbookStream(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowCommandHelp(c, "getexchangeorderbookstream")
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchangeName string
|
||||
if c.IsSet("exchange") {
|
||||
exchangeName = c.String("exchange")
|
||||
} else {
|
||||
exchangeName = c.Args().First()
|
||||
}
|
||||
|
||||
if !validExchange(exchangeName) {
|
||||
return errInvalidExchange
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.GetExchangeOrderbookStream(context.Background(),
|
||||
&gctrpc.GetExchangeOrderbookStreamRequest{
|
||||
Exchange: exchangeName,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
resp, err := result.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = clearScreen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Orderbook streamed for %s %s",
|
||||
exchangeName,
|
||||
resp.Pair.String())
|
||||
}
|
||||
}
|
||||
|
||||
var getTickerStreamCommand = cli.Command{
|
||||
Name: "gettickerstream",
|
||||
Usage: "gets the ticker stream for a specific currency pair and exchange",
|
||||
ArgsUsage: "<exchange> <currencyPair> <asset>",
|
||||
Action: getTickerStream,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "the exchange to get the ticker from",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "pair",
|
||||
Usage: "currency pair",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "asset",
|
||||
Usage: "the asset type of the currency pair",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func getTickerStream(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowCommandHelp(c, "gettickerstream")
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchangeName string
|
||||
var pair string
|
||||
var assetType string
|
||||
|
||||
if c.IsSet("exchange") {
|
||||
exchangeName = c.String("exchange")
|
||||
} else {
|
||||
exchangeName = c.Args().First()
|
||||
}
|
||||
|
||||
if !validExchange(exchangeName) {
|
||||
return errInvalidExchange
|
||||
}
|
||||
|
||||
if c.IsSet("pair") {
|
||||
pair = c.String("pair")
|
||||
} else {
|
||||
pair = c.Args().Get(1)
|
||||
}
|
||||
|
||||
if !validPair(pair) {
|
||||
return errInvalidPair
|
||||
}
|
||||
|
||||
if c.IsSet("asset") {
|
||||
assetType = c.String("asset")
|
||||
} else {
|
||||
assetType = c.Args().Get(2)
|
||||
}
|
||||
|
||||
assetType = strings.ToLower(assetType)
|
||||
|
||||
if !validAsset(assetType) {
|
||||
return errInvalidAsset
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
p := currency.NewPairDelimiter(pair, pairDelimiter)
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.GetTickerStream(context.Background(),
|
||||
&gctrpc.GetTickerStreamRequest{
|
||||
Exchange: exchangeName,
|
||||
Pair: &gctrpc.CurrencyPair{
|
||||
Base: p.Base.String(),
|
||||
Quote: p.Quote.String(),
|
||||
Delimiter: p.Delimiter,
|
||||
},
|
||||
AssetType: assetType,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
resp, err := result.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = clearScreen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Ticker stream for %s %s:\n", exchangeName,
|
||||
resp.Pair.String())
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("LAST: %f\n HIGH: %f\n LOW: %f\n BID: %f\n ASK: %f\n VOLUME: %f\n PRICEATH: %f\n LASTUPDATED: %d\n",
|
||||
resp.Last,
|
||||
resp.High,
|
||||
resp.Low,
|
||||
resp.Bid,
|
||||
resp.Ask,
|
||||
resp.Volume,
|
||||
resp.PriceAth,
|
||||
resp.LastUpdated)
|
||||
}
|
||||
}
|
||||
|
||||
var getExchangeTickerStreamCommand = cli.Command{
|
||||
Name: "getexchangetickerstream",
|
||||
Usage: "gets a stream for all tickers associated with an exchange",
|
||||
ArgsUsage: "<exchange>",
|
||||
Action: getExchangeTickerStream,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "the exchange to get the ticker from",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func getExchangeTickerStream(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowCommandHelp(c, "getexchangetickerstream")
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchangeName string
|
||||
if c.IsSet("exchange") {
|
||||
exchangeName = c.String("exchange")
|
||||
} else {
|
||||
exchangeName = c.Args().First()
|
||||
}
|
||||
|
||||
if !validExchange(exchangeName) {
|
||||
return errInvalidExchange
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.GetExchangeTickerStream(context.Background(),
|
||||
&gctrpc.GetExchangeTickerStreamRequest{
|
||||
Exchange: exchangeName,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
resp, err := result.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Ticker stream for %s %s:\n",
|
||||
exchangeName,
|
||||
resp.Pair.String())
|
||||
|
||||
fmt.Printf("LAST: %f HIGH: %f LOW: %f BID: %f ASK: %f VOLUME: %f PRICEATH: %f LASTUPDATED: %d\n",
|
||||
resp.Last,
|
||||
resp.High,
|
||||
resp.Low,
|
||||
resp.Bid,
|
||||
resp.Ask,
|
||||
resp.Volume,
|
||||
resp.PriceAth,
|
||||
resp.LastUpdated)
|
||||
}
|
||||
}
|
||||
|
||||
func clearScreen() error {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
cmd := exec.Command("cmd", "/c", "cls")
|
||||
cmd.Stdout = os.Stdout
|
||||
return cmd.Run()
|
||||
default:
|
||||
cmd := exec.Command("clear")
|
||||
cmd.Stdout = os.Stdout
|
||||
return cmd.Run()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,10 @@ func main() {
|
||||
getExchangePairsCommand,
|
||||
enableExchangePairCommand,
|
||||
disableExchangePairCommand,
|
||||
getOrderbookStreamCommand,
|
||||
getExchangeOrderbookStreamCommand,
|
||||
getTickerStreamCommand,
|
||||
getExchangeTickerStreamCommand,
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
|
||||
@@ -5,11 +5,13 @@ import (
|
||||
"strings"
|
||||
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidPair = errors.New("invalid currency pair supplied")
|
||||
errInvalidExchange = errors.New("invalid exchange supplied")
|
||||
errInvalidAsset = errors.New("invalid asset supplied")
|
||||
)
|
||||
|
||||
func validPair(pair string) bool {
|
||||
@@ -19,3 +21,7 @@ func validPair(pair string) bool {
|
||||
func validExchange(exch string) bool {
|
||||
return exchange.IsSupported(exch)
|
||||
}
|
||||
|
||||
func validAsset(i string) bool {
|
||||
return asset.IsValid(asset.Item(i))
|
||||
}
|
||||
|
||||
357
dispatch/dispatch.go
Normal file
357
dispatch/dispatch.go
Normal file
@@ -0,0 +1,357 @@
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
func init() {
|
||||
dispatcher = &Dispatcher{
|
||||
routes: make(map[uuid.UUID][]chan interface{}),
|
||||
jobs: make(chan *job, DefaultJobBuffer),
|
||||
outbound: sync.Pool{
|
||||
New: func() interface{} {
|
||||
// Create unbuffered channel for data pass
|
||||
return make(chan interface{})
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Start starts the dispatch system by spawning workers and allocating memory
|
||||
func Start(workers int64) error {
|
||||
if dispatcher == nil {
|
||||
return errors.New(errNotInitialised)
|
||||
}
|
||||
|
||||
mtx.Lock()
|
||||
defer mtx.Unlock()
|
||||
return dispatcher.start(workers)
|
||||
}
|
||||
|
||||
// Stop attempts to stop the dispatch service, this will close all pipe channels
|
||||
// flush job list and drop all workers
|
||||
func Stop() error {
|
||||
if dispatcher == nil {
|
||||
return errors.New(errNotInitialised)
|
||||
}
|
||||
|
||||
log.Debugln(log.DispatchMgr, "Dispatch manager shutting down...")
|
||||
|
||||
mtx.Lock()
|
||||
defer mtx.Unlock()
|
||||
return dispatcher.stop()
|
||||
}
|
||||
|
||||
// IsRunning checks to see if the dispatch service is running
|
||||
func IsRunning() bool {
|
||||
if dispatcher == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return dispatcher.isRunning()
|
||||
}
|
||||
|
||||
// DropWorker drops a worker routine
|
||||
func DropWorker() error {
|
||||
if dispatcher == nil {
|
||||
return errors.New(errNotInitialised)
|
||||
}
|
||||
|
||||
dispatcher.dropWorker()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SpawnWorker starts a new worker routine
|
||||
func SpawnWorker() error {
|
||||
if dispatcher == nil {
|
||||
return errors.New(errNotInitialised)
|
||||
}
|
||||
return dispatcher.spawnWorker()
|
||||
}
|
||||
|
||||
// start compares atomic running value, sets defaults, overides with
|
||||
// configuration, then spawns workers
|
||||
func (d *Dispatcher) start(workers int64) error {
|
||||
if atomic.LoadUint32(&d.running) == 1 {
|
||||
return errors.New(errAlreadyStarted)
|
||||
}
|
||||
|
||||
if workers < 1 {
|
||||
log.Warn(log.DispatchMgr,
|
||||
"Dispatcher: workers cannot be zero using default values")
|
||||
workers = DefaultMaxWorkers
|
||||
}
|
||||
|
||||
d.maxWorkers = workers
|
||||
d.shutdown = make(chan *sync.WaitGroup)
|
||||
|
||||
if atomic.LoadInt64(&d.count) != 0 {
|
||||
return errors.New("dispatcher leaked workers found")
|
||||
}
|
||||
|
||||
for i := int64(0); i < d.maxWorkers; i++ {
|
||||
err := d.spawnWorker()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
atomic.SwapUint32(&d.running, 1)
|
||||
return nil
|
||||
}
|
||||
|
||||
// stop stops the service and shuts down all worker routines
|
||||
func (d *Dispatcher) stop() error {
|
||||
if !atomic.CompareAndSwapUint32(&d.running, 1, 0) {
|
||||
return errors.New(errCannotShutdown)
|
||||
}
|
||||
close(d.shutdown)
|
||||
ch := make(chan struct{})
|
||||
timer := time.NewTimer(1 * time.Second)
|
||||
defer func() {
|
||||
if !timer.Stop() {
|
||||
select {
|
||||
case <-timer.C:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}()
|
||||
go func(ch chan struct{}) { d.wg.Wait(); ch <- struct{}{} }(ch)
|
||||
select {
|
||||
case <-ch:
|
||||
// close all routes
|
||||
for key := range d.routes {
|
||||
for i := range d.routes[key] {
|
||||
close(d.routes[key][i])
|
||||
}
|
||||
|
||||
d.routes[key] = nil
|
||||
}
|
||||
|
||||
for len(d.jobs) != 0 { // drain jobs channel for old data
|
||||
<-d.jobs
|
||||
}
|
||||
|
||||
log.Debugln(log.DispatchMgr, "Dispatch manager shutdown.")
|
||||
|
||||
return nil
|
||||
case <-timer.C:
|
||||
return errors.New(errShutdownRoutines)
|
||||
}
|
||||
}
|
||||
|
||||
// isRunning returns if the dispatch system is running
|
||||
func (d *Dispatcher) isRunning() bool {
|
||||
return atomic.LoadUint32(&d.running) == 1
|
||||
}
|
||||
|
||||
// dropWorker deallocates a worker routine
|
||||
func (d *Dispatcher) dropWorker() {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
d.shutdown <- &wg
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// spawnWorker allocates a new worker for job processing
|
||||
func (d *Dispatcher) spawnWorker() error {
|
||||
if atomic.LoadInt64(&d.count) >= d.maxWorkers {
|
||||
return errors.New("dispatcher cannot spawn more workers; ceiling reached")
|
||||
}
|
||||
var spawnWg sync.WaitGroup
|
||||
spawnWg.Add(1)
|
||||
go d.relayer(&spawnWg)
|
||||
spawnWg.Wait()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Relayer routine relays communications across the defined routes
|
||||
func (d *Dispatcher) relayer(i *sync.WaitGroup) {
|
||||
atomic.AddInt64(&d.count, 1)
|
||||
d.wg.Add(1)
|
||||
timeout := time.NewTimer(0)
|
||||
i.Done()
|
||||
for {
|
||||
select {
|
||||
case j := <-d.jobs:
|
||||
d.rMtx.RLock()
|
||||
if _, ok := d.routes[j.ID]; !ok {
|
||||
d.rMtx.RUnlock()
|
||||
continue
|
||||
}
|
||||
// Channel handshake timeout feature if a channel is blocked for any
|
||||
// period of time due to an issue with the receiving routine.
|
||||
// This will wait on channel then fall over to the next route when
|
||||
// the timer actuates and continue over the route list. Have to
|
||||
// iterate across full length of routes so every routine can get
|
||||
// their new info, cannot be buffered as we dont want to have an old
|
||||
// orderbook etc contained in a buffered channel when a routine
|
||||
// actually is ready for a receive.
|
||||
// TODO: Need to consider optimal timer length
|
||||
for i := range d.routes[j.ID] {
|
||||
if !timeout.Stop() { // Stop timer before reset
|
||||
// Drain channel if timer has already actuated
|
||||
select {
|
||||
case <-timeout.C:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
timeout.Reset(DefaultHandshakeTimeout)
|
||||
select {
|
||||
case d.routes[j.ID][i] <- j.Data:
|
||||
case <-timeout.C:
|
||||
}
|
||||
}
|
||||
d.rMtx.RUnlock()
|
||||
|
||||
case v := <-d.shutdown:
|
||||
if !timeout.Stop() {
|
||||
select {
|
||||
case <-timeout.C:
|
||||
default:
|
||||
}
|
||||
}
|
||||
atomic.AddInt64(&d.count, -1)
|
||||
if v != nil {
|
||||
v.Done()
|
||||
}
|
||||
d.wg.Done()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// publish relays data to the subscribed subsystems
|
||||
func (d *Dispatcher) publish(id uuid.UUID, data interface{}) error {
|
||||
if data == nil {
|
||||
return errors.New("dispatcher data cannot be nil")
|
||||
}
|
||||
|
||||
if id == (uuid.UUID{}) {
|
||||
return errors.New("dispatcher uuid not set")
|
||||
}
|
||||
|
||||
if atomic.LoadUint32(&d.running) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create a new job to publish
|
||||
newJob := &job{
|
||||
Data: data,
|
||||
ID: id,
|
||||
}
|
||||
|
||||
// Push job on stack here
|
||||
select {
|
||||
case d.jobs <- newJob:
|
||||
default:
|
||||
return fmt.Errorf("dispatcher buffer at max capacity [%d] current worker count [%d], spawn more workers via --dispatchworkers=x",
|
||||
len(d.jobs),
|
||||
atomic.LoadInt64(&d.count))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Subscribe subscribes a system and returns a communication chan, this does not
|
||||
// ensure initial push. If your routine is out of sync with heartbeat and the
|
||||
// system does not get a change, its up to you to in turn get initial state.
|
||||
func (d *Dispatcher) subscribe(id uuid.UUID) (chan interface{}, error) {
|
||||
if atomic.LoadUint32(&d.running) == 0 {
|
||||
return nil, errors.New(errNotInitialised)
|
||||
}
|
||||
|
||||
// Read lock to read route list
|
||||
d.rMtx.RLock()
|
||||
_, ok := d.routes[id]
|
||||
d.rMtx.RUnlock()
|
||||
if !ok {
|
||||
return nil, errors.New("dispatcher uuid not found in route list")
|
||||
}
|
||||
|
||||
// Get an unused channel from the channel pool
|
||||
unusedChan := d.outbound.Get().(chan interface{})
|
||||
|
||||
// Lock for writing to the route list
|
||||
d.rMtx.Lock()
|
||||
d.routes[id] = append(d.routes[id], unusedChan)
|
||||
d.rMtx.Unlock()
|
||||
|
||||
return unusedChan, nil
|
||||
}
|
||||
|
||||
// Unsubscribe unsubs a routine from the dispatcher
|
||||
func (d *Dispatcher) unsubscribe(id uuid.UUID, usedChan chan interface{}) error {
|
||||
if atomic.LoadUint32(&d.running) == 0 {
|
||||
// reference will already be released in the stop function
|
||||
return nil
|
||||
}
|
||||
|
||||
// Read lock to read route list
|
||||
d.rMtx.RLock()
|
||||
_, ok := d.routes[id]
|
||||
d.rMtx.RUnlock()
|
||||
if !ok {
|
||||
return errors.New("dispatcher uuid does not reference any channels")
|
||||
}
|
||||
|
||||
// Lock for write to delete references
|
||||
d.rMtx.Lock()
|
||||
for i := range d.routes[id] {
|
||||
if d.routes[id][i] != usedChan {
|
||||
continue
|
||||
}
|
||||
// Delete individual reference
|
||||
d.routes[id][i] = d.routes[id][len(d.routes[id])-1]
|
||||
d.routes[id][len(d.routes[id])-1] = nil
|
||||
d.routes[id] = d.routes[id][:len(d.routes[id])-1]
|
||||
|
||||
d.rMtx.Unlock()
|
||||
|
||||
// Drain and put the used chan back in pool; only if it is not closed.
|
||||
select {
|
||||
case _, ok := <-usedChan:
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
d.outbound.Put(usedChan)
|
||||
return nil
|
||||
}
|
||||
d.rMtx.Unlock()
|
||||
return errors.New("dispatcher channel not found in uuid reference slice")
|
||||
}
|
||||
|
||||
// GetNewID returns a new ID
|
||||
func (d *Dispatcher) getNewID() (uuid.UUID, error) {
|
||||
// Generate new uuid
|
||||
newID, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
return uuid.UUID{}, err
|
||||
}
|
||||
|
||||
// Check to see if it already exists
|
||||
d.rMtx.RLock()
|
||||
_, ok := d.routes[newID]
|
||||
d.rMtx.RUnlock()
|
||||
if ok {
|
||||
return newID, errors.New("dispatcher collision detected, uuid already exists")
|
||||
}
|
||||
|
||||
// Write the key into system
|
||||
d.rMtx.Lock()
|
||||
d.routes[newID] = nil
|
||||
d.rMtx.Unlock()
|
||||
|
||||
return newID, nil
|
||||
}
|
||||
307
dispatch/dispatch_test.go
Normal file
307
dispatch/dispatch_test.go
Normal file
@@ -0,0 +1,307 @@
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
var mux *Mux
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
err := Start(DefaultMaxWorkers)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cpyDispatch = dispatcher
|
||||
mux = GetNewMux()
|
||||
cpyMux = mux
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
var cpyDispatch *Dispatcher
|
||||
var cpyMux *Mux
|
||||
|
||||
func TestDispatcher(t *testing.T) {
|
||||
dispatcher = nil
|
||||
err := Stop()
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = Start(10)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
if IsRunning() {
|
||||
t.Error("should be false")
|
||||
}
|
||||
|
||||
err = DropWorker()
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = SpawnWorker()
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
dispatcher = cpyDispatch
|
||||
|
||||
if !IsRunning() {
|
||||
t.Error("should be true")
|
||||
}
|
||||
|
||||
err = Start(10)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = DropWorker()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = DropWorker()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = SpawnWorker()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = SpawnWorker()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = SpawnWorker()
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = Stop()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = Stop()
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = Start(0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
payload := "something"
|
||||
|
||||
err = dispatcher.publish(uuid.UUID{}, &payload)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = dispatcher.publish(uuid.UUID{}, nil)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
id, errrrrrrrr := dispatcher.getNewID()
|
||||
if errrrrrrrr != nil {
|
||||
t.Error(errrrrrrrr)
|
||||
}
|
||||
|
||||
err = dispatcher.publish(id, &payload)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = dispatcher.stop()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = dispatcher.publish(id, &payload)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = dispatcher.subscribe(id)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = dispatcher.start(10)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
someID, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = dispatcher.subscribe(someID)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
randomChan := make(chan interface{})
|
||||
err = dispatcher.unsubscribe(someID, randomChan)
|
||||
if err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = dispatcher.unsubscribe(id, randomChan)
|
||||
if err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
close(randomChan)
|
||||
err = dispatcher.unsubscribe(id, randomChan)
|
||||
if err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMux(t *testing.T) {
|
||||
mux = nil
|
||||
_, err := mux.Subscribe(uuid.UUID{})
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = mux.Unsubscribe(uuid.UUID{}, nil)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = mux.Publish(nil, nil)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
_, err = mux.GetID()
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
mux = cpyMux
|
||||
|
||||
err = mux.Publish(nil, nil)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
payload := "string"
|
||||
id, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = mux.Publish([]uuid.UUID{id}, &payload)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = mux.Subscribe(uuid.UUID{})
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
_, err = mux.Subscribe(id)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubscribe(t *testing.T) {
|
||||
itemID, err := mux.GetID()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var pipes []Pipe
|
||||
for i := 0; i < 1000; i++ {
|
||||
newPipe, err := mux.Subscribe(itemID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
pipes = append(pipes, newPipe)
|
||||
}
|
||||
|
||||
for i := range pipes {
|
||||
err := pipes[i].Release()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublish(t *testing.T) {
|
||||
itemID, err := mux.GetID()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pipe, err := mux.Subscribe(itemID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func(wg *sync.WaitGroup) {
|
||||
wg.Done()
|
||||
for {
|
||||
_, ok := <-pipe.C
|
||||
if !ok {
|
||||
pErr := pipe.Release()
|
||||
if pErr != nil {
|
||||
t.Error(pErr)
|
||||
}
|
||||
wg.Done()
|
||||
return
|
||||
}
|
||||
}
|
||||
}(&wg)
|
||||
wg.Wait()
|
||||
wg.Add(1)
|
||||
mainPayload := "PAYLOAD"
|
||||
for i := 0; i < 100; i++ {
|
||||
errMux := mux.Publish([]uuid.UUID{itemID}, &mainPayload)
|
||||
if errMux != nil {
|
||||
t.Error(errMux)
|
||||
}
|
||||
}
|
||||
|
||||
// Shut down dispatch system
|
||||
err = Stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func BenchmarkSubscribe(b *testing.B) {
|
||||
newID, err := mux.GetID()
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
_, err := mux.Subscribe(newID)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
88
dispatch/dispatch_types.go
Normal file
88
dispatch/dispatch_types.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultJobBuffer defines a maxiumum amount of jobs allowed in channel
|
||||
DefaultJobBuffer = 100
|
||||
|
||||
// DefaultMaxWorkers is the package default worker ceiling amount
|
||||
DefaultMaxWorkers = 10
|
||||
|
||||
// DefaultHandshakeTimeout defines a workers max length of time to wait on a
|
||||
// an unbuffered channel for a receiver before moving on to next route
|
||||
DefaultHandshakeTimeout = 200 * time.Nanosecond
|
||||
|
||||
errNotInitialised = "dispatcher not initialised"
|
||||
errAlreadyStarted = "dispatcher already started"
|
||||
errCannotShutdown = "dispatcher cannot shutdown, already stopped"
|
||||
errShutdownRoutines = "dispatcher did not shutdown properly, routines failed to close"
|
||||
)
|
||||
|
||||
// dispatcher is our main in memory instance with a stop/start mtx below
|
||||
var dispatcher *Dispatcher
|
||||
var mtx sync.Mutex
|
||||
|
||||
// Dispatcher defines an internal subsystem communication/change state publisher
|
||||
type Dispatcher struct {
|
||||
// routes refers to a subystem uuid ticket map with associated publish
|
||||
// channels, a relayer will be given a unique id through its job channel,
|
||||
// then publish the data across the full registered channels for that uuid.
|
||||
// See relayer() method below.
|
||||
routes map[uuid.UUID][]chan interface{}
|
||||
|
||||
// rMtx protects the routes variable ensuring acceptable read/write access
|
||||
rMtx sync.RWMutex
|
||||
|
||||
// Persistent buffered job queue for relayers
|
||||
jobs chan *job
|
||||
|
||||
// Dynamic channel pool; returns an unbuffered channel for routes map
|
||||
outbound sync.Pool
|
||||
|
||||
// MaxWorkers defines max worker ceiling
|
||||
maxWorkers int64
|
||||
|
||||
// Atomic values -----------------------
|
||||
// Worker counter
|
||||
count int64
|
||||
// Dispatch status
|
||||
running uint32
|
||||
|
||||
// Unbufferd shutdown chan, sync wg for ensuring concurrency when only
|
||||
// dropping a single relayer routine
|
||||
shutdown chan *sync.WaitGroup
|
||||
|
||||
// Relayer shutdown tracking
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// job defines a relaying job associated with a ticket which allows routing to
|
||||
// routines that require specific data
|
||||
type job struct {
|
||||
Data interface{}
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
// Mux defines a new multiplexor for the dispatch system, these a generated
|
||||
// per subsystem
|
||||
type Mux struct {
|
||||
// Reference to the main running dispatch service
|
||||
d *Dispatcher
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
// Pipe defines an outbound object to the desired routine
|
||||
type Pipe struct {
|
||||
// Channel to get all our lovely informations
|
||||
C chan interface{}
|
||||
// ID to tracked system
|
||||
id uuid.UUID
|
||||
// Reference to multiplexor
|
||||
m *Mux
|
||||
}
|
||||
77
dispatch/mux.go
Normal file
77
dispatch/mux.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
// GetNewMux returns a new multiplexor to track subsystem updates
|
||||
func GetNewMux() *Mux {
|
||||
return &Mux{d: dispatcher}
|
||||
}
|
||||
|
||||
// Subscribe takes in a package defined signature element pointing to an ID set
|
||||
// and returns the associated pipe
|
||||
func (m *Mux) Subscribe(id uuid.UUID) (Pipe, error) {
|
||||
if m == nil {
|
||||
return Pipe{}, errors.New("mux is nil")
|
||||
}
|
||||
|
||||
if id == (uuid.UUID{}) {
|
||||
return Pipe{}, errors.New("id not set")
|
||||
}
|
||||
|
||||
ch, err := m.d.subscribe(id)
|
||||
if err != nil {
|
||||
return Pipe{}, err
|
||||
}
|
||||
|
||||
return Pipe{C: ch, id: id, m: m}, nil
|
||||
}
|
||||
|
||||
// Unsubscribe returns channel to the pool for the full signature set
|
||||
func (m *Mux) Unsubscribe(id uuid.UUID, ch chan interface{}) error {
|
||||
if m == nil {
|
||||
return errors.New("mux is nil")
|
||||
}
|
||||
return m.d.unsubscribe(id, ch)
|
||||
}
|
||||
|
||||
// Publish takes in a persistent memory address and dispatches changes to
|
||||
// required pipes. Data should be of *type.
|
||||
func (m *Mux) Publish(ids []uuid.UUID, data interface{}) error {
|
||||
if m == nil {
|
||||
return errors.New("mux is nil")
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return errors.New("data payload is nil")
|
||||
}
|
||||
|
||||
cpy := reflect.ValueOf(data).Elem().Interface()
|
||||
|
||||
for i := range ids {
|
||||
// Create copy to not interfere with stored value
|
||||
err := m.d.publish(ids[i], &cpy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetID gets a lovely new ID
|
||||
func (m *Mux) GetID() (uuid.UUID, error) {
|
||||
if m == nil {
|
||||
return uuid.UUID{}, errors.New("mux is nil")
|
||||
}
|
||||
|
||||
return m.d.getNewID()
|
||||
}
|
||||
|
||||
// Release returns the channel to the communications pool to be reused
|
||||
func (p *Pipe) Release() error {
|
||||
return p.m.Unsubscribe(p.id, p.C)
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency/coinmarketcap"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -111,6 +112,7 @@ func ValidateSettings(b *Engine, s *Settings) {
|
||||
b.Settings.EnablePortfolioManager = s.EnablePortfolioManager
|
||||
b.Settings.EnableCoinmarketcapAnalysis = s.EnableCoinmarketcapAnalysis
|
||||
b.Settings.EnableDatabaseManager = s.EnableDatabaseManager
|
||||
b.Settings.EnableDispatcher = s.EnableDispatcher
|
||||
|
||||
// TO-DO: FIXME
|
||||
if flag.Lookup("grpc") != nil {
|
||||
@@ -203,6 +205,7 @@ func ValidateSettings(b *Engine, s *Settings) {
|
||||
}
|
||||
|
||||
b.Settings.GlobalHTTPProxy = s.GlobalHTTPProxy
|
||||
b.Settings.DispatchMaxWorkerAmount = s.DispatchMaxWorkerAmount
|
||||
}
|
||||
|
||||
// PrintSettings returns the engine settings
|
||||
@@ -230,6 +233,8 @@ func PrintSettings(s *Settings) {
|
||||
log.Debugf(log.Global, "\t Enable orderbook syncing: %v", s.EnableOrderbookSyncing)
|
||||
log.Debugf(log.Global, "\t Enable websocket routine: %v\n", s.EnableWebsocketRoutine)
|
||||
log.Debugf(log.Global, "\t Enable NTP client: %v", s.EnableNTPClient)
|
||||
log.Debugf(log.Global, "\t Enable dispatcher: %v", s.EnableDispatcher)
|
||||
log.Debugf(log.Global, "\t Dispatch package max worker amount: %d", s.DispatchMaxWorkerAmount)
|
||||
log.Debugf(log.Global, "- FOREX SETTINGS:")
|
||||
log.Debugf(log.Global, "\t Enable currency conveter: %v", s.EnableCurrencyConverter)
|
||||
log.Debugf(log.Global, "\t Enable currency layer: %v", s.EnableCurrencyLayer)
|
||||
@@ -266,6 +271,12 @@ func (e *Engine) Start() error {
|
||||
}
|
||||
}
|
||||
|
||||
if e.Settings.EnableDispatcher {
|
||||
if err := dispatch.Start(e.Settings.DispatchMaxWorkerAmount); err != nil {
|
||||
log.Errorf(log.DispatchMgr, "Dispatcher unable to start: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Sets up internet connectivity monitor
|
||||
if e.Settings.EnableConnectivityMonitor {
|
||||
if err := e.ConnectionManager.Start(); err != nil {
|
||||
@@ -436,6 +447,12 @@ func (e *Engine) Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
if dispatch.IsRunning() {
|
||||
if err := dispatch.Stop(); err != nil {
|
||||
log.Errorf(log.DispatchMgr, "Dispatch system unable to stop. Error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if !e.Settings.EnableDryRun {
|
||||
err := e.Config.SaveConfig(e.Settings.ConfigFile, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -61,4 +61,8 @@ type Settings struct {
|
||||
ExchangeHTTPTimeout time.Duration
|
||||
ExchangeHTTPUserAgent string
|
||||
ExchangeHTTPProxy string
|
||||
|
||||
// Dispatch system settings
|
||||
EnableDispatcher bool
|
||||
DispatchMaxWorkerAmount int64
|
||||
}
|
||||
|
||||
@@ -149,12 +149,6 @@ func TestProcessTicker(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
// this will throw an err with an unpopulated ticker
|
||||
ticker.Tickers = nil
|
||||
if r := e.processTicker(); r {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
// now populate it with a 0 entry
|
||||
tick := ticker.Price{
|
||||
Pair: currency.NewPair(currency.BTC, currency.USD),
|
||||
@@ -222,12 +216,6 @@ func TestProcessOrderbook(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
// this will throw an err with an unpopulated orderbook
|
||||
orderbook.Orderbooks = nil
|
||||
if r := e.processOrderbook(); r {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
// now populate it with a 0 entry
|
||||
o := orderbook.Base{
|
||||
Pair: currency.NewPair(currency.BTC, currency.USD),
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/pquerna/otp/totp"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
@@ -42,6 +43,7 @@ func GetSubsystemsStatus() map[string]bool {
|
||||
systems["grpc_proxy"] = Bot.Settings.EnableGRPCProxy
|
||||
systems["deprecated_rpc"] = Bot.Settings.EnableDeprecatedRPC
|
||||
systems["websocket_rpc"] = Bot.Settings.EnableWebsocketRPC
|
||||
systems["dispatch"] = dispatch.IsRunning()
|
||||
return systems
|
||||
}
|
||||
|
||||
@@ -106,6 +108,11 @@ func SetSubsystem(subsys string, enable bool) error {
|
||||
Bot.ExchangeCurrencyPairManager.Start()
|
||||
}
|
||||
Bot.ExchangeCurrencyPairManager.Stop()
|
||||
case "dispatch":
|
||||
if enable {
|
||||
return dispatch.Start(Bot.Settings.DispatchMaxWorkerAmount)
|
||||
}
|
||||
return dispatch.Stop()
|
||||
}
|
||||
return errors.New("subsystem not found")
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/stats"
|
||||
@@ -186,101 +185,6 @@ func relayWebsocketEvent(result interface{}, event, assetType, exchangeName stri
|
||||
}
|
||||
}
|
||||
|
||||
// TickerUpdaterRoutine fetches and updates the ticker for all enabled
|
||||
// currency pairs and exchanges
|
||||
func TickerUpdaterRoutine() {
|
||||
log.Debugln(log.Ticker, "Starting ticker updater routine.")
|
||||
var wg sync.WaitGroup
|
||||
for {
|
||||
wg.Add(len(Bot.Exchanges))
|
||||
for x := range Bot.Exchanges {
|
||||
go func(x int, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
if Bot.Exchanges[x] == nil || !Bot.Exchanges[x].SupportsREST() {
|
||||
return
|
||||
}
|
||||
|
||||
exchangeName := Bot.Exchanges[x].GetName()
|
||||
supportsBatching := Bot.Exchanges[x].SupportsRESTTickerBatchUpdates()
|
||||
assetTypes := Bot.Exchanges[x].GetAssetTypes()
|
||||
|
||||
processTicker := func(exch exchange.IBotExchange, update bool, c currency.Pair, assetType asset.Item) {
|
||||
var result ticker.Price
|
||||
var err error
|
||||
if update {
|
||||
result, err = exch.UpdateTicker(c, assetType)
|
||||
} else {
|
||||
result, err = exch.FetchTicker(c, assetType)
|
||||
}
|
||||
printTickerSummary(&result, c, assetType, exchangeName, err)
|
||||
if err == nil {
|
||||
if Bot.Config.RemoteControl.WebsocketRPC.Enabled {
|
||||
relayWebsocketEvent(result, "ticker_update", assetType.String(), exchangeName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for y := range assetTypes {
|
||||
enabledCurrencies := Bot.Exchanges[x].GetEnabledPairs(assetTypes[y])
|
||||
for z := range enabledCurrencies {
|
||||
if supportsBatching && z > 0 {
|
||||
processTicker(Bot.Exchanges[x], false, enabledCurrencies[z], assetTypes[y])
|
||||
continue
|
||||
}
|
||||
processTicker(Bot.Exchanges[x], true, enabledCurrencies[z], assetTypes[y])
|
||||
}
|
||||
}
|
||||
}(x, &wg)
|
||||
}
|
||||
wg.Wait()
|
||||
log.Debugln(log.Ticker, "All enabled currency tickers fetched.")
|
||||
time.Sleep(time.Second * 10)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderbookUpdaterRoutine fetches and updates the orderbooks for all enabled
|
||||
// currency pairs and exchanges
|
||||
func OrderbookUpdaterRoutine() {
|
||||
log.Debugln(log.OrderBook, "Starting orderbook updater routine.")
|
||||
var wg sync.WaitGroup
|
||||
for {
|
||||
wg.Add(len(Bot.Exchanges))
|
||||
for x := range Bot.Exchanges {
|
||||
go func(x int, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
if Bot.Exchanges[x] == nil || !Bot.Exchanges[x].SupportsREST() {
|
||||
return
|
||||
}
|
||||
|
||||
exchangeName := Bot.Exchanges[x].GetName()
|
||||
assetTypes := Bot.Exchanges[x].GetAssetTypes()
|
||||
|
||||
processOrderbook := func(exch exchange.IBotExchange, c currency.Pair, assetType asset.Item) {
|
||||
result, err := exch.UpdateOrderbook(c, assetType)
|
||||
printOrderbookSummary(&result, c, assetType, exchangeName, err)
|
||||
if err == nil {
|
||||
if Bot.Config.RemoteControl.WebsocketRPC.Enabled {
|
||||
relayWebsocketEvent(result, "orderbook_update", assetType.String(), exchangeName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for y := range assetTypes {
|
||||
enabledCurrencies := Bot.Exchanges[x].GetEnabledPairs(assetTypes[y])
|
||||
for z := range enabledCurrencies {
|
||||
processOrderbook(Bot.Exchanges[x], enabledCurrencies[z], assetTypes[y])
|
||||
}
|
||||
}
|
||||
}(x, &wg)
|
||||
}
|
||||
wg.Wait()
|
||||
log.Debugln(log.OrderBook, "All enabled currency orderbooks fetched.")
|
||||
time.Sleep(time.Second * 10)
|
||||
}
|
||||
}
|
||||
|
||||
// WebsocketRoutine Initial routine management system for websocket
|
||||
func WebsocketRoutine() {
|
||||
if Bot.Settings.Verbose {
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctrpc"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctrpc/auth"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -27,6 +29,13 @@ import (
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
errExchangeNameUnset = "exchange name unset"
|
||||
errCurrencyPairUnset = "currency pair unset"
|
||||
errAssetTypeUnset = "asset type unset"
|
||||
errDispatchSystem = "dispatch system offline"
|
||||
)
|
||||
|
||||
// RPCServer struct
|
||||
type RPCServer struct{}
|
||||
|
||||
@@ -953,5 +962,200 @@ func (s *RPCServer) DisableExchangePair(ctx context.Context, r *gctrpc.ExchangeP
|
||||
err = GetExchangeByName(r.Exchange).GetBase().CurrencyPairs.DisablePair(
|
||||
asset.Item(r.AssetType), p)
|
||||
return &gctrpc.GenericExchangeNameResponse{}, err
|
||||
|
||||
}
|
||||
|
||||
// GetOrderbookStream streams the requested updated orderbook
|
||||
func (s *RPCServer) GetOrderbookStream(r *gctrpc.GetOrderbookStreamRequest, stream gctrpc.GoCryptoTrader_GetOrderbookStreamServer) error {
|
||||
if r.Exchange == "" {
|
||||
return errors.New(errExchangeNameUnset)
|
||||
}
|
||||
|
||||
if r.Pair.String() == "" {
|
||||
return errors.New(errCurrencyPairUnset)
|
||||
}
|
||||
|
||||
if r.AssetType == "" {
|
||||
return errors.New(errAssetTypeUnset)
|
||||
}
|
||||
|
||||
p := currency.NewPairFromStrings(r.Pair.Base, r.Pair.Quote)
|
||||
|
||||
pipe, err := orderbook.SubscribeOrderbook(r.Exchange, p, asset.Item(r.AssetType))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer pipe.Release()
|
||||
|
||||
for {
|
||||
data, ok := <-pipe.C
|
||||
if !ok {
|
||||
return errors.New(errDispatchSystem)
|
||||
}
|
||||
|
||||
ob := (*data.(*interface{})).(orderbook.Base)
|
||||
var bids, asks []*gctrpc.OrderbookItem
|
||||
for i := range ob.Bids {
|
||||
bids = append(bids, &gctrpc.OrderbookItem{
|
||||
Amount: ob.Bids[i].Amount,
|
||||
Price: ob.Bids[i].Price,
|
||||
Id: ob.Bids[i].ID,
|
||||
})
|
||||
}
|
||||
for i := range ob.Asks {
|
||||
asks = append(asks, &gctrpc.OrderbookItem{
|
||||
Amount: ob.Asks[i].Amount,
|
||||
Price: ob.Asks[i].Price,
|
||||
Id: ob.Asks[i].ID,
|
||||
})
|
||||
}
|
||||
err := stream.Send(&gctrpc.OrderbookResponse{
|
||||
Pair: &gctrpc.CurrencyPair{Base: ob.Pair.Base.String(),
|
||||
Quote: ob.Pair.Quote.String()},
|
||||
Bids: bids,
|
||||
Asks: asks,
|
||||
AssetType: ob.AssetType.String(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetExchangeOrderbookStream streams all orderbooks associated with an exchange
|
||||
func (s *RPCServer) GetExchangeOrderbookStream(r *gctrpc.GetExchangeOrderbookStreamRequest, stream gctrpc.GoCryptoTrader_GetExchangeOrderbookStreamServer) error {
|
||||
if r.Exchange == "" {
|
||||
return errors.New(errExchangeNameUnset)
|
||||
}
|
||||
|
||||
pipe, err := orderbook.SubscribeToExchangeOrderbooks(r.Exchange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer pipe.Release()
|
||||
|
||||
for {
|
||||
data, ok := <-pipe.C
|
||||
if !ok {
|
||||
return errors.New(errDispatchSystem)
|
||||
}
|
||||
|
||||
ob := (*data.(*interface{})).(orderbook.Base)
|
||||
var bids, asks []*gctrpc.OrderbookItem
|
||||
for i := range ob.Bids {
|
||||
bids = append(bids, &gctrpc.OrderbookItem{
|
||||
Amount: ob.Bids[i].Amount,
|
||||
Price: ob.Bids[i].Price,
|
||||
Id: ob.Bids[i].ID,
|
||||
})
|
||||
}
|
||||
for i := range ob.Asks {
|
||||
asks = append(asks, &gctrpc.OrderbookItem{
|
||||
Amount: ob.Asks[i].Amount,
|
||||
Price: ob.Asks[i].Price,
|
||||
Id: ob.Asks[i].ID,
|
||||
})
|
||||
}
|
||||
err := stream.Send(&gctrpc.OrderbookResponse{
|
||||
Pair: &gctrpc.CurrencyPair{Base: ob.Pair.Base.String(),
|
||||
Quote: ob.Pair.Quote.String()},
|
||||
Bids: bids,
|
||||
Asks: asks,
|
||||
AssetType: ob.AssetType.String(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetTickerStream streams the requested updated ticker
|
||||
func (s *RPCServer) GetTickerStream(r *gctrpc.GetTickerStreamRequest, stream gctrpc.GoCryptoTrader_GetTickerStreamServer) error {
|
||||
if r.Exchange == "" {
|
||||
return errors.New(errExchangeNameUnset)
|
||||
}
|
||||
|
||||
if r.Pair.String() == "" {
|
||||
return errors.New(errCurrencyPairUnset)
|
||||
}
|
||||
|
||||
if r.AssetType == "" {
|
||||
return errors.New(errAssetTypeUnset)
|
||||
}
|
||||
|
||||
p := currency.NewPairFromStrings(r.Pair.Base, r.Pair.Quote)
|
||||
|
||||
pipe, err := ticker.SubscribeTicker(r.Exchange, p, asset.Item(r.AssetType))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer pipe.Release()
|
||||
|
||||
for {
|
||||
data, ok := <-pipe.C
|
||||
if !ok {
|
||||
return errors.New(errDispatchSystem)
|
||||
}
|
||||
t := (*data.(*interface{})).(ticker.Price)
|
||||
|
||||
err := stream.Send(&gctrpc.TickerResponse{
|
||||
Pair: &gctrpc.CurrencyPair{
|
||||
Base: t.Pair.Base.String(),
|
||||
Quote: t.Pair.Quote.String(),
|
||||
Delimiter: t.Pair.Delimiter},
|
||||
LastUpdated: t.LastUpdated.Unix(),
|
||||
Last: t.Last,
|
||||
High: t.High,
|
||||
Low: t.Low,
|
||||
Bid: t.Bid,
|
||||
Ask: t.Ask,
|
||||
Volume: t.Volume,
|
||||
PriceAth: t.PriceATH,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetExchangeTickerStream streams all tickers associated with an exchange
|
||||
func (s *RPCServer) GetExchangeTickerStream(r *gctrpc.GetExchangeTickerStreamRequest, stream gctrpc.GoCryptoTrader_GetExchangeTickerStreamServer) error {
|
||||
if r.Exchange == "" {
|
||||
return errors.New(errExchangeNameUnset)
|
||||
}
|
||||
|
||||
pipe, err := ticker.SubscribeToExchangeTickers(r.Exchange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer pipe.Release()
|
||||
|
||||
for {
|
||||
data, ok := <-pipe.C
|
||||
if !ok {
|
||||
return errors.New(errDispatchSystem)
|
||||
}
|
||||
t := (*data.(*interface{})).(ticker.Price)
|
||||
|
||||
err := stream.Send(&gctrpc.TickerResponse{
|
||||
Pair: &gctrpc.CurrencyPair{
|
||||
Base: t.Pair.Base.String(),
|
||||
Quote: t.Pair.Quote.String(),
|
||||
Delimiter: t.Pair.Delimiter},
|
||||
LastUpdated: t.LastUpdated.Unix(),
|
||||
Last: t.Last,
|
||||
High: t.High,
|
||||
Low: t.Low,
|
||||
Bid: t.Bid,
|
||||
Ask: t.Ask,
|
||||
Volume: t.Volume,
|
||||
PriceAth: t.PriceATH,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ func TestUpdateOrderbook(t *testing.T) {
|
||||
Quote: currency.USD}
|
||||
|
||||
_, err := a.UpdateOrderbook(q, "spot")
|
||||
if err != nil {
|
||||
t.Fatalf("Update for orderbook failed: %v", err)
|
||||
if err == nil {
|
||||
t.Fatalf("error cannot be nil as the endpoint returns no orderbook information")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,6 +247,7 @@ func (b *Binance) SeedLocalCache(p currency.Pair) error {
|
||||
newOrderBook.LastUpdated = time.Unix(orderbookNew.LastUpdateID, 0)
|
||||
newOrderBook.Pair = p
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.ExchangeName = b.GetName()
|
||||
|
||||
return b.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
}
|
||||
|
||||
@@ -482,6 +482,8 @@ func (b *Bitfinex) WsInsertSnapshot(p currency.Pair, assetType asset.Item, books
|
||||
newOrderBook.AssetType = assetType
|
||||
newOrderBook.Bids = bid
|
||||
newOrderBook.Pair = p
|
||||
newOrderBook.ExchangeName = b.GetName()
|
||||
|
||||
err := b.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bitfinex.go error - %s", err)
|
||||
|
||||
@@ -361,6 +361,8 @@ func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPai
|
||||
newOrderBook.Bids = bids
|
||||
newOrderBook.AssetType = assetType
|
||||
newOrderBook.Pair = currencyPair
|
||||
newOrderBook.ExchangeName = b.GetName()
|
||||
|
||||
err := b.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bitmex_websocket.go process orderbook error - %s",
|
||||
|
||||
@@ -247,6 +247,7 @@ func (b *Bitstamp) seedOrderBook() error {
|
||||
newOrderBook.Bids = bids
|
||||
newOrderBook.Pair = p[x]
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.ExchangeName = b.GetName()
|
||||
|
||||
err = b.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
if err != nil {
|
||||
|
||||
@@ -216,6 +216,7 @@ func (c *CoinbasePro) ProcessSnapshot(snapshot *WebsocketOrderbookSnapshot) erro
|
||||
pair := currency.NewPairFromString(snapshot.ProductID)
|
||||
base.AssetType = asset.Spot
|
||||
base.Pair = pair
|
||||
base.ExchangeName = c.GetName()
|
||||
|
||||
err := c.Websocket.Orderbook.LoadSnapshot(&base)
|
||||
if err != nil {
|
||||
|
||||
@@ -288,6 +288,7 @@ func (c *COINUT) WsProcessOrderbookSnapshot(ob *WsOrderbookSnapshot) error {
|
||||
c.GetPairFormat(asset.Spot, true),
|
||||
)
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.ExchangeName = c.GetName()
|
||||
|
||||
return c.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
}
|
||||
|
||||
@@ -237,6 +237,7 @@ func (g *Gateio) WsHandleData() {
|
||||
newOrderBook.Bids = bids
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.Pair = currency.NewPairFromString(c)
|
||||
newOrderBook.ExchangeName = g.GetName()
|
||||
|
||||
err = g.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
if err != nil {
|
||||
|
||||
@@ -282,6 +282,7 @@ func (g *Gemini) wsProcessUpdate(result WsMarketUpdateResponse, pair currency.Pa
|
||||
newOrderBook.Bids = bids
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.Pair = pair
|
||||
newOrderBook.ExchangeName = g.GetName()
|
||||
err := g.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
if err != nil {
|
||||
g.Websocket.DataHandler <- err
|
||||
|
||||
@@ -250,6 +250,7 @@ func (h *HitBTC) WsProcessOrderbookSnapshot(ob WsOrderbook) error {
|
||||
newOrderBook.Bids = bids
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.Pair = p
|
||||
newOrderBook.ExchangeName = h.GetName()
|
||||
|
||||
err := h.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,235 +2,259 @@ package orderbook
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"sync"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
// const values for orderbook package
|
||||
const (
|
||||
errExchangeOrderbookNotFound = "orderbook for exchange does not exist"
|
||||
errPairNotSet = "orderbook currency pair not set"
|
||||
errAssetTypeNotSet = "orderbook asset type not set"
|
||||
errBaseCurrencyNotFound = "orderbook base currency not found"
|
||||
errQuoteCurrencyNotFound = "orderbook quote currency not found"
|
||||
)
|
||||
|
||||
// Vars for the orderbook package
|
||||
var (
|
||||
Orderbooks []Orderbook
|
||||
m sync.Mutex
|
||||
)
|
||||
|
||||
// Item stores the amount and price values
|
||||
type Item struct {
|
||||
Amount float64
|
||||
Price float64
|
||||
ID int64
|
||||
// Get checks and returns the orderbook given an exchange name and currency pair
|
||||
// if it exists
|
||||
func Get(exchange string, p currency.Pair, a asset.Item) (Base, error) {
|
||||
o, err := service.Retrieve(exchange, p, a)
|
||||
if err != nil {
|
||||
return Base{}, err
|
||||
}
|
||||
return *o, nil
|
||||
}
|
||||
|
||||
// Base holds the fields for the orderbook base
|
||||
type Base struct {
|
||||
Pair currency.Pair `json:"pair"`
|
||||
Bids []Item `json:"bids"`
|
||||
Asks []Item `json:"asks"`
|
||||
LastUpdated time.Time `json:"lastUpdated"`
|
||||
AssetType asset.Item `json:"assetType"`
|
||||
ExchangeName string `json:"exchangeName"`
|
||||
// SubscribeOrderbook subcribes to an orderbook and returns a communication
|
||||
// channel to stream orderbook data updates
|
||||
func SubscribeOrderbook(exchange string, p currency.Pair, a asset.Item) (dispatch.Pipe, error) {
|
||||
exchange = strings.ToLower(exchange)
|
||||
service.RLock()
|
||||
defer service.RUnlock()
|
||||
book, ok := service.Books[exchange][p.Base.Item][p.Quote.Item][a]
|
||||
if !ok {
|
||||
return dispatch.Pipe{}, fmt.Errorf("orderbook item not found for %s %s %s",
|
||||
exchange,
|
||||
p,
|
||||
a)
|
||||
}
|
||||
|
||||
return service.mux.Subscribe(book.Main)
|
||||
}
|
||||
|
||||
// Orderbook holds the orderbook information for a currency pair and type
|
||||
type Orderbook struct {
|
||||
Orderbook map[*currency.Item]map[*currency.Item]map[asset.Item]Base
|
||||
ExchangeName string
|
||||
// SubscribeToExchangeOrderbooks subcribes to all orderbooks on an exchange
|
||||
func SubscribeToExchangeOrderbooks(exchange string) (dispatch.Pipe, error) {
|
||||
exchange = strings.ToLower(exchange)
|
||||
service.RLock()
|
||||
defer service.RUnlock()
|
||||
id, ok := service.Exchange[exchange]
|
||||
if !ok {
|
||||
return dispatch.Pipe{}, fmt.Errorf("%s exchange orderbooks not found",
|
||||
exchange)
|
||||
}
|
||||
|
||||
return service.mux.Subscribe(id)
|
||||
}
|
||||
|
||||
type byOBPrice []Item
|
||||
// Update stores orderbook data
|
||||
func (s *Service) Update(b *Base) error {
|
||||
var ids []uuid.UUID
|
||||
|
||||
func (a byOBPrice) Len() int { return len(a) }
|
||||
func (a byOBPrice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a byOBPrice) Less(i, j int) bool { return a[i].Price < a[j].Price }
|
||||
|
||||
// Verify ensures that the orderbook items are correctly sorted
|
||||
// Bids should always go from a high price to a low price and
|
||||
// asks should always go from a low price to a higher price
|
||||
func (o *Base) Verify() {
|
||||
var lastPrice float64
|
||||
var sortBids, sortAsks bool
|
||||
for x := range o.Bids {
|
||||
if lastPrice != 0 && o.Bids[x].Price >= lastPrice {
|
||||
sortBids = true
|
||||
break
|
||||
s.Lock()
|
||||
switch {
|
||||
case s.Books[b.ExchangeName] == nil:
|
||||
s.Books[b.ExchangeName] = make(map[*currency.Item]map[*currency.Item]map[asset.Item]*Book)
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item] = make(map[*currency.Item]map[asset.Item]*Book)
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item] = make(map[asset.Item]*Book)
|
||||
err := s.SetNewData(b)
|
||||
if err != nil {
|
||||
s.Unlock()
|
||||
return err
|
||||
}
|
||||
lastPrice = o.Bids[x].Price
|
||||
}
|
||||
|
||||
lastPrice = 0
|
||||
for x := range o.Asks {
|
||||
if lastPrice != 0 && o.Asks[x].Price <= lastPrice {
|
||||
sortAsks = true
|
||||
break
|
||||
case s.Books[b.ExchangeName][b.Pair.Base.Item] == nil:
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item] = make(map[*currency.Item]map[asset.Item]*Book)
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item] = make(map[asset.Item]*Book)
|
||||
err := s.SetNewData(b)
|
||||
if err != nil {
|
||||
s.Unlock()
|
||||
return err
|
||||
}
|
||||
lastPrice = o.Asks[x].Price
|
||||
|
||||
case s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item] == nil:
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item] = make(map[asset.Item]*Book)
|
||||
err := s.SetNewData(b)
|
||||
if err != nil {
|
||||
s.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
case s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item][b.AssetType] == nil:
|
||||
err := s.SetNewData(b)
|
||||
if err != nil {
|
||||
s.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
default:
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item][b.AssetType].b.Bids = b.Bids
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item][b.AssetType].b.Asks = b.Asks
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item][b.AssetType].b.LastUpdated = b.LastUpdated
|
||||
ids = s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item][b.AssetType].Assoc
|
||||
ids = append(ids, s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item][b.AssetType].Main)
|
||||
}
|
||||
s.Unlock()
|
||||
return s.mux.Publish(ids, b)
|
||||
}
|
||||
|
||||
// SetNewData sets new data
|
||||
func (s *Service) SetNewData(b *Base) error {
|
||||
ids, err := s.GetAssociations(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
singleID, err := s.mux.GetID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if sortBids {
|
||||
sort.Sort(sort.Reverse(byOBPrice(o.Bids)))
|
||||
s.Books[b.ExchangeName][b.Pair.Base.Item][b.Pair.Quote.Item][b.AssetType] = &Book{b: b,
|
||||
Main: singleID,
|
||||
Assoc: ids}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAssociations links a singular book with it's dispatch associations
|
||||
func (s *Service) GetAssociations(b *Base) ([]uuid.UUID, error) {
|
||||
if b == nil {
|
||||
return nil, errors.New("orderbook is nil")
|
||||
}
|
||||
|
||||
if sortAsks {
|
||||
sort.Sort((byOBPrice(o.Asks)))
|
||||
var ids []uuid.UUID
|
||||
exchangeID, ok := s.Exchange[b.ExchangeName]
|
||||
if !ok {
|
||||
var err error
|
||||
exchangeID, err = s.mux.GetID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Exchange[b.ExchangeName] = exchangeID
|
||||
}
|
||||
|
||||
ids = append(ids, exchangeID)
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// Retrieve gets orderbook data from the slice
|
||||
func (s *Service) Retrieve(exchange string, p currency.Pair, a asset.Item) (*Base, error) {
|
||||
exchange = strings.ToLower(exchange)
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
if s.Books[exchange] == nil {
|
||||
return nil, fmt.Errorf("no orderbooks for %s exchange", exchange)
|
||||
}
|
||||
|
||||
if s.Books[exchange][p.Base.Item] == nil {
|
||||
return nil, fmt.Errorf("no orderbooks associated with base currency %s",
|
||||
p.Base)
|
||||
}
|
||||
|
||||
if s.Books[exchange][p.Base.Item][p.Quote.Item] == nil {
|
||||
return nil, fmt.Errorf("no orderbooks associated with quote currency %s",
|
||||
p.Quote)
|
||||
}
|
||||
|
||||
if s.Books[exchange][p.Base.Item][p.Quote.Item][a] == nil {
|
||||
return nil, fmt.Errorf("no orderbooks associated with asset type %s",
|
||||
a)
|
||||
}
|
||||
|
||||
return s.Books[exchange][p.Base.Item][p.Quote.Item][a].b, nil
|
||||
}
|
||||
|
||||
// TotalBidsAmount returns the total amount of bids and the total orderbook
|
||||
// bids value
|
||||
func (o *Base) TotalBidsAmount() (amountCollated, total float64) {
|
||||
for _, x := range o.Bids {
|
||||
amountCollated += x.Amount
|
||||
total += x.Amount * x.Price
|
||||
func (b *Base) TotalBidsAmount() (amountCollated, total float64) {
|
||||
for x := range b.Bids {
|
||||
amountCollated += b.Bids[x].Amount
|
||||
total += b.Bids[x].Amount * b.Bids[x].Price
|
||||
}
|
||||
return amountCollated, total
|
||||
}
|
||||
|
||||
// TotalAsksAmount returns the total amount of asks and the total orderbook
|
||||
// asks value
|
||||
func (o *Base) TotalAsksAmount() (amountCollated, total float64) {
|
||||
for _, x := range o.Asks {
|
||||
amountCollated += x.Amount
|
||||
total += x.Amount * x.Price
|
||||
func (b *Base) TotalAsksAmount() (amountCollated, total float64) {
|
||||
for y := range b.Asks {
|
||||
amountCollated += b.Asks[y].Amount
|
||||
total += b.Asks[y].Amount * b.Asks[y].Price
|
||||
}
|
||||
return amountCollated, total
|
||||
}
|
||||
|
||||
// Update updates the bids and asks
|
||||
func (o *Base) Update(bids, asks []Item) {
|
||||
o.Bids = bids
|
||||
o.Asks = asks
|
||||
o.LastUpdated = time.Now()
|
||||
func (b *Base) Update(bids, asks []Item) {
|
||||
b.Bids = bids
|
||||
b.Asks = asks
|
||||
b.LastUpdated = time.Now()
|
||||
}
|
||||
|
||||
// Get checks and returns the orderbook given an exchange name and currency pair
|
||||
// if it exists
|
||||
func Get(exchange string, p currency.Pair, orderbookType asset.Item) (Base, error) {
|
||||
orderbook, err := GetByExchange(exchange)
|
||||
if err != nil {
|
||||
return Base{}, err
|
||||
}
|
||||
|
||||
if !BaseCurrencyExists(exchange, p.Base) {
|
||||
return Base{}, errors.New(errBaseCurrencyNotFound)
|
||||
}
|
||||
|
||||
if !QuoteCurrencyExists(exchange, p) {
|
||||
return Base{}, errors.New(errQuoteCurrencyNotFound)
|
||||
}
|
||||
|
||||
return orderbook.Orderbook[p.Base.Item][p.Quote.Item][orderbookType], nil
|
||||
}
|
||||
|
||||
// GetByExchange returns an exchange orderbook
|
||||
func GetByExchange(exchange string) (*Orderbook, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for x := range Orderbooks {
|
||||
if Orderbooks[x].ExchangeName == exchange {
|
||||
return &Orderbooks[x], nil
|
||||
// Verify ensures that the orderbook items are correctly sorted
|
||||
// Bids should always go from a high price to a low price and
|
||||
// asks should always go from a low price to a higher price
|
||||
func (b *Base) Verify() {
|
||||
var lastPrice float64
|
||||
var sortBids, sortAsks bool
|
||||
for x := range b.Bids {
|
||||
if lastPrice != 0 && b.Bids[x].Price >= lastPrice {
|
||||
sortBids = true
|
||||
break
|
||||
}
|
||||
lastPrice = b.Bids[x].Price
|
||||
}
|
||||
return nil, errors.New(errExchangeOrderbookNotFound)
|
||||
}
|
||||
|
||||
// BaseCurrencyExists checks to see if the base currency of the orderbook map
|
||||
// exists
|
||||
func BaseCurrencyExists(exchange string, currency currency.Code) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Orderbooks {
|
||||
if y.ExchangeName == exchange {
|
||||
if _, ok := y.Orderbook[currency.Item]; ok {
|
||||
return true
|
||||
}
|
||||
lastPrice = 0
|
||||
for x := range b.Asks {
|
||||
if lastPrice != 0 && b.Asks[x].Price <= lastPrice {
|
||||
sortAsks = true
|
||||
break
|
||||
}
|
||||
lastPrice = b.Asks[x].Price
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// QuoteCurrencyExists checks to see if the quote currency of the orderbook
|
||||
// map exists
|
||||
func QuoteCurrencyExists(exchange string, p currency.Pair) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Orderbooks {
|
||||
if y.ExchangeName == exchange {
|
||||
if _, ok := y.Orderbook[p.Base.Item]; ok {
|
||||
if _, ok := y.Orderbook[p.Base.Item][p.Quote.Item]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
if sortBids {
|
||||
sort.Sort(sort.Reverse(byOBPrice(b.Bids)))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateNewOrderbook creates a new orderbook
|
||||
func CreateNewOrderbook(exchangeName string, orderbookNew *Base, orderbookType asset.Item) *Orderbook {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
orderbook := Orderbook{}
|
||||
orderbook.ExchangeName = exchangeName
|
||||
orderbook.Orderbook = make(map[*currency.Item]map[*currency.Item]map[asset.Item]Base)
|
||||
a := make(map[*currency.Item]map[asset.Item]Base)
|
||||
b := make(map[asset.Item]Base)
|
||||
b[orderbookType] = *orderbookNew
|
||||
a[orderbookNew.Pair.Quote.Item] = b
|
||||
orderbook.Orderbook[orderbookNew.Pair.Base.Item] = a
|
||||
Orderbooks = append(Orderbooks, orderbook)
|
||||
return &orderbook
|
||||
if sortAsks {
|
||||
sort.Sort((byOBPrice(b.Asks)))
|
||||
}
|
||||
}
|
||||
|
||||
// Process processes incoming orderbooks, creating or updating the orderbook
|
||||
// list
|
||||
func (o *Base) Process() error {
|
||||
if o.Pair.IsEmpty() {
|
||||
func (b *Base) Process() error {
|
||||
if b.ExchangeName == "" {
|
||||
return errors.New(errExchangeNameUnset)
|
||||
}
|
||||
|
||||
b.ExchangeName = strings.ToLower(b.ExchangeName)
|
||||
|
||||
if b.Pair.IsEmpty() {
|
||||
return errors.New(errPairNotSet)
|
||||
}
|
||||
|
||||
if o.AssetType == "" {
|
||||
if b.AssetType.String() == "" {
|
||||
return errors.New(errAssetTypeNotSet)
|
||||
}
|
||||
|
||||
if o.LastUpdated.IsZero() {
|
||||
o.LastUpdated = time.Now()
|
||||
if len(b.Asks) == 0 && len(b.Bids) == 0 {
|
||||
return errors.New(errNoOrderbook)
|
||||
}
|
||||
|
||||
o.Verify()
|
||||
|
||||
orderbook, err := GetByExchange(o.ExchangeName)
|
||||
if err != nil {
|
||||
CreateNewOrderbook(o.ExchangeName, o, o.AssetType)
|
||||
return nil
|
||||
if b.LastUpdated.IsZero() {
|
||||
b.LastUpdated = time.Now()
|
||||
}
|
||||
|
||||
if BaseCurrencyExists(o.ExchangeName, o.Pair.Base) {
|
||||
m.Lock()
|
||||
a := make(map[asset.Item]Base)
|
||||
a[o.AssetType] = *o
|
||||
orderbook.Orderbook[o.Pair.Base.Item][o.Pair.Quote.Item] = a
|
||||
m.Unlock()
|
||||
return nil
|
||||
}
|
||||
b.Verify()
|
||||
|
||||
m.Lock()
|
||||
a := make(map[*currency.Item]map[asset.Item]Base)
|
||||
b := make(map[asset.Item]Base)
|
||||
b[o.AssetType] = *o
|
||||
a[o.Pair.Quote.Item] = b
|
||||
orderbook.Orderbook[o.Pair.Base.Item] = a
|
||||
m.Unlock()
|
||||
return nil
|
||||
return service.Update(b)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,139 @@
|
||||
package orderbook
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
err := dispatch.Start(1)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
cpyMux = service.mux
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
var cpyMux *dispatch.Mux
|
||||
|
||||
func TestSubscribeOrderbook(t *testing.T) {
|
||||
_, err := SubscribeOrderbook("", currency.Pair{}, asset.Item(""))
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
p := currency.NewPair(currency.BTC, currency.USD)
|
||||
|
||||
b := Base{
|
||||
Pair: p,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
err = b.Process()
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
b.ExchangeName = "SubscribeOBTest"
|
||||
|
||||
err = b.Process()
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
b.Bids = []Item{{}}
|
||||
|
||||
err = b.Process()
|
||||
if err != nil {
|
||||
t.Error("test failed - process error", err)
|
||||
}
|
||||
|
||||
_, err = SubscribeOrderbook("SubscribeOBTest", p, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
// process redundant update
|
||||
err = b.Process()
|
||||
if err != nil {
|
||||
t.Error("test failed - process error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateBooks(t *testing.T) {
|
||||
p := currency.NewPair(currency.BTC, currency.USD)
|
||||
|
||||
b := Base{
|
||||
Pair: p,
|
||||
AssetType: asset.Spot,
|
||||
ExchangeName: "UpdateTest",
|
||||
}
|
||||
|
||||
service.mux = nil
|
||||
|
||||
err := service.Update(&b)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
b.Pair.Base = currency.CYC
|
||||
err = service.Update(&b)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
b.Pair.Quote = currency.ENAU
|
||||
err = service.Update(&b)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
b.AssetType = "unicorns"
|
||||
err = service.Update(&b)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
service.mux = cpyMux
|
||||
}
|
||||
|
||||
func TestSubscribeToExchangeOrderbooks(t *testing.T) {
|
||||
_, err := SubscribeToExchangeOrderbooks("")
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
p := currency.NewPair(currency.BTC, currency.USD)
|
||||
|
||||
b := Base{
|
||||
Pair: p,
|
||||
AssetType: asset.Spot,
|
||||
ExchangeName: "SubscribeToExchangeOrderbooks",
|
||||
Bids: []Item{{}},
|
||||
}
|
||||
|
||||
err = b.Process()
|
||||
if err != nil {
|
||||
t.Error("test failed:", err)
|
||||
}
|
||||
|
||||
_, err = SubscribeToExchangeOrderbooks("SubscribeToExchangeOrderbooks")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerify(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := Base{
|
||||
@@ -95,13 +218,18 @@ func TestUpdate(t *testing.T) {
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
c := currency.NewPairFromStrings("BTC", "USD")
|
||||
base := Base{
|
||||
Pair: c,
|
||||
Asks: []Item{{Price: 100, Amount: 10}},
|
||||
Bids: []Item{{Price: 200, Amount: 10}},
|
||||
base := &Base{
|
||||
Pair: c,
|
||||
Asks: []Item{{Price: 100, Amount: 10}},
|
||||
Bids: []Item{{Price: 200, Amount: 10}},
|
||||
ExchangeName: "Exchange",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
CreateNewOrderbook("Exchange", &base, asset.Spot)
|
||||
err := base.Process()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
result, err := Get("Exchange", c, asset.Spot)
|
||||
if err != nil {
|
||||
@@ -128,83 +256,37 @@ func TestGetOrderbook(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("Test failed. TestGetOrderbook retrieved non-existent orderbook using invalid second currency")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderbookByExchange(t *testing.T) {
|
||||
currency := currency.NewPairFromStrings("BTC", "USD")
|
||||
base := Base{
|
||||
Pair: currency,
|
||||
Asks: []Item{{Price: 100, Amount: 10}},
|
||||
Bids: []Item{{Price: 200, Amount: 10}},
|
||||
}
|
||||
|
||||
CreateNewOrderbook("Exchange", &base, asset.Spot)
|
||||
|
||||
_, err := GetByExchange("Exchange")
|
||||
base.Pair = newCurrency
|
||||
err = base.Process()
|
||||
if err != nil {
|
||||
t.Fatalf("Test failed. TestGetOrderbookByExchange failed to get orderbook. Error %s",
|
||||
err)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = GetByExchange("nonexistent")
|
||||
_, err = Get("Exchange", newCurrency, "meowCats")
|
||||
if err == nil {
|
||||
t.Fatal("Test failed. TestGetOrderbookByExchange retrieved non-existent orderbook")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirstCurrencyExists(t *testing.T) {
|
||||
c := currency.NewPairFromStrings("BTC", "AUD")
|
||||
base := Base{
|
||||
Pair: c,
|
||||
Asks: []Item{{Price: 100, Amount: 10}},
|
||||
Bids: []Item{{Price: 200, Amount: 10}},
|
||||
}
|
||||
|
||||
CreateNewOrderbook("Exchange", &base, asset.Spot)
|
||||
|
||||
if !BaseCurrencyExists("Exchange", c.Base) {
|
||||
t.Fatal("Test failed. TestFirstCurrencyExists expected first currency doesn't exist")
|
||||
}
|
||||
|
||||
var item = currency.NewCode("blah")
|
||||
if BaseCurrencyExists("Exchange", item) {
|
||||
t.Fatal("Test failed. TestFirstCurrencyExists unexpected first currency exists")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecondCurrencyExists(t *testing.T) {
|
||||
c := currency.NewPairFromStrings("BTC", "USD")
|
||||
base := Base{
|
||||
Pair: c,
|
||||
Asks: []Item{{Price: 100, Amount: 10}},
|
||||
Bids: []Item{{Price: 200, Amount: 10}},
|
||||
}
|
||||
|
||||
CreateNewOrderbook("Exchange", &base, asset.Spot)
|
||||
|
||||
if !QuoteCurrencyExists("Exchange", c) {
|
||||
t.Fatal("Test failed. TestSecondCurrencyExists expected first currency doesn't exist")
|
||||
}
|
||||
|
||||
c.Quote = currency.NewCode("blah")
|
||||
if QuoteCurrencyExists("Exchange", c) {
|
||||
t.Fatal("Test failed. TestSecondCurrencyExists unexpected first currency exists")
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateNewOrderbook(t *testing.T) {
|
||||
c := currency.NewPairFromStrings("BTC", "USD")
|
||||
base := Base{
|
||||
Pair: c,
|
||||
Asks: []Item{{Price: 100, Amount: 10}},
|
||||
Bids: []Item{{Price: 200, Amount: 10}},
|
||||
base := &Base{
|
||||
Pair: c,
|
||||
Asks: []Item{{Price: 100, Amount: 10}},
|
||||
Bids: []Item{{Price: 200, Amount: 10}},
|
||||
ExchangeName: "testCreateNewOrderbook",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
CreateNewOrderbook("Exchange", &base, asset.Spot)
|
||||
|
||||
result, err := Get("Exchange", c, asset.Spot)
|
||||
err := base.Process()
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestCreateNewOrderbook failed to create new orderbook")
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
result, err := Get("testCreateNewOrderbook", c, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestCreateNewOrderbook failed to create new orderbook", err)
|
||||
}
|
||||
|
||||
if !result.Pair.Equal(c) {
|
||||
@@ -223,12 +305,11 @@ func TestCreateNewOrderbook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessOrderbook(t *testing.T) {
|
||||
Orderbooks = []Orderbook{}
|
||||
c := currency.NewPairFromStrings("BTC", "USD")
|
||||
base := Base{
|
||||
Asks: []Item{{Price: 100, Amount: 10}},
|
||||
Bids: []Item{{Price: 200, Amount: 10}},
|
||||
ExchangeName: "Exchange",
|
||||
ExchangeName: "ProcessOrderbook",
|
||||
}
|
||||
|
||||
// test for empty pair
|
||||
@@ -251,7 +332,7 @@ func TestProcessOrderbook(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("unexpcted result: ", err)
|
||||
}
|
||||
result, err := Get("Exchange", c, asset.Spot)
|
||||
result, err := Get("ProcessOrderbook", c, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessOrderbook failed to create new orderbook")
|
||||
}
|
||||
@@ -266,7 +347,7 @@ func TestProcessOrderbook(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Process() error", err)
|
||||
}
|
||||
result, err = Get("Exchange", c, asset.Spot)
|
||||
result, err = Get("ProcessOrderbook", c, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessOrderbook failed to retrieve new orderbook")
|
||||
}
|
||||
@@ -281,7 +362,7 @@ func TestProcessOrderbook(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Process() error", err)
|
||||
}
|
||||
result, err = Get("Exchange", c, asset.Spot)
|
||||
result, err = Get("ProcessOrderbook", c, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessOrderbook failed to retrieve new orderbook")
|
||||
}
|
||||
@@ -296,7 +377,7 @@ func TestProcessOrderbook(t *testing.T) {
|
||||
t.Error("Test Failed - Process() error", err)
|
||||
}
|
||||
|
||||
result, err = Get("Exchange", c, "monthly")
|
||||
result, err = Get("ProcessOrderbook", c, "monthly")
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessOrderbook failed to retrieve new orderbook")
|
||||
}
|
||||
@@ -408,3 +489,17 @@ func TestProcessOrderbook(t *testing.T) {
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestSetNewData(t *testing.T) {
|
||||
err := service.SetNewData(nil)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil ")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAssociations(t *testing.T) {
|
||||
_, err := service.GetAssociations(nil)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil ")
|
||||
}
|
||||
}
|
||||
|
||||
69
exchanges/orderbook/orderbook_types.go
Normal file
69
exchanges/orderbook/orderbook_types.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package orderbook
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
// const values for orderbook package
|
||||
const (
|
||||
errExchangeNameUnset = "orderbook exchange name not set"
|
||||
errPairNotSet = "orderbook currency pair not set"
|
||||
errAssetTypeNotSet = "orderbook asset type not set"
|
||||
errNoOrderbook = "orderbook bids and asks are empty"
|
||||
)
|
||||
|
||||
// Vars for the orderbook package
|
||||
var (
|
||||
service *Service
|
||||
)
|
||||
|
||||
func init() {
|
||||
service = new(Service)
|
||||
service.mux = dispatch.GetNewMux()
|
||||
service.Books = make(map[string]map[*currency.Item]map[*currency.Item]map[asset.Item]*Book)
|
||||
service.Exchange = make(map[string]uuid.UUID)
|
||||
}
|
||||
|
||||
// Book defines an orderbook with its links to different dispatch outputs
|
||||
type Book struct {
|
||||
b *Base
|
||||
Main uuid.UUID
|
||||
Assoc []uuid.UUID
|
||||
}
|
||||
|
||||
// Service holds orderbook information for each individual exchange
|
||||
type Service struct {
|
||||
Books map[string]map[*currency.Item]map[*currency.Item]map[asset.Item]*Book
|
||||
Exchange map[string]uuid.UUID
|
||||
mux *dispatch.Mux
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
// Item stores the amount and price values
|
||||
type Item struct {
|
||||
Amount float64
|
||||
Price float64
|
||||
ID int64
|
||||
}
|
||||
|
||||
// Base holds the fields for the orderbook base
|
||||
type Base struct {
|
||||
Pair currency.Pair `json:"pair"`
|
||||
Bids []Item `json:"bids"`
|
||||
Asks []Item `json:"asks"`
|
||||
LastUpdated time.Time `json:"lastUpdated"`
|
||||
AssetType asset.Item `json:"assetType"`
|
||||
ExchangeName string `json:"exchangeName"`
|
||||
}
|
||||
|
||||
type byOBPrice []Item
|
||||
|
||||
func (a byOBPrice) Len() int { return len(a) }
|
||||
func (a byOBPrice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a byOBPrice) Less(i, j int) bool { return a[i].Price < a[j].Price }
|
||||
@@ -329,6 +329,7 @@ func (p *Poloniex) WsProcessOrderbookSnapshot(ob []interface{}, symbol string) e
|
||||
newOrderBook.Bids = bids
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.Pair = currency.NewPairFromString(symbol)
|
||||
newOrderBook.ExchangeName = p.GetName()
|
||||
|
||||
return p.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
}
|
||||
|
||||
@@ -3,191 +3,205 @@ package ticker
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
// const values for the ticker package
|
||||
const (
|
||||
errExchangeTickerNotFound = "ticker for exchange does not exist"
|
||||
errPairNotSet = "ticker currency pair not set"
|
||||
errAssetTypeNotSet = "ticker asset type not set"
|
||||
errBaseCurrencyNotFound = "ticker base currency not found"
|
||||
errQuoteCurrencyNotFound = "ticker quote currency not found"
|
||||
)
|
||||
|
||||
// Vars for the ticker package
|
||||
var (
|
||||
Tickers []Ticker
|
||||
m sync.Mutex
|
||||
)
|
||||
|
||||
// Price struct stores the currency pair and pricing information
|
||||
type Price struct {
|
||||
Last float64 `json:"Last"`
|
||||
High float64 `json:"High"`
|
||||
Low float64 `json:"Low"`
|
||||
Bid float64 `json:"Bid"`
|
||||
Ask float64 `json:"Ask"`
|
||||
Volume float64 `json:"Volume"`
|
||||
QuoteVolume float64 `json:"QuoteVolume"`
|
||||
PriceATH float64 `json:"PriceATH"`
|
||||
Open float64 `json:"Open"`
|
||||
Close float64 `json:"Close"`
|
||||
Pair currency.Pair `json:"Pair"`
|
||||
LastUpdated time.Time
|
||||
func init() {
|
||||
service = new(Service)
|
||||
service.Tickers = make(map[string]map[*currency.Item]map[*currency.Item]map[asset.Item]*Ticker)
|
||||
service.Exchange = make(map[string]uuid.UUID)
|
||||
service.mux = dispatch.GetNewMux()
|
||||
}
|
||||
|
||||
// Ticker struct holds the ticker information for a currency pair and type
|
||||
type Ticker struct {
|
||||
Price map[string]map[string]map[string]Price
|
||||
ExchangeName string
|
||||
}
|
||||
// SubscribeTicker subcribes to a ticker and returns a communication channel to
|
||||
// stream new ticker updates
|
||||
func SubscribeTicker(exchange string, p currency.Pair, a asset.Item) (dispatch.Pipe, error) {
|
||||
exchange = strings.ToLower(exchange)
|
||||
service.RLock()
|
||||
defer service.RUnlock()
|
||||
|
||||
// PriceToString returns the string version of a stored price field
|
||||
func (t *Ticker) PriceToString(p currency.Pair, priceType string, tickerType asset.Item) string {
|
||||
priceType = strings.ToLower(priceType)
|
||||
|
||||
switch priceType {
|
||||
case "last":
|
||||
return strconv.FormatFloat(t.Price[p.Base.Upper().String()][p.Quote.Upper().String()][tickerType.String()].Last, 'f', -1, 64)
|
||||
case "high":
|
||||
return strconv.FormatFloat(t.Price[p.Base.Upper().String()][p.Quote.Upper().String()][tickerType.String()].High, 'f', -1, 64)
|
||||
case "low":
|
||||
return strconv.FormatFloat(t.Price[p.Base.Upper().String()][p.Quote.Upper().String()][tickerType.String()].Low, 'f', -1, 64)
|
||||
case "bid":
|
||||
return strconv.FormatFloat(t.Price[p.Base.Upper().String()][p.Quote.Upper().String()][tickerType.String()].Bid, 'f', -1, 64)
|
||||
case "ask":
|
||||
return strconv.FormatFloat(t.Price[p.Base.Upper().String()][p.Quote.Upper().String()][tickerType.String()].Ask, 'f', -1, 64)
|
||||
case "volume":
|
||||
return strconv.FormatFloat(t.Price[p.Base.Upper().String()][p.Quote.Upper().String()][tickerType.String()].Volume, 'f', -1, 64)
|
||||
case "ath":
|
||||
return strconv.FormatFloat(t.Price[p.Base.Upper().String()][p.Quote.Upper().String()][tickerType.String()].PriceATH, 'f', -1, 64)
|
||||
default:
|
||||
return ""
|
||||
tick, ok := service.Tickers[exchange][p.Base.Item][p.Quote.Item][a]
|
||||
if !ok {
|
||||
return dispatch.Pipe{}, fmt.Errorf("ticker item not found for %s %s %s",
|
||||
exchange,
|
||||
p,
|
||||
a)
|
||||
}
|
||||
|
||||
return service.mux.Subscribe(tick.Main)
|
||||
}
|
||||
|
||||
// SubscribeToExchangeTickers subcribes to all tickers on an exchange
|
||||
func SubscribeToExchangeTickers(exchange string) (dispatch.Pipe, error) {
|
||||
exchange = strings.ToLower(exchange)
|
||||
service.RLock()
|
||||
defer service.RUnlock()
|
||||
id, ok := service.Exchange[exchange]
|
||||
if !ok {
|
||||
return dispatch.Pipe{}, fmt.Errorf("%s exchange tickers not found",
|
||||
exchange)
|
||||
}
|
||||
|
||||
return service.mux.Subscribe(id)
|
||||
}
|
||||
|
||||
// GetTicker checks and returns a requested ticker if it exists
|
||||
func GetTicker(exchange string, p currency.Pair, tickerType asset.Item) (Price, error) {
|
||||
ticker, err := GetTickerByExchange(exchange)
|
||||
if err != nil {
|
||||
return Price{}, err
|
||||
exchange = strings.ToLower(exchange)
|
||||
service.RLock()
|
||||
defer service.RUnlock()
|
||||
if service.Tickers[exchange] == nil {
|
||||
return Price{}, fmt.Errorf("no tickers for %s exchange", exchange)
|
||||
}
|
||||
|
||||
if !BaseCurrencyExists(exchange, p.Base) {
|
||||
return Price{}, errors.New(errBaseCurrencyNotFound)
|
||||
if service.Tickers[exchange][p.Base.Item] == nil {
|
||||
return Price{}, fmt.Errorf("no tickers associated with base currency %s",
|
||||
p.Base)
|
||||
}
|
||||
|
||||
if !QuoteCurrencyExists(exchange, p) {
|
||||
return Price{}, errors.New(errQuoteCurrencyNotFound)
|
||||
if service.Tickers[exchange][p.Base.Item][p.Quote.Item] == nil {
|
||||
return Price{}, fmt.Errorf("no tickers associated with quote currency %s",
|
||||
p.Quote)
|
||||
}
|
||||
|
||||
return ticker.Price[p.Base.Upper().String()][p.Quote.Upper().String()][tickerType.String()], nil
|
||||
}
|
||||
|
||||
// GetTickerByExchange returns an exchange Ticker
|
||||
func GetTickerByExchange(exchange string) (*Ticker, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for x := range Tickers {
|
||||
if Tickers[x].ExchangeName == exchange {
|
||||
return &Tickers[x], nil
|
||||
}
|
||||
if service.Tickers[exchange][p.Base.Item][p.Quote.Item][tickerType] == nil {
|
||||
return Price{}, fmt.Errorf("no tickers associated with asset type %s",
|
||||
tickerType)
|
||||
}
|
||||
return nil, errors.New(errExchangeTickerNotFound)
|
||||
}
|
||||
|
||||
// BaseCurrencyExists checks to see if the base currency of the ticker map
|
||||
// exists
|
||||
func BaseCurrencyExists(exchange string, currency currency.Code) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Tickers {
|
||||
if y.ExchangeName == exchange {
|
||||
if _, ok := y.Price[currency.Upper().String()]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// QuoteCurrencyExists checks to see if the quote currency of the ticker map
|
||||
// exists
|
||||
func QuoteCurrencyExists(exchange string, p currency.Pair) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Tickers {
|
||||
if y.ExchangeName == exchange {
|
||||
if _, ok := y.Price[p.Base.Upper().String()]; ok {
|
||||
if _, ok := y.Price[p.Base.Upper().String()][p.Quote.Upper().String()]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateNewTicker creates a new Ticker
|
||||
func CreateNewTicker(exchangeName string, tickerNew *Price, tickerType asset.Item) Ticker {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
ticker := Ticker{}
|
||||
ticker.ExchangeName = exchangeName
|
||||
ticker.Price = make(map[string]map[string]map[string]Price)
|
||||
a := make(map[string]map[string]Price)
|
||||
b := make(map[string]Price)
|
||||
b[tickerType.String()] = *tickerNew
|
||||
a[tickerNew.Pair.Quote.Upper().String()] = b
|
||||
ticker.Price[tickerNew.Pair.Base.Upper().String()] = a
|
||||
Tickers = append(Tickers, ticker)
|
||||
return ticker
|
||||
return service.Tickers[exchange][p.Base.Item][p.Quote.Item][tickerType].Price, nil
|
||||
}
|
||||
|
||||
// ProcessTicker processes incoming tickers, creating or updating the Tickers
|
||||
// list
|
||||
func ProcessTicker(exchangeName string, tickerNew *Price, assetType asset.Item) error {
|
||||
if exchangeName == "" {
|
||||
return fmt.Errorf(errExchangeNameUnset)
|
||||
}
|
||||
|
||||
tickerNew.ExchangeName = strings.ToLower(exchangeName)
|
||||
|
||||
if tickerNew.Pair.IsEmpty() {
|
||||
return fmt.Errorf("%v %v", exchangeName, errPairNotSet)
|
||||
return fmt.Errorf("%s %s", exchangeName, errPairNotSet)
|
||||
}
|
||||
|
||||
if assetType == "" {
|
||||
return fmt.Errorf("%v %v %v", exchangeName, tickerNew.Pair.String(), errAssetTypeNotSet)
|
||||
return fmt.Errorf("%s %s %s", exchangeName,
|
||||
tickerNew.Pair,
|
||||
errAssetTypeNotSet)
|
||||
}
|
||||
|
||||
tickerNew.AssetType = assetType
|
||||
|
||||
if tickerNew.LastUpdated.IsZero() {
|
||||
tickerNew.LastUpdated = time.Now()
|
||||
}
|
||||
|
||||
ticker, err := GetTickerByExchange(exchangeName)
|
||||
return service.Update(tickerNew)
|
||||
}
|
||||
|
||||
// Update updates ticker price
|
||||
func (s *Service) Update(p *Price) error {
|
||||
var ids []uuid.UUID
|
||||
|
||||
s.Lock()
|
||||
switch {
|
||||
case s.Tickers[p.ExchangeName] == nil:
|
||||
s.Tickers[p.ExchangeName] = make(map[*currency.Item]map[*currency.Item]map[asset.Item]*Ticker)
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item] = make(map[*currency.Item]map[asset.Item]*Ticker)
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item] = make(map[asset.Item]*Ticker)
|
||||
err := s.SetItemID(p)
|
||||
if err != nil {
|
||||
s.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
case s.Tickers[p.ExchangeName][p.Pair.Base.Item] == nil:
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item] = make(map[*currency.Item]map[asset.Item]*Ticker)
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item] = make(map[asset.Item]*Ticker)
|
||||
err := s.SetItemID(p)
|
||||
if err != nil {
|
||||
s.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
case s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item] == nil:
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item] = make(map[asset.Item]*Ticker)
|
||||
err := s.SetItemID(p)
|
||||
if err != nil {
|
||||
s.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
case s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType] == nil:
|
||||
err := s.SetItemID(p)
|
||||
if err != nil {
|
||||
s.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
default:
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Last = p.Last
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].High = p.High
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Low = p.Low
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Bid = p.Bid
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Ask = p.Ask
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Volume = p.Volume
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].QuoteVolume = p.QuoteVolume
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].PriceATH = p.PriceATH
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Open = p.Open
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Close = p.Close
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].LastUpdated = p.LastUpdated
|
||||
ids = s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Assoc
|
||||
ids = append(ids, s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType].Main)
|
||||
}
|
||||
s.Unlock()
|
||||
return s.mux.Publish(ids, p)
|
||||
}
|
||||
|
||||
// SetItemID retrieves and sets dispatch mux publish IDs
|
||||
func (s *Service) SetItemID(p *Price) error {
|
||||
if p == nil {
|
||||
return errors.New(errTickerPriceIsNil)
|
||||
}
|
||||
|
||||
ids, err := s.GetAssociations(p)
|
||||
if err != nil {
|
||||
CreateNewTicker(exchangeName, tickerNew, assetType)
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
singleID, err := s.mux.GetID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if BaseCurrencyExists(exchangeName, tickerNew.Pair.Base) {
|
||||
m.Lock()
|
||||
a := make(map[string]Price)
|
||||
a[assetType.String()] = *tickerNew
|
||||
ticker.Price[tickerNew.Pair.Base.Upper().String()][tickerNew.Pair.Quote.Upper().String()] = a
|
||||
m.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
|
||||
a := make(map[string]map[string]Price)
|
||||
b := make(map[string]Price)
|
||||
b[assetType.String()] = *tickerNew
|
||||
a[tickerNew.Pair.Quote.Upper().String()] = b
|
||||
ticker.Price[tickerNew.Pair.Base.Upper().String()] = a
|
||||
m.Unlock()
|
||||
s.Tickers[p.ExchangeName][p.Pair.Base.Item][p.Pair.Quote.Item][p.AssetType] = &Ticker{Price: *p,
|
||||
Main: singleID,
|
||||
Assoc: ids}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAssociations links a singular book with it's dispatch associations
|
||||
func (s *Service) GetAssociations(p *Price) ([]uuid.UUID, error) {
|
||||
if p == nil || *p == (Price{}) {
|
||||
return nil, errors.New(errTickerPriceIsNil)
|
||||
}
|
||||
var ids []uuid.UUID
|
||||
exchangeID, ok := s.Exchange[p.ExchangeName]
|
||||
if !ok {
|
||||
var err error
|
||||
exchangeID, err = s.mux.GetID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Exchange[p.ExchangeName] = exchangeID
|
||||
}
|
||||
|
||||
ids = append(ids, exchangeID)
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
@@ -1,55 +1,94 @@
|
||||
package ticker
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
func TestPriceToString(t *testing.T) {
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
func TestMain(m *testing.M) {
|
||||
err := dispatch.Start(1)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
newTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
|
||||
cpyMux = service.mux
|
||||
|
||||
if newTicker.PriceToString(newPair, "last", asset.Spot) != "1200" {
|
||||
t.Error("Test Failed - ticker PriceToString last value is incorrect")
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
var cpyMux *dispatch.Mux
|
||||
|
||||
func TestSubscribeTicker(t *testing.T) {
|
||||
_, err := SubscribeTicker("", currency.Pair{}, asset.Item(""))
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "high", asset.Spot) != "1298" {
|
||||
t.Error("Test Failed - ticker PriceToString high value is incorrect")
|
||||
|
||||
p := currency.NewPair(currency.BTC, currency.USD)
|
||||
|
||||
// force error
|
||||
service.mux = nil
|
||||
err = ProcessTicker("subscribetest", &Price{Pair: p}, asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "low", asset.Spot) != "1148" {
|
||||
t.Error("Test Failed - ticker PriceToString low value is incorrect")
|
||||
|
||||
sillyP := p
|
||||
sillyP.Base = currency.GALA_NEO
|
||||
err = ProcessTicker("subscribetest", &Price{Pair: sillyP}, asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "bid", asset.Spot) != "1195" {
|
||||
t.Error("Test Failed - ticker PriceToString bid value is incorrect")
|
||||
|
||||
sillyP.Quote = currency.AAA
|
||||
err = ProcessTicker("subscribetest", &Price{Pair: sillyP}, asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "ask", asset.Spot) != "1220" {
|
||||
t.Error("Test Failed - ticker PriceToString ask value is incorrect")
|
||||
|
||||
err = ProcessTicker("subscribetest", &Price{Pair: sillyP}, "silly")
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "volume", asset.Spot) != "5" {
|
||||
t.Error("Test Failed - ticker PriceToString volume value is incorrect")
|
||||
// reinstate mux
|
||||
service.mux = cpyMux
|
||||
|
||||
err = ProcessTicker("subscribetest", &Price{Pair: p}, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "ath", asset.Spot) != "1337" {
|
||||
t.Error("Test Failed - ticker PriceToString ath value is incorrect")
|
||||
|
||||
_, err = SubscribeTicker("subscribetest", p, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("cannot subscribe to ticker", err)
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "obtuse", asset.Spot) != "" {
|
||||
t.Error("Test Failed - ticker PriceToString obtuse value is incorrect")
|
||||
}
|
||||
|
||||
func TestSubscribeToExchangeTickers(t *testing.T) {
|
||||
_, err := SubscribeToExchangeTickers("")
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
p := currency.NewPair(currency.BTC, currency.USD)
|
||||
|
||||
err = ProcessTicker("subscribeExchangeTest", &Price{Pair: p}, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = SubscribeToExchangeTickers("subscribeExchangeTest")
|
||||
if err != nil {
|
||||
t.Error("error cannot be nil", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,142 +150,25 @@ func TestGetTicker(t *testing.T) {
|
||||
if tickerPrice.PriceATH != 9001 {
|
||||
t.Error("Test Failed - ticker tickerPrice.PriceATH value is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTickerByExchange(t *testing.T) {
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
_, err = GetTicker("bitfinex", newPair, "meowCats")
|
||||
if err == nil {
|
||||
t.Error("Test Failed - Ticker GetTicker error cannot be nil")
|
||||
}
|
||||
|
||||
anxTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
|
||||
Tickers = append(Tickers, anxTicker)
|
||||
|
||||
tickerPtr, err := GetTickerByExchange("ANX")
|
||||
err = ProcessTicker("bitfinex", &priceStruct, "meowCats")
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - GetTickerByExchange init error: %s", err)
|
||||
}
|
||||
if tickerPtr.ExchangeName != "ANX" {
|
||||
t.Error("Test Failed - GetTickerByExchange ExchangeName value is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseCurrencyExists(t *testing.T) {
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
t.Fatal("Test failed. ProcessTicker error", err)
|
||||
}
|
||||
|
||||
alphaTicker := CreateNewTicker("alphapoint", &priceStruct, asset.Spot)
|
||||
Tickers = append(Tickers, alphaTicker)
|
||||
|
||||
if !BaseCurrencyExists("alphapoint", currency.BTC) {
|
||||
t.Error("Test Failed - BaseCurrencyExists1 value return is incorrect")
|
||||
}
|
||||
if BaseCurrencyExists("alphapoint", currency.NewCode("CATS")) {
|
||||
t.Error("Test Failed - BaseCurrencyExists2 value return is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuoteCurrencyExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
bitstampTicker := CreateNewTicker("bitstamp", &priceStruct, asset.Spot)
|
||||
Tickers = append(Tickers, bitstampTicker)
|
||||
|
||||
if !QuoteCurrencyExists("bitstamp", newPair) {
|
||||
t.Error("Test Failed - QuoteCurrencyExists1 value return is incorrect")
|
||||
}
|
||||
|
||||
newPair.Quote = currency.NewCode("DOGS")
|
||||
if QuoteCurrencyExists("bitstamp", newPair) {
|
||||
t.Error("Test Failed - QuoteCurrencyExists2 value return is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateNewTicker(t *testing.T) {
|
||||
const float64Type = "float64"
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
Bid: 1195,
|
||||
Ask: 1220,
|
||||
Volume: 5,
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
newTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
|
||||
|
||||
if reflect.ValueOf(newTicker).NumField() != 2 {
|
||||
t.Error("Test Failed - ticker CreateNewTicker struct change/or updated")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.ExchangeName).String() != "string" {
|
||||
t.Error("Test Failed - ticker CreateNewTicker.ExchangeName value is not a string")
|
||||
}
|
||||
if newTicker.ExchangeName != "ANX" {
|
||||
t.Error("Test Failed - ticker CreateNewTicker.ExchangeName value is not ANX")
|
||||
}
|
||||
|
||||
if !newTicker.Price[currency.BTC.Upper().String()][currency.USD.Upper().String()][asset.Spot.String()].Pair.Equal(newPair) {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Pair.Pair().String() value is not expected 'BTCUSD'")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Ask).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Ask value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Bid).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Bid value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Pair).String() != "currency.Pair" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].CurrencyPair value is not a currency.Pair")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].High).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].High value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Last).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Last value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Low).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Low value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].PriceATH).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].PriceATH value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Volume).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Volume value is not a float64")
|
||||
// process update again
|
||||
err = ProcessTicker("bitfinex", &priceStruct, "meowCats")
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. ProcessTicker error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
Tickers = []Ticker{}
|
||||
exchName := "bitstamp"
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
priceStruct := Price{
|
||||
@@ -259,8 +181,13 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
err := ProcessTicker("", &priceStruct, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("empty exchange should throw an err")
|
||||
}
|
||||
|
||||
// test for empty pair
|
||||
err := ProcessTicker(exchName, &priceStruct, asset.Spot)
|
||||
err = ProcessTicker(exchName, &priceStruct, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("empty pair should throw an err")
|
||||
}
|
||||
@@ -389,5 +316,44 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
}
|
||||
|
||||
func TestSetItemID(t *testing.T) {
|
||||
err := service.SetItemID(nil)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
err = service.SetItemID(&Price{})
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
p := currency.NewPair(currency.CYC, currency.CYG)
|
||||
|
||||
service.mux = nil
|
||||
err = service.SetItemID(&Price{Pair: p, ExchangeName: "SetItemID"})
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
service.mux = cpyMux
|
||||
}
|
||||
|
||||
func TestGetAssociation(t *testing.T) {
|
||||
_, err := service.GetAssociations(nil)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil ")
|
||||
}
|
||||
|
||||
p := currency.NewPair(currency.CYC, currency.CYG)
|
||||
|
||||
service.mux = nil
|
||||
|
||||
_, err = service.GetAssociations(&Price{Pair: p, ExchangeName: "GetAssociation"})
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil ")
|
||||
}
|
||||
|
||||
service.mux = cpyMux
|
||||
}
|
||||
|
||||
57
exchanges/ticker/ticker_types.go
Normal file
57
exchanges/ticker/ticker_types.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package ticker
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
// const values for the ticker package
|
||||
const (
|
||||
errExchangeNameUnset = "ticker exchange name not set"
|
||||
errPairNotSet = "ticker currency pair not set"
|
||||
errAssetTypeNotSet = "ticker asset type not set"
|
||||
errTickerPriceIsNil = "ticker price is nil"
|
||||
)
|
||||
|
||||
// Vars for the ticker package
|
||||
var (
|
||||
service *Service
|
||||
)
|
||||
|
||||
// Service holds ticker information for each individual exchange
|
||||
type Service struct {
|
||||
Tickers map[string]map[*currency.Item]map[*currency.Item]map[asset.Item]*Ticker
|
||||
Exchange map[string]uuid.UUID
|
||||
mux *dispatch.Mux
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
// Price struct stores the currency pair and pricing information
|
||||
type Price struct {
|
||||
Last float64 `json:"Last"`
|
||||
High float64 `json:"High"`
|
||||
Low float64 `json:"Low"`
|
||||
Bid float64 `json:"Bid"`
|
||||
Ask float64 `json:"Ask"`
|
||||
Volume float64 `json:"Volume"`
|
||||
QuoteVolume float64 `json:"QuoteVolume"`
|
||||
PriceATH float64 `json:"PriceATH"`
|
||||
Open float64 `json:"Open"`
|
||||
Close float64 `json:"Close"`
|
||||
Pair currency.Pair `json:"Pair"`
|
||||
ExchangeName string `json:"exchangeName"`
|
||||
AssetType asset.Item `json:"assetType"`
|
||||
LastUpdated time.Time
|
||||
}
|
||||
|
||||
// Ticker struct holds the ticker information for a currency pair and type
|
||||
type Ticker struct {
|
||||
Price
|
||||
Main uuid.UUID
|
||||
Assoc []uuid.UUID
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package wsorderbook
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"sync"
|
||||
@@ -205,6 +206,19 @@ func (w *WebsocketOrderbookLocal) LoadSnapshot(newOrderbook *orderbook.Base) err
|
||||
if len(newOrderbook.Asks) == 0 || len(newOrderbook.Bids) == 0 {
|
||||
return fmt.Errorf("%v snapshot ask and bids are nil", w.exchangeName)
|
||||
}
|
||||
|
||||
if newOrderbook.Pair.IsEmpty() {
|
||||
return errors.New("websocket orderbook pair unset")
|
||||
}
|
||||
|
||||
if newOrderbook.AssetType.String() == "" {
|
||||
return errors.New("websocket orderbook asset type unset")
|
||||
}
|
||||
|
||||
if newOrderbook.ExchangeName == "" {
|
||||
return errors.New("websocket orderbook exchange name unset")
|
||||
}
|
||||
|
||||
w.m.Lock()
|
||||
defer w.m.Unlock()
|
||||
if w.ob == nil {
|
||||
|
||||
@@ -26,6 +26,7 @@ const (
|
||||
|
||||
func createSnapshot() (obl *WebsocketOrderbookLocal, curr currency.Pair, asks, bids []orderbook.Item, err error) {
|
||||
var snapShot1 orderbook.Base
|
||||
snapShot1.ExchangeName = exchangeName
|
||||
curr = currency.NewPairFromString("BTCUSD")
|
||||
asks = []orderbook.Item{
|
||||
{Price: 4000, Amount: 1, ID: 6},
|
||||
@@ -37,19 +38,28 @@ func createSnapshot() (obl *WebsocketOrderbookLocal, curr currency.Pair, asks, b
|
||||
snapShot1.Bids = bids
|
||||
snapShot1.AssetType = asset.Spot
|
||||
snapShot1.Pair = curr
|
||||
obl = &WebsocketOrderbookLocal{}
|
||||
obl = &WebsocketOrderbookLocal{exchangeName: exchangeName}
|
||||
err = obl.LoadSnapshot(&snapShot1)
|
||||
return
|
||||
}
|
||||
|
||||
// BenchmarkBufferPerformance demonstrates buffer more performant than multi process calls
|
||||
// BenchmarkBufferPerformance demonstrates buffer more performant than multi
|
||||
// process calls
|
||||
func BenchmarkBufferPerformance(b *testing.B) {
|
||||
obl, curr, asks, bids, err := createSnapshot()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
obl.sortBuffer = true
|
||||
cp := currency.NewPairFromString("BTCUSD")
|
||||
// This is to ensure we do not send in zero orderbook info to our main book
|
||||
// in orderbook.go, orderbooks should not be zero even after an update.
|
||||
dummyItem := orderbook.Item{
|
||||
Amount: 1333337,
|
||||
Price: 1337.1337,
|
||||
ID: 1337,
|
||||
}
|
||||
obl.ob[cp][asset.Spot].Bids = append(obl.ob[cp][asset.Spot].Bids, dummyItem)
|
||||
update := &WebsocketOrderbookUpdate{
|
||||
Bids: bids,
|
||||
Asks: asks,
|
||||
@@ -74,7 +84,6 @@ func BenchmarkBufferSortingPerformance(b *testing.B) {
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
obl.sortBuffer = true
|
||||
obl.bufferEnabled = true
|
||||
obl.obBufferLimit = 5
|
||||
@@ -96,13 +105,22 @@ func BenchmarkBufferSortingPerformance(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkNoBufferPerformance demonstrates orderbook process less performant than buffer
|
||||
// BenchmarkNoBufferPerformance demonstrates orderbook process less performant
|
||||
// than buffer
|
||||
func BenchmarkNoBufferPerformance(b *testing.B) {
|
||||
obl, curr, asks, bids, err := createSnapshot()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
cp := currency.NewPairFromString("BTCUSD")
|
||||
// This is to ensure we do not send in zero orderbook info to our main book
|
||||
// in orderbook.go, orderbooks should not be zero even after an update.
|
||||
dummyItem := orderbook.Item{
|
||||
Amount: 1333337,
|
||||
Price: 1337.1337,
|
||||
ID: 1337,
|
||||
}
|
||||
obl.ob[cp][asset.Spot].Bids = append(obl.ob[cp][asset.Spot].Bids, dummyItem)
|
||||
update := &WebsocketOrderbookUpdate{
|
||||
Bids: bids,
|
||||
Asks: asks,
|
||||
@@ -127,7 +145,6 @@ func TestHittingTheBuffer(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
obl.bufferEnabled = true
|
||||
obl.obBufferLimit = 5
|
||||
for i := 0; i < len(itemArray); i++ {
|
||||
@@ -146,10 +163,12 @@ func TestHittingTheBuffer(t *testing.T) {
|
||||
}
|
||||
if len(obl.ob[curr][asset.Spot].Asks) != 3 {
|
||||
t.Log(obl.ob[curr][asset.Spot])
|
||||
t.Errorf("expected 3 entries, received: %v", len(obl.ob[curr][asset.Spot].Asks))
|
||||
t.Errorf("expected 3 entries, received: %v",
|
||||
len(obl.ob[curr][asset.Spot].Asks))
|
||||
}
|
||||
if len(obl.ob[curr][asset.Spot].Bids) != 3 {
|
||||
t.Errorf("expected 3 entries, received: %v", len(obl.ob[curr][asset.Spot].Bids))
|
||||
t.Errorf("expected 3 entries, received: %v",
|
||||
len(obl.ob[curr][asset.Spot].Bids))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +178,6 @@ func TestInsertWithIDs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
obl.bufferEnabled = true
|
||||
obl.updateEntriesByID = true
|
||||
obl.obBufferLimit = 5
|
||||
@@ -179,10 +197,12 @@ func TestInsertWithIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if len(obl.ob[curr][asset.Spot].Asks) != 6 {
|
||||
t.Errorf("expected 6 entries, received: %v", len(obl.ob[curr][asset.Spot].Asks))
|
||||
t.Errorf("expected 6 entries, received: %v",
|
||||
len(obl.ob[curr][asset.Spot].Asks))
|
||||
}
|
||||
if len(obl.ob[curr][asset.Spot].Bids) != 6 {
|
||||
t.Errorf("expected 6 entries, received: %v", len(obl.ob[curr][asset.Spot].Bids))
|
||||
t.Errorf("expected 6 entries, received: %v",
|
||||
len(obl.ob[curr][asset.Spot].Bids))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +212,6 @@ func TestSortIDs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
obl.bufferEnabled = true
|
||||
obl.sortBufferByUpdateIDs = true
|
||||
obl.sortBuffer = true
|
||||
@@ -212,10 +231,12 @@ func TestSortIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if len(obl.ob[curr][asset.Spot].Asks) != 3 {
|
||||
t.Errorf("expected 6 entries, received: %v", len(obl.ob[curr][asset.Spot].Asks))
|
||||
t.Errorf("expected 3 entries, received: %v",
|
||||
len(obl.ob[curr][asset.Spot].Asks))
|
||||
}
|
||||
if len(obl.ob[curr][asset.Spot].Bids) != 3 {
|
||||
t.Errorf("expected 6 entries, received: %v", len(obl.ob[curr][asset.Spot].Bids))
|
||||
t.Errorf("expected 3 entries, received: %v",
|
||||
len(obl.ob[curr][asset.Spot].Bids))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +246,16 @@ func TestDeleteWithIDs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
|
||||
cp := currency.NewPairFromString("BTCUSD")
|
||||
// This is to ensure we do not send in zero orderbook info to our main book
|
||||
// in orderbook.go, orderbooks should not be zero even after an update.
|
||||
dummyItem := orderbook.Item{
|
||||
Amount: 1333337,
|
||||
Price: 1337.1337,
|
||||
ID: 1337,
|
||||
}
|
||||
obl.ob[cp][asset.Spot].Bids = append(obl.ob[cp][asset.Spot].Bids, dummyItem)
|
||||
obl.updateEntriesByID = true
|
||||
for i := 0; i < len(itemArray); i++ {
|
||||
asks := itemArray[i]
|
||||
@@ -243,10 +273,12 @@ func TestDeleteWithIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if len(obl.ob[curr][asset.Spot].Asks) != 0 {
|
||||
t.Errorf("expected 0 entries, received: %v", len(obl.ob[curr][asset.Spot].Asks))
|
||||
t.Errorf("expected 0 entries, received: %v",
|
||||
len(obl.ob[curr][asset.Spot].Asks))
|
||||
}
|
||||
if len(obl.ob[curr][asset.Spot].Bids) != 0 {
|
||||
t.Errorf("expected 0 entries, received: %v", len(obl.ob[curr][asset.Spot].Bids))
|
||||
if len(obl.ob[curr][asset.Spot].Bids) != 1 {
|
||||
t.Errorf("expected 1 entries, received: %v",
|
||||
len(obl.ob[curr][asset.Spot].Bids))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +288,6 @@ func TestUpdateWithIDs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
obl.updateEntriesByID = true
|
||||
for i := 0; i < len(itemArray); i++ {
|
||||
asks := itemArray[i]
|
||||
@@ -288,11 +319,10 @@ func TestOutOfOrderIDs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
outOFOrderIDs := []int64{2, 1, 5, 3, 4, 6}
|
||||
outOFOrderIDs := []int64{2, 1, 5, 3, 4, 6, 7}
|
||||
if itemArray[0][0].Price != 1000 {
|
||||
t.Errorf("expected sorted price to be 3000, received: %v", itemArray[1][0].Price)
|
||||
}
|
||||
obl.exchangeName = exchangeName
|
||||
obl.bufferEnabled = true
|
||||
obl.sortBuffer = true
|
||||
obl.obBufferLimit = 5
|
||||
@@ -366,7 +396,8 @@ func TestRunUpdateWithoutAnyUpdates(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("expected an error running update with no snapshot loaded")
|
||||
}
|
||||
if err.Error() != fmt.Sprintf("%v cannot have bids and ask targets both nil", exchangeName) {
|
||||
if err.Error() != fmt.Sprintf("%v cannot have bids and ask targets both nil",
|
||||
exchangeName) {
|
||||
t.Fatal("expected nil asks and bids error")
|
||||
}
|
||||
}
|
||||
@@ -395,6 +426,7 @@ func TestRunSnapshotWithNoData(t *testing.T) {
|
||||
func TestLoadSnapshot(t *testing.T) {
|
||||
var obl WebsocketOrderbookLocal
|
||||
var snapShot1 orderbook.Base
|
||||
snapShot1.ExchangeName = "SnapshotWithOverride"
|
||||
curr := currency.NewPairFromString("BTCUSD")
|
||||
asks := []orderbook.Item{
|
||||
{Price: 4000, Amount: 1, ID: 8},
|
||||
@@ -432,6 +464,7 @@ func TestFlushCache(t *testing.T) {
|
||||
func TestInsertingSnapShots(t *testing.T) {
|
||||
var obl WebsocketOrderbookLocal
|
||||
var snapShot1 orderbook.Base
|
||||
snapShot1.ExchangeName = "WSORDERBOOKTEST1"
|
||||
asks := []orderbook.Item{
|
||||
{Price: 6000, Amount: 1, ID: 1},
|
||||
{Price: 6001, Amount: 0.5, ID: 2},
|
||||
@@ -469,6 +502,7 @@ func TestInsertingSnapShots(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var snapShot2 orderbook.Base
|
||||
snapShot2.ExchangeName = "WSORDERBOOKTEST2"
|
||||
asks = []orderbook.Item{
|
||||
{Price: 51, Amount: 1, ID: 1},
|
||||
{Price: 52, Amount: 0.5, ID: 2},
|
||||
@@ -506,6 +540,7 @@ func TestInsertingSnapShots(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var snapShot3 orderbook.Base
|
||||
snapShot3.ExchangeName = "WSORDERBOOKTEST3"
|
||||
asks = []orderbook.Item{
|
||||
{Price: 511, Amount: 1, ID: 1},
|
||||
{Price: 52, Amount: 0.5, ID: 2},
|
||||
|
||||
@@ -142,6 +142,7 @@ func (z *ZB) WsHandleData() {
|
||||
newOrderBook.Bids = bids
|
||||
newOrderBook.AssetType = asset.Spot
|
||||
newOrderBook.Pair = cPair
|
||||
newOrderBook.ExchangeName = z.GetName()
|
||||
|
||||
err = z.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
if err != nil {
|
||||
|
||||
1162
gctrpc/rpc.pb.go
1162
gctrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@@ -9,13 +9,13 @@ It translates gRPC into RESTful JSON APIs.
|
||||
package gctrpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
@@ -54,7 +54,10 @@ func request_GoCryptoTrader_EnableSubsystem_0(ctx context.Context, marshaler run
|
||||
var protoReq GenericSubsystemRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_GoCryptoTrader_EnableSubsystem_0); err != nil {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_EnableSubsystem_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
@@ -71,7 +74,10 @@ func request_GoCryptoTrader_DisableSubsystem_0(ctx context.Context, marshaler ru
|
||||
var protoReq GenericSubsystemRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_GoCryptoTrader_DisableSubsystem_0); err != nil {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_DisableSubsystem_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
@@ -106,7 +112,10 @@ func request_GoCryptoTrader_GetExchanges_0(ctx context.Context, marshaler runtim
|
||||
var protoReq GetExchangesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_GoCryptoTrader_GetExchanges_0); err != nil {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetExchanges_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
@@ -140,7 +149,10 @@ func request_GoCryptoTrader_GetExchangeInfo_0(ctx context.Context, marshaler run
|
||||
var protoReq GenericExchangeNameRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_GoCryptoTrader_GetExchangeInfo_0); err != nil {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetExchangeInfo_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
@@ -157,7 +169,10 @@ func request_GoCryptoTrader_GetExchangeOTPCode_0(ctx context.Context, marshaler
|
||||
var protoReq GenericExchangeNameRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_GoCryptoTrader_GetExchangeOTPCode_0); err != nil {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetExchangeOTPCode_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
@@ -252,7 +267,10 @@ func request_GoCryptoTrader_GetAccountInfo_0(ctx context.Context, marshaler runt
|
||||
var protoReq GetAccountInfoRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_GoCryptoTrader_GetAccountInfo_0); err != nil {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetAccountInfo_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
@@ -578,7 +596,10 @@ func request_GoCryptoTrader_GetLoggerDetails_0(ctx context.Context, marshaler ru
|
||||
var protoReq GetLoggerDetailsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_GoCryptoTrader_GetLoggerDetails_0); err != nil {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetLoggerDetails_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
@@ -655,6 +676,118 @@ func request_GoCryptoTrader_DisableExchangePair_0(ctx context.Context, marshaler
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_GoCryptoTrader_GetOrderbookStream_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_GoCryptoTrader_GetOrderbookStream_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderClient, req *http.Request, pathParams map[string]string) (GoCryptoTrader_GetOrderbookStreamClient, runtime.ServerMetadata, error) {
|
||||
var protoReq GetOrderbookStreamRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetOrderbookStream_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
stream, err := client.GetOrderbookStream(ctx, &protoReq)
|
||||
if err != nil {
|
||||
return nil, metadata, err
|
||||
}
|
||||
header, err := stream.Header()
|
||||
if err != nil {
|
||||
return nil, metadata, err
|
||||
}
|
||||
metadata.HeaderMD = header
|
||||
return stream, metadata, nil
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_GoCryptoTrader_GetExchangeOrderbookStream_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_GoCryptoTrader_GetExchangeOrderbookStream_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderClient, req *http.Request, pathParams map[string]string) (GoCryptoTrader_GetExchangeOrderbookStreamClient, runtime.ServerMetadata, error) {
|
||||
var protoReq GetExchangeOrderbookStreamRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetExchangeOrderbookStream_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
stream, err := client.GetExchangeOrderbookStream(ctx, &protoReq)
|
||||
if err != nil {
|
||||
return nil, metadata, err
|
||||
}
|
||||
header, err := stream.Header()
|
||||
if err != nil {
|
||||
return nil, metadata, err
|
||||
}
|
||||
metadata.HeaderMD = header
|
||||
return stream, metadata, nil
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_GoCryptoTrader_GetTickerStream_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_GoCryptoTrader_GetTickerStream_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderClient, req *http.Request, pathParams map[string]string) (GoCryptoTrader_GetTickerStreamClient, runtime.ServerMetadata, error) {
|
||||
var protoReq GetTickerStreamRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetTickerStream_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
stream, err := client.GetTickerStream(ctx, &protoReq)
|
||||
if err != nil {
|
||||
return nil, metadata, err
|
||||
}
|
||||
header, err := stream.Header()
|
||||
if err != nil {
|
||||
return nil, metadata, err
|
||||
}
|
||||
metadata.HeaderMD = header
|
||||
return stream, metadata, nil
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_GoCryptoTrader_GetExchangeTickerStream_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_GoCryptoTrader_GetExchangeTickerStream_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderClient, req *http.Request, pathParams map[string]string) (GoCryptoTrader_GetExchangeTickerStreamClient, runtime.ServerMetadata, error) {
|
||||
var protoReq GetExchangeTickerStreamRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_GetExchangeTickerStream_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
stream, err := client.GetExchangeTickerStream(ctx, &protoReq)
|
||||
if err != nil {
|
||||
return nil, metadata, err
|
||||
}
|
||||
header, err := stream.Header()
|
||||
if err != nil {
|
||||
return nil, metadata, err
|
||||
}
|
||||
metadata.HeaderMD = header
|
||||
return stream, metadata, nil
|
||||
|
||||
}
|
||||
|
||||
// RegisterGoCryptoTraderHandlerFromEndpoint is same as RegisterGoCryptoTraderHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterGoCryptoTraderHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
@@ -1553,95 +1686,183 @@ func RegisterGoCryptoTraderHandlerClient(ctx context.Context, mux *runtime.Serve
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_GoCryptoTrader_GetOrderbookStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_GoCryptoTrader_GetOrderbookStream_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_GoCryptoTrader_GetOrderbookStream_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_GoCryptoTrader_GetExchangeOrderbookStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_GoCryptoTrader_GetExchangeOrderbookStream_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_GoCryptoTrader_GetExchangeOrderbookStream_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_GoCryptoTrader_GetTickerStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_GoCryptoTrader_GetTickerStream_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_GoCryptoTrader_GetTickerStream_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_GoCryptoTrader_GetExchangeTickerStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_GoCryptoTrader_GetExchangeTickerStream_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_GoCryptoTrader_GetExchangeTickerStream_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_GoCryptoTrader_GetInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getinfo"}, ""))
|
||||
pattern_GoCryptoTrader_GetInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getinfo"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetSubsystems_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getsusbsystems"}, ""))
|
||||
pattern_GoCryptoTrader_GetSubsystems_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getsusbsystems"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_EnableSubsystem_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "enablesubsystem"}, ""))
|
||||
pattern_GoCryptoTrader_EnableSubsystem_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "enablesubsystem"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_DisableSubsystem_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "disablesubsystem"}, ""))
|
||||
pattern_GoCryptoTrader_DisableSubsystem_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "disablesubsystem"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetRPCEndpoints_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getrpcendpoints"}, ""))
|
||||
pattern_GoCryptoTrader_GetRPCEndpoints_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getrpcendpoints"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetCommunicationRelayers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getcommunicationrelayers"}, ""))
|
||||
pattern_GoCryptoTrader_GetCommunicationRelayers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getcommunicationrelayers"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetExchanges_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchanges"}, ""))
|
||||
pattern_GoCryptoTrader_GetExchanges_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchanges"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_DisableExchange_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "disableexchange"}, ""))
|
||||
pattern_GoCryptoTrader_DisableExchange_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "disableexchange"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetExchangeInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangeinfo"}, ""))
|
||||
pattern_GoCryptoTrader_GetExchangeInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangeinfo"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetExchangeOTPCode_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangeotp"}, ""))
|
||||
pattern_GoCryptoTrader_GetExchangeOTPCode_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangeotp"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetExchangeOTPCodes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangeotps"}, ""))
|
||||
pattern_GoCryptoTrader_GetExchangeOTPCodes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangeotps"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_EnableExchange_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "enableexchange"}, ""))
|
||||
pattern_GoCryptoTrader_EnableExchange_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "enableexchange"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetTicker_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getticker"}, ""))
|
||||
pattern_GoCryptoTrader_GetTicker_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getticker"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetTickers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "gettickers"}, ""))
|
||||
pattern_GoCryptoTrader_GetTickers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "gettickers"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetOrderbook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorderbook"}, ""))
|
||||
pattern_GoCryptoTrader_GetOrderbook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorderbook"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetOrderbooks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorderbooks"}, ""))
|
||||
pattern_GoCryptoTrader_GetOrderbooks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorderbooks"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetAccountInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getaccountinfo"}, ""))
|
||||
pattern_GoCryptoTrader_GetAccountInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getaccountinfo"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetConfig_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getconfig"}, ""))
|
||||
pattern_GoCryptoTrader_GetConfig_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getconfig"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetPortfolio_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getportfolio"}, ""))
|
||||
pattern_GoCryptoTrader_GetPortfolio_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getportfolio"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetPortfolioSummary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getportfoliosummary"}, ""))
|
||||
pattern_GoCryptoTrader_GetPortfolioSummary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getportfoliosummary"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_AddPortfolioAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "addportfolioaddress"}, ""))
|
||||
pattern_GoCryptoTrader_AddPortfolioAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "addportfolioaddress"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_RemovePortfolioAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "removeportfolioaddress"}, ""))
|
||||
pattern_GoCryptoTrader_RemovePortfolioAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "removeportfolioaddress"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetForexProviders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getforexproviders"}, ""))
|
||||
pattern_GoCryptoTrader_GetForexProviders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getforexproviders"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetForexRates_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getforexrates"}, ""))
|
||||
pattern_GoCryptoTrader_GetForexRates_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getforexrates"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetOrders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorders"}, ""))
|
||||
pattern_GoCryptoTrader_GetOrders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorders"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorder"}, ""))
|
||||
pattern_GoCryptoTrader_GetOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorder"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_SubmitOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "submitorder"}, ""))
|
||||
pattern_GoCryptoTrader_SubmitOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "submitorder"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_SimulateOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "simulateorder"}, ""))
|
||||
pattern_GoCryptoTrader_SimulateOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "simulateorder"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_WhaleBomb_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "whalebomb"}, ""))
|
||||
pattern_GoCryptoTrader_WhaleBomb_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "whalebomb"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_CancelOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "cancelorder"}, ""))
|
||||
pattern_GoCryptoTrader_CancelOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "cancelorder"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_CancelAllOrders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "cancelallorders"}, ""))
|
||||
pattern_GoCryptoTrader_CancelAllOrders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "cancelallorders"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetEvents_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getevents"}, ""))
|
||||
pattern_GoCryptoTrader_GetEvents_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getevents"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_AddEvent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "addevent"}, ""))
|
||||
pattern_GoCryptoTrader_AddEvent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "addevent"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_RemoveEvent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "removeevent"}, ""))
|
||||
pattern_GoCryptoTrader_RemoveEvent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "removeevent"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetCryptocurrencyDepositAddresses_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getcryptodepositaddresses"}, ""))
|
||||
pattern_GoCryptoTrader_GetCryptocurrencyDepositAddresses_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getcryptodepositaddresses"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetCryptocurrencyDepositAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getcryptodepositaddress"}, ""))
|
||||
pattern_GoCryptoTrader_GetCryptocurrencyDepositAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getcryptodepositaddress"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_WithdrawCryptocurrencyFunds_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "withdrawcryptofunds"}, ""))
|
||||
pattern_GoCryptoTrader_WithdrawCryptocurrencyFunds_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "withdrawcryptofunds"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_WithdrawFiatFunds_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "withdrawfiatfunds"}, ""))
|
||||
pattern_GoCryptoTrader_WithdrawFiatFunds_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "withdrawfiatfunds"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetLoggerDetails_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getloggerdetails"}, ""))
|
||||
pattern_GoCryptoTrader_GetLoggerDetails_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getloggerdetails"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_SetLoggerDetails_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "setloggerdetails"}, ""))
|
||||
pattern_GoCryptoTrader_SetLoggerDetails_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "setloggerdetails"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetExchangePairs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangepairs"}, ""))
|
||||
pattern_GoCryptoTrader_GetExchangePairs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangepairs"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_EnableExchangePair_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "enableexchangepair"}, ""))
|
||||
pattern_GoCryptoTrader_EnableExchangePair_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "enableexchangepair"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_DisableExchangePair_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "disableexchangepair"}, ""))
|
||||
pattern_GoCryptoTrader_DisableExchangePair_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "disableexchangepair"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetOrderbookStream_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getorderbookstream"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetExchangeOrderbookStream_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangeorderbookstream"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetTickerStream_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getTickerstream"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_GoCryptoTrader_GetExchangeTickerStream_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getexchangetickerstream"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -1730,4 +1951,12 @@ var (
|
||||
forward_GoCryptoTrader_EnableExchangePair_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_GoCryptoTrader_DisableExchangePair_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_GoCryptoTrader_GetOrderbookStream_0 = runtime.ForwardResponseStream
|
||||
|
||||
forward_GoCryptoTrader_GetExchangeOrderbookStream_0 = runtime.ForwardResponseStream
|
||||
|
||||
forward_GoCryptoTrader_GetTickerStream_0 = runtime.ForwardResponseStream
|
||||
|
||||
forward_GoCryptoTrader_GetExchangeTickerStream_0 = runtime.ForwardResponseStream
|
||||
)
|
||||
|
||||
@@ -489,6 +489,26 @@ message ExchangePairRequest {
|
||||
CurrencyPair pair = 3;
|
||||
}
|
||||
|
||||
message GetOrderbookStreamRequest {
|
||||
string exchange = 1;
|
||||
CurrencyPair pair = 2;
|
||||
string asset_type = 3;
|
||||
}
|
||||
|
||||
message GetExchangeOrderbookStreamRequest {
|
||||
string exchange = 1;
|
||||
}
|
||||
|
||||
message GetTickerStreamRequest {
|
||||
string exchange = 1;
|
||||
CurrencyPair pair = 2;
|
||||
string asset_type = 3;
|
||||
}
|
||||
|
||||
message GetExchangeTickerStreamRequest {
|
||||
string exchange = 1;
|
||||
}
|
||||
|
||||
service GoCryptoTrader {
|
||||
rpc GetInfo (GetInfoRequest) returns (GetInfoResponse) {
|
||||
option (google.api.http) = {
|
||||
@@ -771,4 +791,28 @@ service GoCryptoTrader {
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc GetOrderbookStream(GetOrderbookStreamRequest) returns (stream OrderbookResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/getorderbookstream"
|
||||
};
|
||||
}
|
||||
|
||||
rpc GetExchangeOrderbookStream(GetExchangeOrderbookStreamRequest) returns (stream OrderbookResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/getexchangeorderbookstream"
|
||||
};
|
||||
}
|
||||
|
||||
rpc GetTickerStream(GetTickerStreamRequest) returns (stream TickerResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/getTickerstream"
|
||||
};
|
||||
}
|
||||
|
||||
rpc GetExchangeTickerStream(GetExchangeTickerStreamRequest) returns (stream TickerResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/getexchangetickerstream"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,6 +271,54 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/getTickerstream": {
|
||||
"get": {
|
||||
"operationId": "GetTickerStream",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.(streaming responses)",
|
||||
"schema": {
|
||||
"$ref": "#/x-stream-definitions/gctrpcTickerResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "exchange",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.delimiter",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.base",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.quote",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "asset_type",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"GoCryptoTrader"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/getaccountinfo": {
|
||||
"get": {
|
||||
"operationId": "GetAccountInfo",
|
||||
@@ -419,6 +467,30 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/getexchangeorderbookstream": {
|
||||
"get": {
|
||||
"operationId": "GetExchangeOrderbookStream",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.(streaming responses)",
|
||||
"schema": {
|
||||
"$ref": "#/x-stream-definitions/gctrpcOrderbookResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "exchange",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"GoCryptoTrader"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/getexchangeotp": {
|
||||
"get": {
|
||||
"operationId": "GetExchangeOTPCode",
|
||||
@@ -510,6 +582,30 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/getexchangetickerstream": {
|
||||
"get": {
|
||||
"operationId": "GetExchangeTickerStream",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.(streaming responses)",
|
||||
"schema": {
|
||||
"$ref": "#/x-stream-definitions/gctrpcTickerResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "exchange",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"GoCryptoTrader"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/getforexproviders": {
|
||||
"get": {
|
||||
"operationId": "GetForexProviders",
|
||||
@@ -650,6 +746,54 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/getorderbookstream": {
|
||||
"get": {
|
||||
"operationId": "GetOrderbookStream",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.(streaming responses)",
|
||||
"schema": {
|
||||
"$ref": "#/x-stream-definitions/gctrpcOrderbookResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "exchange",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.delimiter",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.base",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.quote",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "asset_type",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"GoCryptoTrader"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/getorders": {
|
||||
"post": {
|
||||
"operationId": "GetOrders",
|
||||
@@ -2175,6 +2319,69 @@
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"protobufAny": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"format": "byte"
|
||||
}
|
||||
}
|
||||
},
|
||||
"runtimeStreamError": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"grpc_code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"http_code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"http_status": {
|
||||
"type": "string"
|
||||
},
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/protobufAny"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-stream-definitions": {
|
||||
"gctrpcOrderbookResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": {
|
||||
"$ref": "#/definitions/gctrpcOrderbookResponse"
|
||||
},
|
||||
"error": {
|
||||
"$ref": "#/definitions/runtimeStreamError"
|
||||
}
|
||||
},
|
||||
"title": "Stream result of gctrpcOrderbookResponse"
|
||||
},
|
||||
"gctrpcTickerResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": {
|
||||
"$ref": "#/definitions/gctrpcTickerResponse"
|
||||
},
|
||||
"error": {
|
||||
"$ref": "#/definitions/runtimeStreamError"
|
||||
}
|
||||
},
|
||||
"title": "Stream result of gctrpcTickerResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
go.mod
7
go.mod
@@ -3,6 +3,7 @@ module github.com/thrasher-corp/gocryptotrader
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/cockroachdb/apd v1.1.0 // indirect
|
||||
github.com/gofrs/uuid v3.2.0+incompatible
|
||||
github.com/gogo/protobuf v1.2.1 // indirect
|
||||
github.com/golang/protobuf v1.3.1
|
||||
@@ -11,16 +12,18 @@ require (
|
||||
github.com/gorilla/websocket v1.4.0
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.2
|
||||
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
|
||||
github.com/jackc/pgx v3.5.0+incompatible
|
||||
github.com/jmoiron/sqlx v1.2.0
|
||||
github.com/mattn/go-sqlite3 v1.11.0
|
||||
github.com/pkg/errors v0.8.1 // indirect
|
||||
github.com/pquerna/otp v1.2.0
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
|
||||
github.com/shopspring/decimal v0.0.0-20190905144223-a36b5d85f337 // indirect
|
||||
github.com/toorop/go-pusher v0.0.0-20180521062818-4521e2eb39fb
|
||||
github.com/urfave/cli v1.20.0
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5
|
||||
golang.org/x/net v0.0.0-20190606173856-1492cefac77f
|
||||
golang.org/x/net v0.0.0-20190606173856-1492cefac77f // indirect
|
||||
google.golang.org/genproto v0.0.0-20190605220351-eb0b1bdb6ae6
|
||||
google.golang.org/grpc v1.21.1
|
||||
)
|
||||
|
||||
9
go.sum
9
go.sum
@@ -4,9 +4,12 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
|
||||
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
@@ -29,6 +32,8 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmo
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.2 h1:S+ef0492XaIknb8LMjcwgW2i3cNTzDYMmDrOThOJNWc=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.2/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 h1:vr3AYkKovP8uR8AvSGGUK1IDqRa5lAAvEkZG1LKaCRc=
|
||||
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ=
|
||||
github.com/jackc/pgx v3.5.0+incompatible h1:BRJ4G3UPtvml5R1ey0biqqGuYUGayMYekm3woO75orY=
|
||||
github.com/jackc/pgx v3.5.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
|
||||
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
|
||||
@@ -40,6 +45,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mattn/go-sqlite3 v1.11.0 h1:LDdKkqtYlom37fkvqs8rMPFKAMe8+SgjbwZ6ex1/A/Q=
|
||||
@@ -53,6 +59,8 @@ github.com/pquerna/otp v1.2.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/shopspring/decimal v0.0.0-20190905144223-a36b5d85f337 h1:Da9XEUfFxgyDOqUfwgoTDcWzmnlOnCGi6i4iPS+8Fbw=
|
||||
github.com/shopspring/decimal v0.0.0-20190905144223-a36b5d85f337/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
@@ -61,7 +69,6 @@ github.com/toorop/go-pusher v0.0.0-20180521062818-4521e2eb39fb/go.mod h1:VTLqNCX
|
||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
|
||||
@@ -146,6 +146,7 @@ func init() {
|
||||
TimeMgr = registerNewSubLogger("timekeeper")
|
||||
WebsocketMgr = registerNewSubLogger("websocket")
|
||||
EventMgr = registerNewSubLogger("event")
|
||||
DispatchMgr = registerNewSubLogger("dispatch")
|
||||
|
||||
ExchangeSys = registerNewSubLogger("exchange")
|
||||
GRPCSys = registerNewSubLogger("grpc")
|
||||
|
||||
@@ -15,6 +15,7 @@ var (
|
||||
TimeMgr *subLogger
|
||||
WebsocketMgr *subLogger
|
||||
EventMgr *subLogger
|
||||
DispatchMgr *subLogger
|
||||
|
||||
ExchangeSys *subLogger
|
||||
GRPCSys *subLogger
|
||||
|
||||
3
main.go
3
main.go
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
mg "github.com/thrasher-corp/gocryptotrader/database/migration"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
"github.com/thrasher-corp/gocryptotrader/engine"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -48,6 +49,8 @@ func main() {
|
||||
flag.BoolVar(&settings.EnableDatabaseManager, "databasemanager", true, "enables database manager")
|
||||
flag.DurationVar(&settings.EventManagerDelay, "eventmanagerdelay", time.Duration(0), "sets the event managers sleep delay between event checking")
|
||||
flag.BoolVar(&settings.EnableNTPClient, "ntpclient", true, "enables the NTP client to check system clock drift")
|
||||
flag.BoolVar(&settings.EnableDispatcher, "dispatch", true, "enables the dispatch system")
|
||||
flag.Int64Var(&settings.DispatchMaxWorkerAmount, "dispatchworkers", dispatch.DefaultMaxWorkers, "sets the dispatch package max worker generation limit")
|
||||
|
||||
// Forex provider settings
|
||||
flag.BoolVar(&settings.EnableCurrencyConverter, "currencyconverter", false, "overrides config and sets up foreign exchange Currency Converter")
|
||||
|
||||
Reference in New Issue
Block a user