ticker

package
v0.0.0-...-ce1dffb Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TickerInstrumentsTableName = "ticker_instruments"
	TickerDataTableName        = "ticker_data"
	TickerLogTableName         = "_ticker_logs"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LogLevel

type LogLevel string

TICKER LOGS ----------------------------------------------------- LogLevel represents the severity of a log message

const (
	DEBUG LogLevel = "DEBUG"
	INFO  LogLevel = "INFO"
	WARN  LogLevel = "WARN"
	ERROR LogLevel = "ERROR"
	FATAL LogLevel = "FATAL"
)

type Repository

type Repository struct {
	DB *gorm.DB
}

func NewRepository

func NewRepository(db *gorm.DB) *Repository

NewRepository creates a new Repository

func (*Repository) Debug

func (r *Repository) Debug(eventType, message string) error

Debug logs a debug message

func (*Repository) DeleteTickerInstruments

func (r *Repository) DeleteTickerInstruments(userID string, instruments []string) (int64, error)

DeleteTickerInstruments deletes the ticker instruments

func (*Repository) Error

func (r *Repository) Error(eventType, message string) error

Error logs an error message

func (*Repository) Fatal

func (r *Repository) Fatal(eventType, message string) error

Fatal logs a fatal message

func (*Repository) GetInstrumentToken

func (r *Repository) GetInstrumentToken(exchange, symbol string) (uint32, error)

-------------------------------------------- Other funcs --------------------------------------------

func (*Repository) GetTickerInstrumentCount

func (r *Repository) GetTickerInstrumentCount(userID string) (int64, error)

GetTickerInstrumentCount gets the ticker instrument count

func (*Repository) GetTickerInstruments

func (r *Repository) GetTickerInstruments(userID string) ([]TickerInstrument, error)

GetTickerInstruments gets the ticker instruments

func (*Repository) Info

func (r *Repository) Info(eventType, message string) error

Info logs an info message

func (*Repository) TruncateTickerData

func (r *Repository) TruncateTickerData() error

-------------------------------------------- TickerData func's grouped together -------------------------------------------- TruncateTickerData truncates the ticker data

func (*Repository) TruncateTickerInstruments

func (r *Repository) TruncateTickerInstruments() (int64, error)

-------------------------------------------- TickerInstruments func's grouped together -------------------------------------------- TruncateTickerInstruments truncates the ticker instruments

func (*Repository) UpsertTickerData

func (r *Repository) UpsertTickerData(tickerData []TickerData) error

func (*Repository) UpsertTickerInstruments

func (r *Repository) UpsertTickerInstruments(userID string, instrumentsTokenMap map[string]uint32) (int, int, error)

UpsertTickerInstruments upserts the instruments

func (*Repository) Warn

func (r *Repository) Warn(eventType, message string) error

Warn logs a warning message

type TickerData

type TickerData struct {
	Instrument         string         `gorm:"index" json:"instrument"`
	InstrumentToken    uint32         `gorm:"primaryKey"  json:"instrument_token"`
	Mode               string         `gorm:"type:varchar(10)" json:"mode"`
	IsTradable         bool           `json:"is_tradable"`
	IsIndex            bool           `json:"is_index"`
	Timestamp          time.Time      `json:"timestamp"`
	LastTradeTime      time.Time      `json:"last_trade_time"`
	LastPrice          float64        `gorm:"type:decimal(10,2);column:last_price" json:"last_price"`
	LastTradedQuantity uint32         `gorm:"type:bigint;column:last_traded_quantity" json:"last_traded_quantity"`
	TotalBuyQuantity   uint32         `gorm:"type:bigint;column:total_buy_quantity" json:"total_buy_quantity"`
	TotalSellQuantity  uint32         `gorm:"type:bigint;column:total_sell_quantity" json:"total_sell_quantity"`
	VolumeTraded       uint32         `gorm:"type:bigint;column:volume" json:"volume"`
	AverageTradePrice  float64        `gorm:"type:decimal(10,2);column:average_price" json:"average_price"`
	OI                 uint32         `gorm:"type:bigint;column:oi" json:"oi"`
	OIDayHigh          uint32         `gorm:"type:bigint;column:oi_day_high" json:"oi_day_high"`
	OIDayLow           uint32         `gorm:"type:bigint;column:oi_day_low" json:"oi_day_low"`
	NetChange          float64        `gorm:"type:decimal(10,2)" json:"net_change"`
	OHLC               datatypes.JSON `gorm:"type:jsonb;column:ohlc" json:"ohlc"`
	Depth              datatypes.JSON `gorm:"type:jsonb;column:depth" json:"depth"`
	UpdatedAt          time.Time      `gorm:"autoUpdateTime:nano"  json:"updated_at"`
}

