feat go-client

This commit is contained in:
2026-08-28 08:48:06 +08:00
parent a4791b477a
commit e0ecdfba52
2 changed files with 1 additions and 24 deletions

View File

@@ -29,7 +29,7 @@ func main() {
if err != nil {
fatal("获取资产失败: %v", err)
}
positions, err := client.Positions(ctx)
_, positions, err := client.Positions(ctx)
if err != nil {
fatal("获取持仓失败: %v", err)
}

View File

@@ -20,30 +20,7 @@ var (
)
func managePositions(client *sdk.Client, ticks map[string]sdk.Tick, positions []sdk.Position, marketOK bool) {
for _, pos := range positions {
item, err := QuantState.Get(code)
if err != nil || item.BaseStatus == StatusIng || item.AddedStatus == StatusIng || position.Volume != item.BaseQty+item.AddedQty {
continue
}
price := ticks[code].LastPrice
if price <= 0 {
continue
}
if item.AddedQty > 0 {
pnl := (price - item.AddedCost) / item.AddedCost * 100
if shouldSell(code, legAdded, pnl) {
sell(client, item, position.CanUseVolume, item.AddedQty, legAdded, pnl)
}
continue
}
pnl := (price - item.BaseCost) / item.BaseCost * 100
if shouldSell(code, legBase, pnl) {
sell(client, item, position.CanUseVolume, item.BaseQty, legBase, pnl)
} else if pnl <= config.Account.LossTriggerPct {
buyAdded(client, item, price, marketOK, budget)
}
}
}
func syncAdded(item *StateItem, position sdk.Position) {