models

package
v0.0.0-...-90ad8ca Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UNKNOWN                = 0
	FIX                    = 1
	STRIKE_FEE             = 100
	STRIKE_ADD             = 110
	STRIKE_SUB             = 120
	STRIKE_UNLOCK          = 130
	ORDER_SUBMIT           = 600
	ORDER_CANCEL           = 610
	ORDER_FULLFILLED       = 620
	TRANSFER               = 700
	TRANSFER_BACK          = 710
	WALLET_TRANSFER        = 720
	WALLET_TRANSFER_BACK   = 730
	WALLET_TRANSFER_LOCK   = 735
	WALLET_TRANSFER_UNLOCK = 736
	WITHDRAW_LOCK          = 800
	WITHDRAW_UNLOCK        = 810
	DEPOSIT                = 1000
	WITHDRAW               = 2000
	AWARD                  = 3000
	OTC_ORDER_SUBMIT       = 900
	OTC_ORDER_FINISHED     = 910
	OTC_ORDER_FINISHED_2   = 911
	OTC_ORDER_CANCELLED    = 920
	OTC_ORDER_CANCELLED_2  = 921
	OPTION_DEPOSIT         = 1100
	OPTION_UNLOCK          = 1200
	OPTION_CANCEL          = 1500
	PROFIT_LOCK            = 1300
	PROFIT_UNLOCK          = 1400
	RECYCLE_TRANS_FEE      = 1600

	FUNS = map[string]int{
		"UnlockFunds":         1,
		"LockFunds":           2,
		"PlusFunds":           3,
		"SubFunds":            4,
		"UnlockedAndSubFunds": 5,
	}
)
View Source
var (
	CANCEL = 0
	WAIT   = 100
	DONE   = 200
)
View Source
var AllCurrencies []Currency
View Source
var AllMarkets []Market
View Source
var (
	TickersRedisKey = "goDCE:tickers"
)

Functions

func AutoMigrations

func AutoMigrations()

func InitAllCurrencies

func InitAllCurrencies(db *utils.GormDB)

func InitAllMarkets

func InitAllMarkets(db *utils.GormDB)

Types

type Account

type Account struct {
	CommonModel
	UserId     int             `json:"user_id"`
	CurrencyId int             `json:"currency_id"`
	Balance    decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"balance"`
	Locked     decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"locked"`
}

func (*Account) AfterSave

func (account *Account) AfterSave(db *gorm.DB)

func (*Account) Amount

func (account *Account) Amount() (amount decimal.Decimal)

func (*Account) LockFunds

func (account *Account) LockFunds(db *utils.GormDB, amount decimal.Decimal, reason, modifiableId int, modifiableType string) (err error)

func (*Account) PlusFunds

func (account *Account) PlusFunds(db *utils.GormDB, amount, fee decimal.Decimal, reason, modifiableId int, modifiableType string) (err error)

func (*Account) SubFunds

func (account *Account) SubFunds(db *utils.GormDB, amount, fee decimal.Decimal, reason, modifiableId int, modifiableType string) (err error)

func (*Account) UnlockFunds

func (account *Account) UnlockFunds(db *utils.GormDB, amount decimal.Decimal, reason, modifiableId int, modifiableType string) (err error)

func (*Account) UnlockedAndSubFunds

func (account *Account) UnlockedAndSubFunds(db *utils.GormDB, amount, locked, fee decimal.Decimal, reason, modifiableId int, modifiableType string) (err error)

type AccountVersion

type AccountVersion struct {
	CommonModel
	UserId         int             `json:"user_id"`
	AccountId      int             `json:"account_id"`
	Reason         int             `json:"reason"`
	Balance        decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"balance"`
	Locked         decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"locked"`
	Fee            decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"fee"`
	Amount         decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"amount"`
	ModifiableId   int             `json:"modifiable_id"`
	ModifiableType string          `json:"modifiable_type"`
	CurrencyId     int             `json:"currency_id"`
	Fun            int             `json:"fun"`
}

type AccountVersionCheckPoint

