db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectSQL

func ConnectSQL(name, user, host, port, password string)

连接数据库

func Engine

func Engine() *xorm.Engine

func StringToSymbol

func StringToSymbol(s string) conset.SYMBOL

func SymbolToString

func SymbolToString(symbol conset.SYMBOL) string

Types

type Account

type Account struct {
	Id        int64
	Name      string    `xorm:"varchar(255) unique(n-p-s)"` // 名称
	Plat      string    `xorm:"varchar(255) unique(n-p-s)"` // 平台名称
	Symbol    string    `xorm:"varchar(255) unique(n-p-s)"` // Token
	Used      float32   `xorm:"float"`                      // 总值
	Total     float32   `xorm:"float"`                      // 总值
	CreatedAt time.Time `xorm:"created"`
	UpdatedAt time.Time `xorm:"updated"`
}

func (*Account) Account

func (self *Account) Account(pt conset.PLAT, symbol conset.SYMBOL) error

func (*Account) Clear

func (self *Account) Clear() error

func (*Account) Inserts

func (self *Account) Inserts(pt conset.PLAT, symbol conset.SYMBOL) error

func (*Account) Update

func (self *Account) Update() error

type AccountDay

type AccountDay struct {
	Id         int64
	Name       string    `xorm:"varchar(255)"`                            // 名称
	Plat       string    `xorm:"varchar(255)"`                            // 平台名称
	Symbol     string    `xorm:"varchar(255)"`                            // Token
	Used       float32   `xorm:"float"`                                   // 总值
	Total      float32   `xorm:"float"`                                   // 总值
	CreateTime time.Time `json:"create_time" xorm:"create_time DateTime"` // 时间
	CreatedAt  time.Time `xorm:"created"`
	UpdatedAt  time.Time `xorm:"updated"`
}

func (*AccountDay) Inserts

func (self *AccountDay) Inserts(pt conset.PLAT, symbol conset.SYMBOL) error

type Coin

type Coin struct {
	Id         int64
	Plat       string    `xorm:"plat varchar(255) unique(pl-time) index(pl-sy-t) index(p-s-t-c)"`
	Symbol     string    `xorm:"symbol varchar(255) unique(pl-time) index(pl-sy-t) index(p-s-t-c)"`
	Times      string    `xorm:"times varchar(255) unique(pl-time) index(pl-sy-t) index(p-s-t-c)"` // 时间间隔
	Open       float32   `xorm:"float"`
	Close      float32   `xorm:"float"`
	High       float32   `xorm:"float"`
	Low        float32   `xorm:"float"`
	Volume     float32   `xorm:"float"`
	Timestamp  int64     `json:"time_stamp" xorm:"bigint time_stamp index unique(pl-time)"` // 毫秒
	CreateTime time.Time `json:"create_time" xorm:"DATETIME create_time index(p-s-t-c)"`
	CreatedAt  time.Time `xorm:"created"`
	UpdatedAt  time.Time `xorm:"updated"`
}

Coin K线数据

func (*Coin) ATR

func (self *Coin) ATR(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES, limit int, end time.Time) float32

平均波动幅度 1、当前交易日的最高价与最低价间的波幅 2、前一交易日收盘价与当个交易日最高价间的波幅 3、前一交易日收盘价与当个交易日最低价间的波幅

func (*Coin) All

func (self *Coin) All(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES, start time.Time) ([]*Coin, error)

func (*Coin) Chanel

func (self *Coin) Chanel(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES, limit int, end time.Time) (float32, float32)

通道 N日移动平均线=N日收市价之和/N

func (*Coin) Create

func (self *Coin) Create(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES, open, close, high, low, volume float32, timetamp int64) error

func (*Coin) EMA

func (self *Coin) EMA(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES, limit int, end time.Time) float32

平滑移动平均线 EMA(12) = [2/(12+1)]*今日收盘价+[11/(12+1)]*作日EMA(12)

func (*Coin) EMAStart

func (self *Coin) EMAStart(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES, limit int, end time.Time) float32

func (*Coin) LastTime

func (self *Coin) LastTime(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES) (bool, time.Time)

func (*Coin) Lasts

func (self *Coin) Lasts(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES, limit int, end time.Time) ([]Coin, error)

func (*Coin) MA

func (self *Coin) MA(pt conset.PLAT, symbol conset.SYMBOL, times conset.TIMES, limit int, end time.Time) float32

移动平均线 N日移动平均线=N日收市价之和/N

type Indexs

type Indexs struct {
	Id        int64
	Plat      string    `xorm:"varchar(255) unique(p-n-s-d)"` // 平台名称
	Name      string    `xorm:"varchar(255) unique(p-n-s-d)"` // 指标名称
	Symbol    string    `xorm:"varchar(255) unique(p-n-s-d)"` // 币种
	Date      string    `xorm:"varchar(255) unique(p-n-s-d)"` // 格式化时间
	P1        float32   `xorm:"p_1"`
	P2        float32   `xorm:"p_2"`
	P3        float32   `xorm:"p_3"`
	P4        float32   `xorm:"p_4"`
	P5        float32   `xorm:"p_5"`
	CreatedAt time.Time `xorm:"created"`
	UpdatedAt time.Time `xorm:"updated"`
}

type Record

type Record struct {
	Id            int64
	Name          string    `xorm:"name index(name-symbol-period) index(n-s-s) index(n-s-o-p)"`   // 策略
	Plat          string    `xorm:"plat"`                                                         // 平台名称
	Symbol        string    `xorm:"symbol index(name-symbol-period) index(n-s-s) index(n-s-o-p)"` // Token
	Period        string    `xorm:"period index(name-symbol-period)"`                             // 周期 spot|week|quarter
	Operation     int32     `xorm:"int index(n-s-o-p)"`                                           // 1: 开多 2: 开空 3: 平仓
	Position      int32     `xorm:"int index(n-s-o-p)"`                                           // 加仓层数
	Price         float32   `xorm:"float"`                                                        // 当前价格
	AvgPrice      float32   `xorm:"float"`                                                        // 均价
	Used          float32   `xorm:"float"`                                                        // 已开仓Token
	Size          float32   `xorm:"float"`                                                        // 开仓张数
	Total         float32   `xorm:"float"`                                                        // 当前账户总值
	LossPrice     float32   `xorm:"float"`                                                        // 止损价
	EstimatedLoss float32   `xorm:"float"`                                                        // 预计亏损
	Detail        string    `xorm:"detail text"`                                                  // 描述 usd->token | ust<-token
	Profit        float32   `xorm:"float"`                                                        // 收益
	ProfitRate    float32   `xorm:"float"`                                                        // 收益率(百分比 %)
	TotalRate     float32   `xorm:"float"`                                                        // 总收益率(百分比 %)
	Status        int32     `xorm:"status index(n-s-s)"`                                          // 状态
	CreateTime    time.Time `json:"create_time" xorm:"create_time DateTime index"`                // 时间
	CreatedAt     time.Time `xorm:"created"`
	UpdatedAt     time.Time `xorm:"updated"`
}

Record 交易记录

func (*Record) Clear

func (self *Record) Clear() error

func (*Record) Insert

func (self *Record) Insert(pt conset.PLAT, symbol conset.SYMBOL) error

func (*Record) Last

func (self *Record) Last(pt conset.PLAT, symbol conset.SYMBOL) error

Jump to

Keyboard shortcuts

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