smp

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2021 License: MIT Imports: 6 Imported by: 0

README

stock_market_primitives

Documentation

Index

Constants

View Source
const H24 = time.Hour * 24

Variables

View Source
var Errors map[int]string = map[int]string{
	500000000: "strategies.TakeProfitBuy: Command: `%v` does not exists",
	500000010: "strategies.TakeProfitBuy: Command: `%v` param not set",
	500000011: "strategies.TakeProfitBuy: Command: `%v` param `%v` is not float64",
	500000020: "strategies.TakeProfitBuy: Command: `%v` param not set",
	500000021: "strategies.TakeProfitBuy: Command: `%v` param `%v` is not int",
	500000030: "strategies.TakeProfitBuy: Command: `%v` param not set",
	500000031: "strategies.TakeProfitBuy: Command: `%v` param `%v` is not bool",

	500000100: "strategies.TakeProfitBuy: Step: fail order book get",
	500000101: "strategies.TakeProfitBuy: Step: fail buy by price",
	500000102: "strategies.TakeProfitBuy: Step: fail get info about buy order",

	500000200: "strategies.TakeProfitSell: Command: `%v` does not exists",
	500000210: "strategies.TakeProfitSell: Command: `%v` param not set",
	500000211: "strategies.TakeProfitSell: Command: `%v` param `%v` is not float64",
	500000220: "strategies.TakeProfitSell: Command: `%v` param not set",
	500000221: "strategies.TakeProfitSell: Command: `%v` param `%v` is not int",
	500000230: "strategies.TakeProfitSell: Command: `%v` param not set",
	500000231: "strategies.TakeProfitSell: Command: `%v` param `%v` is not bool",

	500000300: "strategies.TakeProfitSell: Step: fail order book get",
	500000301: "strategies.TakeProfitSell: Step: fail sell by price",
	500000302: "strategies.TakeProfitSell: Step: fail get info about sell order",

	500000400: "strategies.WingedSwing: Command: `%v` does not exists",
	500000410: "strategies.WingedSwing: Command: `%v` param not set",
	500000411: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000412: "strategies.WingedSwing: Command: `%v` param not set",
	500000413: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000414: "strategies.WingedSwing: Command: `%v` param not set",
	500000415: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000420: "strategies.WingedSwing: Command: `%v` param not set",
	500000421: "strategies.WingedSwing: Command: `%v` param `%v` is not int",
	500000430: "strategies.WingedSwing: Command: `%v` param not set",
	500000431: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000432: "strategies.WingedSwing: Command: `%v` param not set",
	500000433: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",

	500000500: "strategies.WingedSwing: Step: fail order book get",
	500000501: "strategies.WingedSwing: Step: fail buy by price",
	500000502: "strategies.WingedSwing: Step: fail get info about buy order",
	500000503: "strategies.WingedSwing: Step: fail get info about sell order",
	500000504: "strategies.WingedSwing: Step: fail sell by price",
	500000505: "strategies.WingedSwing: Step: unexpected situation InMarket: %v",
	500000506: "strategies.WingedSwing: Step: unexpected situation InMarket: %v; s.Volume: %v",
	500000507: "strategies.WingedSwing: Step: fail cancel sell on prepare to stop loss",
	500000508: "strategies.WingedSwing: Step: fail sell by market !!! stop loss",
	500000509: "strategies.WingedSwing: Step: fail sell to StopLostBank !!! stop loss",
	500000510: "strategies.WingedSwing: Step: fail buy from StopLostBank",
	500000511: "strategies.WingedSwing: Step: fail buy from StopLostBank add_place",
	500000512: "strategies.WingedSwing: Step: fail cancel buy on buy from stop loss bank",
	500000513: "strategies.WingedSwing: Step: fail cancel buy task",
	500000514: "strategies.WingedSwing: Step: fail cancel sell task",
	500000515: "strategies.WingedSwing: Step: fail send STOP LOSS to StopLostBank",
	500000516: "strategies.WingedSwing: Step: fail send REQUEST SALE to StopLostBank",

	500000600: "strategies.WingedSwing: Command: `%v` does not exists",
	500000610: "strategies.WingedSwing: Command: `%v` param not set",
	500000611: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000612: "strategies.WingedSwing: Command: `%v` param not set",
	500000613: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000614: "strategies.WingedSwing: Command: `%v` param not set",
	500000615: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000616: "strategies.WingedSwing: Command: `%v` param not set",
	500000617: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000618: "strategies.WingedSwing: Command: `%v` param not set",
	500000619: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000620: "strategies.WingedSwing: Command: `%v` param not set",
	500000621: "strategies.WingedSwing: Command: `%v` param `%v` is not int",
	500000640: "strategies.WingedSwing: Command: `%v` param `%v` not set",
	500000641: "strategies.WingedSwing: Command: `%v` value `%v` is not int (param `%v`)",
	500000642: "strategies.WingedSwing: Command: `%v` param `%v` not set",
	500000643: "strategies.WingedSwing: Command: `%v` value `%v` is not int (param `%v`)",
	500000644: "strategies.WingedSwing: Command: `%v` param `%v` not set",
	500000645: "strategies.WingedSwing: Command: `%v` value `%v` is not int (param `%v`)",
	500000646: "strategies.WingedSwing: Command: `%v` param `%v` not set",
	500000647: "strategies.WingedSwing: Command: `%v` value `%v` is not int (param `%v`)",
	500000650: "strategies.WingedSwing: Command: `%v` lavel `i` does not exists",
	500000651: "strategies.WingedSwing: Command: `%v` lavel `i` value `%v` is not int (element `%v`)",
	500000660: "strategies.WingedSwing: Command: `%v` param not set",
	500000661: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",
	500000662: "strategies.WingedSwing: Command: `%v` param not set",
	500000663: "strategies.WingedSwing: Command: `%v` param `%v` is not float64",

	500000700: "strategies.WingedSwing: Step: fail do some nested steps faild: %v of %v",
}

