db

package
v0.0.0-...-ed9f599 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTrade

func AddTrade(tx *gorm.DB, tr *Trade) error

func FindTradesByTsId

func FindTradesByTsId(tx *gorm.DB, tsId uint) (*[]Trade, error)

func FindTradesByTsIds

func FindTradesByTsIds(tx *gorm.DB, ids []uint) (*[]Trade, error)

func FindTradesFromTime

func FindTradesFromTime(tx *gorm.DB, tsIds []uint, fromTime time.Time) (*[]Trade, error)

func GetTradingSystems

func GetTradingSystems(tx *gorm.DB, filter map[string]any, offset int, limit int) (*[]TradingSystem, error)

func GetTradingSystemsByIdsAsMap

func GetTradingSystemsByIdsAsMap(tx *gorm.DB, ids []uint) (map[uint]*TradingSystem, error)

func GetTradingSystemsByUser

func GetTradingSystemsByUser(tx *gorm.DB, name string) (*[]TradingSystem, error)

func GetTradingSystemsInIdle

func GetTradingSystemsInIdle(tx *gorm.DB, days int) (*[]TradingSystem, error)

func GetUsersWithTradingSystems

func GetUsersWithTradingSystems(tx *gorm.DB) ([]string, error)

func InitDatabase

func InitDatabase(cfg *core.Database)

func RunInTransaction

func RunInTransaction(f func(tx *gorm.DB) error) error

func SetTradingFilter

func SetTradingFilter(tx *gorm.DB, tf *TradingFilter) error

func UpdateBrokerProductInfo

func UpdateBrokerProductInfo(tx *gorm.DB, brokerProductId uint, values map[string]interface{}) error

func UpdateTradingSystem

func UpdateTradingSystem(tx *gorm.DB, ts *TradingSystem) error

Types

type ParamMap

type ParamMap map[string]any

func (*ParamMap) Scan

func (pm *ParamMap) Scan(value interface{}) error

func (ParamMap) Value

func (pm ParamMap) Value() (driver.Value, error)

type Trade

type Trade struct {
	Id              uint       `json:"id" gorm:"primaryKey"`
	TradingSystemId uint       `json:"tradingSystemId"`
	TradeType       TradeType  `json:"tradeType"`
	EntryTime       *time.Time `json:"entryTime"`
	EntryValue      float64    `json:"entryValue"`
	ExitTime        *time.Time `json:"exitTime"`
	ExitValue       float64    `json:"exitValue"`
	GrossProfit     float64    `json:"grossProfit"`
	NumContracts    int        `json:"numContracts"`
}

func FindLastTrade

func FindLastTrade(tx *gorm.DB, tsId uint) (*Trade, error)

func (Trade) TableName

func (Trade) TableName() string

type TradeType

type TradeType int8
const (
	TradeTypeLong  TradeType = 0
	TradeTypeShort TradeType = 1
)

type TradingFilter

type TradingFilter struct {
	TradingSystemId  uint `json:"tradingSystemId" gorm:"primaryKey"`
	EquAvgEnabled    bool `json:"equAvgEnabled"`
	EquAvgLen        int  `json:"equAvgLen"`
	PosProEnabled    bool `json:"posProEnabled"`
	PosProLen        int  `json:"posProLen"`
	WinPerEnabled    bool `json:"winPerEnabled"`
	WinPerLen        int  `json:"winPerLen"`
	WinPerValue      int  `json:"winPerValue"`
	OldNewEnabled    bool `json:"oldNewEnabled"`
	OldNewOldLen     int  `json:"oldNewOldLen"`
	OldNewOldPerc    int  `json:"oldNewOldPerc"`
	OldNewNewLen     int  `json:"oldNewNewLen"`
	TrendlineEnabled bool `json:"trendlineEnabled"`
	TrendlineLen     int  `json:"trendlineLen"`
	TrendlineValue   int  `json:"trendlineValue"`
}

func GetTradingFilterByTsId

func GetTradingFilterByTsId(tx *gorm.DB, tsId uint) (*TradingFilter, error)

func (TradingFilter) TableName

func (TradingFilter) TableName() string

type TradingSystem

type TradingSystem struct {
	Id               uint         `json:"id" gorm:"primaryKey"`
	Username         string       `json:"username"`
	WorkspaceCode    string       `json:"workspaceCode"`
	Name             string       `json:"name"`
	Running          bool         `json:"running"`
	Activation       TsActivation `json:"activation"`
	Active           bool         `json:"active"`
	Status           TsStatus     `json:"status"`
	SuggestedAction  TsSuggAction `json:"suggestedAction"`
	FirstTrade       *time.Time   `json:"firstTrade"`
	LastTrade        *time.Time   `json:"lastTrade"`
	LastUpdate       *time.Time   `json:"lastUpdate"`
	LmNetProfit      float64      `json:"lmNetProfit"`
	LmNetAvgTrade    float64      `json:"lmNetAvgTrade"`
	LmNumTrades      int          `json:"lmNumTrades"`
	BrokerProductId  uint         `json:"brokerProductId"`
	BrokerSymbol     string       `json:"brokerSymbol"`
	PointValue       float32      `json:"pointValue"`
	CostPerOperation float32      `json:"costPerOperation"`
	MarginValue      float32      `json:"marginValue"`
	Increment        float64      `json:"increment"`
	CurrencyId       uint         `json:"currencyId"`
	CurrencyCode     string       `json:"currencyCode"`
}

func GetTradingSystemById

func GetTradingSystemById(tx *gorm.DB, id uint) (*TradingSystem, error)

func GetTradingSystemByName

func GetTradingSystemByName(tx *gorm.DB, name string) (*TradingSystem, error)

func (TradingSystem) TableName

func (TradingSystem) TableName() string

type TsActivation

type TsActivation int8
const (
	TsActivationManual TsActivation = 0
	TsActivationAuto   TsActivation = 1
)

type TsStatus

type TsStatus int8
const (
	TsStatusOff     TsStatus = 0
	TsStatusPaused  TsStatus = 1
	TsStatusRunning TsStatus = 2
	TsStatusIdle    TsStatus = 3
	TsStatusBroken  TsStatus = 4
)

type TsSuggAction

type TsSuggAction int8
const (
	TsActionNone            TsSuggAction = 0
	TsActionTurnOff         TsSuggAction = 1
	TsActionTurnOn          TsSuggAction = 2
	TsActionCheck           TsSuggAction = 3
	TsActionTurnOffAndCheck TsSuggAction = 4
	TsActionNoneTurnedOff   TsSuggAction = 5
	TsActionNoneTurnedOn    TsSuggAction = 6
)

Jump to

Keyboard shortcuts

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