db

package
v0.0.0-...-41c3c42 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 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

Types

type Account

type Account struct {
	Id     int64
	Plat   string  `xorm:"varchar(255)"` // 平台名称
	Symbol string  `xorm:"varchar(255)"` // Token
	Total  float32 `xorm:"float"`        // 总值
}

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 Coin

type Coin struct {
	Id         int64
	Plat       string    `xorm:"plat varchar(255) unique(pl-time) index(pl-sy-t)"`
	Symbol     string    `xorm:"symbol varchar(255) unique(pl-time) index(pl-sy-t)"`
	Times      string    `xorm:"times varchar(255) unique(pl-time) index(pl-sy-t)"`         // 时间间隔
	Period     string    `json:"period" xorm:"varchar(255) unique(pl-time) index(pl-sy-t)"` // 合约类型 spot,week
	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"`
}

Coin K线数据

func (*Coin) ATR

func (self *Coin) ATR(pt conset.PLAT, symbol conset.SYMBOL, period conset.PERIOD, 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, period conset.PERIOD, times conset.TIMES, start time.Time) ([]*Coin, error)

func (*Coin) Chanel

func (self *Coin) Chanel(pt conset.PLAT, symbol conset.SYMBOL, period conset.PERIOD, 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, period conset.PERIOD, 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, period conset.PERIOD, times conset.TIMES, limit int, end time.Time) float32

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

func (*Coin) LastTime

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

func (*Coin) Lasts

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

todo 模拟测试 需要去掉最后一条数据

func (*Coin) MA

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

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

type Record

type Record struct {
	Id         int64
	Plat       string    `xorm:"varchar(255) plat index(plat-symbol-period)"`   // 平台名称
	Symbol     string    `xorm:"varchar(255) symbol index(plat-symbol-period)"` // Token
	Period     string    `xorm:"varchar(255) period index(plat-symbol-period)"` // 周期 spot|week|quarter
	Operation  int32     `xorm:"int"`                                           // 1: 开多 2: 开空 3: 平仓
	Position   int32     `xorm:"int"`                                           // 加仓层数
	Price      float32   `xorm:"float"`                                         // 当前价格
	AvgPrice   float32   `xorm:"float"`                                         // 均价
	Used       float32   `xorm:"float"`                                         // 已开仓Token
	Size       float32   `xorm:"float"`                                         // 开仓张数
	Total      float32   `xorm:"float"`                                         // 当前账户总值
	Detail     string    `xorm:"detail text"`                                   // 描述 usd->token | ust<-token
	Profit     float32   `xorm:"float"`                                         // 收益
	ProfitRate float32   `xorm:"float"`                                         // 收益率
	TotalRate  float32   `xorm:"float"`                                         // 总收益率
	CreateTime time.Time `json:"create_time" xorm:"create_time DateTime index"` // 时间
}

MarginRecord 交易记录

func (*Record) Clear

func (self *Record) Clear() error

func (*Record) Insert

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

func (*Record) Last

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

Jump to

Keyboard shortcuts

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