feat go-client
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user