type AccountVersionCheckPoint struct {
	CommonModel
	AccountVersionId int             `json:"account_version_id"`
	UserId           int             `json:"user_id"`
	AccountId        int             `json:"account_id"`
	Fixed            string          `json:"fixed"`
	FixedNum         decimal.Decimal `json:"fixed_num" gorm:"type:decimal(32,16)"`
	Balance          decimal.Decimal `json:"balance" gorm:"type:decimal(32,16)"`
}

type ApiToken

type ApiToken struct {
	CommonModel
	UserId    int       `json:"user_id"`
	AccessKey string    `gorm:"type:varchar(64)" json:"access_key"`
	SecretKey string    `gorm:"type:varchar(64)" json:"secret_key"`
	Label     string    `gorm:"type:varchar(32)" json:"label"`
	Scopes    string    `gorm:"type:varchar(32)" json:"scopes"`
	ExpireAt  time.Time `json:"expire_at" gorm:"default:null"`
	DeletedAt time.Time `json:"-" gorm:"default:null"`
}

type Attrs

type Attrs struct {
	Tid    int             `json:"tid"`
	Amount decimal.Decimal `json:"amount"`
	Price  decimal.Decimal `json:"price"`
	Date   int64           `json:"date"`
}

type CommonModel

type CommonModel struct {
	Id        int       `json:"id" gorm:"primary_key"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

type Currency

type Currency struct {
	CommonModel
	Key         string `json:"key"`
	Code        string `json:"code"`
	Symbol      string `json:"-"`
	Coin        bool   `json:"coin"`
	Precision   int    `json:"precision"`
	Erc20       bool   `json:"erc20"`
	Erc23       bool   `json:"erc23"`
	Visible     bool   `json:"visible"`
	Tradable    bool   `json:"tradable"`
	Depositable bool   `json:"depositable"`
}

func (*Currency) IsEthereum

func (currency *Currency) IsEthereum() (result bool)

type Device

type Device struct {
	CommonModel
	UserId    int    `json:"user_id"`
	IsUsed    bool   `json:"is_used"`
	Token     string `json:"token" gorm:"type:varchar(64)"`
	PublicKey string `json:"-"`
}

func (*Device) InitializeToken

func (device *Device) InitializeToken()

type Fee

type Fee struct {
	CurrencyId   int             `json:"currency_id"`
	CurrencyCode string          `json:"currency_code" gorm:"type:varchar(16)"`
	Amount       decimal.Decimal `json:"amount"`
}

type Identity

type Identity struct {
	CommonModel
	UserId int    `json:"user_id"`
	Source string `json:"source" gorm:"type:varchar(32)"` // Email or Phone,
	Symbol string `json:"symbol" gorm:"type:varchar(64)"` // Email address or Phone number
}

type KLine

type KLine struct {
	CommonModel
	MarketId int `json:"market_id"`
	Period   int `json:"period"`

	Timestamp int64           `json:"timestamp"`                                       // 时间戳
	Open      decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"open"`   // 开盘价
	High      decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"high"`   // 最高价
	Low       decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"low"`    // 最低价
	Close     decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"close"`  // 收盘价
	Volume    decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"volume"` // 交易量
}

func (*KLine) Data

func (k *KLine) Data() (data [5]string)

func (*KLine) RedisKey

func (k *KLine) RedisKey() string

type Market

