diff --git a/cmd/haobase/base/symbols/func.go b/cmd/haobase/base/symbols/func.go index 870142d4..0434f31f 100644 --- a/cmd/haobase/base/symbols/func.go +++ b/cmd/haobase/base/symbols/func.go @@ -12,7 +12,7 @@ func NewTradingVarieties(symbol string) *TradingVarieties { db.Where("symbol=?", symbol).Get(&row) if row.Id > 0 { row.Target = *newVarietiesById(row.TargetSymbolId) - row.Standard = *newVarietiesById(row.StandardSymbolId) + row.Base = *newVarietiesById(row.BaseSymbolId) } return &row } diff --git a/cmd/haobase/base/symbols/init.go b/cmd/haobase/base/symbols/init.go index 83364933..10241a68 100644 --- a/cmd/haobase/base/symbols/init.go +++ b/cmd/haobase/base/symbols/init.go @@ -64,32 +64,32 @@ func DemoData() { eur := NewVarieties("eur") pairs := []TradingVarieties{ TradingVarieties{ - Symbol: "usdjpy", - Name: "美日", - TargetSymbolId: usd.Id, - StandardSymbolId: jpy.Id, - PricePrecision: 3, - QtyPrecision: 2, - Status: StatusEnabled, - AllowMinQty: "0.01", - AllowMaxQty: "0", - AllowMinAmount: "1", - AllowMaxAmount: "0", - FeeRate: "0.005", + Symbol: "usdjpy", + Name: "美日", + TargetSymbolId: usd.Id, + BaseSymbolId: jpy.Id, + PricePrecision: 3, + QtyPrecision: 2, + Status: StatusEnabled, + AllowMinQty: "0.01", + AllowMaxQty: "0", + AllowMinAmount: "1", + AllowMaxAmount: "0", + FeeRate: "0.005", }, TradingVarieties{ - Symbol: "eurusd", - Name: "欧美", - TargetSymbolId: eur.Id, - StandardSymbolId: usd.Id, - PricePrecision: 5, - QtyPrecision: 2, - Status: StatusEnabled, - AllowMinQty: "0.01", - AllowMaxQty: "0", - AllowMinAmount: "1", - AllowMaxAmount: "0", - FeeRate: "0.001", + Symbol: "eurusd", + Name: "欧美", + TargetSymbolId: eur.Id, + BaseSymbolId: usd.Id, + PricePrecision: 5, + QtyPrecision: 2, + Status: StatusEnabled, + AllowMinQty: "0.01", + AllowMaxQty: "0", + AllowMinAmount: "1", + AllowMaxAmount: "0", + FeeRate: "0.001", }, } _, err = db.Insert(pairs) diff --git a/cmd/haobase/base/symbols/symbol.go b/cmd/haobase/base/symbols/symbol.go index 5c035b9d..7a0fa275 100644 --- a/cmd/haobase/base/symbols/symbol.go +++ b/cmd/haobase/base/symbols/symbol.go @@ -19,28 +19,28 @@ type Varieties struct { Name string `xorm:"varchar(250) notnull" json:"name"` ShowPrecision int `xorm:"default(0)" json:"show_precision"` MinPrecision int `xorm:"default(0)" json:"min_precision"` - Standard bool `xorm:"default(0)" json:"standard"` //是否为本位币 + Base bool `xorm:"default(0)" json:"base"` //是否为本位币 Status status `xorm:"default(0) notnull" json:"-"` CreateTime time.Time `xorm:"timestamp created" json:"-"` UpdateTime time.Time `xorm:"timestamp updated" json:"update_at"` } type TradingVarieties struct { - Id int `xorm:"pk autoincr int" json:"-"` - Symbol string `xorm:"varchar(100) notnull unique(symbol)" json:"symbol"` - Name string `xorm:"varchar(250) notnull" json:"name"` - TargetSymbolId int `xorm:"default(0) unique(symbol_base)" json:"target_symbol_id"` //交易物品 - StandardSymbolId int `xorm:"default(0) unique(symbol_base)" json:"standard_symbol_id"` //支付货币 - PricePrecision int `xorm:"default(2)" json:"price_precision"` - QtyPrecision int `xorm:"default(0)" json:"qty_precision"` - AllowMinQty utils.FloatString `xorm:"decimal(40,20) default(0.01)" json:"allow_min_qty"` - AllowMaxQty utils.FloatString `xorm:"decimal(40,20) default(999999)" json:"allow_max_qty"` - AllowMinAmount utils.FloatString `xorm:"decimal(40,20) default(0.01)" json:"allow_min_amount"` - AllowMaxAmount utils.FloatString `xorm:"decimal(40,20) default(999999)" json:"allow_max_amount"` - FeeRate utils.FloatString `xorm:"decimal(40,20) default(0)" json:"fee_rate"` - Status status `xorm:"default(0)" json:"-"` - CreateTime time.Time `xorm:"timestamp created" json:"-"` - UpdateTime time.Time `xorm:"timestamp updated" json:"update_at"` - Target Varieties `xorm:"-" json:"target"` - Standard Varieties `xorm:"-" json:"standard"` + Id int `xorm:"pk autoincr int" json:"-"` + Symbol string `xorm:"varchar(100) notnull unique(symbol)" json:"symbol"` + Name string `xorm:"varchar(250) notnull" json:"name"` + TargetSymbolId int `xorm:"default(0) unique(symbol_base)" json:"target_symbol_id"` //交易物品 + BaseSymbolId int `xorm:"default(0) unique(symbol_base)" json:"base_symbol_id"` //支付货币 + PricePrecision int `xorm:"default(2)" json:"price_precision"` + QtyPrecision int `xorm:"default(0)" json:"qty_precision"` + AllowMinQty utils.FloatString `xorm:"decimal(40,20) default(0.01)" json:"allow_min_qty"` + AllowMaxQty utils.FloatString `xorm:"decimal(40,20) default(999999)" json:"allow_max_qty"` + AllowMinAmount utils.FloatString `xorm:"decimal(40,20) default(0.01)" json:"allow_min_amount"` + AllowMaxAmount utils.FloatString `xorm:"decimal(40,20) default(999999)" json:"allow_max_amount"` + FeeRate utils.FloatString `xorm:"decimal(40,20) default(0)" json:"fee_rate"` + Status status `xorm:"default(0)" json:"-"` + CreateTime time.Time `xorm:"timestamp created" json:"-"` + UpdateTime time.Time `xorm:"timestamp updated" json:"update_at"` + Target Varieties `xorm:"-" json:"target"` + Base Varieties `xorm:"-" json:"Base"` } diff --git a/cmd/haobase/clearing/clearing_flow.go b/cmd/haobase/clearing/clearing_flow.go index 338a7231..f5d99c5a 100644 --- a/cmd/haobase/clearing/clearing_flow.go +++ b/cmd/haobase/clearing/clearing_flow.go @@ -176,13 +176,13 @@ func (c *clean) transfer() error { //扣除fee fee := utils.D(c.tradelog.BidFee).Add(utils.D(c.tradelog.AskFee)) - _, err = assets.Transfer(c.db, c.bid.UserId, c.ask.UserId, c.trading_varieties.Standard.Symbol, amount.Sub(fee).String(), c.tradelog.TradeId, assets.Behavior_Trade) + _, err = assets.Transfer(c.db, c.bid.UserId, c.ask.UserId, c.trading_varieties.Base.Symbol, amount.Sub(fee).String(), c.tradelog.TradeId, assets.Behavior_Trade) if err != nil { return err } //手续费收入到一个全局的账号里 - _, err = assets.Transfer(c.db, c.bid.UserId, assets.UserSystemFee, c.trading_varieties.Standard.Symbol, fee.String(), c.tradelog.TradeId, assets.Behavior_Trade) + _, err = assets.Transfer(c.db, c.bid.UserId, assets.UserSystemFee, c.trading_varieties.Base.Symbol, fee.String(), c.tradelog.TradeId, assets.Behavior_Trade) if err != nil { return err } diff --git a/cmd/haobase/orders/limit_order.go b/cmd/haobase/orders/limit_order.go index f515b1e1..ae0edddc 100644 --- a/cmd/haobase/orders/limit_order.go +++ b/cmd/haobase/orders/limit_order.go @@ -70,7 +70,7 @@ func limit_order(user_id string, symbol string, side trading_core.OrderSide, pri //fee、tradeamount字段在结算程序中修改 neworder.FreezeQty = freeze_amount - _, err = assets.FreezeAssets(db, false, user_id, varieties.Standard.Symbol, freeze_amount, neworder.OrderId, assets.Behavior_Trade) + _, err = assets.FreezeAssets(db, false, user_id, varieties.Base.Symbol, freeze_amount, neworder.OrderId, assets.Behavior_Trade) if err != nil { return nil, err } diff --git a/cmd/haobase/orders/market_order.go b/cmd/haobase/orders/market_order.go index e0a467d2..72881130 100644 --- a/cmd/haobase/orders/market_order.go +++ b/cmd/haobase/orders/market_order.go @@ -59,7 +59,7 @@ func market_order_qty(user_id string, symbol string, side trading_core.OrderSide neworder.FreezeQty = qty } else if neworder.OrderSide == trading_core.OrderSideBuy { //冻结所有可用 - _, err = assets.FreezeTotalAssets(db, false, user_id, varieties.Standard.Symbol, neworder.OrderId, assets.Behavior_Trade) + _, err = assets.FreezeTotalAssets(db, false, user_id, varieties.Base.Symbol, neworder.OrderId, assets.Behavior_Trade) if err != nil { return nil, err } @@ -149,7 +149,7 @@ func market_order_amount(user_id string, symbol string, side trading_core.OrderS neworder.FreezeQty = freeze.FreezeAmount } else if neworder.OrderSide == trading_core.OrderSideBuy { - _, err = assets.FreezeAssets(db, false, user_id, varieties.Standard.Symbol, amount, neworder.OrderId, assets.Behavior_Trade) + _, err = assets.FreezeAssets(db, false, user_id, varieties.Base.Symbol, amount, neworder.OrderId, assets.Behavior_Trade) if err != nil { return nil, err }