models

package
v0.0.0-...-87ff82d Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Running  = "running"
	Paused   = "paused"
	Resuming = "resuming"
	Removed  = "removed"
	Waiting  = "waiting"
)

Variables

This section is empty.

Functions

func ConvLogicToYamlString

func ConvLogicToYamlString(l Logic) (string, error)

func Migrate

func Migrate(db *gorm.DB) error

Types

type Balance

type Balance struct {
	Available float64
	OnOrders  float64
}

func NewBalance

func NewBalance(available float64, onOrders float64) *Balance

type Chart

type Chart struct {
	gorm.Model

	Last       float64
	Open       float64
	High       float64
	Low        float64
	Volume     float64
	Duration   int        `gorm:"index"`
	Datetime   time.Time  `gorm:"index"`
	Pair       string     `gorm:"index"`
	ExchangeID ExchangeID `gorm:"index"`
}

type ExchangeID

type ExchangeID int
const (
	Poloniex ExchangeID = iota + 1
	Hitbtc
	Bitflyer
	Binance

	UnknownExchange
)

func ExchangeIDString

func ExchangeIDString(s string) (ExchangeID, error)

func (ExchangeID) String

func (i ExchangeID) String() string

type Logic

type Logic interface {
	Execute([]Chart) bool
}

func And

func And(a Logic, b Logic) Logic

func NewEMADif

func NewEMADif(period int, difRate float64) Logic

func NewFakeLogic

func NewFakeLogic(isPassed bool) Logic

func NewGoldenCross

func NewGoldenCross(positionType PositionType, period int, param float64) Logic

func NewOBV

func NewOBV(positionType PositionType, period int, param float64) Logic

func NewRSIContrarian

func NewRSIContrarian(positionType PositionType, period int, param float64) Logic

func NewRSIFollow

func NewRSIFollow(positionType PositionType, period int, param float64) Logic

func NewSMADif

func NewSMADif(period int, difRate float64) Logic

func NewSmaLineCross

func NewSmaLineCross(positionType PositionType, shortPeriod int, longPeriod int, keepPeriod int) Logic

func NewWMADif

func NewWMADif(period int, difRate float64) Logic

func Not

func Not(a Logic) Logic

func Or

func Or(a Logic, b Logic) Logic

type LogicYaml

type LogicYaml map[string]interface{}

func (LogicYaml) MarshalJSON

func (y LogicYaml) MarshalJSON() ([]byte, error)

type Order

type Order struct {
	ExchangeOrderID string
	Type            OrderType
	Trading         string
	Settlement      string
	Price           float64
	Amount          float64
}

type OrderGorm

type OrderGorm struct {
	gorm.Model
	Order

	ExchangeID ExchangeID `json:"exchange_id"`
	TraderID   uint       `json:"trader_id"`
	PositionID uint
	Pair       string `json:"currency_pair"`
	OrderID    string `json:"order_id"`

	Datetime     time.Time    `json:"datetime"`
	Status       bool         `json:"status"`
	ExcutePrice  float64      `json:"price"`
	ExcuteAmount float64      `json:"amount"`
	TradeType    PositionType `json:"trade_type"`
}

type OrderType

type OrderType int
const (
	Ask OrderType = iota
	Bid
)

type Position

type Position struct {
	ID                    uint `gorm:"primary_key" json:"position_id"`
	CreatedAt             time.Time
	UpdatedAt             time.Time
	DeletedAt             *time.Time
	ExchangeID            ExchangeID
	AssetDistributionRate float64
	EntryPrice            float64 `json:"entry_price"`
	ProfitTakeRate        float64
	LossCutRate           float64
	PositionType          PositionType `json:"position_type" sql:"DEFAULT:false"`
	Trading               string
	Settlement            string
	WaitLimitSecond       int
	EntryOrder            OrderGorm
	EntryOrderID          uint `gorm:"type:bigint" json:"entry_order_id"`
	ExitOrder             OrderGorm
	ExitOrderID           uint `gorm:"type:bigint" json:"exit_order_id"`
	IsMade                bool `json:"is_made"`
	IsClosed              bool `json:"is_closed"`
	TraderID              uint `json:"trader_id"`
}

A position is a struct used by Trader. It opens and closes positions according to evaluate methods it has.

func (*Position) IsLossCuttable

func (p *Position) IsLossCuttable(rate float64) bool

func (*Position) IsProfitTakable

func (p *Position) IsProfitTakable(rate float64) bool

func (*Position) SetPrice

func (p *Position) SetPrice(price float64)

type PositionType

type PositionType int

Long:true False:false

const (
	Long  PositionType = 1
	Short              = 0
)

type Status

type Status string

type TradePhase

type TradePhase int
const (
	Boot TradePhase = iota + 1
	Resume
	JudgeEntry
	MakePosition
	JudgeExit
	ClosePosition
	Reset

	ShutDown
)

type TraderGorm

type TraderGorm struct {
	gorm.Model
	ExchangeID               ExchangeID `yaml:"exchange_id"`
	APIKey                   string     `yaml:"api_key"`
	SecretKey                string     `yaml:"secret_key"`
	Trading                  string     `yaml:"trading"`
	Settlement               string     `yaml:"settlement"`
	LossCutRate              float64    `yaml:"loss_cut_rate"`
	ProfitTakeRate           float64    `yaml:"profit_take_rate"`
	AssetDistributionRate    float64    `yaml:"asset_distribution_rate"`
	TradingAmount            float64
	PositionType             PositionType `yaml:"position_type"`
	Duration                 int          `yaml:"duration"`
	WaitLimitSecond          int          `yaml:"wait_limit_second"`
	MakePositionLogicsString string       `yaml:"make_position_logics" sql:"type:text"`
	MakePositionLogicsYaml   LogicYaml    `sql:"-" yaml:"make_position_logics_yaml"`
	Status                   string       `yaml:"status"`
}

func (*TraderGorm) AfterFind

func (t *TraderGorm) AfterFind() (err error)

func (*TraderGorm) BeforeSave

func (t *TraderGorm) BeforeSave(scope *gorm.Scope) (err error)

type YamlParser

type YamlParser struct {
}

func NewYamlParser

func NewYamlParser() *YamlParser

func (*YamlParser) Parse

func (p *YamlParser) Parse(src string) (logic Logic, err error)

func (*YamlParser) ParseLogicYaml

func (p *YamlParser) ParseLogicYaml(yml LogicYaml) (logic Logic, err error)

Jump to

Keyboard shortcuts

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