type Market struct {
	CommonModel
	Name            string          `json:"name"" gorm:"type:varchar(16)"`
	Code            string          `json:"code" gorm:"type:varchar(16)"`
	PriceGroupFixed int             `json:"price_group_fixed"`
	SortOrder       int             `json:"sort_order"`
	AskCurrencyId   int             `json:"ask_currency_id"`
	BidCurrencyId   int             `json:"bid_currency_id"`
	AskFee          decimal.Decimal `json:"ask_fee" gorm:"type:decimal(32,16);default:null;"`
	BidFee          decimal.Decimal `json:"bid_fee" gorm:"type:decimal(32,16);default:null;"`
	AskFixed        int             `json:"ask_fixed"`
	BidFixed        int             `json:"bid_fixed"`
	Visible         bool            `json:"visible"`
	Tradable        bool            `json:"tradable"`

	// 暂存数据
	Ticker       *TickerAspect `sql:"-" json:"ticker"`
	LatestKLines map[int]KLine `sql:"-" json:"-"`

	// 撮合相关属性
	Ack             bool   `json:"-"`
	Durable         bool   `json:"-"`
	MatchingAble    bool   `json:"-"`
	MatchingNode    string `json:"-" gorm:"default:'a'; type:varchar(11)"`
	TradeTreatNode  string `json:"-" gorm:"default:'a'; type:varchar(11)"`
	OrderCancelNode string `json:"-" gorm:"default:'a'; type:varchar(11)"`
	Running         bool   `json:"-" sql:"-"`

	Matching    string `json:"-"`
	TradeTreat  string `json:"-"`
	OrderCancel string `json:"-"`
}

func FindAllMarket

func FindAllMarket() []Market

func FindMarketByCode

func FindMarketByCode(code string) (Market, error)

func FindMarketById

func FindMarketById(id int) (Market, error)

func (*Market) AfterCreate

func (market *Market) AfterCreate(db *gorm.DB)

func (*Market) AfterFind

func (market *Market) AfterFind(db *gorm.DB)

func (*Market) AskRedisKey

func (market *Market) AskRedisKey() string

func (*Market) BidRedisKey

func (market *Market) BidRedisKey() string

func (*Market) KLineNotify

func (market *Market) KLineNotify(period int64) string

Notify

func (*Market) KLineRedisKey

func (market *Market) KLineRedisKey(period int64) string

func (*Market) LatestTradesRedisKey

func (market *Market) LatestTradesRedisKey() string

func (*Market) MatchingExchange

func (assignment *Market) MatchingExchange() string

Exchange

func (*Market) MatchingQueue

func (assignment *Market) MatchingQueue() string

Queue

func (*Market) OrderCancelExchange

func (assignment *Market) OrderCancelExchange() string

func (*Market) OrderCancelQueue

func (assignment *Market) OrderCancelQueue() string

func (*Market) TickerNotify

func (market *Market) TickerNotify() string

func (*Market) TickerRedisKey

func (market *Market) TickerRedisKey() string

func (*Market) TradeTreatExchange

func (assignment *Market) TradeTreatExchange() string

func (*Market) TradeTreatQueue

func (assignment *Market) TradeTreatQueue() string

type MatchingPayload

type MatchingPayload struct {
	Action string    `json:"action"`
	Order  OrderJson `json:"order"`
}

func (*MatchingPayload) OrderAttrs

func (mp *MatchingPayload) OrderAttrs() (attrs map[string]string)

type Order

type Order struct {
	CommonModel
	UserId        int             `json:"user_id"`
	AskAccountId  int             `json:"ask_account_id" gorm:"default:null"`
	BidAccountId  int             `json:"bid_account_id" gorm:"default:null"`
	MarketId      int             `json:"market_id"`
	State         int             `json:"-"`
	Type          string          `gorm:"type:varchar(16)" json:"type"`
	Sn            string          `gorm:"type:varchar(16)" json:"sn" gorm:"default:null"`
	Source        string          `gorm:"type:varchar(16)" json:"source"`
	OrderType     string          `gorm:"type:varchar(16)" json:"order_type"`
	Price         decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"price"`
	Volume        decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"volume"`
	OriginVolume  decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"origin_volume"`
	Locked        decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"locked"`
	OriginLocked  decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"origin_locked"`
	FundsReceived decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"funds_received"`
	TradesCount   int             `json:"trades_count"`

	Market   Market          `sql:"-" json:"-"`
	StateStr string          `sql:"-" json:"state"`
	AvgPrice decimal.Decimal `sql:"-" json:"avg_price"`
	// contains filtered or unexported fields
}

func (*Order) AfterFind

func (order *Order) AfterFind(db *gorm.DB)

func (*Order) CalculationAvgPrice

func (order *Order) CalculationAvgPrice()

func (*Order) Fee

func (order *Order) Fee() (fee decimal.Decimal)

func (*Order) InitStateStr

