trademodel

package module
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: GPL-3.0 Imports: 3 Imported by: 38

README

trademodel

Common trade model used by ztrade

Documentation

Index

Constants

View Source
const (
	Long  = 1
	Short = 2
)
View Source
const (
	SymbolTypeSpot    = "spot"
	SymbolTypeIndex   = "index"
	SymbolTypeFutures = "futures"
)
View Source
const (
	CancelOne   TradeType = -2
	CancelAll   TradeType = -1
	DirectLong  TradeType = 1
	DirectShort TradeType = 1 << 1

	Limit  TradeType = 1 << 3
	Market TradeType = 1 << 4
	Stop   TradeType = 1 << 5

	Open  TradeType = 1 << 6
	Close TradeType = 1 << 7

	OpenLong   = Open | DirectLong
	OpenShort  = Open | DirectShort
	CloseLong  = Close | DirectLong
	CloseShort = Close | DirectShort // 130
	StopLong   = Stop | DirectLong   // 33
	StopShort  = Stop | DirectShort  // 34
)

Variables

View Source
var (
	OrderStatusFilled   = "FILLED"
	OrderStatusCanceled = "CANCELED"
)

Functions

This section is empty.

Types

type Balance

type Balance struct {
	Currency  string
	Available float64
	Frozen    float64
	Balance   float64
}

type Candle

type Candle struct {
	ID       int64   `xorm:"pk autoincr 'id'"`
	Start    int64   `xorm:"unique index 'start'"`
	Open     float64 `xorm:"notnull 'open'"`
	High     float64 `xorm:"notnull 'high'"`
	Low      float64 `xorm:"notnull 'low'"`
	Close    float64 `xorm:"notnull 'close'"`
	Volume   float64 `xorm:"notnull 'volume'"`
	Turnover float64 `xorm:"turnover 'turnover'"`
	Trades   int64   `xorm:"notnull 'trades'"`
	Table    string  `xorm:"-"`
}

func (Candle) GetStart

func (c Candle) GetStart() int64

func (Candle) GetTable

func (c Candle) GetTable() string

func (*Candle) SetTable

func (c *Candle) SetTable(tbl string)

func (Candle) String

func (c Candle) String() string

func (Candle) TableName

func (c Candle) TableName() string

func (Candle) Time

func (c Candle) Time() time.Time

type CandleList

type CandleList []*Candle

CandleList candle list

func (CandleList) High

func (l CandleList) High() (ret float64)

func (CandleList) Low

func (l CandleList) Low() (ret float64)

func (CandleList) Merge

func (l CandleList) Merge() (ret *Candle)

Merge merge multi candle to one

type Currency

type Currency struct {
	Coin string
	Base string
}

func (Currency) String

func (currency Currency) String() string

type Depth

type Depth Orderbook

type DepthInfo

type DepthInfo struct {
	Price  float64
	Amount float64
}

type Order

type Order struct {
	OrderID  string
	Symbol   string
	Currency string
	Amount   float64
	Price    float64
	Status   string
	Side     string
	Time     time.Time
	Remark   string
	Filled   float64
}

type Orderbook

type Orderbook struct {
	Sells      []DepthInfo
	Buys       []DepthInfo
	UpdateTime time.Time
}

type Position added in v1.1.1

type Position struct {
	Symbol      string
	Type        int     // 合约类型,Long: 多头,Short: 空头
	Hold        float64 // 持有仓位
	Price       float64 //开仓价格
	ProfitRatio float64 // 盈利比例,正数表示盈利,负数表示亏岁
}

type Symbol

type Symbol struct {
	Name        string `json:"name"`
	Symbol      string `json:"code"`
	Exchange    string `json:"exchange"`
	Description string `json:"description"`
	Type        string `json:"type"`
	// 交易时间
	Session string `json:"session"`

	// price decimal places
	Precision int `json:"precision"`
	// amount decimal places
	AmountPrecision int `json:"volume_precision"`

	Expired bool `json:"expired"`
	// only use if expired = true
	ExpirationDate time.Time `json:"expiration_date"`
	Resolutions    string    `json:"resolutions"`

	// mini size between two price
	PriceStep float64 `json:"price_step"`
	// mini size between two amount
	AmountStep float64 `json:"amount_step"`
}

func (*Symbol) FixPrice added in v1.1.6

func (s *Symbol) FixPrice(price float64) float64

func (*Symbol) GetResolutions added in v1.1.6

func (s *Symbol) GetResolutions() []string

type Ticker

type Ticker struct {
	CurrencyPair string
	Last         float64
	High         float64
	Low          float64
	Bid          float64
	Ask          float64
	Volume       float64
}

type Trade

type Trade struct {
	ID     string
	Action TradeType
	Time   time.Time
	Price  float64
	Amount float64
	Side   string
	Remark string
}

type TradeAction

type TradeAction struct {
	ID     string
	Action TradeType
	Amount float64
	Price  float64
	Time   time.Time
	Symbol string
}

TradeAction trade action

type TradeType

type TradeType int

func NewTradeType added in v1.1.4

func NewTradeType(typ string) (t TradeType, err error)

func (TradeType) IsLong

func (a TradeType) IsLong() bool

func (TradeType) IsOpen

func (a TradeType) IsOpen() bool

func (TradeType) IsStop

func (a TradeType) IsStop() bool

func (TradeType) String

func (t TradeType) String() (ret string)

Jump to

Keyboard shortcuts

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