第十阶段 stage 1(二):永续合约单仓位、保证金金额一行、名义价值

This commit is contained in:
ZHU MINCHAO committed 2026-11-05 01:25:46 +08:00
1 parent ad60b07ca9
commit f732304f38
11 files changed
+72 -57

No files matched your search

+3 -2
View File
@@ -22,7 +22,7 @@ namespace Decentralized.Domain
: (Margin + Size * Entry) / (Size * (1 + Tuning.PerpMaint));
}
public enum PerpResult { Ok, Banned, Debt, Leverage, Size, Funds, Opposite, NoPosition, Margin, Thin }
public enum PerpResult { Ok, Banned, Debt, Leverage, Size, Funds, Opposite, NoPosition, Margin, Thin, Single }
/// <summary>夜间发生的事:强平、自动减仓、催收没收、核销。</summary>
public sealed class PerpEvent
@@ -73,7 +73,7 @@ namespace Decentralized.Domain
return total > 0 ? Math.Min(1, amount * price(Assets.CRC) / total) : 0;
}
/// <summary>开仓或加仓(同方向):保证金 + 手续费从账户的 CRC 里扣,污点与成本按保证金的价值比例随保证金进仓位。</summary>
/// <summary>开仓(同一时间只有一个仓位,已有仓位时只能 <see cref="AddMargin"/>):保证金 + 手续费从账户的 CRC 里扣,污点与成本按保证金的价值比例随保证金进仓位。</summary>
public PerpResult Open(Wallet acct, string product, bool isLong, double margin, int leverage, double price, int day, Func<string, double> pr)
{
if (Banned(day)) return PerpResult.Banned;
@@ -82,6 +82,7 @@ namespace Decentralized.Domain
if (margin <= 0 || price <= 0) return PerpResult.Margin;
var pos = Of(product);
if (pos != null && pos.Long != isLong) return PerpResult.Opposite;
if (Positions.Count > 0) return PerpResult.Single; // 只支持逐仓、一个仓位:有仓位后只能追加保证金
double notional = margin * leverage, fee = notional * Tuning.PerpFee;
double spot = price;
price = Exec(price, notional, isLong, day);