feat: 手续费改为逐笔USD累算 + Vite React前端 + system_orders表 + README
This commit is contained in:
+29
-1
@@ -48,6 +48,20 @@ type OrderRecord struct {
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// SystemOrderRecord represents one system-level arbitrage action (entry/scale/exit).
|
||||
type SystemOrderRecord struct {
|
||||
ID int64
|
||||
TradeID int64
|
||||
Type string // entry / scale / exit
|
||||
Status string // filled / failed
|
||||
Spread *float64
|
||||
LongPrice *float64
|
||||
ShortPrice *float64
|
||||
LongOrderID *int64
|
||||
ShortOrderID *int64
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// SaveTrade inserts a new trade and returns its ID.
|
||||
func (d *DB) SaveTrade(t *TradeRecord) (int64, error) {
|
||||
res, err := d.Exec(`INSERT INTO trades (
|
||||
@@ -150,6 +164,20 @@ func (d *DB) SaveOrder(o *OrderRecord) (int64, error) {
|
||||
return res.LastInsertId()
|
||||
}
|
||||
|
||||
// SaveSystemOrder inserts a system-level order record.
|
||||
func (d *DB) SaveSystemOrder(o *SystemOrderRecord) (int64, error) {
|
||||
res, err := d.Exec(`INSERT INTO system_orders
|
||||
(trade_id, type, status, spread, long_price, short_price, long_order_id, short_order_id, created_at)
|
||||
VALUES (?,?,?,?,?, ?,?,?,?)`,
|
||||
o.TradeID, o.Type, o.Status, o.Spread,
|
||||
o.LongPrice, o.ShortPrice, o.LongOrderID, o.ShortOrderID, o.CreatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.LastInsertId()
|
||||
}
|
||||
|
||||
// GetTradeByID returns a single trade with its orders.
|
||||
func (d *DB) GetTradeByID(id int64) (*TradeRecord, []OrderRecord, error) {
|
||||
row := d.QueryRow(`SELECT id, coin, direction, status, entry_spread, exit_spread,
|
||||
@@ -222,4 +250,4 @@ func (d *DB) GetClosedStats() (converged, diverged, flat, total int, err error)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user