71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"big-qmt/go-client/sdk"
|
|
)
|
|
|
|
func overview(cfg Config, assets *sdk.Assets, positions []sdk.Position) {
|
|
fmt.Println("\n" + strings.Repeat("=", 80))
|
|
fmt.Printf("【时间】%s\n", time.Now().Format("2006-01-02 15:04:05"))
|
|
fmt.Printf("【配置】account_id: %s host_key: %s open_money: %.0f\n", cfg.AccountID, cfg.HostKey, cfg.OpenMoney)
|
|
if assets != nil {
|
|
fmt.Printf("【资金】总资产:%.2f元,可用资金:%.2f元\n", assets.Total, assets.Available)
|
|
} else {
|
|
fmt.Println("【资金】查询失败")
|
|
}
|
|
fmt.Printf("【持仓】%d只\n", len(positions))
|
|
fmt.Println(strings.Repeat("=", 80))
|
|
for _, p := range positions {
|
|
if p.Volume <= 0 {
|
|
continue
|
|
}
|
|
code := normalizeCode(p.StockCode, "")
|
|
fmt.Printf("【持仓】%s %s 持仓=%d 可用=%d 冻结=%d 在途=%d 昨仓=%d 成本=%.3f 现价=%.3f 市值=%.2f 浮盈=%.2f 盈亏比例=%.2f%%\n",
|
|
code, p.StockName, p.Volume, p.CanUseVolume, p.FrozenVolume, p.OnRoadVolume, p.YesterdayVolume,
|
|
p.OpenPrice, p.LastPrice, p.MarketValue, p.FloatProfit, p.ProfitRate*100)
|
|
}
|
|
}
|
|
|
|
func runRound(ctx context.Context, client *sdk.Client, books *orderBook, cfg Config, assets *sdk.Assets, ticks map[string]sdk.Tick, positions []sdk.Position) {
|
|
signals := fetchSignal(cfg, "dcm_signal")
|
|
books.cancelExpired(ctx, client, cfg)
|
|
|
|
hold := positionCodes(positions)
|
|
openSignals := map[string]map[string]any{}
|
|
for code, signal := range signals {
|
|
norm := normalizeCode(code, "")
|
|
if norm == "" {
|
|
norm = code
|
|
}
|
|
if _, held := hold[norm]; held {
|
|
continue
|
|
}
|
|
openSignals[norm] = signal
|
|
}
|
|
if len(openSignals) > 0 {
|
|
if books.refresh(ctx, client, cfg) {
|
|
buys, _, ok := books.activeSets(ctx, client, cfg)
|
|
if ok {
|
|
filtered := map[string]map[string]any{}
|
|
for code, signal := range openSignals {
|
|
if _, buying := buys[code]; buying {
|
|
continue
|
|
}
|
|
filtered[code] = signal
|
|
}
|
|
openSignals = filtered
|
|
}
|
|
}
|
|
}
|
|
marketOK := marketAllowOpen(cfg)
|
|
if len(openSignals) > 0 {
|
|
openSignal(ctx, client, books, cfg, assets, ticks, openSignals, marketOK)
|
|
}
|
|
managePositions(ctx, client, books, cfg, ticks, positions, marketOK)
|
|
}
|