Settle sub-cent orders and migrate historical book prices
This commit is contained in:
@@ -674,7 +674,7 @@ sequenceDiagram
|
|||||||
E->>D: 按市场查步长和最小份额
|
E->>D: 按市场查步长和最小份额
|
||||||
E->>E: 校验价格、向下取百分之一份、计算抵押金额
|
E->>E: 校验价格、向下取百分之一份、计算抵押金额
|
||||||
E-->>C: 返回 makerAmount、takerAmount 和本地精度支持标记
|
E-->>C: 返回 makerAmount、takerAmount 和本地精度支持标记
|
||||||
C->>E: order 提交整分价格,份额按 0.01 份向下取整
|
C->>E: order 提交符合步长的 price_micros,份额按 0.01 份向下取整
|
||||||
E->>D: 检查价格符合市场步长
|
E->>D: 检查价格符合市场步长
|
||||||
E->>B: 盘前挂单或连续撮合
|
E->>B: 盘前挂单或连续撮合
|
||||||
O->>E: open
|
O->>E: open
|
||||||
@@ -796,3 +796,32 @@ sequenceDiagram
|
|||||||
C->>E: 撤销余单
|
C->>E: 撤销余单
|
||||||
E->>D: 退回 0.73 份
|
E->>D: 退回 0.73 份
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 细步长价格、保护价与恢复
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
cmd["command.rs / estimate.rs"] --> grid["tick_size.rs"]
|
||||||
|
market["market.rs"] --> grid
|
||||||
|
market --> book["book.rs"]
|
||||||
|
book --> resident["resident.rs"]
|
||||||
|
book --> settlement["ledger.rs / fees.rs"]
|
||||||
|
lots["lots.rs"] --> migrate["price_migration.sql"]
|
||||||
|
quotes["quotes.rs / catalog.rs"] --> migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant C as 操作员
|
||||||
|
participant E as Exchange
|
||||||
|
participant B as 常驻订单簿
|
||||||
|
participant D as SQLite
|
||||||
|
C->>E: 买 5.12 YES,最高 0.014 美元
|
||||||
|
E->>D: 按市场步长 0.001 校验,预留 71680 微美元
|
||||||
|
E->>B: 限价 140 个价格单位,数量 512 个单位
|
||||||
|
B-->>E: 命中在先卖单,成交价 130
|
||||||
|
E->>D: 入账 66560 微美元,买方退回 5120 微美元
|
||||||
|
E->>D: 同事务记录成交和真实余量
|
||||||
|
C->>E: 重启后读取盘口和成交曲线
|
||||||
|
E-->>C: 余单按原序号恢复,历史返回 price_micros=13000
|
||||||
|
```
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ impl Filter {
|
|||||||
orders.push(
|
orders.push(
|
||||||
json!({"order":id,"market":market,"asset_id":crate::assets::id(&market,&outcome),
|
json!({"order":id,"market":market,"asset_id":crate::assets::id(&market,&outcome),
|
||||||
"outcome":outcome,"side":row.get::<_,String>(3)?,
|
"outcome":outcome,"side":row.get::<_,String>(3)?,
|
||||||
"price_micros":row.get::<_,i64>(4)?*10000,"original_size":crate::lots::display(quantity),
|
"price_micros":row.get::<_,i64>(4)?*100,"original_size":crate::lots::display(quantity),
|
||||||
"size_matched":crate::lots::display(quantity-remaining),"open_size":crate::lots::display(if status=="live"{remaining}else{0}),
|
"size_matched":crate::lots::display(quantity-remaining),"open_size":crate::lots::display(if status=="live"{remaining}else{0}),
|
||||||
"status":status,"expiration":row.get::<_,Option<i64>>(8)?,
|
"status":status,"expiration":row.get::<_,Option<i64>>(8)?,
|
||||||
"amount_cents":row.get::<_,Option<i64>>(9)?,"spent_cents":row.get::<_,Option<i64>>(10)?.map(|v|crate::inventory::decimal(v.into(),10000)),"fee_micros":row.get::<_,i64>(11)?,"key_id":row.get::<_,Option<String>>(12)?}),
|
"amount_cents":row.get::<_,Option<i64>>(9)?,"spent_cents":row.get::<_,Option<i64>>(10)?.map(|v|crate::inventory::decimal(v.into(),10000)),"fee_micros":row.get::<_,i64>(11)?,"key_id":row.get::<_,Option<String>>(12)?}),
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ impl Filter {
|
|||||||
trades.push(
|
trades.push(
|
||||||
json!({"execution":execution,"order":order,"market":market,"outcome":outcome,
|
json!({"execution":execution,"order":order,"market":market,"outcome":outcome,
|
||||||
"asset_id":assets::id(&market,&outcome),"side":r.get::<_,String>(4)?,
|
"asset_id":assets::id(&market,&outcome),"side":r.get::<_,String>(4)?,
|
||||||
"kind":r.get::<_,String>(5)?,"price_micros":price*10000,"size":crate::lots::display(size),
|
"kind":r.get::<_,String>(5)?,"price_micros":price*100,"size":crate::lots::display(size),
|
||||||
"gross_cents":crate::inventory::decimal(i128::from(price)*i128::from(size),100),"fee_micros":r.get::<_,i64>(10)?,"at_ms":r.get::<_,Option<i64>>(8)?,
|
"gross_cents":crate::inventory::decimal(i128::from(price)*i128::from(size),10000),"fee_micros":r.get::<_,i64>(10)?,"at_ms":r.get::<_,Option<i64>>(8)?,
|
||||||
"role":r.get::<_,Option<String>>(9)?}),
|
"role":r.get::<_,Option<String>>(9)?}),
|
||||||
);
|
);
|
||||||
last = Some((execution, order));
|
last = Some((execution, order));
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ impl Filter {
|
|||||||
items.push(json!({"type":r.get::<_,String>(5)?,"account":self.account,"at_ms":r.get::<_,Option<i64>>(4)?,
|
items.push(json!({"type":r.get::<_,String>(5)?,"account":self.account,"at_ms":r.get::<_,Option<i64>>(4)?,
|
||||||
"market":market,"group":r.get::<_,Option<String>>(7)?,"asset_id":asset,"outcome":outcome,
|
"market":market,"group":r.get::<_,Option<String>>(7)?,"asset_id":asset,"outcome":outcome,
|
||||||
"shares":shares,"cash_delta_cents":cash_cents,"fee_micros":fee,"net_cash_delta_micros":gross-i128::from(fee),
|
"shares":shares,"cash_delta_cents":cash_cents,"fee_micros":fee,"net_cash_delta_micros":gross-i128::from(fee),
|
||||||
"side":r.get::<_,Option<String>>(12)?,"price_micros":r.get::<_,Option<i64>>(13)?.map(|p|p*10000),
|
"side":r.get::<_,Option<String>>(12)?,"price_micros":r.get::<_,Option<i64>>(13)?.map(|p|p*100),
|
||||||
"request_id":r.get::<_,Option<String>>(10)?,"execution":(source==1).then_some(seq),"order":(source==1).then_some(leg)}));
|
"request_id":r.get::<_,Option<String>>(10)?,"execution":(source==1).then_some(seq),"order":(source==1).then_some(leg)}));
|
||||||
last = Some(Cursor {
|
last = Some(Cursor {
|
||||||
asc,
|
asc,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ WITH activity(source,seq,leg,at_ms,kind,market,group_id,shares,cash_delta,reques
|
|||||||
)
|
)
|
||||||
SELECT COALESCE(at_ms,-1) AS ts,source,seq,leg,at_ms,kind,market,group_id,shares,cash_delta,request_id,outcome,side,price,
|
SELECT COALESCE(at_ms,-1) AS ts,source,seq,leg,at_ms,kind,market,group_id,shares,cash_delta,request_id,outcome,side,price,
|
||||||
COALESCE((SELECT fee_micros FROM execution_fees WHERE source=1 AND execution=seq AND taker_order=leg),0),
|
COALESCE((SELECT fee_micros FROM execution_fees WHERE source=1 AND execution=seq AND taker_order=leg),0),
|
||||||
CASE WHEN source=1 THEN cash_delta*100 WHEN kind='DEPOSIT' THEN (SELECT json_extract(response,'$.funded_micros')
|
CASE WHEN source=1 THEN cash_delta WHEN kind='DEPOSIT' THEN (SELECT json_extract(response,'$.funded_micros')
|
||||||
FROM requests WHERE id=activity.request_id) ELSE
|
FROM requests WHERE id=activity.request_id) ELSE
|
||||||
(SELECT cash_micros FROM precise_movements WHERE request_id=activity.request_id AND account=?1) END,
|
(SELECT cash_micros FROM precise_movements WHERE request_id=activity.request_id AND account=?1) END,
|
||||||
CASE WHEN source=1 THEN shares*10000 ELSE (SELECT shares_micros FROM precise_movements WHERE request_id=activity.request_id AND account=?1) END
|
CASE WHEN source=1 THEN shares*10000 ELSE (SELECT shares_micros FROM precise_movements WHERE request_id=activity.request_id AND account=?1) END
|
||||||
|
|||||||
@@ -31,17 +31,4 @@ SELECT r.* FROM receipt_movements r WHERE NOT EXISTS (SELECT 1 FROM wallet_migra
|
|||||||
ORDER BY r.request_id ON CONFLICT(request_id,account) DO NOTHING;
|
ORDER BY r.request_id ON CONFLICT(request_id,account) DO NOTHING;
|
||||||
INSERT OR IGNORE INTO wallet_migration VALUES(1);
|
INSERT OR IGNORE INTO wallet_migration VALUES(1);
|
||||||
|
|
||||||
CREATE VIEW IF NOT EXISTS wallet_trade_legs AS
|
|
||||||
SELECT f.seq AS execution,o.seq AS order_seq,o.account,o.market,o.outcome,o.side,
|
|
||||||
'transfer' AS kind,f.price,f.quantity,t.at_ms
|
|
||||||
FROM fills f JOIN orders o ON o.seq=f.bid LEFT JOIN trade_prices t ON t.fill=f.seq
|
|
||||||
UNION ALL
|
|
||||||
SELECT f.seq,o.seq,o.account,o.market,o.outcome,o.side,'transfer',f.price,f.quantity,t.at_ms
|
|
||||||
FROM fills f JOIN orders o ON o.seq=f.ask LEFT JOIN trade_prices t ON t.fill=f.seq
|
|
||||||
UNION ALL
|
|
||||||
SELECT f.seq,o.seq,o.account,o.market,o.outcome,o.side,f.kind,f.yes_price,f.quantity,f.at_ms
|
|
||||||
FROM paired_fills f JOIN orders o ON o.seq=f.yes_order
|
|
||||||
UNION ALL
|
|
||||||
SELECT f.seq,o.seq,o.account,o.market,o.outcome,o.side,f.kind,100-f.yes_price,f.quantity,f.at_ms
|
|
||||||
FROM paired_fills f JOIN orders o ON o.seq=f.no_order;
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|||||||
+22
-16
@@ -39,7 +39,7 @@ impl ShareExecution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn gross_micros(fills: &[Fill]) -> i64 {
|
pub(crate) fn gross_micros(fills: &[Fill]) -> i64 {
|
||||||
fills.iter().map(|f| f.price * f.quantity * 100).sum()
|
fills.iter().map(|f| f.price * f.quantity).sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn submit(tx: &Transaction, books: &Books, order: NewOrder) -> Result<ShareExecution> {
|
pub(crate) fn submit(tx: &Transaction, books: &Books, order: NewOrder) -> Result<ShareExecution> {
|
||||||
@@ -65,7 +65,10 @@ pub(crate) fn submit(tx: &Transaction, books: &Books, order: NewOrder) -> Result
|
|||||||
matches!(outcome.as_str(), "YES" | "NO") && matches!(side.as_str(), "buy" | "sell"),
|
matches!(outcome.as_str(), "YES" | "NO") && matches!(side.as_str(), "buy" | "sell"),
|
||||||
"invalid instrument or side"
|
"invalid instrument or side"
|
||||||
);
|
);
|
||||||
ensure!((0..=100).contains(&price), "invalid price");
|
ensure!(
|
||||||
|
(0..=crate::tick_size::PAR).contains(&price),
|
||||||
|
"invalid price"
|
||||||
|
);
|
||||||
ensure!(
|
ensure!(
|
||||||
tif == TimeInForce::Gtc || stage == "continuous",
|
tif == TimeInForce::Gtc || stage == "continuous",
|
||||||
"unsupported time in force"
|
"unsupported time in force"
|
||||||
@@ -77,9 +80,10 @@ pub(crate) fn submit(tx: &Transaction, books: &Books, order: NewOrder) -> Result
|
|||||||
if let Some(minimum) = crate::minimum_size::MinimumSize::load(tx, &market)? {
|
if let Some(minimum) = crate::minimum_size::MinimumSize::load(tx, &market)? {
|
||||||
minimum.check_microshares(qty * crate::lots::MICROS)?;
|
minimum.check_microshares(qty * crate::lots::MICROS)?;
|
||||||
}
|
}
|
||||||
if let Some(tick) = crate::tick_size::TickSize::load(tx, &market)? {
|
crate::tick_size::validate(
|
||||||
tick.check(price * 10000)?;
|
crate::tick_size::TickSize::load(tx, &market)?.as_ref(),
|
||||||
}
|
price,
|
||||||
|
)?;
|
||||||
let deadline = match tif {
|
let deadline = match tif {
|
||||||
TimeInForce::Gtd => {
|
TimeInForce::Gtd => {
|
||||||
let expiration =
|
let expiration =
|
||||||
@@ -97,7 +101,7 @@ pub(crate) fn submit(tx: &Transaction, books: &Books, order: NewOrder) -> Result
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if side == "buy" {
|
if side == "buy" {
|
||||||
ledger::cash_micros(tx, &account, -price * qty * 100)?;
|
ledger::cash_micros(tx, &account, -price * qty)?;
|
||||||
} else {
|
} else {
|
||||||
crate::inventory::position(tx, &account, &market, &outcome, -qty * crate::lots::MICROS)?;
|
crate::inventory::position(tx, &account, &market, &outcome, -qty * crate::lots::MICROS)?;
|
||||||
}
|
}
|
||||||
@@ -185,7 +189,8 @@ pub(crate) fn market_buy(tx: &Transaction, books: &Books, order: BudgetBuy) -> R
|
|||||||
amount(amount_cents)?;
|
amount(amount_cents)?;
|
||||||
phase(tx, &market, &["continuous"])?;
|
phase(tx, &market, &["continuous"])?;
|
||||||
ensure!(
|
ensure!(
|
||||||
matches!(outcome.as_str(), "YES" | "NO") && (0..=100).contains(&max_price),
|
matches!(outcome.as_str(), "YES" | "NO")
|
||||||
|
&& (0..=crate::tick_size::PAR).contains(&max_price),
|
||||||
"invalid outcome or price"
|
"invalid outcome or price"
|
||||||
);
|
);
|
||||||
ensure!(
|
ensure!(
|
||||||
@@ -196,9 +201,10 @@ pub(crate) fn market_buy(tx: &Transaction, books: &Books, order: BudgetBuy) -> R
|
|||||||
if let Some(minimum) = crate::minimum_size::MinimumSize::load(tx, &market)? {
|
if let Some(minimum) = crate::minimum_size::MinimumSize::load(tx, &market)? {
|
||||||
minimum.check_budget(amount_cents, max_price, rate)?;
|
minimum.check_budget(amount_cents, max_price, rate)?;
|
||||||
}
|
}
|
||||||
if let Some(tick) = crate::tick_size::TickSize::load(tx, &market)? {
|
crate::tick_size::validate(
|
||||||
tick.check(max_price * 10000)?;
|
crate::tick_size::TickSize::load(tx, &market)?.as_ref(),
|
||||||
}
|
max_price,
|
||||||
|
)?;
|
||||||
ledger::cash(tx, &account, -amount_cents)?;
|
ledger::cash(tx, &account, -amount_cents)?;
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"INSERT INTO orders(account,market,outcome,side,price,quantity,remaining,status)
|
"INSERT INTO orders(account,market,outcome,side,price,quantity,remaining,status)
|
||||||
@@ -209,7 +215,7 @@ pub(crate) fn market_buy(tx: &Transaction, books: &Books, order: BudgetBuy) -> R
|
|||||||
crate::heartbeat::record_key(tx, seq, key_id.as_deref())?;
|
crate::heartbeat::record_key(tx, seq, key_id.as_deref())?;
|
||||||
let mut fills = books
|
let mut fills = books
|
||||||
.get(&market, &outcome)
|
.get(&market, &outcome)
|
||||||
.map(|b| b.match_budget_buy(seq, max_price, amount_cents * 100))
|
.map(|b| b.match_budget_buy(seq, max_price, amount_cents * 10000))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
crate::fees::fit_budget(rate, &mut fills, amount_cents);
|
crate::fees::fit_budget(rate, &mut fills, amount_cents);
|
||||||
ensure!(!fills.is_empty(), "no affordable liquidity");
|
ensure!(!fills.is_empty(), "no affordable liquidity");
|
||||||
@@ -287,12 +293,12 @@ fn book_leg(
|
|||||||
let price = if outcome == view {
|
let price = if outcome == view {
|
||||||
fill.price
|
fill.price
|
||||||
} else {
|
} else {
|
||||||
100 - fill.price
|
crate::tick_size::PAR - fill.price
|
||||||
};
|
};
|
||||||
if side == "buy" {
|
if side == "buy" {
|
||||||
ensure!(price <= limit, "buy limit exceeded");
|
ensure!(price <= limit, "buy limit exceeded");
|
||||||
if taker != Some(Taker::Budget(seq)) {
|
if taker != Some(Taker::Budget(seq)) {
|
||||||
ledger::cash_micros(tx, &account, (limit - price) * fill.quantity * 100)?;
|
ledger::cash_micros(tx, &account, (limit - price) * fill.quantity)?;
|
||||||
}
|
}
|
||||||
crate::inventory::position(
|
crate::inventory::position(
|
||||||
tx,
|
tx,
|
||||||
@@ -305,7 +311,7 @@ fn book_leg(
|
|||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
ensure!(price >= limit, "sell limit exceeded");
|
ensure!(price >= limit, "sell limit exceeded");
|
||||||
ledger::cash_micros(tx, &account, price * fill.quantity * 100)?;
|
ledger::cash_micros(tx, &account, price * fill.quantity)?;
|
||||||
}
|
}
|
||||||
Ok(ExecutedLeg {
|
Ok(ExecutedLeg {
|
||||||
seq,
|
seq,
|
||||||
@@ -375,7 +381,7 @@ pub(crate) fn settle(
|
|||||||
params![execution, taker.map(Taker::seq)],
|
params![execution, taker.map(Taker::seq)],
|
||||||
)?;
|
)?;
|
||||||
if let Some(taker) = taker {
|
if let Some(taker) = taker {
|
||||||
let fee = crate::fees::lot_fee(rate, f.price * 10000, f.quantity);
|
let fee = crate::fees::lot_fee(rate, f.price * 100, f.quantity);
|
||||||
if fee > 0 {
|
if fee > 0 {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"INSERT INTO execution_fees VALUES(?,?,?)",
|
"INSERT INTO execution_fees VALUES(?,?,?)",
|
||||||
@@ -404,7 +410,7 @@ pub(crate) fn release(
|
|||||||
) -> Result<i64> {
|
) -> Result<i64> {
|
||||||
let (market,outcome,side,price,qty):(String,String,String,i64,i64)=tx.query_row("SELECT market,outcome,side,price,remaining FROM orders WHERE seq=? AND account=? AND status='live'",params![seq,owner],|r|Ok((r.get(0)?,r.get(1)?,r.get(2)?,r.get(3)?,r.get(4)?)))?;
|
let (market,outcome,side,price,qty):(String,String,String,i64,i64)=tx.query_row("SELECT market,outcome,side,price,remaining FROM orders WHERE seq=? AND account=? AND status='live'",params![seq,owner],|r|Ok((r.get(0)?,r.get(1)?,r.get(2)?,r.get(3)?,r.get(4)?)))?;
|
||||||
if side == "buy" {
|
if side == "buy" {
|
||||||
ledger::cash_micros(tx, owner, price * qty * 100)?;
|
ledger::cash_micros(tx, owner, price * qty)?;
|
||||||
} else {
|
} else {
|
||||||
crate::inventory::position(tx, owner, &market, &outcome, qty * crate::lots::MICROS)?;
|
crate::inventory::position(tx, owner, &market, &outcome, qty * crate::lots::MICROS)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,9 +334,8 @@ impl Query {
|
|||||||
let price: i64 = row.get(1)?;
|
let price: i64 = row.get(1)?;
|
||||||
let size: i64 = row.get(2)?;
|
let size: i64 = row.get(2)?;
|
||||||
let levels = if side == "buy" { &mut bids } else { &mut asks };
|
let levels = if side == "buy" { &mut bids } else { &mut asks };
|
||||||
levels.push(
|
levels
|
||||||
json!({"price_micros":price*10000,"size":crate::lots::display(size)}),
|
.push(json!({"price_micros":price*100,"size":crate::lots::display(size)}));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
let minimum =
|
let minimum =
|
||||||
crate::minimum_size::MinimumSize::load(db, &market)?.map(|size| size.text());
|
crate::minimum_size::MinimumSize::load(db, &market)?.map(|size| size.text());
|
||||||
@@ -359,8 +358,8 @@ impl Query {
|
|||||||
.unzip();
|
.unzip();
|
||||||
Ok(
|
Ok(
|
||||||
json!({"asset_id":assets::id(&market,&outcome),"market":market,"outcome":outcome,"phase":phase,
|
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),
|
"quote_seq":quote.seq,"best_bid_micros":bid.map(|p|p*100),"best_ask_micros":ask.map(|p|p*100),
|
||||||
"last_trade_micros":last.map(|p|p*10000),"display_price_micros":display,"source":source}),
|
"last_trade_micros":last.map(|p|p*100),"display_price_micros":display,"source":source}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Self::Events {
|
Self::Events {
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ pub(crate) enum Command {
|
|||||||
key_id: Option<String>,
|
key_id: Option<String>,
|
||||||
outcome: String,
|
outcome: String,
|
||||||
side: String,
|
side: String,
|
||||||
price: i64,
|
price: Option<i64>,
|
||||||
|
price_micros: Option<i64>,
|
||||||
qty: Option<i64>,
|
qty: Option<i64>,
|
||||||
size_micros: Option<i64>,
|
size_micros: Option<i64>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@@ -87,7 +88,8 @@ pub(crate) enum Command {
|
|||||||
outcome: String,
|
outcome: String,
|
||||||
qty: Option<i64>,
|
qty: Option<i64>,
|
||||||
size_micros: Option<i64>,
|
size_micros: Option<i64>,
|
||||||
min_price: i64,
|
min_price: Option<i64>,
|
||||||
|
min_price_micros: Option<i64>,
|
||||||
tif: Option<TimeInForce>,
|
tif: Option<TimeInForce>,
|
||||||
},
|
},
|
||||||
#[serde(rename = "market_buy")]
|
#[serde(rename = "market_buy")]
|
||||||
@@ -97,7 +99,8 @@ pub(crate) enum Command {
|
|||||||
account: String,
|
account: String,
|
||||||
key_id: Option<String>,
|
key_id: Option<String>,
|
||||||
amount_cents: i64,
|
amount_cents: i64,
|
||||||
max_price: i64,
|
max_price: Option<i64>,
|
||||||
|
max_price_micros: Option<i64>,
|
||||||
tif: Option<TimeInForce>,
|
tif: Option<TimeInForce>,
|
||||||
},
|
},
|
||||||
Cancel {
|
Cancel {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ pub(crate) enum Request {
|
|||||||
outcome: String,
|
outcome: String,
|
||||||
amount_cents: i64,
|
amount_cents: i64,
|
||||||
max_price: Option<i64>,
|
max_price: Option<i64>,
|
||||||
|
max_price_micros: Option<i64>,
|
||||||
tif: Option<TimeInForce>,
|
tif: Option<TimeInForce>,
|
||||||
},
|
},
|
||||||
Sell {
|
Sell {
|
||||||
@@ -27,6 +28,7 @@ pub(crate) enum Request {
|
|||||||
qty: Option<i64>,
|
qty: Option<i64>,
|
||||||
size_micros: Option<i64>,
|
size_micros: Option<i64>,
|
||||||
min_price: Option<i64>,
|
min_price: Option<i64>,
|
||||||
|
min_price_micros: Option<i64>,
|
||||||
tif: Option<TimeInForce>,
|
tif: Option<TimeInForce>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -39,27 +41,40 @@ impl Request {
|
|||||||
outcome,
|
outcome,
|
||||||
amount_cents,
|
amount_cents,
|
||||||
max_price,
|
max_price,
|
||||||
|
max_price_micros,
|
||||||
tif,
|
tif,
|
||||||
} => (market, outcome, Side::Buy, amount_cents, max_price, tif),
|
} => (
|
||||||
|
market,
|
||||||
|
outcome,
|
||||||
|
Side::Buy,
|
||||||
|
amount_cents,
|
||||||
|
crate::tick_size::input(max_price, max_price_micros)?,
|
||||||
|
tif,
|
||||||
|
),
|
||||||
Self::Sell {
|
Self::Sell {
|
||||||
market,
|
market,
|
||||||
outcome,
|
outcome,
|
||||||
qty,
|
qty,
|
||||||
size_micros,
|
size_micros,
|
||||||
min_price,
|
min_price,
|
||||||
|
min_price_micros,
|
||||||
tif,
|
tif,
|
||||||
} => (
|
} => (
|
||||||
market,
|
market,
|
||||||
outcome,
|
outcome,
|
||||||
Side::Sell,
|
Side::Sell,
|
||||||
crate::lots::amount(qty, size_micros)?,
|
crate::lots::amount(qty, size_micros)?,
|
||||||
min_price,
|
crate::tick_size::input(min_price, min_price_micros)?,
|
||||||
tif,
|
tif,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
let tick = crate::tick_size::TickSize::load(tx, &market)?;
|
let tick = crate::tick_size::TickSize::load(tx, &market)?;
|
||||||
let edge = tick.as_ref().map_or(0, |t| i64::from(t.local_step().get()));
|
let edge = tick.as_ref().map_or(0, |t| i64::from(t.local_step().get()));
|
||||||
let limit = limit.unwrap_or(if side == Side::Buy { 100 - edge } else { edge });
|
let limit = limit.unwrap_or(if side == Side::Buy {
|
||||||
|
crate::tick_size::PAR - edge
|
||||||
|
} else {
|
||||||
|
edge
|
||||||
|
});
|
||||||
let tif = tif.unwrap_or(TimeInForce::Fak);
|
let tif = tif.unwrap_or(TimeInForce::Fak);
|
||||||
if side == Side::Buy {
|
if side == Side::Buy {
|
||||||
amount(requested)?;
|
amount(requested)?;
|
||||||
@@ -69,12 +84,11 @@ impl Request {
|
|||||||
"estimate requires FAK or FOK"
|
"estimate requires FAK or FOK"
|
||||||
);
|
);
|
||||||
ensure!(
|
ensure!(
|
||||||
matches!(outcome.as_str(), "YES" | "NO") && (0..=100).contains(&limit),
|
matches!(outcome.as_str(), "YES" | "NO")
|
||||||
|
&& (0..=crate::tick_size::PAR).contains(&limit),
|
||||||
"invalid outcome or price"
|
"invalid outcome or price"
|
||||||
);
|
);
|
||||||
if let Some(tick) = tick {
|
crate::tick_size::validate(tick.as_ref(), limit)?;
|
||||||
tick.check(limit * 10000)?;
|
|
||||||
}
|
|
||||||
phase(tx, &market, &["continuous"])?;
|
phase(tx, &market, &["continuous"])?;
|
||||||
let rate = crate::fees::rate(tx, &market)?;
|
let rate = crate::fees::rate(tx, &market)?;
|
||||||
if let Some(minimum) = crate::minimum_size::MinimumSize::load(tx, &market)? {
|
if let Some(minimum) = crate::minimum_size::MinimumSize::load(tx, &market)? {
|
||||||
@@ -89,7 +103,7 @@ impl Request {
|
|||||||
let mut fills = books
|
let mut fills = books
|
||||||
.get(&market, &outcome)
|
.get(&market, &outcome)
|
||||||
.map(|b| match side {
|
.map(|b| match side {
|
||||||
Side::Buy => b.match_budget_buy(i64::MAX, limit, requested * 100),
|
Side::Buy => b.match_budget_buy(i64::MAX, limit, requested * 10000),
|
||||||
Side::Sell => b.match_incoming(&Order {
|
Side::Sell => b.match_incoming(&Order {
|
||||||
seq: i64::MAX,
|
seq: i64::MAX,
|
||||||
side,
|
side,
|
||||||
@@ -114,8 +128,8 @@ impl Request {
|
|||||||
Side::Sell => requested == shares,
|
Side::Sell => requested == shares,
|
||||||
};
|
};
|
||||||
let mut result = json!({"asset_id":assets::id(&market,&outcome),"filled_shares":crate::lots::display(shares),
|
let mut result = json!({"asset_id":assets::id(&market,&outcome),"filled_shares":crate::lots::display(shares),
|
||||||
"gross_cents":crate::inventory::decimal(gross.into(),10000),"best_fill_price":fills.first().map(|f|f.price),
|
"gross_cents":crate::inventory::decimal(gross.into(),10000),"best_fill_price":fills.first().map(|f|crate::inventory::decimal(f.price.into(),100)),
|
||||||
"worst_fill_price":fills.last().map(|f|f.price),
|
"worst_fill_price":fills.last().map(|f|crate::inventory::decimal(f.price.into(),100)),
|
||||||
"average_price_micros":(i128::from(gross)*100).checked_div(i128::from(shares)),
|
"average_price_micros":(i128::from(gross)*100).checked_div(i128::from(shares)),
|
||||||
"fee_micros":fee,"taker_fee_rate_ppm":rate,
|
"fee_micros":fee,"taker_fee_rate_ppm":rate,
|
||||||
"fully_fillable":fully_fillable,"executable":shares>0 && (tif==TimeInForce::Fak || fully_fillable)});
|
"fully_fillable":fully_fillable,"executable":shares>0 && (tif==TimeInForce::Fak || fully_fillable)});
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub(crate) fn lot_fee(rate: i64, price_micros: i64, lots: i64) -> i64 {
|
|||||||
pub(crate) fn total(rate: i64, fills: &[Fill]) -> i64 {
|
pub(crate) fn total(rate: i64, fills: &[Fill]) -> i64 {
|
||||||
fills
|
fills
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| lot_fee(rate, f.price * 10000, f.quantity))
|
.map(|f| lot_fee(rate, f.price * 100, f.quantity))
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +42,7 @@ pub(crate) fn fit_budget(rate: i64, fills: &mut Vec<Fill>, budget: i64) {
|
|||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for f in fills.iter_mut() {
|
for f in fills.iter_mut() {
|
||||||
let cost = |qty: i64| {
|
let cost = |qty: i64| {
|
||||||
i128::from(qty) * i128::from(f.price) * 100
|
i128::from(qty) * i128::from(f.price) + i128::from(lot_fee(rate, f.price * 100, qty))
|
||||||
+ i128::from(lot_fee(rate, f.price * 10000, qty))
|
|
||||||
};
|
};
|
||||||
if cost(f.quantity) <= i128::from(remaining) {
|
if cost(f.quantity) <= i128::from(remaining) {
|
||||||
remaining -= cost(f.quantity) as i64;
|
remaining -= cost(f.quantity) as i64;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ pub(crate) fn balance(db: &Connection, account: &str) -> Result<Value> {
|
|||||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
|
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
|
||||||
)?;
|
)?;
|
||||||
let available = i128::from(cash) * 10000 + i128::from(remainder);
|
let available = i128::from(cash) * 10000 + i128::from(remainder);
|
||||||
let reserved = i128::from(reserved) * 100;
|
let reserved = i128::from(reserved);
|
||||||
Ok(
|
Ok(
|
||||||
json!({"account":account, "available_micros":available, "reserved_micros":reserved,
|
json!({"account":account, "available_micros":available, "reserved_micros":reserved,
|
||||||
"total_cash_micros":available+reserved}),
|
"total_cash_micros":available+reserved}),
|
||||||
|
|||||||
@@ -177,6 +177,12 @@ impl Exchange {
|
|||||||
{
|
{
|
||||||
json!(lots::display(n))
|
json!(lots::display(n))
|
||||||
}
|
}
|
||||||
|
ValueRef::Integer(n)
|
||||||
|
if matches!(table, "orders" | "fills" | "paired_fills")
|
||||||
|
&& matches!(name.as_str(), "price" | "yes_price") =>
|
||||||
|
{
|
||||||
|
json!(crate::inventory::decimal(n.into(), 100))
|
||||||
|
}
|
||||||
ValueRef::Integer(n) => json!(n),
|
ValueRef::Integer(n) => json!(n),
|
||||||
ValueRef::Text(s) => json!(std::str::from_utf8(s)?),
|
ValueRef::Text(s) => json!(std::str::from_utf8(s)?),
|
||||||
_ => anyhow::bail!("unexpected column type"),
|
_ => anyhow::bail!("unexpected column type"),
|
||||||
|
|||||||
@@ -21,16 +21,23 @@ pub(crate) fn amount(qty: Option<i64>, size_micros: Option<i64>) -> Result<i64>
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn migrate(db: &mut Connection) -> Result<()> {
|
pub(crate) fn migrate(db: &mut Connection) -> Result<()> {
|
||||||
let ready = |c: &Connection| {
|
let ready = |c: &Connection, table: &str| {
|
||||||
c.query_row("SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='table' AND name='order_lot_format')",[],|r|r.get::<_,bool>(0))
|
c.query_row(
|
||||||
|
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='table' AND name=?)",
|
||||||
|
[table],
|
||||||
|
|r| r.get::<_, bool>(0),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
if ready(db)? {
|
if ready(db, "order_price_format")? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let tx = db.transaction_with_behavior(TransactionBehavior::Immediate)?;
|
let tx = db.transaction_with_behavior(TransactionBehavior::Immediate)?;
|
||||||
if !ready(&tx)? {
|
if !ready(&tx, "order_lot_format")? {
|
||||||
tx.execute_batch(include_str!("lot_migration.sql"))?;
|
tx.execute_batch(include_str!("lot_migration.sql"))?;
|
||||||
}
|
}
|
||||||
|
if !ready(&tx, "order_price_format")? {
|
||||||
|
tx.execute_batch(include_str!("price_migration.sql"))?;
|
||||||
|
}
|
||||||
tx.commit()?;
|
tx.commit()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ pub(crate) fn apply(
|
|||||||
outcome,
|
outcome,
|
||||||
side,
|
side,
|
||||||
price,
|
price,
|
||||||
|
price_micros,
|
||||||
qty,
|
qty,
|
||||||
size_micros,
|
size_micros,
|
||||||
tif,
|
tif,
|
||||||
@@ -144,7 +145,7 @@ pub(crate) fn apply(
|
|||||||
key_id,
|
key_id,
|
||||||
outcome,
|
outcome,
|
||||||
side,
|
side,
|
||||||
price,
|
price: crate::tick_size::required(price, price_micros)?,
|
||||||
qty: crate::lots::amount(qty, size_micros)?,
|
qty: crate::lots::amount(qty, size_micros)?,
|
||||||
tif: tif.unwrap_or_else(|| {
|
tif: tif.unwrap_or_else(|| {
|
||||||
if expiration.unwrap_or(0) != 0 {
|
if expiration.unwrap_or(0) != 0 {
|
||||||
@@ -165,6 +166,7 @@ pub(crate) fn apply(
|
|||||||
outcome,
|
outcome,
|
||||||
qty,
|
qty,
|
||||||
min_price,
|
min_price,
|
||||||
|
min_price_micros,
|
||||||
size_micros,
|
size_micros,
|
||||||
tif,
|
tif,
|
||||||
} => {
|
} => {
|
||||||
@@ -186,7 +188,7 @@ pub(crate) fn apply(
|
|||||||
key_id,
|
key_id,
|
||||||
outcome,
|
outcome,
|
||||||
side: "sell".to_owned(),
|
side: "sell".to_owned(),
|
||||||
price: min_price,
|
price: crate::tick_size::required(min_price, min_price_micros)?,
|
||||||
qty,
|
qty,
|
||||||
tif,
|
tif,
|
||||||
expiration: None,
|
expiration: None,
|
||||||
@@ -209,6 +211,7 @@ pub(crate) fn apply(
|
|||||||
key_id,
|
key_id,
|
||||||
amount_cents,
|
amount_cents,
|
||||||
max_price,
|
max_price,
|
||||||
|
max_price_micros,
|
||||||
tif,
|
tif,
|
||||||
} => book::market_buy(
|
} => book::market_buy(
|
||||||
tx,
|
tx,
|
||||||
@@ -219,7 +222,7 @@ pub(crate) fn apply(
|
|||||||
account,
|
account,
|
||||||
key_id,
|
key_id,
|
||||||
amount_cents,
|
amount_cents,
|
||||||
max_price,
|
max_price: crate::tick_size::required(max_price, max_price_micros)?,
|
||||||
tif: tif.unwrap_or(crate::command::TimeInForce::Fak),
|
tif: tif.unwrap_or(crate::command::TimeInForce::Fak),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -249,7 +252,9 @@ pub(crate) fn apply(
|
|||||||
.get(&market, &outcome)
|
.get(&market, &outcome)
|
||||||
.ok_or_else(|| anyhow::anyhow!("missing auction book"))?;
|
.ok_or_else(|| anyhow::anyhow!("missing auction book"))?;
|
||||||
let step = crate::tick_size::TickSize::load(tx, &market)?
|
let step = crate::tick_size::TickSize::load(tx, &market)?
|
||||||
.map_or(std::num::NonZeroU32::MIN, |tick| tick.local_step());
|
.map_or(std::num::NonZeroU32::new(100).unwrap(), |tick| {
|
||||||
|
tick.local_step()
|
||||||
|
});
|
||||||
book::settle(tx, &market, &outcome, book.opening_with_step(step), None)?;
|
book::settle(tx, &market, &outcome, book.opening_with_step(step), None)?;
|
||||||
}
|
}
|
||||||
tx.execute("UPDATE markets SET phase='continuous' WHERE id=?", [market])?;
|
tx.execute("UPDATE markets SET phase='continuous' WHERE id=?", [market])?;
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ impl MinimumSize {
|
|||||||
|
|
||||||
pub fn check_budget(&self, cents: i64, max_price: i64, fee_rate: i64) -> Result<()> {
|
pub fn check_budget(&self, cents: i64, max_price: i64, fee_rate: i64) -> Result<()> {
|
||||||
let lots = (self.0 + crate::lots::MICROS - 1) / crate::lots::MICROS;
|
let lots = (self.0 + crate::lots::MICROS - 1) / crate::lots::MICROS;
|
||||||
let required =
|
let required = lots * max_price + crate::fees::lot_fee(fee_rate, max_price * 100, lots);
|
||||||
lots * max_price * 100 + crate::fees::lot_fee(fee_rate, max_price * 10000, lots);
|
|
||||||
ensure!(
|
ensure!(
|
||||||
cents * 10000 >= required,
|
cents * 10000 >= required,
|
||||||
"cash budget at protection price is below min_order_size of {} shares",
|
"cash budget at protection price is below min_order_size of {} shares",
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
-- Run once under the same write lock as the format check. Monetary history
|
||||||
|
-- in trade_prices is already in micros and retains its original timestamps.
|
||||||
|
CREATE TABLE order_price_format(version INTEGER PRIMARY KEY CHECK(version=1));
|
||||||
|
INSERT INTO order_price_format
|
||||||
|
SELECT CASE WHEN EXISTS(SELECT 1 FROM orders WHERE price NOT BETWEEN 0 AND 100)
|
||||||
|
OR EXISTS(SELECT 1 FROM fills WHERE price NOT BETWEEN 0 AND 100)
|
||||||
|
THEN 0 ELSE 1 END;
|
||||||
|
UPDATE orders SET price=price*100;
|
||||||
|
UPDATE fills SET price=price*100;
|
||||||
|
UPDATE quote_events SET yes_bid=yes_bid*100,yes_ask=yes_ask*100;
|
||||||
|
UPDATE last_asset_trades SET price=price*100;
|
||||||
|
|
||||||
|
-- Replace the historical 0..100 check. No foreign key references this table.
|
||||||
|
CREATE TEMP TABLE migrate_paired_prices AS SELECT * FROM paired_fills;
|
||||||
|
DROP TABLE paired_fills;
|
||||||
|
CREATE TABLE IF NOT EXISTS paired_fills (
|
||||||
|
seq INTEGER PRIMARY KEY, market TEXT NOT NULL REFERENCES markets,
|
||||||
|
kind TEXT NOT NULL CHECK(kind IN ('mint','merge')),
|
||||||
|
yes_order INTEGER NOT NULL REFERENCES orders, no_order INTEGER NOT NULL REFERENCES orders,
|
||||||
|
yes_price INTEGER NOT NULL CHECK(yes_price BETWEEN 0 AND 10000),
|
||||||
|
quantity INTEGER NOT NULL CHECK(quantity>0),
|
||||||
|
at_ms INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec')*1000 AS INTEGER))
|
||||||
|
);
|
||||||
|
INSERT INTO paired_fills(seq,market,kind,yes_order,no_order,yes_price,quantity,at_ms)
|
||||||
|
SELECT seq,market,kind,yes_order,no_order,yes_price*100,quantity,at_ms FROM migrate_paired_prices;
|
||||||
|
DROP TABLE temp.migrate_paired_prices;
|
||||||
|
CREATE INDEX IF NOT EXISTS public_paired_time ON paired_fills(at_ms,seq);
|
||||||
|
CREATE INDEX IF NOT EXISTS paired_history ON paired_fills(market,at_ms,seq);
|
||||||
|
CREATE INDEX IF NOT EXISTS paired_by_yes ON paired_fills(yes_order,seq);
|
||||||
|
CREATE INDEX IF NOT EXISTS paired_by_no ON paired_fills(no_order,seq);
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS record_trade_price;
|
||||||
|
CREATE TRIGGER IF NOT EXISTS record_trade_price AFTER INSERT ON fills BEGIN
|
||||||
|
INSERT INTO trade_prices(fill,market,outcome,at_ms,price_micros,quantity)
|
||||||
|
SELECT NEW.seq,market,outcome,CAST(unixepoch('subsec')*1000 AS INTEGER),
|
||||||
|
NEW.price*100,NEW.quantity FROM orders WHERE seq=NEW.bid;
|
||||||
|
END;
|
||||||
|
|
||||||
|
DROP VIEW IF EXISTS visible_orders;
|
||||||
|
CREATE VIEW IF NOT EXISTS visible_orders AS
|
||||||
|
SELECT market,outcome,side,price,remaining FROM orders WHERE status='live'
|
||||||
|
UNION ALL
|
||||||
|
SELECT market,CASE outcome WHEN 'YES' THEN 'NO' ELSE 'YES' END,
|
||||||
|
CASE side WHEN 'buy' THEN 'sell' ELSE 'buy' END,10000-price,remaining
|
||||||
|
FROM orders WHERE status='live';
|
||||||
|
|
||||||
|
DROP VIEW IF EXISTS outcome_trade_prices;
|
||||||
|
CREATE VIEW IF NOT EXISTS outcome_trade_prices AS
|
||||||
|
SELECT fill,market,outcome,at_ms,price_micros,quantity FROM trade_prices
|
||||||
|
UNION ALL SELECT seq,market,'YES',at_ms,yes_price*100,quantity FROM paired_fills
|
||||||
|
UNION ALL SELECT seq,market,'NO',at_ms,(10000-yes_price)*100,quantity FROM paired_fills;
|
||||||
|
|
||||||
|
DROP VIEW IF EXISTS wallet_trade_legs;
|
||||||
|
CREATE VIEW IF NOT EXISTS wallet_trade_legs AS
|
||||||
|
SELECT f.seq AS execution,o.seq AS order_seq,o.account,o.market,o.outcome,o.side,
|
||||||
|
'transfer' AS kind,f.price,f.quantity,t.at_ms
|
||||||
|
FROM fills f JOIN orders o ON o.seq=f.bid LEFT JOIN trade_prices t ON t.fill=f.seq
|
||||||
|
UNION ALL
|
||||||
|
SELECT f.seq,o.seq,o.account,o.market,o.outcome,o.side,'transfer',f.price,f.quantity,t.at_ms
|
||||||
|
FROM fills f JOIN orders o ON o.seq=f.ask LEFT JOIN trade_prices t ON t.fill=f.seq
|
||||||
|
UNION ALL
|
||||||
|
SELECT f.seq,o.seq,o.account,o.market,o.outcome,o.side,f.kind,f.yes_price,f.quantity,f.at_ms
|
||||||
|
FROM paired_fills f JOIN orders o ON o.seq=f.yes_order
|
||||||
|
UNION ALL
|
||||||
|
SELECT f.seq,o.seq,o.account,o.market,o.outcome,o.side,f.kind,10000-f.yes_price,f.quantity,f.at_ms
|
||||||
|
FROM paired_fills f JOIN orders o ON o.seq=f.no_order;
|
||||||
|
|
||||||
|
DROP VIEW IF EXISTS changed_quotes;
|
||||||
|
CREATE VIEW IF NOT EXISTS changed_quotes AS
|
||||||
|
WITH edges AS MATERIALIZED (
|
||||||
|
SELECT p.market,
|
||||||
|
(SELECT MAX(price) FROM orders WHERE market=p.market AND outcome='YES' AND side='buy' AND status='live') AS direct_bid,
|
||||||
|
(SELECT MIN(price) FROM orders WHERE market=p.market AND outcome='YES' AND side='sell' AND status='live') AS direct_ask,
|
||||||
|
10000-(SELECT MIN(price) FROM orders WHERE market=p.market AND outcome='NO' AND side='sell' AND status='live') AS reflected_bid,
|
||||||
|
10000-(SELECT MAX(price) FROM orders WHERE market=p.market AND outcome='NO' AND side='buy' AND status='live') AS reflected_ask,
|
||||||
|
(SELECT MAX(seq) FROM quote_events WHERE market=p.market) AS previous
|
||||||
|
FROM quote_pending p
|
||||||
|
), best AS (
|
||||||
|
SELECT market,previous,
|
||||||
|
COALESCE(MAX(direct_bid,reflected_bid),direct_bid,reflected_bid) AS bid,
|
||||||
|
COALESCE(MIN(direct_ask,reflected_ask),direct_ask,reflected_ask) AS ask
|
||||||
|
FROM edges
|
||||||
|
)
|
||||||
|
SELECT b.market,b.bid,b.ask,CAST(unixepoch('subsec')*1000 AS INTEGER) AS at_ms
|
||||||
|
FROM best b LEFT JOIN quote_events old ON old.seq=b.previous
|
||||||
|
WHERE b.bid IS NOT old.yes_bid OR b.ask IS NOT old.yes_ask;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS last_asset_paired;
|
||||||
|
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,10000-NEW.yes_price)
|
||||||
|
ON CONFLICT(market,outcome) DO UPDATE SET execution=excluded.execution,price=excluded.price
|
||||||
|
WHERE excluded.execution>last_asset_trades.execution;
|
||||||
|
END;
|
||||||
@@ -126,7 +126,7 @@ impl Request {
|
|||||||
let size: i64 = r.get(9)?;
|
let size: i64 = r.get(9)?;
|
||||||
data.push(json!({"at_ms":at,"execution":seq,"account":r.get::<_,String>(3)?,"market":market,
|
data.push(json!({"at_ms":at,"execution":seq,"account":r.get::<_,String>(3)?,"market":market,
|
||||||
"outcome":outcome,"asset_id":assets::id(&market,&outcome),"side":r.get::<_,String>(6)?,
|
"outcome":outcome,"asset_id":assets::id(&market,&outcome),"side":r.get::<_,String>(6)?,
|
||||||
"kind":r.get::<_,String>(7)?,"price_micros":price*10000,"size":crate::lots::display(size),"gross_cents":crate::inventory::decimal(i128::from(price)*i128::from(size),100),
|
"kind":r.get::<_,String>(7)?,"price_micros":price*100,"size":crate::lots::display(size),"gross_cents":crate::inventory::decimal(i128::from(price)*i128::from(size),10000),
|
||||||
"role":r.get::<_,Option<String>>(10)?}));
|
"role":r.get::<_,Option<String>>(10)?}));
|
||||||
page.before = (at, seq, r.get(2)?);
|
page.before = (at, seq, r.get(2)?);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ WITH selected_events AS (
|
|||||||
WHERE at_ms BETWEEN :start AND :before_ms AND (at_ms,seq)<=(:before_ms,:before_execution)
|
WHERE at_ms BETWEEN :start AND :before_ms AND (at_ms,seq)<=(:before_ms,:before_execution)
|
||||||
), legs AS (
|
), legs AS (
|
||||||
SELECT e.at_ms,e.execution,e.market,o.seq AS order_seq,o.account,o.outcome,o.side,e.kind,
|
SELECT e.at_ms,e.execution,e.market,o.seq AS order_seq,o.account,o.outcome,o.side,e.kind,
|
||||||
CASE WHEN e.kind<>'transfer' AND o.seq=e.second_order THEN 100-e.price ELSE e.price END AS price,
|
CASE WHEN e.kind<>'transfer' AND o.seq=e.second_order THEN 10000-e.price ELSE e.price END AS price,
|
||||||
e.quantity,
|
e.quantity,
|
||||||
CASE WHEN c.execution IS NULL THEN NULL WHEN c.taker_order IS NULL THEN 'auction'
|
CASE WHEN c.execution IS NULL THEN NULL WHEN c.taker_order IS NULL THEN 'auction'
|
||||||
WHEN c.taker_order=o.seq THEN 'taker' ELSE 'maker' END AS role
|
WHEN c.taker_order=o.seq THEN 'taker' ELSE 'maker' END AS role
|
||||||
@@ -26,5 +26,5 @@ WITH selected_events AS (
|
|||||||
AND (e.at_ms,e.execution,o.seq)<(:before_ms,:before_execution,:before_order)
|
AND (e.at_ms,e.execution,o.seq)<(:before_ms,:before_execution,:before_order)
|
||||||
)
|
)
|
||||||
SELECT at_ms,execution,order_seq,account,market,outcome,side,kind,price,quantity,role
|
SELECT at_ms,execution,order_seq,account,market,outcome,side,kind,price,quantity,role
|
||||||
FROM legs WHERE CASE WHEN :cash THEN price*quantity/10000.0 ELSE quantity/100.0 END >= :minimum
|
FROM legs WHERE CASE WHEN :cash THEN price*quantity/1000000.0 ELSE quantity/100.0 END >= :minimum
|
||||||
ORDER BY at_ms DESC,execution DESC,order_seq DESC LIMIT :limit
|
ORDER BY at_ms DESC,execution DESC,order_seq DESC LIMIT :limit
|
||||||
|
|||||||
@@ -16,24 +16,6 @@ WHEN (OLD.status='live')<>(NEW.status='live') BEGIN
|
|||||||
INSERT OR IGNORE INTO quote_pending VALUES(NEW.market);
|
INSERT OR IGNORE INTO quote_pending VALUES(NEW.market);
|
||||||
END;
|
END;
|
||||||
|
|
||||||
CREATE VIEW IF NOT EXISTS changed_quotes AS
|
|
||||||
WITH edges AS MATERIALIZED (
|
|
||||||
SELECT p.market,
|
|
||||||
(SELECT MAX(price) FROM orders WHERE market=p.market AND outcome='YES' AND side='buy' AND status='live') AS direct_bid,
|
|
||||||
(SELECT MIN(price) FROM orders WHERE market=p.market AND outcome='YES' AND side='sell' AND status='live') AS direct_ask,
|
|
||||||
100-(SELECT MIN(price) FROM orders WHERE market=p.market AND outcome='NO' AND side='sell' AND status='live') AS reflected_bid,
|
|
||||||
100-(SELECT MAX(price) FROM orders WHERE market=p.market AND outcome='NO' AND side='buy' AND status='live') AS reflected_ask,
|
|
||||||
(SELECT MAX(seq) FROM quote_events WHERE market=p.market) AS previous
|
|
||||||
FROM quote_pending p
|
|
||||||
), best AS (
|
|
||||||
SELECT market,previous,
|
|
||||||
COALESCE(MAX(direct_bid,reflected_bid),direct_bid,reflected_bid) AS bid,
|
|
||||||
COALESCE(MIN(direct_ask,reflected_ask),direct_ask,reflected_ask) AS ask
|
|
||||||
FROM edges
|
|
||||||
)
|
|
||||||
SELECT b.market,b.bid,b.ask,CAST(unixepoch('subsec')*1000 AS INTEGER) AS at_ms
|
|
||||||
FROM best b LEFT JOIN quote_events old ON old.seq=b.previous
|
|
||||||
WHERE b.bid IS NOT old.yes_bid OR b.ask IS NOT old.yes_ask;
|
|
||||||
-- Capture the final book of a successful command in its receipt transaction.
|
-- Capture the final book of a successful command in its receipt transaction.
|
||||||
CREATE TRIGGER IF NOT EXISTS record_quote_on_receipt AFTER INSERT ON requests
|
CREATE TRIGGER IF NOT EXISTS record_quote_on_receipt AFTER INSERT ON requests
|
||||||
WHEN EXISTS(SELECT 1 FROM quote_pending) BEGIN
|
WHEN EXISTS(SELECT 1 FROM quote_pending) BEGIN
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ impl Quote {
|
|||||||
let (bid, ask) = if outcome == "YES" {
|
let (bid, ask) = if outcome == "YES" {
|
||||||
(bid, ask)
|
(bid, ask)
|
||||||
} else {
|
} else {
|
||||||
(ask.map(|p| 100 - p), bid.map(|p| 100 - p))
|
(
|
||||||
|
ask.map(|p| crate::tick_size::PAR - p),
|
||||||
|
bid.map(|p| crate::tick_size::PAR - p),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
seq: row.get(0)?,
|
seq: row.get(0)?,
|
||||||
@@ -55,22 +58,22 @@ impl Quote {
|
|||||||
pub fn mark(&self, phase: &str) -> Option<(i64, &'static str)> {
|
pub fn mark(&self, phase: &str) -> Option<(i64, &'static str)> {
|
||||||
if phase == "continuous" {
|
if phase == "continuous" {
|
||||||
if let (Some(b), Some(a)) = (self.bid, self.ask) {
|
if let (Some(b), Some(a)) = (self.bid, self.ask) {
|
||||||
if (0..=10).contains(&(a - b)) {
|
if (0..=1000).contains(&(a - b)) {
|
||||||
return Some(((a + b) * 5000, "midpoint"));
|
return Some(((a + b) * 50, "midpoint"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if matches!(phase, "continuous" | "closed") {
|
if matches!(phase, "continuous" | "closed") {
|
||||||
return self.last.map(|p| (p * 10000, "last_trade"));
|
return self.last.map(|p| (p * 100, "last_trade"));
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn event(&self) -> Value {
|
fn event(&self) -> Value {
|
||||||
let pair = self.bid.zip(self.ask);
|
let pair = self.bid.zip(self.ask);
|
||||||
json!({"seq":self.seq,"at_ms":self.at_ms,"best_bid_micros":self.bid.map(|p|p*10000),
|
json!({"seq":self.seq,"at_ms":self.at_ms,"best_bid_micros":self.bid.map(|p|p*100),
|
||||||
"best_ask_micros":self.ask.map(|p|p*10000),"spread_micros":pair.map(|(b,a)|(a-b)*10000),
|
"best_ask_micros":self.ask.map(|p|p*100),"spread_micros":pair.map(|(b,a)|(a-b)*100),
|
||||||
"midpoint_micros":pair.map(|(b,a)|(a+b)*5000)})
|
"midpoint_micros":pair.map(|(b,a)|(a+b)*50)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +187,13 @@ fn price_rows(db: &Connection, requests: &[PriceRequest]) -> Result<Vec<Option<S
|
|||||||
Side::Buy => quote.ask,
|
Side::Buy => quote.ask,
|
||||||
Side::Sell => quote.bid,
|
Side::Sell => quote.bid,
|
||||||
};
|
};
|
||||||
prices.push(price.map(|cents| format!("{}.{:02}", cents / 100, cents % 100)));
|
prices.push(price.map(|p| {
|
||||||
|
let mut text = format!("{}.{:04}", p / 10000, p % 10000);
|
||||||
|
while text.len() > 4 && text.ends_with('0') {
|
||||||
|
text.pop();
|
||||||
|
}
|
||||||
|
text
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
Ok(prices)
|
Ok(prices)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ impl Books {
|
|||||||
let reflected = Order {
|
let reflected = Order {
|
||||||
seq: order.seq,
|
seq: order.seq,
|
||||||
remaining: order.remaining,
|
remaining: order.remaining,
|
||||||
price: 100 - order.price,
|
price: crate::tick_size::PAR - order.price,
|
||||||
side: match order.side {
|
side: match order.side {
|
||||||
Side::Buy => Side::Sell,
|
Side::Buy => Side::Sell,
|
||||||
Side::Sell => Side::Buy,
|
Side::Sell => Side::Buy,
|
||||||
|
|||||||
@@ -81,11 +81,6 @@ CREATE TABLE IF NOT EXISTS trade_prices (
|
|||||||
outcome TEXT NOT NULL, at_ms INTEGER NOT NULL, price_micros INTEGER NOT NULL, quantity INTEGER NOT NULL
|
outcome TEXT NOT NULL, at_ms INTEGER NOT NULL, price_micros INTEGER NOT NULL, quantity INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS trade_series ON trade_prices(market,outcome,at_ms,fill);
|
CREATE INDEX IF NOT EXISTS trade_series ON trade_prices(market,outcome,at_ms,fill);
|
||||||
CREATE TRIGGER IF NOT EXISTS record_trade_price AFTER INSERT ON fills BEGIN
|
|
||||||
INSERT INTO trade_prices(fill,market,outcome,at_ms,price_micros,quantity)
|
|
||||||
SELECT NEW.seq,market,outcome,CAST(unixepoch('subsec')*1000 AS INTEGER),
|
|
||||||
NEW.price*10000,NEW.quantity FROM orders WHERE seq=NEW.bid;
|
|
||||||
END;
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS paired_fills (
|
CREATE TABLE IF NOT EXISTS paired_fills (
|
||||||
seq INTEGER PRIMARY KEY, market TEXT NOT NULL REFERENCES markets,
|
seq INTEGER PRIMARY KEY, market TEXT NOT NULL REFERENCES markets,
|
||||||
@@ -96,23 +91,10 @@ CREATE TABLE IF NOT EXISTS paired_fills (
|
|||||||
at_ms INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec')*1000 AS INTEGER))
|
at_ms INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec')*1000 AS INTEGER))
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS public_direct_time ON trade_prices(at_ms,fill);
|
CREATE INDEX IF NOT EXISTS public_direct_time ON trade_prices(at_ms,fill);
|
||||||
CREATE INDEX IF NOT EXISTS public_paired_time ON paired_fills(at_ms,seq);
|
|
||||||
CREATE INDEX IF NOT EXISTS paired_history ON paired_fills(market,at_ms,seq);
|
|
||||||
CREATE VIEW IF NOT EXISTS next_execution AS
|
CREATE VIEW IF NOT EXISTS next_execution AS
|
||||||
SELECT 1+MAX(COALESCE((SELECT MAX(seq) FROM fills),0),
|
SELECT 1+MAX(COALESCE((SELECT MAX(seq) FROM fills),0),
|
||||||
COALESCE((SELECT MAX(seq) FROM paired_fills),0)) AS id;
|
COALESCE((SELECT MAX(seq) FROM paired_fills),0)) AS id;
|
||||||
CREATE VIEW IF NOT EXISTS outcome_trade_prices AS
|
|
||||||
SELECT fill,market,outcome,at_ms,price_micros,quantity FROM trade_prices
|
|
||||||
UNION ALL SELECT seq,market,'YES',at_ms,yes_price*10000,quantity FROM paired_fills
|
|
||||||
UNION ALL SELECT seq,market,'NO',at_ms,(100-yes_price)*10000,quantity FROM paired_fills;
|
|
||||||
|
|
||||||
-- Each live binary order contributes once to each outcome's depth.
|
|
||||||
CREATE VIEW IF NOT EXISTS visible_orders AS
|
|
||||||
SELECT market,outcome,side,price,remaining FROM orders WHERE status='live'
|
|
||||||
UNION ALL
|
|
||||||
SELECT market,CASE outcome WHEN 'YES' THEN 'NO' ELSE 'YES' END,
|
|
||||||
CASE side WHEN 'buy' THEN 'sell' ELSE 'buy' END,100-price,remaining
|
|
||||||
FROM orders WHERE status='live';
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS order_deadlines (
|
CREATE TABLE IF NOT EXISTS order_deadlines (
|
||||||
seq INTEGER PRIMARY KEY REFERENCES orders,
|
seq INTEGER PRIMARY KEY REFERENCES orders,
|
||||||
@@ -134,8 +116,6 @@ CREATE INDEX IF NOT EXISTS account_orders_history ON orders(account,seq);
|
|||||||
CREATE INDEX IF NOT EXISTS market_buy_orders ON orders(market,seq) WHERE side='buy';
|
CREATE INDEX IF NOT EXISTS market_buy_orders ON orders(market,seq) WHERE side='buy';
|
||||||
CREATE INDEX IF NOT EXISTS fills_by_bid ON fills(bid,seq);
|
CREATE INDEX IF NOT EXISTS fills_by_bid ON fills(bid,seq);
|
||||||
CREATE INDEX IF NOT EXISTS fills_by_ask ON fills(ask,seq);
|
CREATE INDEX IF NOT EXISTS fills_by_ask ON fills(ask,seq);
|
||||||
CREATE INDEX IF NOT EXISTS paired_by_yes ON paired_fills(yes_order,seq);
|
|
||||||
CREATE INDEX IF NOT EXISTS paired_by_no ON paired_fills(no_order,seq);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS optimistic_markets (
|
CREATE TABLE IF NOT EXISTS optimistic_markets (
|
||||||
market TEXT PRIMARY KEY REFERENCES markets(id), eligible_at INTEGER NOT NULL CHECK(eligible_at>=0)
|
market TEXT PRIMARY KEY REFERENCES markets(id), eligible_at INTEGER NOT NULL CHECK(eligible_at>=0)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ impl Change {
|
|||||||
|
|
||||||
let mut stmt = tx.prepare(
|
let mut stmt = tx.prepare(
|
||||||
"SELECT seq,account FROM orders WHERE market=?1 AND status='live'
|
"SELECT seq,account FROM orders WHERE market=?1 AND status='live'
|
||||||
AND (price*10000 NOT BETWEEN ?2 AND 1000000-?2 OR (price*10000)%?2<>0) ORDER BY seq",
|
AND (price*100 NOT BETWEEN ?2 AND 1000000-?2 OR (price*100)%?2<>0) ORDER BY seq",
|
||||||
)?;
|
)?;
|
||||||
let invalid = stmt
|
let invalid = stmt
|
||||||
.query_map(params![self.market, new], |r| {
|
.query_map(params![self.market, new], |r| {
|
||||||
|
|||||||
@@ -7,6 +7,34 @@ use std::num::NonZeroU32;
|
|||||||
|
|
||||||
pub(crate) struct TickSize(pub i64);
|
pub(crate) struct TickSize(pub i64);
|
||||||
|
|
||||||
|
// A stored price is in 0.0001 dollars. One price unit times one order lot
|
||||||
|
// (0.01 shares) is exactly one cash micro.
|
||||||
|
pub(crate) const PAR: i64 = 10_000;
|
||||||
|
pub(crate) const PRICE_MICROS: i64 = 100;
|
||||||
|
pub(crate) fn input(cents: Option<i64>, micros: Option<i64>) -> Result<Option<i64>> {
|
||||||
|
match (cents, micros) {
|
||||||
|
(None, None) => Ok(None),
|
||||||
|
(Some(c), None) if (0..=100).contains(&c) => Ok(Some(c * 100)),
|
||||||
|
(None, Some(m)) if (0..=1_000_000).contains(&m) && m % PRICE_MICROS == 0 => {
|
||||||
|
Ok(Some(m / PRICE_MICROS))
|
||||||
|
}
|
||||||
|
_ => anyhow::bail!("provide one valid price in cents or micros"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) fn required(cents: Option<i64>, micros: Option<i64>) -> Result<i64> {
|
||||||
|
input(cents, micros)?.ok_or_else(|| anyhow::anyhow!("price required"))
|
||||||
|
}
|
||||||
|
pub(crate) fn validate(tick: Option<&TickSize>, price: i64) -> Result<()> {
|
||||||
|
if let Some(tick) = tick {
|
||||||
|
tick.check(price * PRICE_MICROS)
|
||||||
|
} else {
|
||||||
|
ensure!(
|
||||||
|
(0..=PAR).contains(&price) && price % 100 == 0,
|
||||||
|
"legacy market requires a whole-cent price"
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
impl TickSize {
|
impl TickSize {
|
||||||
pub(crate) fn parse(value: &str) -> Result<Self> {
|
pub(crate) fn parse(value: &str) -> Result<Self> {
|
||||||
let micros = match value.trim_end_matches('0') {
|
let micros = match value.trim_end_matches('0') {
|
||||||
@@ -51,8 +79,7 @@ impl TickSize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_step(&self) -> NonZeroU32 {
|
pub fn local_step(&self) -> NonZeroU32 {
|
||||||
// Each supported sub-cent step divides one cent exactly.
|
NonZeroU32::new((self.0 / PRICE_MICROS) as u32).unwrap()
|
||||||
NonZeroU32::new((self.0 / 10_000).max(1) as u32).unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +123,7 @@ impl LimitAmounts {
|
|||||||
json!({"asset_id":assets::id(&self.market,&self.outcome),"tick_size":tick.text(),
|
json!({"asset_id":assets::id(&self.market,&self.outcome),"tick_size":tick.text(),
|
||||||
"price_micros":self.price_micros,"size_micros":shares,"collateral_micros":collateral,
|
"price_micros":self.price_micros,"size_micros":shares,"collateral_micros":collateral,
|
||||||
"makerAmount":maker.to_string(),"takerAmount":taker.to_string(),
|
"makerAmount":maker.to_string(),"takerAmount":taker.to_string(),
|
||||||
"local_precision_supported":self.price_micros%10000==0}),
|
"local_precision_supported":true}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,6 @@ CREATE TRIGGER IF NOT EXISTS last_asset_direct AFTER INSERT ON fills BEGIN
|
|||||||
ON CONFLICT(market,outcome) DO UPDATE SET execution=excluded.execution,price=excluded.price
|
ON CONFLICT(market,outcome) DO UPDATE SET execution=excluded.execution,price=excluded.price
|
||||||
WHERE excluded.execution>last_asset_trades.execution;
|
WHERE excluded.execution>last_asset_trades.execution;
|
||||||
END;
|
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)
|
CREATE INDEX IF NOT EXISTS reserved_position_orders ON orders(account,market,outcome)
|
||||||
WHERE status='live' AND side='sell';
|
WHERE status='live' AND side='sell';
|
||||||
|
|||||||
@@ -11,13 +11,20 @@ fn serialize_hundredths<S: serde::Serializer>(
|
|||||||
crate::lots::display(*value).serialize(serializer)
|
crate::lots::display(*value).serialize(serializer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn serialize_cash_cents<S: serde::Serializer>(
|
||||||
|
value: &i64,
|
||||||
|
serializer: S,
|
||||||
|
) -> std::result::Result<S::Ok, S::Error> {
|
||||||
|
crate::inventory::decimal((*value).into(), 10000).serialize(serializer)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Serialize)]
|
#[derive(Default, Serialize)]
|
||||||
struct Totals {
|
struct Totals {
|
||||||
#[serde(serialize_with = "serialize_hundredths")]
|
#[serde(serialize_with = "serialize_hundredths")]
|
||||||
matched_shares: i64,
|
matched_shares: i64,
|
||||||
#[serde(serialize_with = "serialize_hundredths")]
|
#[serde(serialize_with = "serialize_hundredths")]
|
||||||
taker_shares: i64,
|
taker_shares: i64,
|
||||||
#[serde(serialize_with = "serialize_hundredths")]
|
#[serde(serialize_with = "serialize_cash_cents")]
|
||||||
taker_notional_cents: i64,
|
taker_notional_cents: i64,
|
||||||
#[serde(serialize_with = "serialize_hundredths")]
|
#[serde(serialize_with = "serialize_hundredths")]
|
||||||
unknown_role_shares: i64,
|
unknown_role_shares: i64,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ WITH selected(market) AS MATERIALIZED (
|
|||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT s.market, f.seq, f.quantity, f.at_ms,
|
SELECT s.market, f.seq, f.quantity, f.at_ms,
|
||||||
CASE c.taker_order WHEN f.yes_order THEN f.yes_price
|
CASE c.taker_order WHEN f.yes_order THEN f.yes_price
|
||||||
WHEN f.no_order THEN 100-f.yes_price END
|
WHEN f.no_order THEN 10000-f.yes_price END
|
||||||
FROM selected s CROSS JOIN paired_fills f ON f.market=s.market
|
FROM selected s CROSS JOIN paired_fills f ON f.market=s.market
|
||||||
LEFT JOIN execution_context c ON c.execution=f.seq
|
LEFT JOIN execution_context c ON c.execution=f.seq
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2198,7 +2198,7 @@ fn configured_ticks_bind_order_amounts_execution_and_opening_price() {
|
|||||||
if request["op"] == "limit_amounts" {
|
if request["op"] == "limit_amounts" {
|
||||||
assert_eq!(result["size_micros"], 5120000);
|
assert_eq!(result["size_micros"], 5120000);
|
||||||
assert_eq!(result["collateral_micros"], 66560);
|
assert_eq!(result["collateral_micros"], 66560);
|
||||||
assert_eq!(result["local_precision_supported"], false);
|
assert_eq!(result["local_precision_supported"], true);
|
||||||
let (maker, taker) = if request["side"] == "buy" {
|
let (maker, taker) = if request["side"] == "buy" {
|
||||||
("66560", "5120000")
|
("66560", "5120000")
|
||||||
} else {
|
} else {
|
||||||
@@ -2546,3 +2546,89 @@ fn old_resting_order_is_scaled_once_and_keeps_fifo_after_partial_fill() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(r["cancelled"].to_string(), "0.99");
|
assert_eq!(r["cancelled"].to_string(), "0.99");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn subcent_fills_reconcile_across_restart_budget_and_complement() {
|
||||||
|
let dir = tempdir().unwrap();
|
||||||
|
let path = dir.path().join("fine.db");
|
||||||
|
let mut e = Exchange::open(&path).unwrap();
|
||||||
|
for line in include_str!("../../../docs/examples/fine-price-execution.jsonl").lines() {
|
||||||
|
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||||
|
if cmd["op"] == "price" {
|
||||||
|
drop(e);
|
||||||
|
e = Exchange::open(&path).unwrap();
|
||||||
|
}
|
||||||
|
if cmd["id"] == "buy" {
|
||||||
|
for invalid in [
|
||||||
|
json!({"price_micros":13500}),
|
||||||
|
json!({"price":1,"price_micros":13000}),
|
||||||
|
] {
|
||||||
|
let mut broken = cmd.clone();
|
||||||
|
broken
|
||||||
|
.as_object_mut()
|
||||||
|
.unwrap()
|
||||||
|
.extend(invalid.as_object().unwrap().clone());
|
||||||
|
assert!(e.execute(broken).is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let r = e.execute(cmd.clone()).unwrap();
|
||||||
|
match cmd["op"].as_str().unwrap() {
|
||||||
|
"price" => assert_eq!(r["price"], "0.013"),
|
||||||
|
"balance" => assert_eq!(r["available_micros"], 1_933_440),
|
||||||
|
"estimate" => {
|
||||||
|
assert_eq!(r["total_spent_micros"], 9880);
|
||||||
|
assert_eq!(r["worst_fill_price"].to_string(), "1.3");
|
||||||
|
}
|
||||||
|
"market_buy" => {
|
||||||
|
assert_eq!(r["unspent_micros"], 120);
|
||||||
|
assert_eq!(r["total_spent_micros"], 9880);
|
||||||
|
}
|
||||||
|
"cancel" => assert_eq!(r["cancelled"].to_string(), "0.12"),
|
||||||
|
"history" => {
|
||||||
|
assert_eq!(r["points"][0]["price_micros"], 987000);
|
||||||
|
assert_eq!(r["points"][0]["quantity"].to_string(), "1.01");
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let state = state(&mut e);
|
||||||
|
assert_eq!(state["fills"][0]["price"].to_string(), "1.3");
|
||||||
|
assert_eq!(state["paired_fills"][0]["yes_price"].to_string(), "1.3");
|
||||||
|
assert_eq!(state["markets"][0]["collateral"], 801);
|
||||||
|
let replay = e.execute(json!({"op":"volume","market":"e"})).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
replay["volume"]["all_time"]["taker_notional_cents"].to_string(),
|
||||||
|
"8.957"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn auction_uses_fine_grid_and_coarsening_releases_exact_bid_reserve() {
|
||||||
|
let mut e = Exchange::open(":memory:").unwrap();
|
||||||
|
e.execute(json!({"op":"list","id":"l","market":"e","rules":"r","tick_size":"0.001"}))
|
||||||
|
.unwrap();
|
||||||
|
for (who, cents) in [("maker", 200), ("buyer", 100)] {
|
||||||
|
e.execute(json!({"op":"fund","id":who,"account":who,"cents":cents}))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
e.execute(json!({"op":"split","id":"s","market":"e","account":"maker","qty":2}))
|
||||||
|
.unwrap();
|
||||||
|
for (id, account, side, p, qty) in [
|
||||||
|
("a", "maker", "sell", 12000, 2),
|
||||||
|
("b", "buyer", "buy", 12000, 3),
|
||||||
|
("c", "buyer", "buy", 17000, 2),
|
||||||
|
] {
|
||||||
|
e.execute(json!({"op":"order","id":id,"market":"e","outcome":"YES","account":account,"side":side,"price_micros":p,"qty":qty})).unwrap();
|
||||||
|
}
|
||||||
|
e.execute(json!({"op":"open","id":"o","market":"e"}))
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(state(&mut e)["fills"][0]["price"].to_string(), "1.3");
|
||||||
|
let balance = json!({"op":"balance","account":"buyer"});
|
||||||
|
let before = e.execute(balance.clone()).unwrap();
|
||||||
|
assert_eq!(before["reserved_micros"], 36000);
|
||||||
|
assert_eq!(before["available_micros"], 938000);
|
||||||
|
e.execute(json!({"op":"tick_size_change","id":"wider","asset_id":"eb:YES:e","old_tick_size":"0.001","new_tick_size":"0.01","timestamp":"1"})).unwrap();
|
||||||
|
let after = e.execute(balance).unwrap();
|
||||||
|
assert_eq!(after["available_micros"], 974000);
|
||||||
|
assert_eq!(after["reserved_micros"], 0);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# matching
|
# matching
|
||||||
|
|
||||||
每个 OrderBook 保存一个交易品的常驻盘口。买卖双方各有一棵按价格、原始受理序号排序的 BTreeMap。每本簿的价格均用同一个最小价格步长的整数倍表示,数量用整数表示最小交易单位。exchange 的价格使用美分,每个数量单位为 0.01 份。exchange 按市场和结果持有这些簿,并把已提交的订单余量逐笔应用到对应的树。
|
每个 OrderBook 保存一个交易品的常驻盘口。买卖双方各有一棵按价格、原始受理序号排序的 BTreeMap。每本簿的价格均用同一个最小价格步长的整数倍表示,数量用整数表示最小交易单位。exchange 的价格使用 0.0001 美元,每个数量单位为 0.01 份。exchange 按市场和结果持有这些簿,并把已提交的订单余量逐笔应用到对应的树。
|
||||||
|
|
||||||
## 文件依赖
|
## 文件依赖
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ sequenceDiagram
|
|||||||
B->>M: match_incoming,传入一条新订单
|
B->>M: match_incoming,传入一条新订单
|
||||||
M->>M: 从对手方最优价起遍历,同价按原序号分配
|
M->>M: 从对手方最优价起遍历,同价按原序号分配
|
||||||
else 盘中按金额买入
|
else 盘中按金额买入
|
||||||
B->>M: match_budget_buy,传入买单序号、最高价、以美分乘数量单位折算的总预算
|
B->>M: match_budget_buy,传入买单序号、最高价、以微美元计的总预算
|
||||||
M->>M: 在同一卖盘上逐单扣减可用预算,末档取预算可负担的最大整数单位数
|
M->>M: 在同一卖盘上逐单扣减可用预算,末档取预算可负担的最大整数单位数
|
||||||
else 集合竞价
|
else 集合竞价
|
||||||
B->>M: opening,在买一与卖一之间计算统一成交价
|
B->>M: opening,在买一与卖一之间计算统一成交价
|
||||||
@@ -41,7 +41,7 @@ sequenceDiagram
|
|||||||
|
|
||||||
## 细步长样例
|
## 细步长样例
|
||||||
|
|
||||||
Gamma 市场 559651 的一份公开目录记录中,最小步长为 0.001 美元,买一为 0.012,卖一为 0.013。以这个步长建立内存簿,两个价位分别用整数 12、13 表示。假设盘中在 12 上有两张各 2 份的卖单,在 13 上有一张 2 份卖单,以 13 为限价买入 5 份,会按受理顺序以 12、12、13 成交,合计 61 个步长,即 0.061 美元。这个成交场景使用模拟订单。exchange 的命令、预留资金和持久化价格仍按整分工作,接入细步长需要一起迁移这些字段。[官方目录](https://gamma-api.polymarket.com/markets/559651)
|
Gamma 市场 559651 的一份公开目录记录中,最小步长为 0.001 美元,买一为 0.012,卖一为 0.013。以这个步长建立内存簿,两个价位分别用整数 12、13 表示。假设盘中在 12 上有两张各 2 份的卖单,在 13 上有一张 2 份卖单,以 13 为限价买入 5 份,会按受理顺序以 12、12、13 成交,合计 61 个步长,即 0.061 美元。这个成交场景使用模拟订单。exchange 以 0.0001 美元为内部单位表示价格,实际送入簿内的这两个价位为 120、130,按市场配置的步长 10 进行竞价。[官方目录](https://gamma-api.polymarket.com/markets/559651)
|
||||||
|
|
||||||
开盘沿用 Eventbook 的集合竞价规则。若价位 812 有 2 份卖单,812 和 817 分别有 3 份和 2 份买单,在 812 可成交 2 份,需求多出 3 份;在 813 至 817 均可成交 2 份,供需相等。最终以最低的 813 清算。813 上可以没有挂单。遍历工作量取决于订单和有供需变化的价位数,即使最小步长细化,空价位也无需逐档扫描。若调用方价格单位为分、市场仅允许每 10 分一档,使用 opening_with_step(10),输入委托须已对齐。同样的供需变化在买价 50 分之后要到 60 分才生效。
|
开盘沿用 Eventbook 的集合竞价规则。若价位 812 有 2 份卖单,812 和 817 分别有 3 份和 2 份买单,在 812 可成交 2 份,需求多出 3 份;在 813 至 817 均可成交 2 份,供需相等。最终以最低的 813 清算。813 上可以没有挂单。遍历工作量取决于订单和有供需变化的价位数,即使最小步长细化,空价位也无需逐档扫描。若调用方价格单位为分、市场仅允许每 10 分一档,使用 opening_with_step(10),输入委托须已对齐。同样的供需变化在买价 50 分之后要到 60 分才生效。
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{"op":"list","id":"market","market":"e","rules":"Simulated binary result","tick_size":"0.001"}
|
||||||
|
{"op":"fund","id":"maker","account":"maker","cents":800}
|
||||||
|
{"op":"fund","id":"buyer","account":"buyer","cents":200}
|
||||||
|
{"op":"split","id":"split","market":"e","account":"maker","qty":7}
|
||||||
|
{"op":"open","id":"open","market":"e"}
|
||||||
|
{"op":"order","id":"maker-ask","market":"e","account":"maker","outcome":"YES","side":"sell","price_micros":13000,"qty":6}
|
||||||
|
{"op":"price","token_id":"eb:YES:e","side":"BUY"}
|
||||||
|
{"op":"order","id":"buy","market":"e","account":"buyer","outcome":"YES","side":"buy","price_micros":14000,"size_micros":5129999,"tif":"FOK"}
|
||||||
|
{"op":"balance","account":"buyer"}
|
||||||
|
{"op":"estimate","asset_id":"eb:YES:e","side":"buy","max_price_micros":13000,"amount_cents":1}
|
||||||
|
{"op":"market_buy","id":"cash","market":"e","outcome":"YES","account":"buyer","max_price_micros":13000,"amount_cents":1}
|
||||||
|
{"op":"cancel","id":"cancel","order":1,"account":"maker"}
|
||||||
|
{"op":"order","id":"no-bid","market":"e","account":"maker","outcome":"NO","side":"buy","price_micros":987000,"size_micros":1010000}
|
||||||
|
{"op":"order","id":"yes-bid","market":"e","account":"buyer","outcome":"YES","side":"buy","price_micros":13000,"size_micros":1010000}
|
||||||
|
{"op":"history","market":"e","outcome":"NO","from_ms":0,"to_ms":9000000000000,"limit":10}
|
||||||
@@ -107,7 +107,7 @@ Polymarket 的 CTF 市场使用结果 token ID,Protocol V2 市场使用结果
|
|||||||
|
|
||||||
`{"op":"market_buy","id":"cash-buy-1","asset_id":"eb:YES:e","account":"buyer","amount_cents":170,"max_price":50,"tif":"FAK"}` 在连续交易阶段锁定 170 分预算。若最优卖单为 35 分两份,下一档为 NO 买单映射出的 45 分三份,则成交 4.22 份,实付 169.90 分,退回 0.10 分。订单可查到原始金额和实付金额;精确查询中的 original_size 是本地换算后的成交份数。操作接受现有 market / outcome 寻址,max_price 为每份最高可接受分价。FAK 为本地默认值;剩余预算即时撤销,有余款的回执 status 为 cancelled,filled 保留实际成交份数。
|
`{"op":"market_buy","id":"cash-buy-1","asset_id":"eb:YES:e","account":"buyer","amount_cents":170,"max_price":50,"tif":"FAK"}` 在连续交易阶段锁定 170 分预算。若最优卖单为 35 分两份,下一档为 NO 买单映射出的 45 分三份,则成交 4.22 份,实付 169.90 分,退回 0.10 分。订单可查到原始金额和实付金额;精确查询中的 original_size 是本地换算后的成交份数。操作接受现有 market / outcome 寻址,max_price 为每份最高可接受分价。FAK 为本地默认值;剩余预算即时撤销,有余款的回执 status 为 cancelled,filled 保留实际成交份数。
|
||||||
|
|
||||||
FOK 要求整笔金额成交,无法用完预算时交易回滚。超过最高价、没有可负担份额、账户可用现金不足以预留全部预算时也拒绝。买方按预算预留,遇较优成交价时只产生一次未花金额退款。当前撮合单位为整数份和整分价格,手续费另按五位小数计算。外场小数份额、签名舍入和实际零碎余量行为仍待对照。测试入口为 cash_buy_reconciles_direct_and_complementary_depth_with_an_exact_budget。[Polymarket 市价单与金额口径](https://docs.polymarket.com/trading/place-orders.md)
|
FOK 要求整笔金额成交,无法用完预算时交易回滚。超过最高价、没有可负担份额、账户可用现金不足以预留全部预算时也拒绝。买方按预算预留,遇较优成交价时只产生一次未花金额退款。当前撮合单位为 0.01 份,价格按市场步长校验,手续费另按五位小数计算。外场小数份额、签名舍入和实际零碎余量行为仍待对照。测试入口为 cash_buy_reconciles_direct_and_complementary_depth_with_an_exact_budget。[Polymarket 市价单与金额口径](https://docs.polymarket.com/trading/place-orders.md)
|
||||||
|
|
||||||
## 市价保护价与预估
|
## 市价保护价与预估
|
||||||
|
|
||||||
@@ -235,9 +235,9 @@ list 接受十进制份额字符串,最多六位小数;book、assets 和事
|
|||||||
|
|
||||||
list 可传 tick_size 字符串。资产、盘口与赛事目录返回配置的步长。当前支持 0.1、0.01、0.005、0.0025、0.001、0.0001 美元。配置市场的委托价及市价单保护价必须在 [tick, 1−tick] 且为步长的整数倍。官方对 0.0025 的应用限定于指定世界杯盘型;模拟市场允许操作员配置六种网格,未按赛事资格过滤。上架后的步长可随本地 tick_size_change 命令更新。生产 WebSocket 订阅及资产映射仍待接入。未配置的旧盘返回 null,延续原有整分交易范围。[官方交易约束](https://docs.polymarket.com/market-data/market-details.md#trading-constraints)
|
list 可传 tick_size 字符串。资产、盘口与赛事目录返回配置的步长。当前支持 0.1、0.01、0.005、0.0025、0.001、0.0001 美元。配置市场的委托价及市价单保护价必须在 [tick, 1−tick] 且为步长的整数倍。官方对 0.0025 的应用限定于指定世界杯盘型;模拟市场允许操作员配置六种网格,未按赛事资格过滤。上架后的步长可随本地 tick_size_change 命令更新。生产 WebSocket 订阅及资产映射仍待接入。未配置的旧盘返回 null,延续原有整分交易范围。[官方交易约束](https://docs.polymarket.com/market-data/market-details.md#trading-constraints)
|
||||||
|
|
||||||
[限价金额重放样例](examples/tick-size.jsonl)使用 Gamma 市场 559651 曾公开的 0.001 步长和 0.013 报价。limit_amounts 接收整数 price_micros 和 size_micros,后者向下取到百分之一份后检查最小份额。5.129999 份得到 5.12 份,抵押金额为 0.06656 模拟美元。买单的 makerAmount 为字符串 66560,takerAmount 为 5120000,卖单反向。回执的 local_precision_supported 仅描述价格和舍入后数量能否经现有整分价格、百分之一份的订单入口表示。预览不预留资金,不签名、不发送外场订单。官方六档的价格小数位数加两位份额精度均不超过六位,网格上的上述整数乘法可精确编码。[官方限价金额映射](https://docs.polymarket.com/trading/place-orders.md#limit-orders)
|
[限价金额重放样例](examples/tick-size.jsonl)使用 Gamma 市场 559651 曾公开的 0.001 步长和 0.013 报价。limit_amounts 接收整数 price_micros 和 size_micros,后者向下取到百分之一份后检查最小份额。5.129999 份得到 5.12 份,抵押金额为 0.06656 模拟美元。买单的 makerAmount 为字符串 66560,takerAmount 为 5120000,卖单反向。回执的 local_precision_supported 仅描述价格和舍入后数量能否经现有 price_micros、size_micros 订单入口表示。预览不预留资金,不签名、不发送外场订单。官方六档的价格小数位数加两位份额精度均不超过六位,网格上的上述整数乘法可精确编码。[官方限价金额映射](https://docs.polymarket.com/trading/place-orders.md#limit-orders)
|
||||||
|
|
||||||
样例还包含一个步长 0.1 的本地集合竞价。50 分卖 2 份,对手分别以 50 分买 3 份、70 分买 2 份,开盘以 60 分成交 2 份。同一组订单若步长为 1 分,开盘价是 51 分。细于一分的市场目前只接受其与整分网格重合的本地委托价格。
|
样例还包含一个步长 0.1 的本地集合竞价。50 分卖 2 份,对手分别以 50 分买 3 份、70 分买 2 份,开盘以 60 分成交 2 份。同一组订单若步长为 1 分,开盘价是 51 分。细于一分的市场使用相应网格选择开盘成交价。
|
||||||
|
|
||||||
## 步长变更的顺序与恢复
|
## 步长变更的顺序与恢复
|
||||||
|
|
||||||
@@ -261,8 +261,15 @@ book 的 tick_seq 与盘口快照同事务读取。客户端使用 tick_history
|
|||||||
|
|
||||||
## 百分之一份委托
|
## 百分之一份委托
|
||||||
|
|
||||||
order、market_sell 和卖出 estimate 可用 size_micros 输入数量,也可以用 qty 表示整份。输入 1,239,999 微份会截为 1.23 份,再检查市场门槛。整分报价下,每一笔成交金额都能精确换算为微美元。实际分配、资金或份额预留、部分成交撤单、互补成交与重启恢复共用一个数量单位。预算买入也能吃到部分份额。以 0.52 报价的现金市单在官方文档中可编码到四位小数份额;目前模拟预算买单的执行粒度为 0.01 份,细于一分的报价仍只可预览。[官方委托精度与市价单样例](https://docs.polymarket.com/trading/place-orders.md)
|
order、market_sell 和卖出 estimate 可用 size_micros 输入数量,也可以用 qty 表示整份。输入 1,239,999 微份会截为 1.23 份,再检查市场门槛。在支持的六种价格网格上,每一笔成交金额都能精确换算为微美元。实际分配、资金或份额预留、部分成交撤单、互补成交与重启恢复共用一个数量单位。预算买入也能吃到部分份额。以 0.52 报价的现金市单在官方文档中可编码到四位小数份额;目前模拟预算买单的执行粒度为 0.01 份。[官方委托精度与市价单样例](https://docs.polymarket.com/trading/place-orders.md)
|
||||||
|
|
||||||
[可重放样例](examples/fractional-orders.jsonl)中,1.239999 份委托按 1.23 份入簿。开盘成交 0.50 份,盘中成交 0.29 份,剩余 0.44 份可撤回。
|
[可重放样例](examples/fractional-orders.jsonl)中,1.239999 份委托按 1.23 份入簿。开盘成交 0.50 份,盘中成交 0.29 份,剩余 0.44 份可撤回。
|
||||||
|
|
||||||
升级已有 SQLite 文件前须停止使用旧版的所有进程。首次用新版打开时,订单、普通成交、互补成交和成交曲线中的历史数量在同一写事务内乘以 100,旧回执保持原文。同一文件由多个新版进程打开时只转换一次。升级后的文件不能与按整份解释原始列的旧程序共用。
|
升级已有 SQLite 文件前须停止使用旧版的所有进程。首次用新版打开时,订单、普通成交、互补成交和成交曲线中的历史数量在同一写事务内乘以 100,旧回执保持原文。同一文件由多个新版进程打开时只转换一次。升级后的文件不能与按整份解释原始列的旧程序共用。
|
||||||
|
|
||||||
|
|
||||||
|
## 细步长价格成交
|
||||||
|
|
||||||
|
[逐行样例](examples/fine-price-execution.jsonl)中,买单限价 0.014 美元,实际按在先卖价 0.013 成交 5.12 份,成交额为 66,560 微美元。接着用 1 美分预算最多再买 0.76 份,实付 9,880 微美元,退回 120 微美元。YES 和 NO 的互补价格相加为 1 美元。已有整分输入 price、min_price、max_price 继续可用,也可以分别传 price_micros、min_price_micros、max_price_micros,每组择一。缺少已配置步长的旧盘沿用整分钱格。本地样例只使用模拟资金。生产撮合回执、手续费和到账顺序仍需对照。[官方限价和保护价定义](https://docs.polymarket.com/trading/place-orders.md)
|
||||||
|
|
||||||
|
首次升级价格格式需要停止旧版写入进程。新版在一个 SQLite 写事务内迁移订单价格、历史成交、报价和最近成交缓存。已经以微美元保存的价格曲线及其时间戳保持原始记录。迁移完成后只使用新版重新打开该数据库。
|
||||||
|
|||||||
Reference in New Issue
Block a user