tinkoffinvest

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOrderWaitExecution = errors.New("order is waiting for execution")
	ErrOrderRejected      = errors.New("order rejected")
	ErrOrderCancelled     = errors.New("order cancelled by user")
)
View Source
var ErrInvalidToken = errors.New("invalid token")
View Source
var ErrNotEnoughStocks = errors.New("not enough stocks (shares or money)")

Functions

func BestPriceForBuy

func BestPriceForBuy(ob OrderBook) decimal.Decimal

BestPriceForBuy returns the lowest price among sell orders.

func BestPriceForSell

func BestPriceForSell(ob OrderBook) decimal.Decimal

BestPriceForSell returns the highest price among buy orders.

func CountLots

func CountLots(orders []Order) int

CountLots counts sum of orders' lots.

func Spread

func Spread(ob OrderBook) float64

Spread returns order book spread as percentage. May be negative. Can affect OrderBook.Bids & OrderBook.Asks slices order.

Types

type AccountID

type AccountID string //

func (AccountID) S

func (id AccountID) S() string

type Client

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

func NewClient

func NewClient(cc grpc.ClientConnInterface, token string, appName string, useSandbox bool) (*Client, error)

func (*Client) CancelOrder

func (c *Client) CancelOrder(ctx context.Context, accountID AccountID, orderID OrderID) error

func (*Client) GetBalance

func (c *Client) GetBalance(ctx context.Context, accountID AccountID) (decimal.Decimal, error)

func (*Client) GetOrderBook

func (c *Client) GetOrderBook(ctx context.Context, req OrderBookRequest) (*OrderBookResponse, error)

func (*Client) GetOrderState

func (c *Client) GetOrderState(ctx context.Context, accountID AccountID, orderID OrderID) (decimal.Decimal, error)

GetOrderState returns executed price if the order was executed and one of errors otherwise: - ErrOrderWaitExecution - ErrOrderRejected - ErrOrderCancelled.

func (*Client) GetPortfolio

func (c *Client) GetPortfolio(ctx context.Context, accountID AccountID) (*Portfolio, error)

func (*Client) GetShareByFIGI

func (c *Client) GetShareByFIGI(ctx context.Context, figi FIGI) (*Instrument, error)

func (*Client) GetTradeAvailableShares

func (c *Client) GetTradeAvailableShares(ctx context.Context) ([]Instrument, error)

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(ctx context.Context) (*UserInfo, error)

func (*Client) PlaceLimitBuyOrder

func (c *Client) PlaceLimitBuyOrder(ctx context.Context, request PlaceOrderRequest) (OrderID, error)

func (*Client) PlaceLimitSellOrder

func (c *Client) PlaceLimitSellOrder(ctx context.Context, request PlaceOrderRequest) (OrderID, error)

func (*Client) PlaceMarketBuyOrder

func (c *Client) PlaceMarketBuyOrder(ctx context.Context, request PlaceOrderRequest) (OrderID, error)

func (*Client) PlaceMarketSellOrder

func (c *Client) PlaceMarketSellOrder(ctx context.Context, request PlaceOrderRequest) (OrderID, error)

func (*Client) SubscribeForOrderBookChanges

func (c *Client) SubscribeForOrderBookChanges(ctx context.Context, reqs []OrderBookRequest) (<-chan OrderBookChange, error)

func (*Client) WaitForOrderExecution

func (c *Client) WaitForOrderExecution(ctx context.Context, accountID AccountID, orderID OrderID) (decimal.Decimal, error)

WaitForOrderExecution allows waiting order execution via simple polling with GetOrderState method. Useful because investpb.OrdersStreamServiceClient is not working in sandbox.

type FIGI

type FIGI string //

func (FIGI) S

func (id FIGI) S() string

type Instrument

type Instrument struct {
	FIGI              FIGI
	ISIN              string
	Name              string
	Lot               int
	MinPriceIncrement decimal.Decimal
}

type Order

type Order struct {
	Price decimal.Decimal
	Lots  int
}

type OrderBook

type OrderBook struct {
	FIGI FIGI
	// Bids are orders to buy.
	Bids []Order
	// Asks are orders to sell.
	Asks []Order
	// LimitUp limits buy orders.
	LimitUp decimal.Decimal
	// LimitDown limits sell orders.
	LimitDown decimal.Decimal
}

type OrderBookChange

type OrderBookChange struct {
	OrderBook
	IsConsistent bool
	FormedAt     time.Time
}

type OrderBookRequest

type OrderBookRequest struct {
	FIGI  FIGI
	Depth int
}

type OrderBookResponse

type OrderBookResponse struct {
	OrderBook
	LastPrice decimal.Decimal
}

type OrderID

type OrderID string //

func (OrderID) S

func (id OrderID) S() string

type PlaceOrderRequest

type PlaceOrderRequest struct {
	AccountID AccountID
	FIGI      FIGI
	Lots      int
	Price     decimal.Decimal // For limit orders only.
}

type Portfolio

type Portfolio struct {
	TotalSharesPrice decimal.Decimal
	Shares           []PortfolioPosition
}

type PortfolioPosition

type PortfolioPosition struct {
	FIGI     FIGI
	Quantity int
	AvgPrice decimal.Decimal
}

type UserInfo

type UserInfo struct {
	PremStatus           bool
	QualStatus           bool
	QualifiedForWorkWith []string
	Tariff               string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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