市场成交与持仓数据及含吃单手续费的本地交割 #7
@@ -7,7 +7,7 @@ version.workspace = true
|
||||
matching = { path = "../matching" }
|
||||
anyhow.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde_json = { workspace = true, features = ["arbitrary_precision"] }
|
||||
rusqlite.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -32,6 +32,10 @@ flowchart LR
|
||||
queries -->|账户挂单与单笔状态| acct["src/account_orders.rs"]
|
||||
acct -->|校验账户和市场| valid
|
||||
queries -->|账户持仓| portfolio["src/portfolio.rs"]
|
||||
portfolio -->|获取每份持仓估值| marks["src/quotes.rs"]
|
||||
api -->|迁移末笔成交及持仓视图| markschema["src/valuation_schema.sql"]
|
||||
marks -->|读取资产末笔成交| markschema
|
||||
positions -->|查询可用及预留份额| markschema
|
||||
portfolio -->|查询参数与分页| positions["src/portfolio.sql"]
|
||||
portfolio -->|校验账户和市场| valid
|
||||
market -->|提案、争议与终裁检查| res["src/resolution.rs"]
|
||||
@@ -434,3 +438,25 @@ sequenceDiagram
|
||||
E-->>C: 统计时刻、总量及按累计吃单份额降序的成员
|
||||
end
|
||||
```
|
||||
|
||||
## 账户持仓估值
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant C as 客户端
|
||||
participant E as Exchange
|
||||
participant P as portfolio.rs
|
||||
participant D as SQLite
|
||||
C->>E: positions(account) 或 portfolio_value(account)
|
||||
E->>P: 在同一读快照查询
|
||||
P->>D: 取得可用份额、预留卖单及裁决状态
|
||||
loop 每个持仓
|
||||
alt 已裁决
|
||||
P->>P: 按该结果兑付率估值
|
||||
else 尚未裁决
|
||||
P->>D: 查最新盘口及该结果的末笔成交
|
||||
P->>P: 选取可用价格,保留缺价状态
|
||||
end
|
||||
end
|
||||
P-->>C: 逐项估值或全账户总值、已知小计及缺价持仓数
|
||||
```
|
||||
|
||||
@@ -248,6 +248,9 @@ pub(crate) enum Query {
|
||||
market: String,
|
||||
},
|
||||
Positions(crate::portfolio::Filter),
|
||||
PortfolioValue {
|
||||
account: String,
|
||||
},
|
||||
Activity(crate::activity::Filter),
|
||||
OpenOrders(crate::account_orders::Filter),
|
||||
Trades(crate::account_trades::Filter),
|
||||
@@ -293,6 +296,7 @@ impl Query {
|
||||
Self::Resolution { market } => crate::resolution::read(db, &market),
|
||||
Self::Assets { market } => assets::market_assets(db, &market),
|
||||
Self::Activity(filter) => filter.read(db),
|
||||
Self::PortfolioValue { account } => crate::portfolio::value(db, &account),
|
||||
Self::Positions(filter) => filter.read(db),
|
||||
Self::Trades(filter) => filter.read(db),
|
||||
Self::OpenOrders(filter) => filter.read(db),
|
||||
@@ -320,22 +324,13 @@ impl Query {
|
||||
let phase = market_phase(db, &market, &outcome)?;
|
||||
let quote = crate::quotes::Quote::current(db, &market, &outcome)?;
|
||||
let (bid, ask) = (quote.bid, quote.ask);
|
||||
// Fills also cover databases created before timestamped history was introduced.
|
||||
let last: Option<i64> = db.query_row(
|
||||
"SELECT (SELECT price FROM (
|
||||
SELECT f.seq, f.price FROM fills f JOIN orders o ON o.seq=f.bid WHERE o.market=?1 AND o.outcome=?2
|
||||
UNION ALL SELECT seq, CASE WHEN ?2='YES' THEN yes_price ELSE 100-yes_price END FROM paired_fills WHERE market=?1
|
||||
) ORDER BY seq DESC LIMIT 1)",
|
||||
params![market, outcome],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
let (display, source) = match (phase.as_str(), bid, ask, last) {
|
||||
("continuous", Some(b), Some(a), _) if (0..=10).contains(&(a - b)) => {
|
||||
(Some((a + b) * 5000), Some("midpoint"))
|
||||
}
|
||||
("continuous", _, _, Some(p)) => (Some(p * 10000), Some("last_trade")),
|
||||
_ => (None, None),
|
||||
};
|
||||
let last = quote.last;
|
||||
let (display, source) = if phase == "continuous" {
|
||||
quote.mark(&phase)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.unzip();
|
||||
Ok(
|
||||
json!({"asset_id":assets::id(&market,&outcome),"market":market,"outcome":outcome,"phase":phase,
|
||||
"quote_seq":quote.seq,"best_bid_micros":bid.map(|p|p*10000),"best_ask_micros":ask.map(|p|p*10000),
|
||||
|
||||
@@ -53,6 +53,13 @@ impl Exchange {
|
||||
if !quotes_ready {
|
||||
db.execute_batch(include_str!("quote_schema.sql"))?;
|
||||
}
|
||||
let marks_ready: bool = db.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='table' AND name='last_asset_trades')",
|
||||
[], |row| row.get(0),
|
||||
)?;
|
||||
if !marks_ready {
|
||||
db.execute_batch(include_str!("valuation_schema.sql"))?;
|
||||
}
|
||||
let tx = expiry::transaction(&db, TransactionBehavior::Deferred)?;
|
||||
let books = Books::recover(&tx)?;
|
||||
tx.commit()?;
|
||||
@@ -75,6 +82,7 @@ impl Exchange {
|
||||
| "book"
|
||||
| "open_orders"
|
||||
| "positions"
|
||||
| "portfolio_value"
|
||||
| "trades"
|
||||
| "activity"
|
||||
| "resolution"
|
||||
|
||||
@@ -55,12 +55,15 @@ impl Filter {
|
||||
let status: String = row.get(5)?;
|
||||
let payout: Option<i64> = row.get(6)?;
|
||||
let pairs: i64 = row.get(7)?;
|
||||
let phase: String = row.get(13)?;
|
||||
let (mark, source) = price(db, &market, &outcome, &phase, payout)?.unzip();
|
||||
positions.push(json!({
|
||||
"current_price_micros":mark,"price_source":source,"current_value_micros":holding_value(size,mark),
|
||||
"asset_id":crate::assets::id(&market,&outcome),"market":market, "outcome":outcome, "status":status, "size":size,
|
||||
"neg_risk_group":row.get::<_,Option<String>>(10)?,
|
||||
"augmented_role":row.get::<_,Option<String>>(11)?,"outcome_name":row.get::<_,Option<String>>(12)?,
|
||||
"available_size":row.get::<_,i64>(3)?, "reserved_size":row.get::<_,i64>(4)?,
|
||||
"redeemable":status=="REDEEMABLE", "payout_cents":payout.map(|p|p*size),
|
||||
"redeemable":status=="REDEEMABLE", "payout_cents":payout.map(|p|i128::from(p)*i128::from(size)),
|
||||
"mergeable":pairs>0, "available_pairs":row.get::<_,i64>(8)?
|
||||
}));
|
||||
last = Some((row.get::<_, i64>(9)?, market, outcome));
|
||||
@@ -68,3 +71,52 @@ impl Filter {
|
||||
Ok(json!({"positions":positions,"next_after":next_after}))
|
||||
}
|
||||
}
|
||||
|
||||
fn price(
|
||||
db: &Connection,
|
||||
market: &str,
|
||||
outcome: &str,
|
||||
phase: &str,
|
||||
payout: Option<i64>,
|
||||
) -> Result<Option<(i64, &'static str)>> {
|
||||
if let Some(p) = payout {
|
||||
return Ok(Some((p * 10000, "settlement")));
|
||||
}
|
||||
Ok(crate::quotes::Quote::current(db, market, outcome)?.mark(phase))
|
||||
}
|
||||
|
||||
fn holding_value(size: i64, mark: Option<i64>) -> Option<i128> {
|
||||
if size == 0 {
|
||||
return Some(0);
|
||||
}
|
||||
mark.map(|p| i128::from(p) * i128::from(size))
|
||||
}
|
||||
|
||||
pub(crate) fn value(db: &Connection, account: &str) -> Result<Value> {
|
||||
identifier(account)?;
|
||||
let mut stmt = db.prepare(
|
||||
"SELECT market,outcome,available+reserved AS size,phase,payout_per_share
|
||||
FROM position_sizes WHERE account=? AND available+reserved>0",
|
||||
)?;
|
||||
let mut rows = stmt.query([account])?;
|
||||
let mut priced = 0i128;
|
||||
let mut missing = 0u64;
|
||||
while let Some(row) = rows.next()? {
|
||||
let market: String = row.get(0)?;
|
||||
let outcome: String = row.get(1)?;
|
||||
let phase: String = row.get(3)?;
|
||||
let mark = price(db, &market, &outcome, &phase, row.get(4)?)?.map(|(p, _)| p);
|
||||
match holding_value(row.get(2)?, mark) {
|
||||
Some(amount) => {
|
||||
priced = priced
|
||||
.checked_add(amount)
|
||||
.ok_or_else(|| anyhow::anyhow!("portfolio value overflow"))?
|
||||
}
|
||||
None => missing += 1,
|
||||
}
|
||||
}
|
||||
Ok(
|
||||
json!({"account":account,"value_micros":(missing==0).then_some(priced),
|
||||
"priced_value_micros":priced,"unpriced_positions":missing}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
WITH reserved AS (
|
||||
SELECT market,outcome,SUM(remaining) AS qty
|
||||
FROM orders
|
||||
WHERE account=?1 AND status='live' AND side='sell' AND (?2 IS NULL OR market=?2)
|
||||
GROUP BY market,outcome
|
||||
), balances AS (
|
||||
SELECT p.market,p.outcome,p.quantity AS available,COALESCE(r.qty,0) AS reserved,
|
||||
p.quantity+COALESCE(r.qty,0) AS size
|
||||
FROM positions p LEFT JOIN reserved r USING (market,outcome)
|
||||
WHERE p.account=?1 AND (?2 IS NULL OR p.market=?2)
|
||||
WITH balances AS (
|
||||
SELECT market,outcome,available,reserved,available+reserved AS size,phase,payout_per_share
|
||||
FROM position_sizes WHERE account=?1 AND (?2 IS NULL OR market=?2)
|
||||
), holdings AS (
|
||||
SELECT b.*,m.phase,
|
||||
CASE WHEN m.phase='resolved' THEN
|
||||
CASE WHEN m.winner='VOID' THEN 50 WHEN b.outcome=m.winner THEN 100 ELSE 0 END
|
||||
END AS payout_per_share,
|
||||
CASE WHEN m.phase<>'resolved' THEN MIN(b.size,COALESCE(other.size,0)) ELSE 0 END AS pairs,
|
||||
CASE WHEN m.phase<>'resolved' THEN MIN(b.available,COALESCE(other.available,0)) ELSE 0 END AS free_pairs
|
||||
FROM balances b JOIN markets m ON m.id=b.market
|
||||
SELECT b.*,
|
||||
CASE WHEN b.phase<>'resolved' THEN MIN(b.size,COALESCE(other.size,0)) ELSE 0 END AS pairs,
|
||||
CASE WHEN b.phase<>'resolved' THEN MIN(b.available,COALESCE(other.available,0)) ELSE 0 END AS free_pairs
|
||||
FROM balances b
|
||||
LEFT JOIN balances other ON other.market=b.market AND other.outcome<>b.outcome
|
||||
), filtered AS (
|
||||
SELECT *,CASE WHEN size=0 THEN 'CLOSED' WHEN phase='resolved' THEN 'REDEEMABLE' ELSE 'OPEN' END AS row_status,
|
||||
@@ -30,7 +20,7 @@ WITH reserved AS (
|
||||
WHEN 'MERGEABLE' THEN pairs>0
|
||||
END
|
||||
)
|
||||
SELECT market,outcome,size,available,reserved,row_status,payout_per_share,pairs,free_pairs,sort_key,n.group_id,a.role,a.name
|
||||
SELECT market,outcome,size,available,reserved,row_status,payout_per_share,pairs,free_pairs,sort_key,n.group_id,a.role,a.name,phase
|
||||
FROM filtered LEFT JOIN neg_risk_members n USING(market) LEFT JOIN augmented_outcomes a USING(market)
|
||||
WHERE ?4 IS NULL OR (sort_key,market,outcome)>(?4,?5,?6)
|
||||
ORDER BY sort_key,market,outcome LIMIT ?7
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{assets, validation::identifier};
|
||||
use anyhow::{ensure, Result};
|
||||
use rusqlite::{params, Connection, OptionalExtension, Row, Transaction};
|
||||
use rusqlite::{params, Connection, Row, Transaction};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
@@ -18,6 +18,7 @@ pub(crate) struct Quote {
|
||||
pub bid: Option<i64>,
|
||||
pub ask: Option<i64>,
|
||||
at_ms: Option<i64>,
|
||||
pub last: Option<i64>,
|
||||
}
|
||||
impl Quote {
|
||||
fn read(row: &Row, outcome: &str) -> rusqlite::Result<Self> {
|
||||
@@ -33,12 +34,36 @@ impl Quote {
|
||||
bid,
|
||||
ask,
|
||||
at_ms: row.get(3)?,
|
||||
last: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn current(db: &Connection, market: &str, outcome: &str) -> Result<Self> {
|
||||
Ok(db.query_row("SELECT seq,yes_bid,yes_ask,at_ms FROM quote_events WHERE market=? ORDER BY seq DESC LIMIT 1",
|
||||
[market],|r|Self::read(r,outcome)).optional()?.unwrap_or_default())
|
||||
let mut stmt = db.prepare_cached(
|
||||
"SELECT COALESCE(q.seq,0),q.yes_bid,q.yes_ask,q.at_ms,t.price
|
||||
FROM (SELECT ?1 AS market) s LEFT JOIN quote_events q ON q.seq=(
|
||||
SELECT MAX(seq) FROM quote_events WHERE market=s.market)
|
||||
LEFT JOIN last_asset_trades t ON t.market=s.market AND t.outcome=?2",
|
||||
)?;
|
||||
Ok(stmt.query_row(params![market, outcome], |r| {
|
||||
let mut quote = Self::read(r, outcome)?;
|
||||
quote.last = r.get(4)?;
|
||||
Ok(quote)
|
||||
})?)
|
||||
}
|
||||
|
||||
pub fn mark(&self, phase: &str) -> Option<(i64, &'static str)> {
|
||||
if phase == "continuous" {
|
||||
if let (Some(b), Some(a)) = (self.bid, self.ask) {
|
||||
if (0..=10).contains(&(a - b)) {
|
||||
return Some(((a + b) * 5000, "midpoint"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if matches!(phase, "continuous" | "closed") {
|
||||
return self.last.map(|p| (p * 10000, "last_trade"));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn event(&self) -> Value {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
BEGIN IMMEDIATE;
|
||||
CREATE TABLE IF NOT EXISTS last_asset_trades (
|
||||
market TEXT NOT NULL REFERENCES markets, outcome TEXT NOT NULL,
|
||||
execution INTEGER NOT NULL, price INTEGER NOT NULL, PRIMARY KEY(market,outcome)
|
||||
);
|
||||
|
||||
-- One row per priced asset, including legacy fills with no timestamp.
|
||||
-- Execution numbers are unique across the two journals.
|
||||
WITH legs(market,outcome,execution,price) AS (
|
||||
SELECT o.market,o.outcome,f.seq,f.price FROM fills f JOIN orders o ON o.seq=f.bid
|
||||
UNION ALL SELECT market,'YES',seq,yes_price FROM paired_fills
|
||||
UNION ALL SELECT market,'NO',seq,100-yes_price FROM paired_fills
|
||||
)
|
||||
INSERT INTO last_asset_trades(market,outcome,execution,price)
|
||||
SELECT market,outcome,MAX(execution),price FROM legs GROUP BY market,outcome
|
||||
ON CONFLICT(market,outcome) DO UPDATE SET execution=excluded.execution,price=excluded.price
|
||||
WHERE excluded.execution>last_asset_trades.execution;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS last_asset_direct AFTER INSERT ON fills BEGIN
|
||||
INSERT INTO last_asset_trades
|
||||
SELECT market,outcome,NEW.seq,NEW.price FROM orders WHERE seq=NEW.bid
|
||||
ON CONFLICT(market,outcome) DO UPDATE SET execution=excluded.execution,price=excluded.price
|
||||
WHERE excluded.execution>last_asset_trades.execution;
|
||||
END;
|
||||
CREATE TRIGGER IF NOT EXISTS last_asset_paired AFTER INSERT ON paired_fills BEGIN
|
||||
INSERT INTO last_asset_trades VALUES
|
||||
(NEW.market,'YES',NEW.seq,NEW.yes_price),(NEW.market,'NO',NEW.seq,100-NEW.yes_price)
|
||||
ON CONFLICT(market,outcome) DO UPDATE SET execution=excluded.execution,price=excluded.price
|
||||
WHERE excluded.execution>last_asset_trades.execution;
|
||||
END;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS reserved_position_orders ON orders(account,market,outcome)
|
||||
WHERE status='live' AND side='sell';
|
||||
CREATE VIEW IF NOT EXISTS position_sizes AS
|
||||
SELECT p.account,p.market,p.outcome,p.quantity AS available,
|
||||
COALESCE((SELECT SUM(o.remaining) FROM orders o WHERE o.account=p.account AND o.market=p.market
|
||||
AND o.outcome=p.outcome AND o.status='live' AND o.side='sell'),0) AS reserved,
|
||||
m.phase,CASE WHEN m.phase='resolved' THEN
|
||||
CASE WHEN m.winner='VOID' THEN 50 WHEN p.outcome=m.winner THEN 100 ELSE 0 END
|
||||
END AS payout_per_share
|
||||
FROM positions p JOIN markets m ON m.id=p.market;
|
||||
COMMIT;
|
||||
@@ -1674,3 +1674,40 @@ fn catalog_and_ranked_volume_count_executions_once_across_conditions() {
|
||||
assert_eq!(listing["volume"], condition["volume"]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuation_counts_reserved_shares_and_distinguishes_unpriced_from_zero() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("valuation.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
let mut snapshots = Vec::new();
|
||||
for line in include_str!("../../../docs/examples/valuation.jsonl").lines() {
|
||||
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||
let response = e.execute(cmd.clone()).unwrap();
|
||||
match cmd["op"].as_str().unwrap() {
|
||||
"portfolio_value" => snapshots.push(response),
|
||||
"positions" => {
|
||||
let yes = response["positions"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|p| p["outcome"] == "YES")
|
||||
.unwrap();
|
||||
assert_eq!(yes["reserved_size"], 8);
|
||||
assert_eq!(yes["current_price_micros"], 565000);
|
||||
assert_eq!(yes["price_source"], "midpoint");
|
||||
assert_eq!(yes["current_value_micros"], 4520000);
|
||||
drop(e);
|
||||
e = Exchange::open(&path).unwrap();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
assert_eq!(snapshots.len(), 4);
|
||||
assert!(snapshots[0]["value_micros"].is_null());
|
||||
assert_eq!(snapshots[0]["unpriced_positions"], 1);
|
||||
assert_eq!(snapshots[0]["priced_value_micros"], 4800000);
|
||||
assert_eq!(snapshots[1]["value_micros"], 8870000);
|
||||
assert_eq!(snapshots[2]["value_micros"], 8000000);
|
||||
assert_eq!(snapshots[3]["value_micros"], 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{"op":"fund","id":"va","account":"alice","cents":2000}
|
||||
{"op":"fund","id":"vb","account":"bob","cents":2000}
|
||||
{"op":"list","id":"vm","market":"e","rules":"模拟赛事官方终场结果"}
|
||||
{"op":"split","id":"vs","market":"e","account":"alice","qty":10}
|
||||
{"op":"open","id":"vo","market":"e"}
|
||||
{"op":"order","id":"ask","market":"e","outcome":"YES","side":"sell","account":"alice","price":60,"qty":10}
|
||||
{"op":"order","id":"buy","market":"e","outcome":"YES","side":"buy","account":"bob","price":60,"qty":2}
|
||||
{"op":"portfolio_value","account":"alice"}
|
||||
{"op":"order","id":"bid","market":"e","outcome":"YES","side":"buy","account":"bob","price":53,"qty":1}
|
||||
{"op":"positions","account":"alice"}
|
||||
{"op":"portfolio_value","account":"alice"}
|
||||
{"op":"close","id":"vc","market":"e"}
|
||||
{"op":"finalize","id":"vf","market":"e","winner":"YES"}
|
||||
{"op":"portfolio_value","account":"alice"}
|
||||
{"op":"redeem","id":"vr","market":"e","account":"alice"}
|
||||
{"op":"portfolio_value","account":"alice"}
|
||||
@@ -162,3 +162,11 @@ FOK 要求整笔金额成交,无法用完预算时交易回滚。超过最高
|
||||
先重放[足球目录](examples/football.jsonl),再重放[成交量样例](examples/volume.jsonl)。全场比分盘由吃单方买入 NO 三份,每份 40 分;半场比分盘由吃单方买入 YES 两份,每份 30 分。事件累计为 5 份、180 分(模拟美元 1.80),其余四盘为零。挂单、普通拆分以及重复请求不增加成交量。目录保留显示顺序,`volume` 独立查询则按累计吃单份额降序,同量时按市场 ID 升序。单盘也可传 `{"op":"volume","market":"full-2-1"}`。
|
||||
|
||||
每个统计包含 `all_time` 和 `last_24h`,后者为查询时刻往前 86,400,000 毫秒,两端均含。每笔已撮合的数量计入 `matched_shares` 一次;确认吃单的一侧另记 `taker_shares` 和成交价乘数量的 `taker_notional_cents`。互补成交按吃单方实际交易的 YES 或 NO 定价。本地开盘集合竞价没有吃单方,只计入撮合量;缺失角色的旧成交另标 `unknown_role_shares`,缺失时间的计入累计量并标 `unknown_time_shares`。成交金额、滚动窗口及竞价拆分均为本地字段。当前只支持整数份额、整分成交价,官方份额精度可到小数点后六位。
|
||||
|
||||
## 持仓估值与赎回
|
||||
|
||||
官方 Position 的 current_value 以当前持有份额乘以每份估值计算。账户 value 汇总单市场持仓,另含未终结组合的成本。官方展示价在双边价差不超过 10 美分时取中点,超过时采用最近成交价。Data API 对持仓的 live mark 只给出字段定义,行情页展示价与生产持仓估值是否对每个市场相同仍需实际响应对账。[Data API 的 Position 与 PortfolioValue](https://data-api.polymarket.com/v2/openapi.json) · [订单簿展示价](https://docs.polymarket.com/concepts/prices-orderbook.md)
|
||||
|
||||
[本地样例](examples/valuation.jsonl)从 Alice 拆出的 YES、NO 各 10 份开始。卖出两份 YES 后,剩下的八份挂在卖盘,仍计入持仓。此时只有 YES 有末笔价格 0.60,返回已知估值 4.80 模拟美元及一个无法定价的 NO 持仓,总值为 null。当 YES 买一 0.53、卖一 0.60,双方中点分别为 0.565 和 0.435,合计 8 × 0.565 + 10 × 0.435 = 8.87。YES 获胜后总值为 8.00,赎回后持仓总值为 0。赎回款可在账户资金记录中查看。
|
||||
|
||||
本地 positions 新增 current_price_micros、price_source、current_value_micros;portfolio_value 返回全账户 value_micros、已知小计 priced_value_micros 和未定价的非零持仓数 unpriced_positions。100 万微单位等于 1 模拟美元。正常交易时按报价或已成交的该资产估值,封盘待裁决时沿用该资产末笔,裁决后按兑付率。空账户值为零。组合成本、入场成本、费用与盈亏尚未纳入此估值样例。
|
||||
|
||||
Reference in New Issue
Block a user