Errors codes and description

Functions

func GenerateError

func GenerateError(key int, a ...interface{}) *mft.Error

GenerateError -

func GenerateErrorE

func GenerateErrorE(key int, err error, a ...interface{}) *mft.Error

GenerateErrorE -

func GenerateErrorSubList added in v0.0.6

func GenerateErrorSubList(key int, sub []*mft.Error, a ...interface{}) *mft.Error

GenerateError -

func Round added in v0.0.6

func Round(price float64, point int) float64

Types

type Candle

type Candle struct {
	InstrumentId string `json:"instrument_id"`
	Ticker       string `json:"ticker"`

	// End date
	Date  time.Time `json:"date"`
	Start time.Time `json:"start"`
	Open  float64   `json:"open"`
	High  float64   `json:"high"`
	Low   float64   `json:"low"`
	Close float64   `json:"close"`
	Vol   int       `json:"vol"`

	// Last dividend amount
	LastDividend float64 `json:"last_dividend,omitempty"`
	// First date after [last dividend buy date]
	LastDividendDate time.Time `json:"last_dividend_date,omitempty"`
	// sum of all dividends amount
	AggDividend float64 `json:"agg_dividend,omitempty"`

	// Any additional info
	AdditionalInfo map[string]interface{} `json:"add_info,omitempty"`
}

func (*Candle) OrderBook

func (c *Candle) OrderBook() *OrderBook

OrderBook Generates order_book

type Candles

type Candles []Candle

func (Candles) After

func (cs Candles) After(date time.Time) (out Candles)

After returns candels after date include it (after or equal)

func (Candles) AfterIX

func (cs Candles) AfterIX(date time.Time) int

After returns candels after date include it (after or equal) index

func (Candles) Aggregate

func (cs Candles) Aggregate(aggFrame time.Duration) (out Candles)

Aggregate - Aggregate Candles by aggFrame (cs should be sorted)

func (Candles) Before

func (cs Candles) Before(date time.Time) (out Candles)

Befor returns candels befor date exclude it (befor strong)

func (Candles) Bounds

func (cs Candles) Bounds() (firstDate time.Time, lastDate time.Time, min float64, max float64)

func (Candles) Clone

func (cs Candles) Clone() (res Candles)

func (Candles) FillDividents

func (cs Candles) FillDividents(ds Dividends) (out Candles)

func (Candles) Len

func (cs Candles) Len() int

func (Candles) Less

func (cs Candles) Less(i, j int) bool

func (Candles) Sort

func (cs Candles) Sort()

func (Candles) Swap

func (cs Candles) Swap(i, j int)

type Command added in v0.0.6

type Command string
const (
	StartCommand Command = "start"
	StopCommand  Command = "stop"
	ShowCommand  Command = "show"
)

type CommandInfo added in v0.0.9

type CommandInfo struct {
	Order             int
	Description       string
	ParamsDescription string
	Example           string
}

type CommandResult added in v0.0.9

type CommandResult struct {
	Message string
}

type Dividend

type Dividend struct {
	InstrumentId string `json:"instrument_id"`
	Ticker       string `json:"ticker"`

	Amount float64 `json:"amount"`
	// LastDate - Last date for Buy
	LastDate time.Time `json:"last_date"`

	// sum of all dividends amount
	AggDividend float64 `json:"agg_dividend"`
}

func (Dividend) AfterOrEqual24

func (d Dividend) AfterOrEqual24(t time.Time) bool

type Dividends

type Dividends []Dividend

func (Dividends) FindCandleDividend

func (ds Dividends) FindCandleDividend(
	start time.Time, end time.Time,
) (
	lastAmount float64, lastDate time.Time, agg float64,
)

