investgo

package
v0.0.0-...-039b579 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = fmt.Errorf("zip file not found")
	ErrTooManyRequests = fmt.Errorf("too many requests")
	ErrNotOk           = fmt.Errorf("response status is not ok")
)

Functions

func ByFigi

func ByFigi(figi string) pb.InstrumentRequest

func ByPositionUid

func ByPositionUid(positionUid string) pb.InstrumentRequest

func ByTicker

func ByTicker(ticker string, classCode string) pb.InstrumentRequest

func ByUid

func ByUid(uid string) pb.InstrumentRequest

func FloatToQuotation

func FloatToQuotation(f float64) *pb.Quotation

FloatToQuotation converts float64 to Quotation type with proper scaling

func QuotationToFloat

func QuotationToFloat(q *pb.Quotation) float64

QuotationToFloat converts Quotation type to float64 with proper scaling

Types

type CandleSubscription

type CandleSubscription struct {
	// InstrumentId stores unique instrument id that is used in candleSubscriptions as key
	InstrumentId string
	// contains filtered or unexported fields
}

CandleSubscription represents handler for candles stream.

func (*CandleSubscription) Recv

func (cs *CandleSubscription) Recv() <-chan *pb.Candle

Recv returns read only channel with candles market data

type Client

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

func NewClient

func NewClient(target string, token string, opts ...grpc.DialOption) (*Client, error)

NewClient creates SDK client that will be used for all communications with investapi

By default it configures default TLS transport credentials and oauth2.StaticTokenSource for PerRPCCredentials

func (*Client) AllShares

func (c *Client) AllShares(ctx context.Context) ([]*pb.Share, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) DownloadHistoryData

func (c *Client) DownloadHistoryData(ctx context.Context, figi string, year int) ([]*pb.HistoricCandle, error)

DownloadHistoryData downloads zip file with all 1-minute candles from history-data endpoint and returns it as slice of protobufs in investapi format.

func (*Client) GetCandles

func (c *Client) GetCandles(ctx context.Context, uid string, from time.Time, to time.Time, interval pb.CandleInterval) ([]*pb.HistoricCandle, error)

GetCandles splits interval into day chunks and loads HistoricCandle for it.

func (*Client) NewMarketDataStream

func (c *Client) NewMarketDataStream(ctx context.Context, logger Logger) (*MarketDataStream, error)

NewMarketDataStream returns a new MarketDataStream to create subscriptions.

func (*Client) ShareBy

func (c *Client) ShareBy(ctx context.Context, request *pb.InstrumentRequest) (*pb.Share, error)

func (*Client) Shares

func (c *Client) Shares(ctx context.Context, status pb.InstrumentStatus, exchange pb.InstrumentExchangeType) ([]*pb.Share, error)

type Logger

type Logger interface {
	Debug(msg string, keyvals ...interface{})
	Info(msg string, keyvals ...interface{})
	Warn(msg string, keyvals ...interface{})
	Error(msg string, keyvals ...interface{})
}

Logger interface for structural logging

type MarketDataStream

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

MarketDataStream provides interface for managing subscriptions through one stream instance. Channels with data will receive market data from single underlying stream. Subscription will be automatically cancelled when no more channels are listening for it.

func (*MarketDataStream) Close

func (m *MarketDataStream) Close()

Close cancels the MarketDataStream context, which will stop listening on stream

func (*MarketDataStream) SubscribeCandle

func (m *MarketDataStream) SubscribeCandle(id string, waitingClose bool) (*CandleSubscription, error)

SubscribeCandle creates subscriptions for candle with specified id. If subscription already exists – only new channel will be created.

func (*MarketDataStream) UnsubscribeCandle

func (m *MarketDataStream) UnsubscribeCandle(s *CandleSubscription) error

UnsubscribeCandle closes CandleSubscription and removes subscription from subscriptions map. If no more subscription are present with same id – subscription will be cancelled.

type NoopLogger

type NoopLogger struct{}

NoopLogger implements Logger interface but does nothing

func (NoopLogger) Debug

func (NoopLogger) Debug(msg string, keyvals ...interface{})

func (NoopLogger) Error

func (NoopLogger) Error(msg string, keyvals ...interface{})

func (NoopLogger) Info

func (NoopLogger) Info(msg string, keyvals ...interface{})

func (NoopLogger) Warn

func (NoopLogger) Warn(msg string, keyvals ...interface{})

Jump to

Keyboard shortcuts

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