fix(hub): align Binance chart ticks and improve monitor mark price
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,7 +8,7 @@ from pathlib import Path
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "manual_trading_hub"))
|
||||
|
||||
from agent import _position_mark_price # noqa: E402
|
||||
from agent import _position_mark_price, _ticker_mark_price # noqa: E402
|
||||
|
||||
|
||||
class TestHubAgentMarkPrice(unittest.TestCase):
|
||||
@@ -27,6 +27,18 @@ class TestHubAgentMarkPrice(unittest.TestCase):
|
||||
def test_missing_returns_none(self):
|
||||
self.assertIsNone(_position_mark_price({"info": {}}))
|
||||
|
||||
def test_infer_from_notional_and_contracts(self):
|
||||
p = {"notional": 1000, "contracts": 10, "info": {}}
|
||||
px = _position_mark_price(p)
|
||||
self.assertAlmostEqual(px, 100.0)
|
||||
|
||||
def test_ticker_fallback(self):
|
||||
class _Ex:
|
||||
def fetch_ticker(self, sym):
|
||||
return {"mark": 99.5, "info": {}}
|
||||
|
||||
self.assertAlmostEqual(_ticker_mark_price(_Ex(), "BTC/USDT:USDT"), 99.5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -54,6 +54,35 @@ class TestHubOhlcvLib(unittest.TestCase):
|
||||
)
|
||||
self.assertAlmostEqual(tick, 0.01)
|
||||
|
||||
def test_price_tick_from_binance_price_filter(self):
|
||||
class _Ex:
|
||||
markets = {
|
||||
"BTC/USDT:USDT": {
|
||||
"precision": {"price": 2},
|
||||
"info": {
|
||||
"filters": [
|
||||
{"filterType": "PRICE_FILTER", "tickSize": "0.10"},
|
||||
{"filterType": "LOT_SIZE", "stepSize": "0.001"},
|
||||
]
|
||||
},
|
||||
"limits": {},
|
||||
}
|
||||
}
|
||||
|
||||
def load_markets(self):
|
||||
return self.markets
|
||||
|
||||
def market(self, sym):
|
||||
return self.markets[sym]
|
||||
|
||||
def price_to_precision(self, sym, price):
|
||||
return "12345.6"
|
||||
|
||||
from hub_ohlcv_lib import price_tick_from_market
|
||||
|
||||
tick = price_tick_from_market(_Ex(), "BTC/USDT:USDT")
|
||||
self.assertAlmostEqual(tick, 0.10)
|
||||
|
||||
def test_price_tick_from_info_tick_size(self):
|
||||
class _Ex:
|
||||
markets = {
|
||||
|
||||
Reference in New Issue
Block a user