func (Dividends) Len

func (ds Dividends) Len() int

func (Dividends) Less

func (ds Dividends) Less(i, j int) bool

func (Dividends) Sort

func (ds Dividends) Sort()

func (Dividends) Swap

func (ds Dividends) Swap(i, j int)

type InstrumentInfo added in v0.0.6

type InstrumentInfo struct {
	InstrumentId string `json:"instrument_id"`
	Ticker       string `json:"ticker"`

	LotSize int     `json:"lot_size"`
	MinStep float64 `json:"min_step"`
}

type JsonTypedContainer

type JsonTypedContainer struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

type LotPrices added in v0.0.6

type LotPrices struct {
	Count int
	Price float64
}

type MetaForOperations added in v0.0.9

type MetaForOperations struct {
	NameOfStrategy string
	IsStopLoss     bool
}

type MetaForStep added in v0.0.9

type MetaForStep struct {
	IsStopLoss bool
	HasChanges bool
	Name       string
	OpDescr    []string
	SubMeta    []MetaForStep
}

type Operation

type Operation string
const (
	Buy             Operation = "buy"
	Sell            Operation = "sell"
	Tax             Operation = "tax"
	BuyOrderCreate  Operation = "buy_order_create"
	SellOrderCreate Operation = "sell_order_create"
)

type OrderBook

type OrderBook struct {
	InstrumentId string `json:"instrument_id"`
	Ticker       string `json:"ticker"`

	Time  time.Time `json:"time"`
	Depth int       `json:"depth"`
	// under price
	Bids []RestPriceQuantity `json:"bids"`
	// over price
	Asks              []RestPriceQuantity `json:"asks"`
	TradeStatus       TradingStatus       `json:"trade_status"`
	MinPriceIncrement float64             `json:"min_price_increment"`
	LastPrice         float64             `json:"last_price,omitempty"`
	ClosePrice        float64             `json:"close_price,omitempty"`
	LimitUp           float64             `json:"limit_up,omitempty"`
	LimitDown         float64             `json:"limit_down,omitempty"`
}

func (*OrderBook) BuyPrice

func (ob *OrderBook) BuyPrice() float64

func (*OrderBook) Price

func (ob *OrderBook) Price() float64

func (*OrderBook) SellPrice

func (ob *OrderBook) SellPrice() float64

type RestPriceQuantity

type RestPriceQuantity struct {
	Price    float64 `json:"price"`
	Quantity int     `json:"quantity"`
}

type StartegyStatus added in v0.0.6

type StartegyStatus struct {
	IsOnline bool `json:"is_online"`
}

type StatusOrder

type StatusOrder string
const (
	Complete StatusOrder = "complete"
	Canceled StatusOrder = "canceled"
	Unknown  StatusOrder = "unknown"
	Wait     StatusOrder = "wait"
)

type StepParams

type StepParams interface {
	GetCandles(instrumentId string, ticker string, dateFrom time.Time, dateTo time.Time) (cs Candles, err *mft.Error)
	GetOrderBook(instrumentId string, ticker string) (ob *OrderBook, err *mft.Error)
	GetInstrumentInfo(instrumentId string, ticker string) (instrumentInfo *InstrumentInfo, err *mft.Error)

	BuyByMarket(instrumentId string, ticker string, cnt int,
		meta *MetaForOperations) (orderId string, err *mft.Error)
	SellByMarket(instrumentId string, ticker string, cnt int,
		meta *MetaForOperations) (orderId string, err *mft.Error)

	BuyByPrice(instrumentId string, ticker string, cnt int, price float64,
		meta *MetaForOperations) (orderId string, err *mft.Error)
	SellByPrice(instrumentId string, ticker string, cnt int, price float64,
		meta *MetaForOperations) (orderId string, err *mft.Error)

	CancelBuyOrder(instrumentId string, ticker string, orderId string,
		meta *MetaForOperations) (ok bool, err *mft.Error)
	CancelSellOrder(instrumentId string, ticker string, orderId string,
		meta *MetaForOperations) (ok bool, err *mft.Error)

	StatusBuyOrder(instrumentId string, ticker string, orderId string,
		meta *MetaForOperations) (status StatusOrder, prices []LotPrices, err *mft.Error)
	StatusSellOrder(instrumentId string, ticker string, orderId string,
		meta *MetaForOperations) (status StatusOrder, prices []LotPrices, err *mft.Error)
}

type Strategy

type Strategy interface {
	Step(p StepParams) (meta MetaForStep, err *mft.Error)
	Status() StartegyStatus
	String() string
	Type() string
	Json() string
	Command(cmd Command, params map[string]string) (res CommandResult, ok bool, err *mft.Error)
	AllowCommands() map[Command]CommandInfo
	Description() string
}

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"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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