func (order *Order) InitStateStr()

func (*Order) OType

func (order *Order) OType() string

func (*Order) OrderAttrs

func (order *Order) OrderAttrs() (attrs map[string]string)

func (*Order) Strike

func (order *Order) Strike(db *utils.GormDB, trade Trade) (err error)

type OrderCurrency

type OrderCurrency struct {
	Fee        decimal.Decimal `json:"fee"`
	Currency   string          `json:"currency"`
	CurrencyId int             `json:"currency_id"`
	Fixed      int             `json:"fixed"`
}

type OrderJson

type OrderJson struct {
	Id        int             `json:"id"`
	MarketId  int             `json:"market_id"`
	Type      string          `json:"type"`
	OrderType string          `json:"order_type"`
	Volume    decimal.Decimal `json:"volume"`
	Price     decimal.Decimal `json:"price"`
	Locked    decimal.Decimal `json:"locked"`
	Timestamp int64           `json:"timestamp"`
}

type Ticker

type Ticker struct {
	MarketId     int           `json:"market_id"`
	At           int64         `json:"at"`
	Name         string        `json:"name"`
	TickerAspect *TickerAspect `json:"ticker"`
}

type TickerAspect

type TickerAspect struct {
	Buy    decimal.Decimal `json:"buy"`
	Sell   decimal.Decimal `json:"sell"`
	Low    decimal.Decimal `json:"low"`
	High   decimal.Decimal `json:"high"`
	Last   decimal.Decimal `json:"last"`
	Open   decimal.Decimal `json:"open"`
	Volume decimal.Decimal `json:"volume"`
}

type Token

type Token struct {
	CommonModel
	Token        string    `gorm:"type:varchar(64)" json:"token"`
	UserId       int       `json:"user_id"`
	IsUsed       bool      `json:"is_used"`
	ExpireAt     time.Time `gorm:"default:null" json:"expire_at"`
	LastVerifyAt time.Time `gorm:"default:null" json:"last_verify_at"`
}

func (*Token) InitializeLoginToken

func (token *Token) InitializeLoginToken()

type Trade

type Trade struct {
	CommonModel
	Trend    int             `json:"trend"`
	MarketId int             `json:"market_id"`
	AskId    int             `json:"ask_id"`
	BidId    int             `json:"bid_id"`
	Price    decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"price"`
	Volume   decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"volume"`
	Funds    decimal.Decimal `gorm:"type:decimal(32,16);default:null;" json:"funds"`

	Side      string `json:"side" sql:"-" gorm:"type:varchar(4)"`
	Market    Market `json:"market" sql:"-"`
	AskUserId int    `json:"ask_user_id"`
	BidUserId int    `json:"bid_user_id"`
	AskFee    Fee    `json:"ask_fee" sql:"-"`
	BidFee    Fee    `json:"bid_fee" sql:"-"`
}

func (*Trade) AfterFind

func (trade *Trade) AfterFind(db *gorm.DB)

func (*Trade) SimpleAttrs

func (trade *Trade) SimpleAttrs() (attrs Attrs)

type User

type User struct {
	CommonModel
	Sn             string `gorm:"type:varchar(32);default:null" json:"sn"`
	PasswordDigest string `gorm:"type:varchar(64);default:null"`
	Nickname       string `gorm:"type:varchar(32);default:null" json:"nickname"`
	State          int    `gorm:"default:null" json:"state"`
	Activated      bool   `gorm:"default:null" json:"activated"`
	Disabled       bool   `json:"disabled"`
	ApiDisabled    bool   `json:"api_disabled"`

	Password string    `sql:"-"`
	Tokens   []Token   `sql:"-" json:"tokens"`
	Accounts []Account `sql:"-" json:"accounts"`
}

func (*User) AfterSave

func (user *User) AfterSave(db *gorm.DB)

func (*User) CompareHashAndPassword

func (user *User) CompareHashAndPassword() bool

func (*User) GenerateSn

func (user *User) GenerateSn()

func (*User) SetPasswordDigest

func (user *User) SetPasswordDigest()

Jump to

Keyboard shortcuts

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