TICKER DATA -------------------------------------------------------- TickerData represents the tick data for an instrument

func (*TickerData) GetDepth

func (t *TickerData) GetDepth() (TickerDataDepth, error)

func (*TickerData) GetOHLC

func (t *TickerData) GetOHLC() (TickerDataOHLC, error)

func (TickerData) TableName

func (TickerData) TableName() string

type TickerDataDepth

type TickerDataDepth struct {
	Buy  [5]TickerDataDepthItem `json:"buy"`
	Sell [5]TickerDataDepthItem `json:"sell"`
}

type TickerDataDepthItem

type TickerDataDepthItem struct {
	Price    float64 `json:"price"`
	Quantity uint32  `json:"quantity"`
	Orders   uint32  `json:"orders"`
}

type TickerDataOHLC

type TickerDataOHLC struct {
	Open  float64 `json:"open"`
	High  float64 `json:"high"`
	Low   float64 `json:"low"`
	Close float64 `json:"close"`
}

func (*TickerDataOHLC) Scan

func (o *TickerDataOHLC) Scan(value interface{}) error

func (TickerDataOHLC) Value

func (o TickerDataOHLC) Value() (driver.Value, error)

type TickerInstrument

type TickerInstrument struct {
	UserID          string    `gorm:"uniqueIndex:idx_userId_instrument,priority:1;type:varchar(10)" json:"user_id"`
	Instrument      string    `gorm:"uniqueIndex:idx_userId_instrument,priority:2" json:"instrument"`
	InstrumentToken uint32    `json:"instrument_token"`
	CreatedAt       time.Time `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt       time.Time `gorm:"autoUpdateTime" json:"updated_at"`
}

TICKER INSTRUMENTS ------------------------------------------------- TickerInstrument represents the instruments for which tick data is subscribed

func (TickerInstrument) TableName

func (TickerInstrument) TableName() string

type TickerLog

type TickerLog struct {
	ID        uint32     `gorm:"primaryKey"`
	Timestamp *time.Time `gorm:"index"`
	Level     *LogLevel
	EventType *string
	Message   *string
}

func (TickerLog) TableName

func (TickerLog) TableName() string

type TickerService

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

func NewService

func NewService(db *gorm.DB, redisClient *redis.Client) *TickerService

NewService creates a new TickerService

func (*TickerService) AddTickerInstruments

func (s *TickerService) AddTickerInstruments(userID string, instruments []string) (map[string]interface{}, error)

AddTickerInstruments adds the ticker instruments

func (*TickerService) DeleteTickerInstruments

func (s *TickerService) DeleteTickerInstruments(userID string, instruments []string) (int64, error)

func (*TickerService) GetNFOFilterMonths

func (s *TickerService) GetNFOFilterMonths() (string, string, string)

GetNFOFilterMonths gets the NFO filter months

func (*TickerService) GetTickerInstrumentCount

func (s *TickerService) GetTickerInstrumentCount(userID string) (int64, error)

GetTickerInstrumentCount gets the ticker instrument count

func (*TickerService) GetTickerInstruments

func (s *TickerService) GetTickerInstruments(userID string) ([]TickerInstrument, error)

GetTickerInstruments gets the ticker instruments

func (*TickerService) Restart

func (s *TickerService) Restart(userID, enctoken string) error

func (*TickerService) SetReconnectMaxRetries

func (s *TickerService) SetReconnectMaxRetries(retries int)

func (*TickerService) Start

func (s *TickerService) Start(userID, enctoken string) error

Start starts the ticker service

func (*TickerService) Status

func (s *TickerService) Status() bool

Status returns the current status of the ticker

func (*TickerService) Stop

func (s *TickerService) Stop(userID string) error

Stop stops the ticker service

func (*TickerService) TruncateTickerData

func (s *TickerService) TruncateTickerData() error

TruncateTickerData truncates the ticker data

func (*TickerService) TruncateTickerInstruments

func (s *TickerService) TruncateTickerInstruments() (int64, error)

TruncateTickerInstruments truncates the ticker instruments

func (*TickerService) UpsertQueriedInstruments

func (s *TickerService) UpsertQueriedInstruments(userID, exchange, tradingsymbol, expiry, strike, segment string) (map[string]interface{}, error)

UpsertQueriedInstruments upserts the queried instruments

Jump to

Keyboard shortcuts

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