orders

package
v0.0.0-...-0a93553 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderSideSell    OrderSide = "sell"
	OrderSideBuy     OrderSide = "buy"
	OrderSideUnknown OrderSide = "unknown"

	OrderTypeLimit  OrderType = "limit"
	OrderTypeMarket OrderType = "market"

	OrderStatusNew    orderStatus = 0
	OrderStatusDone   orderStatus = 1
	OrderStatusCancel orderStatus = 2
)

Variables

View Source
var ChCancel chan TradeOrder

Functions

func Db

func Db() *xorm.Engine

func GetOrderTableName

func GetOrderTableName(symbol string) string

func Init

func Init(db *xorm.Engine, rdc *redis.Client)

Types

type OrderSide

type OrderSide string

func OrderIDSide

func OrderIDSide(order_id string) OrderSide

type OrderType

type OrderType string

type TradeBy

type TradeBy int
const (
	TradeBySell TradeBy = 1
	TradeByBuy  TradeBy = 2
)

type TradeOrder

type TradeOrder struct {
	Id        int64     `xorm:"pk autoincr bigint" json:"-"`
	Symbol    string    `xorm:"-" json:"symbol"`
	PairId    int       `xorm:"notnull index(pair_id)" json:"-"`
	OrderId   string    `xorm:"varchar(30) unique(order_id) notnull" json:"order_id"`
	OrderSide OrderSide `xorm:"varchar(10) index(order_side)" json:"order_side"`
	OrderType OrderType `xorm:"varchar(10)" json:"order_type"` //价格策略,市价单,限价单
	UserId    int64     `xorm:"bigint index(userid) notnull" json:"-"`
	FeeRate   string    `xorm:"decimal(40,20) notnull default(0)" json:"-"`
	//用户委托原始信息
	OriginalPrice    string `xorm:"decimal(40,20) notnull default(0)" json:"original_price"`
	OriginalQuantity string `xorm:"decimal(40,20) notnull default(0)" json:"original_quantity"`
	OriginalAmount   string `xorm:"decimal(40,20) notnull default(0)" json:"-"`
	//根据订单方向不同,冻结的资产也不同
	FreezeAsset string `xorm:"decimal(40,20) notnull default(0)" json:"-"`

	//成交的部分信息
	TradeAvgPrice string `xorm:"decimal(40,20) notnull default(0)" json:"trade_avg_price"`
	TradeQty      string `xorm:"decimal(40,20) notnull default(0)" json:"trade_qty"`
	TradeAmount   string `xorm:"decimal(40,20) notnull default(0)" json:"trade_amount"`

	Fee        string      `xorm:"decimal(40,20) notnull default(0)" json:"-"`
	Status     orderStatus `xorm:"tinyint(1)" json:"status"`
	CreateTime int64       `xorm:"bigint" json:"create_time"` //时间戳 精确到纳秒
	UpdateTime time.Time   `xorm:"timestamp updated" json:"-"`
}

委托记录表

func NewLimitOrder

func NewLimitOrder(user_id int64, trade_symbol string, side OrderSide, price, qty string) (order *TradeOrder, err error)

限价订单

func NewMarketOrderByAmount

func NewMarketOrderByAmount(user_id int64, trade_symbol string, side OrderSide, amount string) (order *TradeOrder, err error)

func NewMarketOrderByQty

func NewMarketOrderByQty(user_id int64, trade_symbol string, side OrderSide, qty string) (*TradeOrder, error)

func (*TradeOrder) Save

func (to *TradeOrder) Save(db *xorm.Session) error

func (*TradeOrder) TableName

func (to *TradeOrder) TableName() string

type TradeRecord

type TradeRecord struct {
	Id     int64  `xorm:"pk autoincr bigint" json:"-"`
	Symbol string `xorm:"-" json:"-"`

	TradeId string `xorm:"varchar(30) unique(trade)" json:"trade_id"`
	Ask     string `xorm:"varchar(30) unique(trade)" json:"ask"`
	Bid     string `xorm:"varchar(30) unique(trade)" json:"bid"`

	TradeBy  TradeBy `xorm:"tinyint(1)" json:"trade_by"`
	AskUid   int64   `xorm:"bigint notnull" json:"-"`
	BidUid   int64   `xorm:"bigint notnull" json:"-"`
	Price    string  `xorm:"decimal(40,20) notnull default(0)" json:"price"`
	Quantity string  `xorm:"decimal(40,20) notnull default(0)" json:"quantity"`
	Amount   string  `xorm:"decimal(40,20) notnull default(0)" json:"amount"`

	AskFeeRate string `xorm:"decimal(40,20) notnull default(0)" json:"-"`
	AskFee     string `xorm:"decimal(40,20) notnull default(0)" json:"-"`

	BidFeeRate string `xorm:"decimal(40,20) notnull default(0)" json:"-"`
	BidFee     string `xorm:"decimal(40,20) notnull default(0)" json:"-"`

	CreateTime types.Time `xorm:"timestamp created" json:"trade_at"`
	UpdateTime time.Time  `xorm:"timestamp updated" json:"-"`
}

成交记录表

func (*TradeRecord) GetTableName

func (tr *TradeRecord) GetTableName(symbol string) string

func (*TradeRecord) Save

func (tr *TradeRecord) Save(db *xorm.Session) error

func (*TradeRecord) TableName

func (tr *TradeRecord) TableName() string

type UnfinishedOrder

type UnfinishedOrder struct {
	TradeOrder TradeOrder `xorm:"extends"`
}

未完全成交的委托订单记录表

func (*UnfinishedOrder) TableName

func (u *UnfinishedOrder) TableName() string

Jump to

Keyboard shortcuts

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