Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 14, 2023
1 parent 8d49bd2 commit 89c5a35
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion cmd/haobase/base/symbols/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
48 changes: 24 additions & 24 deletions cmd/haobase/base/symbols/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 18 additions & 18 deletions cmd/haobase/base/symbols/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
4 changes: 2 additions & 2 deletions cmd/haobase/clearing/clearing_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/haobase/orders/limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/haobase/orders/market_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 89c5a35

Please sign in to comment.