28
28
from typing import Any , Dict , List , Optional , Union
29
29
30
30
31
+ YES = "yes"
32
+ NO = "no"
31
33
P_YES_FIELD = "p_yes"
32
34
P_NO_FIELD = "p_no"
33
35
CONFIDENCE_FIELD = "confidence"
@@ -136,18 +138,59 @@ class Bet:
136
138
prediction_response : PredictionResponse = dataclasses .field (
137
139
default_factory = get_default_prediction_response
138
140
)
139
- invested_amount : int = 0
140
141
position_liquidity : int = 0
141
142
potential_net_profit : int = 0
142
143
processed_timestamp : int = 0
143
- n_bets : int = 0
144
144
queue_status : QueueStatus = QueueStatus .FRESH
145
+ # a mapping from vote to investment amounts
146
+ investments : Dict [str , List [int ]] = dataclasses .field (default_factory = dict )
147
+
148
+ @property
149
+ def yes_investments (self ) -> List [int ]:
150
+ """Get the yes investments."""
151
+ return self .investments [self .yes ]
152
+
153
+ @property
154
+ def no_investments (self ) -> List [int ]:
155
+ """Get the no investments."""
156
+ return self .investments [self .no ]
157
+
158
+ @property
159
+ def n_yes_bets (self ) -> int :
160
+ """Get the number of yes bets."""
161
+ return len (self .yes_investments )
162
+
163
+ @property
164
+ def n_no_bets (self ) -> int :
165
+ """Get the number of no bets."""
166
+ return len (self .no_investments )
167
+
168
+ @property
169
+ def n_bets (self ) -> int :
170
+ """Get the number of bets."""
171
+ return self .n_yes_bets + self .n_no_bets
172
+
173
+ @property
174
+ def invested_amount_yes (self ) -> int :
175
+ """Get the amount invested in yes bets."""
176
+ return sum (self .yes_investments )
177
+
178
+ @property
179
+ def invested_amount_no (self ) -> int :
180
+ """Get the amount invested in no bets."""
181
+ return sum (self .no_investments )
182
+
183
+ @property
184
+ def invested_amount (self ) -> int :
185
+ """Get the amount invested in bets."""
186
+ return self .invested_amount_yes + self .invested_amount_no
145
187
146
188
def __post_init__ (self ) -> None :
147
189
"""Post initialization to adjust the values."""
148
190
self ._validate ()
149
191
self ._cast ()
150
192
self ._check_usefulness ()
193
+ self .investments = {self .yes : [], self .no : []}
151
194
152
195
def __lt__ (self , other : "Bet" ) -> bool :
153
196
"""Implements less than operator."""
@@ -225,7 +268,7 @@ def _get_binary_outcome(self, no: bool) -> str:
225
268
"""Get an outcome only if it is binary."""
226
269
if self .outcomeSlotCount == BINARY_N_SLOTS :
227
270
return self .get_outcome (int (no ))
228
- requested_outcome = "no" if no else "yes"
271
+ requested_outcome = NO if no else YES
229
272
error = (
230
273
f"A { requested_outcome !r} outcome is only available for binary questions."
231
274
)
@@ -241,6 +284,17 @@ def no(self) -> str:
241
284
"""Return the "no" outcome."""
242
285
return self ._get_binary_outcome (True )
243
286
287
+ def update_investments (self , amount : int ) -> bool :
288
+ """Get the investments for the current vote type."""
289
+ vote = self .prediction_response .vote
290
+ if vote is None :
291
+ return False
292
+
293
+ vote_name = self .get_outcome (vote )
294
+ to_update = self .investments [vote_name ]
295
+ to_update .append (amount )
296
+ return True
297
+
244
298
def update_market_info (self , bet : "Bet" ) -> None :
245
299
"""Update the bet's market information."""
246
300
if (
0 commit comments