feed

package
v0.0.0-...-03f22b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FeedRegistry map[FeedInfo]FeedConstructor

The registry of all supported feedsources

Functions

This section is empty.

Types

type Aggregator

type Aggregator struct {

	// Writing to ForecTick forces aggreagtor to emit tick
	// for specified product
	ForceTick chan ProductType

	// Aggregator starts gracefull shutdown when Done channel is closed
	Done chan struct{}
	// Tick is outbound queue of aggregated messages
	Tick chan *AgrTickMsg
	// contains filtered or unexported fields
}

Aggregator mananges starting/stopping feed source listeners/pollers. Selects best prices from active sources per each product and sends aggregated message to upstream.

func NewAggregator

func NewAggregator(done chan struct{}) (*Aggregator, error)

NewAggregator creates new instance of Aggregator. When passed done channel is closed aggregator will start graceful shutdown.

func (*Aggregator) Run

func (a *Aggregator) Run(feedNameList []string)

Run() starts each feed in a separate goroutine (feed runner). Listens channels to: - external interrupt - register/deregister feeds - update last message for each "product-feed" pair - based on updated last message emits new aggregated message - emit aggregated tick message by force

func (*Aggregator) Wait

func (a *Aggregator) Wait()

type AgrTickMsg

type AgrTickMsg struct {
	Product       ProductType
	PriceSell     float64
	PriceBuy      float64
	TsSell        int64
	TsBuy         int64
	AskPrice      float64
	BidPrice      float64
	ActiveSources int
	TotalSources  int
}

func (AgrTickMsg) String

func (t AgrTickMsg) String() string

type AppspotFeed

type AppspotFeed struct {
	RestFeed
}

type AppspotMsgCurrency

type AppspotMsgCurrency struct {
	To   string  `json:"to"`
	Form string  `json:"from"`
	Rate float64 `json:"rate"`
}

type BaseFeed

type BaseFeed struct {
	Info FeedInfo
	// contains filtered or unexported fields
}

BaseFeed is base 'class' for all feed sources

type BtceFeed

type BtceFeed struct {
	RestFeed
	// contains filtered or unexported fields
}

type BtceMsgTicker

type BtceMsgTicker struct {
	Product struct {
		High    float64 `json:"high"`
		Low     float64 `json:"low"`
		Avg     float64 `json:"avg"`
		Vol     float64 `json:"vol"`
		VolCur  float64 `json:"vol_cur"`
		Last    float64 `json:"last"`
		Buy     float64 `json:"buy"`
		Sell    float64 `json:"sell"`
		Updated int64   `json:"updated"`
	} `json:"btc_usd"`
}

type FakeFeed

type FakeFeed struct {
	BaseFeed
	// contains filtered or unexported fields
}

func (*FakeFeed) GetInfo

func (f *FakeFeed) GetInfo() FeedInfo

func (*FakeFeed) GetName

func (f *FakeFeed) GetName() string

func (*FakeFeed) Run

func (f *FakeFeed) Run() error

func (*FakeFeed) Stop

func (f *FakeFeed) Stop() error

func (*FakeFeed) Wait

func (f *FakeFeed) Wait() chan struct{}

type Feed

type Feed interface {
	// human-readable string name for feed source
	GetName() string
	// FeedInfo about feed source
	GetInfo() FeedInfo
	// run feed (non-blockable)
	Run() error
	// signals feed to exit
	Stop() error
	// feed source should block here until it's safe to exit
	Wait() chan struct{}
}

Feed source interface

func NewAppspotFeed

func NewAppspotFeed(agr *Aggregator) (Feed, error)

func NewBtceFeed

func NewBtceFeed(agr *Aggregator) (Feed, error)

func NewFakeEurUsdFeed

func NewFakeEurUsdFeed(agr *Aggregator) (Feed, error)

func NewFixerFeed

func NewFixerFeed(agr *Aggregator) (Feed, error)

func NewGdaxWebSocketFeed

func NewGdaxWebSocketFeed(agr *Aggregator) (Feed, error)

