poly-position-watcher 0.3.2__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {poly_position_watcher-0.3.2/poly_position_watcher.egg-info → poly_position_watcher-0.3.3}/PKG-INFO +1 -1
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/_version.py +1 -1
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/position_service.py +12 -3
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3/poly_position_watcher.egg-info}/PKG-INFO +1 -1
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/pyproject.toml +1 -1
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/tests/test_position_model.py +23 -4
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/LICENSE +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/MANIFEST.in +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/README.md +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/__init__.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/api_worker.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/common/__init__.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/common/enums.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/common/logger.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/schema/__init__.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/schema/base.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/schema/common_model.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/schema/position_model.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/trade_calculator.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/wss_worker.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher.egg-info/SOURCES.txt +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher.egg-info/dependency_links.txt +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher.egg-info/requires.txt +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher.egg-info/top_level.txt +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/setup.cfg +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/setup.py +0 -0
- {poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/tests/test_trade_calculator.py +0 -0
|
@@ -56,6 +56,7 @@ class PositionStore:
|
|
|
56
56
|
self.trades_by_token: Dict[str, Dict[str, TradeMessage]] = defaultdict(dict)
|
|
57
57
|
self.positions: Dict[str, UserPosition] = {}
|
|
58
58
|
self.orders: Dict[str, OrderMessage] = {}
|
|
59
|
+
self._warned_failed_trade_keys: set[tuple[str, str]] = set()
|
|
59
60
|
self._lock = threading.RLock()
|
|
60
61
|
self.queue_dict: Dict[str, Queue] = {}
|
|
61
62
|
|
|
@@ -201,9 +202,17 @@ class PositionStore:
|
|
|
201
202
|
i for i in success_trades if _status_is(i, TradeStatus.CONFIRMED)
|
|
202
203
|
]
|
|
203
204
|
has_failed = bool(len(failed_trades))
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
new_failed_trades = [
|
|
206
|
+
trade
|
|
207
|
+
for trade in failed_trades
|
|
208
|
+
if (token_id, trade.id) not in self._warned_failed_trade_keys
|
|
209
|
+
]
|
|
210
|
+
if new_failed_trades:
|
|
211
|
+
self._warned_failed_trade_keys.update(
|
|
212
|
+
(token_id, trade.id) for trade in new_failed_trades
|
|
213
|
+
)
|
|
214
|
+
failed_size = sum(i.size for i in new_failed_trades)
|
|
215
|
+
failed_trade_ids = [trade.id for trade in new_failed_trades]
|
|
207
216
|
logger.warning(
|
|
208
217
|
"Found failed trades, total size: {}, ids: {}",
|
|
209
218
|
failed_size,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import unittest
|
|
4
|
+
from unittest.mock import patch
|
|
4
5
|
|
|
6
|
+
from poly_position_watcher.position_service import PositionStore
|
|
5
7
|
from poly_position_watcher.schema.position_model import TradeMessage, UserPosition
|
|
6
8
|
|
|
7
9
|
|
|
8
|
-
def
|
|
10
|
+
def build_trade(trade_id: str, status: str = "FAILED", size: float = 10.0) -> TradeMessage:
|
|
9
11
|
return TradeMessage(
|
|
10
12
|
type="TRADE",
|
|
11
13
|
event_type="trade",
|
|
@@ -19,8 +21,8 @@ def build_failed_trade(trade_id: str) -> TradeMessage:
|
|
|
19
21
|
owner="0xuser",
|
|
20
22
|
price=0.25,
|
|
21
23
|
side="BUY",
|
|
22
|
-
size=
|
|
23
|
-
status=
|
|
24
|
+
size=size,
|
|
25
|
+
status=status,
|
|
24
26
|
taker_order_id=f"0xorder-{trade_id}",
|
|
25
27
|
timestamp=1,
|
|
26
28
|
match_time=1,
|
|
@@ -46,7 +48,7 @@ class UserPositionTests(unittest.TestCase):
|
|
|
46
48
|
market_id="0xmarket",
|
|
47
49
|
outcome="YES",
|
|
48
50
|
has_failed=True,
|
|
49
|
-
failed_trades=[
|
|
51
|
+
failed_trades=[build_trade("failed-1"), build_trade("failed-2")],
|
|
50
52
|
)
|
|
51
53
|
|
|
52
54
|
self.assertEqual(position.failed_trade_ids, ["failed-1", "failed-2"])
|
|
@@ -54,6 +56,23 @@ class UserPositionTests(unittest.TestCase):
|
|
|
54
56
|
self.assertIn("failed_trades: ['failed-1', 'failed-2']", rendered)
|
|
55
57
|
self.assertNotIn("transaction_hash", rendered)
|
|
56
58
|
|
|
59
|
+
def test_failed_trade_warning_logs_once_per_token_and_trade_id(self) -> None:
|
|
60
|
+
store = PositionStore(user_address="0xuser")
|
|
61
|
+
trades = [
|
|
62
|
+
build_trade("confirmed-1", status="CONFIRMED", size=5.0),
|
|
63
|
+
build_trade("failed-1", status="FAILED", size=10.0),
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
with patch("poly_position_watcher.position_service.logger.warning") as warning:
|
|
67
|
+
store.build_position(trades=trades, token_id="0xtoken", outcome="YES")
|
|
68
|
+
store.build_position(trades=trades, token_id="0xtoken", outcome="YES")
|
|
69
|
+
|
|
70
|
+
warning.assert_called_once_with(
|
|
71
|
+
"Found failed trades, total size: {}, ids: {}",
|
|
72
|
+
10.0,
|
|
73
|
+
["failed-1"],
|
|
74
|
+
)
|
|
75
|
+
|
|
57
76
|
|
|
58
77
|
if __name__ == "__main__":
|
|
59
78
|
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/__init__.py
RENAMED
|
File without changes
|
{poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/api_worker.py
RENAMED
|
File without changes
|
{poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/common/__init__.py
RENAMED
|
File without changes
|
{poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/common/enums.py
RENAMED
|
File without changes
|
{poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/common/logger.py
RENAMED
|
File without changes
|
{poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/schema/__init__.py
RENAMED
|
File without changes
|
{poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/schema/base.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{poly_position_watcher-0.3.2 → poly_position_watcher-0.3.3}/poly_position_watcher/wss_worker.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|