Documentation ¶
Overview ¶
Package sdk provides REST and Stream clients for Tinkoff Invest OpenAPI. More documentation https://api-invest.tinkoff.ru/openapi/docs/.
Index ¶
- Constants
- Variables
- type Account
- type AccountType
- type Candle
- type CandleEvent
- type CandleInterval
- type Currency
- type CurrencyBalance
- type Error
- type ErrorEvent
- type Event
- type FullEvent
- type Instrument
- type InstrumentInfo
- type InstrumentInfoEvent
- type InstrumentType
- type Logger
- type MoneyAmount
- type Operation
- type OperationStatus
- type OperationType
- type Order
- type OrderBook
- type OrderBookEvent
- type OrderStatus
- type OrderType
- type PlacedOrder
- type Portfolio
- type PositionBalance
- type PriceQuantity
- type RestClient
- func (c *RestClient) Accounts(ctx context.Context) ([]Account, error)
- func (c *RestClient) Bonds(ctx context.Context) ([]Instrument, error)
- func (c *RestClient) Candles(ctx context.Context, from, to time.Time, interval CandleInterval, figi string) ([]Candle, error)
- func (c *RestClient) Currencies(ctx context.Context) ([]Instrument, error)
- func (c *RestClient) CurrenciesPortfolio(ctx context.Context, accountID string) ([]CurrencyBalance, error)
- func (c *RestClient) ETFs(ctx context.Context) ([]Instrument, error)
- func (c *RestClient) InstrumentByFIGI(ctx context.Context, figi string) (Instrument, error)
- func (c *RestClient) InstrumentByTicker(ctx context.Context, ticker string) ([]Instrument, error)
- func (c *RestClient) LimitOrder(ctx context.Context, accountID, figi string, lots int, operation OperationType, ...) (PlacedOrder, error)
- func (c *RestClient) MarketOrder(ctx context.Context, accountID, figi string, lots int, operation OperationType) (PlacedOrder, error)
- func (c *RestClient) Operations(ctx context.Context, accountID string, from, to time.Time, figi string) ([]Operation, error)
- func (c *RestClient) OrderCancel(ctx context.Context, accountID, id string) error
- func (c *RestClient) Orderbook(ctx context.Context, depth int, figi string) (RestOrderBook, error)
- func (c *RestClient) Orders(ctx context.Context, accountID string) ([]Order, error)
- func (c *RestClient) Portfolio(ctx context.Context, accountID string) (Portfolio, error)
- func (c *RestClient) PositionsPortfolio(ctx context.Context, accountID string) ([]PositionBalance, error)
- func (c *RestClient) Stocks(ctx context.Context) ([]Instrument, error)
- type RestOrderBook
- type RestPriceQuantity
- type SandboxRestClient
- func (c *SandboxRestClient) Clear(ctx context.Context, accountID string) error
- func (c *SandboxRestClient) Register(ctx context.Context, accountType AccountType) (Account, error)
- func (c *SandboxRestClient) Remove(ctx context.Context, accountID string) error
- func (c *SandboxRestClient) SetCurrencyBalance(ctx context.Context, accountID string, currency Currency, balance float64) error
- func (c *SandboxRestClient) SetPositionsBalance(ctx context.Context, accountID, figi string, balance float64) error
- type StreamingClient
- func (c *StreamingClient) Close() error
- func (c *StreamingClient) RunReadLoop(fn func(event interface{}) error) error
- func (c *StreamingClient) SubscribeCandle(figi string, interval CandleInterval, requestID string) error
- func (c *StreamingClient) SubscribeInstrumentInfo(figi, requestID string) error
- func (c *StreamingClient) SubscribeOrderbook(figi string, depth int, requestID string) error
- func (c *StreamingClient) UnsubscribeCandle(figi string, interval CandleInterval, requestID string) error
- func (c *StreamingClient) UnsubscribeInstrumentInfo(figi, requestID string) error
- func (c *StreamingClient) UnsubscribeOrderbook(figi string, depth int, requestID string) error
- type Trade
- type TradingError
- type TradingStatus
Constants ¶
View Source
const DefaultAccount = "" // Номер счета (по умолчанию - Тинькофф)
View Source
const MaxOrderbookDepth = 20
View Source
const RestApiURL = "https://api-invest.tinkoff.ru/openapi"
View Source
const StreamingApiURL = "wss://api-invest.tinkoff.ru/openapi/md/v1/md-openapi/ws"
Variables ¶
View Source
var ErrDepth = errors.Errorf("invalid depth. Should be in interval 0 < x <= %d", MaxOrderbookDepth)
View Source
var ErrForbidden = errors.New("invalid token")
View Source
var ErrNotFound = errors.New("Not found")
Functions ¶
This section is empty.
Types ¶
type Account ¶ added in v0.4.0
type Account struct { Type AccountType `json:"brokerAccountType"` ID string `json:"brokerAccountId"` }
type AccountType ¶ added in v0.4.0
type AccountType string
const ( AccountTinkoff AccountType = "Tinkoff" AccountTinkoffIIS AccountType = "TinkoffIis" )
type CandleEvent ¶
type CandleInterval ¶
type CandleInterval string
const ( CandleInterval1Min CandleInterval = "1min" CandleInterval2Min CandleInterval = "2min" CandleInterval3Min CandleInterval = "3min" CandleInterval5Min CandleInterval = "5min" CandleInterval10Min CandleInterval = "10min" CandleInterval15Min CandleInterval = "15min" CandleInterval30Min CandleInterval = "30min" CandleInterval1Hour CandleInterval = "hour" CandleInterval2Hour CandleInterval = "2hour" CandleInterval4Hour CandleInterval = "4hour" CandleInterval1Day CandleInterval = "day" CandleInterval1Week CandleInterval = "week" CandleInterval1Month CandleInterval = "month" )
type CurrencyBalance ¶
type ErrorEvent ¶
type Instrument ¶
type InstrumentInfo ¶
type InstrumentInfo struct { FIGI string `json:"figi"` TradeStatus TradingStatus `json:"trade_status"` MinPriceIncrement float64 `json:"min_price_increment"` Lot float64 `json:"lot"` AccruedInterest float64 `json:"accrued_interest,omitempty"` LimitUp float64 `json:"limit_up,omitempty"` LimitDown float64 `json:"limit_down,omitempty"` }
type InstrumentInfoEvent ¶
type InstrumentInfoEvent struct { FullEvent Info InstrumentInfo `json:"payload"` }
type InstrumentType ¶ added in v0.3.0
type InstrumentType string
const ( InstrumentTypeStock InstrumentType = "Stock" InstrumentTypeCurrency InstrumentType = "Currency" InstrumentTypeBond InstrumentType = "Bond" InstrumentTypeEtf InstrumentType = "Etf" )
type MoneyAmount ¶
type Operation ¶
type Operation struct { ID string `json:"id"` Status OperationStatus `json:"status"` Trades []Trade `json:"trades"` Commission MoneyAmount `json:"commission"` Currency Currency `json:"currency"` Payment float64 `json:"payment"` Price float64 `json:"price"` Quantity int `json:"quantity"` QuantityExecuted int `json:"quantityExecuted"` FIGI string `json:"figi"` InstrumentType InstrumentType `json:"instrumentType"` IsMarginCall bool `json:"isMarginCall"` DateTime time.Time `json:"date"` OperationType OperationType `json:"operationType"` }
type OperationStatus ¶
type OperationStatus string
const ( OperationStatusDone OperationStatus = "Done" OperationStatusDecline OperationStatus = "Decline" OperationStatusProgress OperationStatus = "Progress" )
type OperationType ¶
type OperationType string
const ( BUY OperationType = "Buy" SELL OperationType = "Sell" OperationTypeBrokerCommission OperationType = "BrokerCommission" OperationTypeExchangeCommission OperationType = "ExchangeCommission" OperationTypeServiceCommission OperationType = "ServiceCommission" OperationTypeMarginCommission OperationType = "MarginCommission" OperationTypeOtherCommission OperationType = "OtherCommission" OperationTypePayIn OperationType = "PayIn" OperationTypePayOut OperationType = "PayOut" OperationTypeTax OperationType = "Tax" OperationTypeTaxLucre OperationType = "TaxLucre" OperationTypeTaxDividend OperationType = "TaxDividend" OperationTypeTaxCoupon OperationType = "TaxCoupon" OperationTypeTaxBack OperationType = "TaxBack" OperationTypeRepayment OperationType = "Repayment" OperationTypePartRepayment OperationType = "PartRepayment" OperationTypeCoupon OperationType = "Coupon" OperationTypeDividend OperationType = "Dividend" OperationTypeSecurityIn OperationType = "SecurityIn" OperationTypeSecurityOut OperationType = "SecurityOut" OperationTypeBuyCard OperationType = "BuyCard" )
type Order ¶
type Order struct { ID string `json:"orderId"` FIGI string `json:"figi"` Operation OperationType `json:"operation"` Status OrderStatus `json:"status"` RequestedLots int `json:"requestedLots"` ExecutedLots int `json:"executedLots"` Type OrderType `json:"type"` Price float64 `json:"price"` }
type OrderBook ¶
type OrderBook struct { FIGI string `json:"figi"` Depth int `json:"depth"` Bids []PriceQuantity `json:"bids"` Asks []PriceQuantity `json:"asks"` }
type OrderBookEvent ¶
type OrderStatus ¶
type OrderStatus string
const ( OrderStatusNew OrderStatus = "New" OrderStatusPartiallyFill OrderStatus = "PartiallyFill" OrderStatusFill OrderStatus = "Fill" OrderStatusCancelled OrderStatus = "Cancelled" OrderStatusReplaced OrderStatus = "Replaced" OrderStatusPendingCancel OrderStatus = "PendingCancel" OrderStatusRejected OrderStatus = "Rejected" OrderStatusPendingReplace OrderStatus = "PendingReplace" OrderStatusPendingNew OrderStatus = "PendingNew" )
type PlacedOrder ¶ added in v0.5.0
type PlacedOrder struct { ID string `json:"orderId"` Operation OperationType `json:"operation"` Status OrderStatus `json:"status"` RejectReason string `json:"rejectReason"` RequestedLots int `json:"requestedLots"` ExecutedLots int `json:"executedLots"` Commission MoneyAmount `json:"commission"` Message string `json:"message,omitempty"` }
type Portfolio ¶
type Portfolio struct { Positions []PositionBalance Currencies []CurrencyBalance }
type PositionBalance ¶
type PositionBalance struct { FIGI string `json:"figi"` Ticker string `json:"ticker"` ISIN string `json:"isin"` InstrumentType InstrumentType `json:"instrumentType"` Balance float64 `json:"balance"` Blocked float64 `json:"blocked"` Lots int `json:"lots"` ExpectedYield MoneyAmount `json:"expectedYield"` AveragePositionPrice MoneyAmount `json:"averagePositionPrice"` AveragePositionPriceNoNkd MoneyAmount `json:"averagePositionPriceNoNkd"` Name string `json:"name"` }
type PriceQuantity ¶
type PriceQuantity [2]float64 // 0 - price, 1 - quantity
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
func NewRestClient ¶
func NewRestClient(token string) *RestClient
func NewRestClientCustom ¶
func NewRestClientCustom(token, apiURL string) *RestClient
func (*RestClient) Accounts ¶ added in v0.4.0
func (c *RestClient) Accounts(ctx context.Context) ([]Account, error)
func (*RestClient) Bonds ¶
func (c *RestClient) Bonds(ctx context.Context) ([]Instrument, error)
func (*RestClient) Candles ¶
func (c *RestClient) Candles(ctx context.Context, from, to time.Time, interval CandleInterval, figi string) ([]Candle, error)
func (*RestClient) Currencies ¶
func (c *RestClient) Currencies(ctx context.Context) ([]Instrument, error)
func (*RestClient) CurrenciesPortfolio ¶
func (c *RestClient) CurrenciesPortfolio(ctx context.Context, accountID string) ([]CurrencyBalance, error)
func (*RestClient) ETFs ¶
func (c *RestClient) ETFs(ctx context.Context) ([]Instrument, error)
func (*RestClient) InstrumentByFIGI ¶ added in v0.6.0
func (c *RestClient) InstrumentByFIGI(ctx context.Context, figi string) (Instrument, error)
func (*RestClient) InstrumentByTicker ¶ added in v0.6.0
func (c *RestClient) InstrumentByTicker(ctx context.Context, ticker string) ([]Instrument, error)
func (*RestClient) LimitOrder ¶
func (c *RestClient) LimitOrder(ctx context.Context, accountID, figi string, lots int, operation OperationType, price float64) (PlacedOrder, error)
func (*RestClient) MarketOrder ¶ added in v0.5.0
func (c *RestClient) MarketOrder(ctx context.Context, accountID, figi string, lots int, operation OperationType) (PlacedOrder, error)
func (*RestClient) Operations ¶
func (*RestClient) OrderCancel ¶
func (c *RestClient) OrderCancel(ctx context.Context, accountID, id string) error
func (*RestClient) Orderbook ¶
func (c *RestClient) Orderbook(ctx context.Context, depth int, figi string) (RestOrderBook, error)
func (*RestClient) PositionsPortfolio ¶
func (c *RestClient) PositionsPortfolio(ctx context.Context, accountID string) ([]PositionBalance, error)
func (*RestClient) Stocks ¶
func (c *RestClient) Stocks(ctx context.Context) ([]Instrument, error)
type RestOrderBook ¶
type RestOrderBook struct { FIGI string `json:"figi"` Depth int `json:"depth"` Bids []RestPriceQuantity `json:"bids"` Asks []RestPriceQuantity `json:"asks"` TradeStatus TradingStatus `json:"tradeStatus"` MinPriceIncrement float64 `json:"minPriceIncrement"` LastPrice float64 `json:"lastPrice,omitempty"` ClosePrice float64 `json:"closePrice,omitempty"` LimitUp float64 `json:"limitUp,omitempty"` LimitDown float64 `json:"limitDown,omitempty"` FaceValue float64 `json:"faceValue,omitempty"` }
type RestPriceQuantity ¶
type SandboxRestClient ¶
type SandboxRestClient struct {
*RestClient
}
func NewSandboxRestClient ¶
func NewSandboxRestClient(token string) *SandboxRestClient
func NewSandboxRestClientCustom ¶
func NewSandboxRestClientCustom(token, apiURL string) *SandboxRestClient
func (*SandboxRestClient) Clear ¶
func (c *SandboxRestClient) Clear(ctx context.Context, accountID string) error
func (*SandboxRestClient) Register ¶
func (c *SandboxRestClient) Register(ctx context.Context, accountType AccountType) (Account, error)
func (*SandboxRestClient) Remove ¶ added in v0.4.0
func (c *SandboxRestClient) Remove(ctx context.Context, accountID string) error
func (*SandboxRestClient) SetCurrencyBalance ¶
func (*SandboxRestClient) SetPositionsBalance ¶
type StreamingClient ¶
type StreamingClient struct {
// contains filtered or unexported fields
}
func NewStreamingClient ¶
func NewStreamingClient(logger Logger, token string) (*StreamingClient, error)
func NewStreamingClientCustom ¶
func NewStreamingClientCustom(logger Logger, token, apiURL string) (*StreamingClient, error)
func (*StreamingClient) Close ¶
func (c *StreamingClient) Close() error
func (*StreamingClient) RunReadLoop ¶
func (c *StreamingClient) RunReadLoop(fn func(event interface{}) error) error
func (*StreamingClient) SubscribeCandle ¶
func (c *StreamingClient) SubscribeCandle(figi string, interval CandleInterval, requestID string) error
func (*StreamingClient) SubscribeInstrumentInfo ¶
func (c *StreamingClient) SubscribeInstrumentInfo(figi, requestID string) error
func (*StreamingClient) SubscribeOrderbook ¶
func (c *StreamingClient) SubscribeOrderbook(figi string, depth int, requestID string) error
func (*StreamingClient) UnsubscribeCandle ¶
func (c *StreamingClient) UnsubscribeCandle(figi string, interval CandleInterval, requestID string) error
func (*StreamingClient) UnsubscribeInstrumentInfo ¶
func (c *StreamingClient) UnsubscribeInstrumentInfo(figi, requestID string) error
func (*StreamingClient) UnsubscribeOrderbook ¶
func (c *StreamingClient) UnsubscribeOrderbook(figi string, depth int, requestID string) error
type TradingError ¶
type TradingError struct { TrackingID string `json:"trackingId"` Status string `json:"status"` Hint string Payload struct { Message string `json:"message"` Code string `json:"code"` } `json:"payload"` }
func (TradingError) Error ¶
func (t TradingError) Error() string
func (TradingError) InvalidTokenSpace ¶ added in v0.4.0
func (t TradingError) InvalidTokenSpace() bool
func (TradingError) NotEnoughBalance ¶
func (t TradingError) NotEnoughBalance() bool
type TradingStatus ¶
type TradingStatus string
const ( BreakInTrading TradingStatus = "break_in_trading" NormalTrading TradingStatus = "normal_trading" NotAvailableForTrading TradingStatus = "not_available_for_trading" ClosingAuction TradingStatus = "closing_auction" ClosingPeriod TradingStatus = "closing_period" DarkPoolAuction TradingStatus = "dark_pool_auction" DiscreteAuction TradingStatus = "discrete_auction" OpeningPeriod TradingStatus = "opening_period" OpeningAuctionPeriod TradingStatus = "opening_auction_period" TradingAtClosingAuctionPrice TradingStatus = "trading_at_closing_auction_price" )
Source Files ¶
Click to show internal directories.
Click to hide internal directories.