func NewGdaxWebSocketFeed(agr *Aggregator, wsUrl string, wsHeaders http.Header) (*GdaxWebSocketFeed, error) {

type FeedConstructor

type FeedConstructor func(*Aggregator) (Feed, error)

type FeedInfo

type FeedInfo struct {
	Product ProductType
	Name    string
}

func (FeedInfo) String

func (i FeedInfo) String() string

type FixerFeed

type FixerFeed struct {
	RestFeed
}

type FixerMsgLatest

type FixerMsgLatest struct {
	Base  string             `json:"base"`
	Date  string             `json:"date"`
	Rates map[string]float64 `json:"rates"`
}

type GdaxWebSocketFeed

type GdaxWebSocketFeed struct {
	Info FeedInfo

	// deadline timeout for websocket read operations
	TimeoutRead time.Duration
	// deadline timeout for websocket write operations
	TimeoutWrite time.Duration
	// contains filtered or unexported fields
}

GDAX websocket feed source

func (*GdaxWebSocketFeed) Close

func (f *GdaxWebSocketFeed) Close()

func (*GdaxWebSocketFeed) GetInfo

func (f *GdaxWebSocketFeed) GetInfo() FeedInfo

func (*GdaxWebSocketFeed) GetName

func (f *GdaxWebSocketFeed) GetName() string

func (*GdaxWebSocketFeed) Run

func (f *GdaxWebSocketFeed) Run() error

Run registers feed source with aggreator. Starts pull and push goroutines in background.

func (*GdaxWebSocketFeed) Stop

func (f *GdaxWebSocketFeed) Stop() error

func (*GdaxWebSocketFeed) Subscribe

func (f *GdaxWebSocketFeed) Subscribe() error

Send "subscribe" message

func (*GdaxWebSocketFeed) Wait

func (f *GdaxWebSocketFeed) Wait() chan struct{}

type MsgGdax

type MsgGdax struct {
	Type      string     `json:"type"`                 // "match" | "error" | "heartbeat"
	Sequence  *int64     `json:"sequence,omitempty"`   // 50
	OrderId   *string    `json:"order_id,omitempty"`   // "d50ec984-77a8-460a-b958-66f114b0de9b"
	Time      *time.Time `json:"time,omitempty"`       // "2014-11-07T08:19:27.028459Z"
	ProductId *string    `json:"product_id,omitempty"` // "BTC-USD"
	Size      *string    `json:"size,omitempty"`       // "5.23512"
	Price     *string    `json:"price,omitempty"`      // "400.23",
	Side      *string    `json:"side,omitempty"`       // "sell"
	Message   *string    `json:"message,omitempty"`    // "error message"
}

Aggregated GDAX Websocket API message stucture with only important fields

type MsgGdaxOrderBook

type MsgGdaxOrderBook struct {
	Asks     [][]string `json:"asks"`
	Bids     [][]string `json:"bids"`
	Sequence int64      `json:"sequence"`
}

REST order book data

type OrderBook

type OrderBook struct {
	// contains filtered or unexported fields
}

func (*OrderBook) AddAsk

func (b *OrderBook) AddAsk(orderId string, price float64)

func (*OrderBook) AddBid

func (b *OrderBook) AddBid(orderId string, price float64)

func (*OrderBook) DeleteAsk

func (b *OrderBook) DeleteAsk(orderId string) bool

func (*OrderBook) DeleteBid

func (b *OrderBook) DeleteBid(orderId string) bool

type RestFeed

type RestFeed struct {
	BaseFeed
	// contains filtered or unexported fields
}

RestFeed is a generic base 'class' for basic http REST-polling feed sources

func NewRestFeed

func NewRestFeed(info FeedInfo, agr *Aggregator, pollInterval, reqTimeout time.Duration) (*RestFeed, error)

func (*RestFeed) GetInfo

func (f *RestFeed) GetInfo() FeedInfo

func (*RestFeed) GetName

func (f *RestFeed) GetName() string

func (*RestFeed) Run

func (f *RestFeed) Run() error

func (*RestFeed) SetPollHandler

func (f *RestFeed) SetPollHandler(h func() (*TickMsg, error))

SetPollHandler() sets handler which will be invoked on each polling round

func (*RestFeed) Stop

func (f *RestFeed) Stop() error

func (*RestFeed) Wait

func (f *RestFeed) Wait() chan struct{}

type TickMsg

type TickMsg struct {
	Info FeedInfo
	// Last price for sell trade
	PriceSell float64
	// Last price for buy trade
	PriceBuy float64
	// Best ask price
	AskPrice float64
	// Best bid price
	BidPrice float64
	// Last timestamp for sell trade
	TsSell int64
	// Last timestamp for buy trade
	TsBuy int64
	// Current timestamp for message
	Ts int64
}

TickMsg contains update message from feed source which should be propagated to aggregator

func (TickMsg) String

func (t TickMsg) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL