Align option display precision with OKX and use exchange position history.
Format prices by tickSz, move bid depth/recovery to card end with plain styling, and load option history from OKX positions-history instead of local DB. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,11 +1,44 @@
|
||||
"""期权平仓/到期状态同步单测."""
|
||||
import sqlite3
|
||||
|
||||
from lib.exchange.okx_options_lib import resolve_option_close_from_history
|
||||
from lib.exchange.okx_options_lib import (
|
||||
format_option_history_row,
|
||||
format_usdc_amount,
|
||||
resolve_option_close_from_history,
|
||||
)
|
||||
from lib.options.options_db import init_options_tables
|
||||
from lib.options.options_monitor_lib import sync_open_options_trades
|
||||
|
||||
|
||||
def test_format_usdc_amount():
|
||||
assert format_usdc_amount(4.896) == "4.896"
|
||||
assert format_usdc_amount(4.90) == "4.9"
|
||||
assert format_usdc_amount(4.0) == "4"
|
||||
|
||||
|
||||
def test_format_option_history_row():
|
||||
raw = {
|
||||
"instId": "BTC-USD_UM-260710-62000-P",
|
||||
"openAvgPx": "380",
|
||||
"closeAvgPx": "0",
|
||||
"closeTotalPos": "1",
|
||||
"openMaxPos": "1",
|
||||
"realizedPnl": "-3.99",
|
||||
"pnlRatio": "-1.049",
|
||||
"type": "2",
|
||||
"cTime": "1784000000000",
|
||||
"uTime": "1784088035000",
|
||||
"posId": "pos-btc",
|
||||
}
|
||||
row = format_option_history_row(raw, tick_sz="0.1", ct_mult=0.01)
|
||||
assert row["inst_id"] == "BTC-USD_UM-260710-62000-P"
|
||||
assert row["sheets"] == 1
|
||||
assert row["realized_pnl"] == -3.99
|
||||
assert row["status_label"] == "已平"
|
||||
assert row["open_avg_px_fmt"] == "380"
|
||||
assert row["premium_paid_fmt"] == "3.8"
|
||||
|
||||
|
||||
def test_resolve_option_close_from_history_picks_latest():
|
||||
rows = [
|
||||
{"instId": "ETH-USD_UM-260709-1700-P", "uTime": "1000", "realizedPnl": "-1.0", "closeAvgPx": "0"},
|
||||
|
||||
Reference in New Issue
Block a user