prediction-market-agent-tooling 0.62.0.dev469__py3-none-any.whl → 0.62.0.dev471__py3-none-any.whl
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.
- prediction_market_agent_tooling/deploy/betting_strategy.py +4 -4
- prediction_market_agent_tooling/gtypes.py +8 -8
- prediction_market_agent_tooling/markets/agent_market.py +20 -20
- prediction_market_agent_tooling/markets/data_models.py +11 -11
- prediction_market_agent_tooling/markets/manifold/data_models.py +9 -9
- prediction_market_agent_tooling/markets/manifold/manifold.py +8 -3
- prediction_market_agent_tooling/markets/market_fees.py +5 -3
- prediction_market_agent_tooling/markets/omen/data_models.py +8 -8
- prediction_market_agent_tooling/markets/omen/omen.py +15 -15
- prediction_market_agent_tooling/markets/polymarket/polymarket.py +2 -2
- prediction_market_agent_tooling/markets/seer/data_models.py +2 -2
- prediction_market_agent_tooling/markets/seer/seer.py +7 -7
- prediction_market_agent_tooling/tools/balances.py +9 -4
- prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +6 -6
- prediction_market_agent_tooling/tools/betting_strategies/market_moving.py +6 -2
- prediction_market_agent_tooling/tools/betting_strategies/utils.py +2 -2
- prediction_market_agent_tooling/tools/contract.py +2 -2
- prediction_market_agent_tooling/tools/cow/cow_manager.py +2 -2
- prediction_market_agent_tooling/tools/cow/cow_order.py +5 -0
- prediction_market_agent_tooling/tools/tokens/usd.py +6 -6
- prediction_market_agent_tooling/tools/utils.py +3 -3
- {prediction_market_agent_tooling-0.62.0.dev469.dist-info → prediction_market_agent_tooling-0.62.0.dev471.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.62.0.dev469.dist-info → prediction_market_agent_tooling-0.62.0.dev471.dist-info}/RECORD +26 -26
- {prediction_market_agent_tooling-0.62.0.dev469.dist-info → prediction_market_agent_tooling-0.62.0.dev471.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.62.0.dev469.dist-info → prediction_market_agent_tooling-0.62.0.dev471.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.62.0.dev469.dist-info → prediction_market_agent_tooling-0.62.0.dev471.dist-info}/entry_points.txt +0 -0
@@ -2,7 +2,7 @@ from abc import ABC, abstractmethod
|
|
2
2
|
|
3
3
|
from scipy.optimize import minimize_scalar
|
4
4
|
|
5
|
-
from prediction_market_agent_tooling.gtypes import USD,
|
5
|
+
from prediction_market_agent_tooling.gtypes import USD, CollateralToken, OutcomeToken
|
6
6
|
from prediction_market_agent_tooling.loggers import logger
|
7
7
|
from prediction_market_agent_tooling.markets.agent_market import AgentMarket, MarketFees
|
8
8
|
from prediction_market_agent_tooling.markets.data_models import (
|
@@ -209,7 +209,7 @@ class KellyBettingStrategy(BettingStrategy):
|
|
209
209
|
def calculate_price_impact_for_bet_amount(
|
210
210
|
self,
|
211
211
|
buy_direction: bool,
|
212
|
-
bet_amount:
|
212
|
+
bet_amount: CollateralToken,
|
213
213
|
yes: OutcomeToken,
|
214
214
|
no: OutcomeToken,
|
215
215
|
fees: MarketFees,
|
@@ -232,7 +232,7 @@ class KellyBettingStrategy(BettingStrategy):
|
|
232
232
|
self,
|
233
233
|
market: AgentMarket,
|
234
234
|
kelly_bet: SimpleBet,
|
235
|
-
) ->
|
235
|
+
) -> CollateralToken:
|
236
236
|
def calculate_price_impact_deviation_from_target_price_impact(
|
237
237
|
bet_amount_usd: float, # Needs to be float because it's used in minimize_scalar internally.
|
238
238
|
) -> float:
|
@@ -269,7 +269,7 @@ class KellyBettingStrategy(BettingStrategy):
|
|
269
269
|
tol=1e-11,
|
270
270
|
options={"maxiter": 10000},
|
271
271
|
)
|
272
|
-
return
|
272
|
+
return CollateralToken(optimized_bet_amount.x)
|
273
273
|
|
274
274
|
def __repr__(self) -> str:
|
275
275
|
return f"{self.__class__.__name__}(max_bet_amount={self.max_bet_amount}, max_price_impact={self.max_price_impact})"
|
@@ -27,7 +27,7 @@ from prediction_market_agent_tooling.tools.hexbytes_custom import ( # noqa: F40
|
|
27
27
|
)
|
28
28
|
|
29
29
|
|
30
|
-
class
|
30
|
+
class CollateralToken(_GenericValue[int | float | str | Decimal, float], parser=float):
|
31
31
|
"""
|
32
32
|
Represents any token in its decimal form, it could be 1.1 GNO, WXDAI, XDAI, Mana, whatever. We don't know the currency, just that it's in the decimal form.
|
33
33
|
"""
|
@@ -46,7 +46,7 @@ class OutcomeToken(_GenericValue[int | float | str | Decimal, float], parser=flo
|
|
46
46
|
"""
|
47
47
|
|
48
48
|
@staticmethod
|
49
|
-
def from_token(token:
|
49
|
+
def from_token(token: CollateralToken) -> "OutcomeToken":
|
50
50
|
return OutcomeToken(token.value)
|
51
51
|
|
52
52
|
@property
|
@@ -54,11 +54,11 @@ class OutcomeToken(_GenericValue[int | float | str | Decimal, float], parser=flo
|
|
54
54
|
return OutcomeWei(Web3.to_wei(self.value, "ether"))
|
55
55
|
|
56
56
|
@property
|
57
|
-
def as_token(self) ->
|
57
|
+
def as_token(self) -> CollateralToken:
|
58
58
|
"""
|
59
59
|
OutcomeToken is essentialy Token as well, when you know you really need to convert it, you can convert it explicitly using this.
|
60
60
|
"""
|
61
|
-
return
|
61
|
+
return CollateralToken(self.value)
|
62
62
|
|
63
63
|
|
64
64
|
class USD(_GenericValue[int | float | str | Decimal, float], parser=float):
|
@@ -69,11 +69,11 @@ class xDai(_GenericValue[int | float | str | Decimal, float], parser=float):
|
|
69
69
|
"""Represents values in xDai."""
|
70
70
|
|
71
71
|
@property
|
72
|
-
def as_token(self) ->
|
72
|
+
def as_token(self) -> CollateralToken:
|
73
73
|
"""
|
74
74
|
xDai is essentialy Token as well, when you know you need to pass it, you can convert it using this.
|
75
75
|
"""
|
76
|
-
return
|
76
|
+
return CollateralToken(self.value)
|
77
77
|
|
78
78
|
@property
|
79
79
|
def as_xdai_wei(self) -> "xDaiWei":
|
@@ -92,8 +92,8 @@ class Wei(_GenericValue[Web3Wei | int | str, Web3Wei], parser=int):
|
|
92
92
|
"""Represents values in Wei. We don't know what currency, but in its integer form called Wei."""
|
93
93
|
|
94
94
|
@property
|
95
|
-
def as_token(self) ->
|
96
|
-
return
|
95
|
+
def as_token(self) -> CollateralToken:
|
96
|
+
return CollateralToken(Web3.from_wei(self.value, "ether"))
|
97
97
|
|
98
98
|
|
99
99
|
class OutcomeWei(_GenericValue[Web3Wei | int | str, Web3Wei], parser=int):
|
@@ -7,20 +7,20 @@ from pydantic_core.core_schema import FieldValidationInfo
|
|
7
7
|
|
8
8
|
from prediction_market_agent_tooling.config import APIKeys
|
9
9
|
from prediction_market_agent_tooling.gtypes import (
|
10
|
+
CollateralToken,
|
10
11
|
OutcomeStr,
|
11
12
|
OutcomeToken,
|
12
13
|
Probability,
|
13
|
-
Token,
|
14
14
|
)
|
15
15
|
from prediction_market_agent_tooling.markets.data_models import (
|
16
16
|
USD,
|
17
17
|
Bet,
|
18
|
+
CollateralToken,
|
18
19
|
ExistingPosition,
|
19
20
|
PlacedTrade,
|
20
21
|
ProbabilisticAnswer,
|
21
22
|
Resolution,
|
22
23
|
ResolvedBet,
|
23
|
-
Token,
|
24
24
|
)
|
25
25
|
from prediction_market_agent_tooling.markets.market_fees import MarketFees
|
26
26
|
from prediction_market_agent_tooling.tools.utils import (
|
@@ -71,7 +71,7 @@ class AgentMarket(BaseModel):
|
|
71
71
|
close_time: DatetimeUTC | None
|
72
72
|
current_p_yes: Probability
|
73
73
|
url: str
|
74
|
-
volume:
|
74
|
+
volume: CollateralToken | None
|
75
75
|
fees: MarketFees
|
76
76
|
|
77
77
|
@field_validator("outcome_token_pool")
|
@@ -103,24 +103,24 @@ class AgentMarket(BaseModel):
|
|
103
103
|
return Probability(1 - self.current_p_yes)
|
104
104
|
|
105
105
|
@property
|
106
|
-
def yes_outcome_price(self) ->
|
106
|
+
def yes_outcome_price(self) -> CollateralToken:
|
107
107
|
"""
|
108
108
|
Price at prediction market is equal to the probability of given outcome.
|
109
109
|
Keep as an extra property, in case it wouldn't be true for some prediction market platform.
|
110
110
|
"""
|
111
|
-
return
|
111
|
+
return CollateralToken(self.current_p_yes)
|
112
112
|
|
113
113
|
@property
|
114
114
|
def yes_outcome_price_usd(self) -> USD:
|
115
115
|
return self.get_token_in_usd(self.yes_outcome_price)
|
116
116
|
|
117
117
|
@property
|
118
|
-
def no_outcome_price(self) ->
|
118
|
+
def no_outcome_price(self) -> CollateralToken:
|
119
119
|
"""
|
120
120
|
Price at prediction market is equal to the probability of given outcome.
|
121
121
|
Keep as an extra property, in case it wouldn't be true for some prediction market platform.
|
122
122
|
"""
|
123
|
-
return
|
123
|
+
return CollateralToken(self.current_p_no)
|
124
124
|
|
125
125
|
@property
|
126
126
|
def no_outcome_price_usd(self) -> USD:
|
@@ -159,11 +159,11 @@ class AgentMarket(BaseModel):
|
|
159
159
|
"""
|
160
160
|
raise NotImplementedError("Subclasses must implement this method")
|
161
161
|
|
162
|
-
def get_last_trade_yes_outcome_price(self) ->
|
162
|
+
def get_last_trade_yes_outcome_price(self) -> CollateralToken | None:
|
163
163
|
# Price on prediction markets are, by definition, equal to the probability of an outcome.
|
164
164
|
# Just making it explicit in this function.
|
165
165
|
if last_trade_p_yes := self.get_last_trade_p_yes():
|
166
|
-
return
|
166
|
+
return CollateralToken(last_trade_p_yes)
|
167
167
|
return None
|
168
168
|
|
169
169
|
def get_last_trade_yes_outcome_price_usd(self) -> USD | None:
|
@@ -171,11 +171,11 @@ class AgentMarket(BaseModel):
|
|
171
171
|
return self.get_token_in_usd(last_trade_yes_outcome_price)
|
172
172
|
return None
|
173
173
|
|
174
|
-
def get_last_trade_no_outcome_price(self) ->
|
174
|
+
def get_last_trade_no_outcome_price(self) -> CollateralToken | None:
|
175
175
|
# Price on prediction markets are, by definition, equal to the probability of an outcome.
|
176
176
|
# Just making it explicit in this function.
|
177
177
|
if last_trade_p_no := self.get_last_trade_p_no():
|
178
|
-
return
|
178
|
+
return CollateralToken(last_trade_p_no)
|
179
179
|
return None
|
180
180
|
|
181
181
|
def get_last_trade_no_outcome_price_usd(self) -> USD | None:
|
@@ -187,13 +187,13 @@ class AgentMarket(BaseModel):
|
|
187
187
|
tiny_amount = self.get_tiny_bet_amount()
|
188
188
|
return OutcomeToken.from_token(tiny_amount / 10)
|
189
189
|
|
190
|
-
def get_token_in_usd(self, x:
|
190
|
+
def get_token_in_usd(self, x: CollateralToken) -> USD:
|
191
191
|
"""
|
192
192
|
Token of this market can have whatever worth (e.g. sDai and ETH markets will have different worth of 1 token). Use this to convert it to USD.
|
193
193
|
"""
|
194
194
|
raise NotImplementedError("Subclasses must implement this method")
|
195
195
|
|
196
|
-
def get_usd_in_token(self, x: USD) ->
|
196
|
+
def get_usd_in_token(self, x: USD) -> CollateralToken:
|
197
197
|
"""
|
198
198
|
Markets on a single platform can have different tokens as collateral (sDai, wxDai, GNO, ...). Use this to convert USD to the token of this market.
|
199
199
|
"""
|
@@ -201,24 +201,24 @@ class AgentMarket(BaseModel):
|
|
201
201
|
|
202
202
|
def get_sell_value_of_outcome_token(
|
203
203
|
self, outcome: str, amount: OutcomeToken
|
204
|
-
) ->
|
204
|
+
) -> CollateralToken:
|
205
205
|
"""
|
206
206
|
When you hold OutcomeToken(s), it's easy to calculate how much you get at the end if you win (1 OutcomeToken will equal to 1 Token).
|
207
207
|
But use this to figure out, how much are these outcome tokens worth right now (for how much you can sell them).
|
208
208
|
"""
|
209
209
|
raise NotImplementedError("Subclasses must implement this method")
|
210
210
|
|
211
|
-
def get_in_usd(self, x: USD |
|
211
|
+
def get_in_usd(self, x: USD | CollateralToken) -> USD:
|
212
212
|
if isinstance(x, USD):
|
213
213
|
return x
|
214
214
|
return self.get_token_in_usd(x)
|
215
215
|
|
216
|
-
def get_in_token(self, x: USD |
|
217
|
-
if isinstance(x,
|
216
|
+
def get_in_token(self, x: USD | CollateralToken) -> CollateralToken:
|
217
|
+
if isinstance(x, CollateralToken):
|
218
218
|
return x
|
219
219
|
return self.get_usd_in_token(x)
|
220
220
|
|
221
|
-
def get_tiny_bet_amount(self) ->
|
221
|
+
def get_tiny_bet_amount(self) -> CollateralToken:
|
222
222
|
"""
|
223
223
|
Tiny bet amount that the platform still allows us to do.
|
224
224
|
"""
|
@@ -234,7 +234,7 @@ class AgentMarket(BaseModel):
|
|
234
234
|
return self.place_bet(outcome=outcome, amount=amount)
|
235
235
|
|
236
236
|
def get_buy_token_amount(
|
237
|
-
self, bet_amount: USD |
|
237
|
+
self, bet_amount: USD | CollateralToken, direction: bool
|
238
238
|
) -> OutcomeToken:
|
239
239
|
raise NotImplementedError("Subclasses must implement this method")
|
240
240
|
|
@@ -319,7 +319,7 @@ class AgentMarket(BaseModel):
|
|
319
319
|
def is_resolved(self) -> bool:
|
320
320
|
return self.resolution is not None
|
321
321
|
|
322
|
-
def get_liquidity(self) ->
|
322
|
+
def get_liquidity(self) -> CollateralToken:
|
323
323
|
raise NotImplementedError("Subclasses must implement this method")
|
324
324
|
|
325
325
|
def has_liquidity(self) -> bool:
|
@@ -5,10 +5,10 @@ from pydantic import BaseModel, BeforeValidator, computed_field
|
|
5
5
|
|
6
6
|
from prediction_market_agent_tooling.gtypes import (
|
7
7
|
USD,
|
8
|
+
CollateralToken,
|
8
9
|
OutcomeStr,
|
9
10
|
OutcomeToken,
|
10
11
|
Probability,
|
11
|
-
Token,
|
12
12
|
)
|
13
13
|
from prediction_market_agent_tooling.tools.utils import DatetimeUTC
|
14
14
|
|
@@ -26,7 +26,7 @@ class Resolution(str, Enum):
|
|
26
26
|
|
27
27
|
class Bet(BaseModel):
|
28
28
|
id: str
|
29
|
-
amount:
|
29
|
+
amount: CollateralToken
|
30
30
|
outcome: bool
|
31
31
|
created_time: DatetimeUTC
|
32
32
|
market_question: str
|
@@ -39,7 +39,7 @@ class Bet(BaseModel):
|
|
39
39
|
class ResolvedBet(Bet):
|
40
40
|
market_outcome: bool
|
41
41
|
resolved_time: DatetimeUTC
|
42
|
-
profit:
|
42
|
+
profit: CollateralToken
|
43
43
|
|
44
44
|
@computed_field # type: ignore[prop-decorator]
|
45
45
|
@property
|
@@ -145,12 +145,12 @@ class SimulatedBetDetail(BaseModel):
|
|
145
145
|
market_p_yes: float
|
146
146
|
agent_p_yes: float
|
147
147
|
agent_conf: float
|
148
|
-
org_bet:
|
149
|
-
sim_bet:
|
148
|
+
org_bet: CollateralToken
|
149
|
+
sim_bet: CollateralToken
|
150
150
|
org_dir: bool
|
151
151
|
sim_dir: bool
|
152
|
-
org_profit:
|
153
|
-
sim_profit:
|
152
|
+
org_profit: CollateralToken
|
153
|
+
sim_profit: CollateralToken
|
154
154
|
timestamp: DatetimeUTC
|
155
155
|
|
156
156
|
|
@@ -162,10 +162,10 @@ class SharpeOutput(BaseModel):
|
|
162
162
|
|
163
163
|
class SimulatedLifetimeDetail(BaseModel):
|
164
164
|
p_yes_mse: float
|
165
|
-
total_bet_amount:
|
166
|
-
total_bet_profit:
|
167
|
-
total_simulated_amount:
|
168
|
-
total_simulated_profit:
|
165
|
+
total_bet_amount: CollateralToken
|
166
|
+
total_bet_profit: CollateralToken
|
167
|
+
total_simulated_amount: CollateralToken
|
168
|
+
total_simulated_profit: CollateralToken
|
169
169
|
roi: float
|
170
170
|
simulated_roi: float
|
171
171
|
sharpe_output_original: SharpeOutput
|
@@ -5,11 +5,11 @@ from pydantic import BaseModel
|
|
5
5
|
|
6
6
|
from prediction_market_agent_tooling.gtypes import (
|
7
7
|
USD,
|
8
|
+
CollateralToken,
|
8
9
|
Mana,
|
9
10
|
OutcomeStr,
|
10
11
|
OutcomeToken,
|
11
12
|
Probability,
|
12
|
-
Token,
|
13
13
|
)
|
14
14
|
from prediction_market_agent_tooling.markets.data_models import Resolution
|
15
15
|
from prediction_market_agent_tooling.tools.utils import DatetimeUTC, should_not_happen
|
@@ -82,11 +82,11 @@ class ManifoldMarket(BaseModel):
|
|
82
82
|
pool: ManifoldPool
|
83
83
|
probability: Probability
|
84
84
|
slug: str
|
85
|
-
totalLiquidity: t.Optional[
|
85
|
+
totalLiquidity: t.Optional[CollateralToken] = None
|
86
86
|
uniqueBettorCount: int
|
87
87
|
url: str
|
88
|
-
volume:
|
89
|
-
volume24Hours:
|
88
|
+
volume: CollateralToken
|
89
|
+
volume24Hours: CollateralToken
|
90
90
|
|
91
91
|
@property
|
92
92
|
def outcomes(self) -> t.Sequence[OutcomeStr]:
|
@@ -181,18 +181,18 @@ class ManifoldBet(BaseModel):
|
|
181
181
|
https://docs.manifold.markets/api#get-v0bets
|
182
182
|
"""
|
183
183
|
|
184
|
-
shares:
|
184
|
+
shares: CollateralToken
|
185
185
|
probBefore: Probability
|
186
186
|
isFilled: t.Optional[bool] = None
|
187
187
|
probAfter: Probability
|
188
188
|
userId: str
|
189
|
-
amount:
|
189
|
+
amount: CollateralToken
|
190
190
|
contractId: str
|
191
191
|
id: str
|
192
192
|
fees: ManifoldBetFees
|
193
193
|
isCancelled: t.Optional[bool] = None
|
194
|
-
loanAmount:
|
195
|
-
orderAmount: t.Optional[
|
194
|
+
loanAmount: CollateralToken | None
|
195
|
+
orderAmount: t.Optional[CollateralToken] = None
|
196
196
|
fills: t.Optional[list[ManifoldBetFills]] = None
|
197
197
|
createdTime: DatetimeUTC
|
198
198
|
outcome: Resolution
|
@@ -205,7 +205,7 @@ class ManifoldBet(BaseModel):
|
|
205
205
|
else:
|
206
206
|
should_not_happen(f"Unexpected bet outcome string, '{self.outcome.value}'.")
|
207
207
|
|
208
|
-
def get_profit(self, market_outcome: bool) ->
|
208
|
+
def get_profit(self, market_outcome: bool) -> CollateralToken:
|
209
209
|
profit = (
|
210
210
|
self.shares - self.amount
|
211
211
|
if self.get_resolved_boolean_outcome() == market_outcome
|
@@ -2,7 +2,12 @@ import typing as t
|
|
2
2
|
from math import ceil
|
3
3
|
|
4
4
|
from prediction_market_agent_tooling.config import APIKeys
|
5
|
-
from prediction_market_agent_tooling.gtypes import
|
5
|
+
from prediction_market_agent_tooling.gtypes import (
|
6
|
+
USD,
|
7
|
+
CollateralToken,
|
8
|
+
Mana,
|
9
|
+
Probability,
|
10
|
+
)
|
6
11
|
from prediction_market_agent_tooling.markets.agent_market import (
|
7
12
|
AgentMarket,
|
8
13
|
FilterBy,
|
@@ -48,8 +53,8 @@ class ManifoldAgentMarket(AgentMarket):
|
|
48
53
|
"""On Manifold, probablities aren't updated after the closure, so we can just use the current probability"""
|
49
54
|
return self.current_p_no
|
50
55
|
|
51
|
-
def get_tiny_bet_amount(self) ->
|
52
|
-
return
|
56
|
+
def get_tiny_bet_amount(self) -> CollateralToken:
|
57
|
+
return CollateralToken(1)
|
53
58
|
|
54
59
|
def get_minimum_bet_to_win(self, answer: bool, amount_to_win: float) -> Mana:
|
55
60
|
# Manifold lowest bet is 1 Mana, so we need to ceil the result.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from pydantic import BaseModel, Field
|
2
2
|
|
3
|
-
from prediction_market_agent_tooling.gtypes import
|
3
|
+
from prediction_market_agent_tooling.gtypes import CollateralToken
|
4
4
|
|
5
5
|
|
6
6
|
class MarketFees(BaseModel):
|
@@ -34,5 +34,7 @@ class MarketFees(BaseModel):
|
|
34
34
|
total_fee = self.total_fee_absolute_value(bet_amount)
|
35
35
|
return total_fee / bet_amount
|
36
36
|
|
37
|
-
def get_after_fees(self, bet_amount:
|
38
|
-
return bet_amount -
|
37
|
+
def get_after_fees(self, bet_amount: CollateralToken) -> CollateralToken:
|
38
|
+
return bet_amount - CollateralToken(
|
39
|
+
self.total_fee_absolute_value(bet_amount.value)
|
40
|
+
)
|
@@ -6,13 +6,13 @@ from web3 import Web3
|
|
6
6
|
from prediction_market_agent_tooling.gtypes import (
|
7
7
|
USD,
|
8
8
|
ChecksumAddress,
|
9
|
+
CollateralToken,
|
9
10
|
HexAddress,
|
10
11
|
HexBytes,
|
11
12
|
HexStr,
|
12
13
|
OutcomeStr,
|
13
14
|
OutcomeWei,
|
14
15
|
Probability,
|
15
|
-
Token,
|
16
16
|
Wei,
|
17
17
|
xDai,
|
18
18
|
xDaiWei,
|
@@ -226,7 +226,7 @@ class OmenMarket(BaseModel):
|
|
226
226
|
collateralToken: HexAddress
|
227
227
|
outcomes: t.Sequence[OutcomeStr]
|
228
228
|
outcomeTokenAmounts: list[OutcomeWei]
|
229
|
-
outcomeTokenMarginalPrices: t.Optional[list[
|
229
|
+
outcomeTokenMarginalPrices: t.Optional[list[CollateralToken]]
|
230
230
|
fee: t.Optional[Wei]
|
231
231
|
resolutionTimestamp: t.Optional[int] = None
|
232
232
|
answerFinalizedTimestamp: t.Optional[int] = None
|
@@ -485,7 +485,7 @@ def calculate_liquidity_parameter(
|
|
485
485
|
|
486
486
|
def calculate_marginal_prices(
|
487
487
|
outcome_token_amounts: list[OutcomeWei],
|
488
|
-
) -> list[
|
488
|
+
) -> list[CollateralToken] | None:
|
489
489
|
"""
|
490
490
|
Converted to Python from https://github.com/protofire/omen-subgraph/blob/f92bbfb6fa31ed9cd5985c416a26a2f640837d8b/src/utils/fpmm.ts#L197.
|
491
491
|
"""
|
@@ -506,7 +506,7 @@ def calculate_marginal_prices(
|
|
506
506
|
sum_weights = sum(weights, start=Wei(0))
|
507
507
|
|
508
508
|
marginal_prices = [weights[i].value / sum_weights.value for i in range(n_outcomes)]
|
509
|
-
return [
|
509
|
+
return [CollateralToken(mp) for mp in marginal_prices]
|
510
510
|
|
511
511
|
|
512
512
|
class OmenBetCreator(BaseModel):
|
@@ -517,8 +517,8 @@ class OmenBet(BaseModel):
|
|
517
517
|
id: HexAddress # A concatenation of: FPMM contract ID, trader ID and nonce. See https://github.com/protofire/omen-subgraph/blob/f92bbfb6fa31ed9cd5985c416a26a2f640837d8b/src/FixedProductMarketMakerMapping.ts#L109
|
518
518
|
title: str
|
519
519
|
collateralToken: HexAddress
|
520
|
-
outcomeTokenMarginalPrice:
|
521
|
-
oldOutcomeTokenMarginalPrice:
|
520
|
+
outcomeTokenMarginalPrice: CollateralToken
|
521
|
+
oldOutcomeTokenMarginalPrice: CollateralToken
|
522
522
|
type: str
|
523
523
|
creator: OmenBetCreator
|
524
524
|
creationTimestamp: int
|
@@ -530,7 +530,7 @@ class OmenBet(BaseModel):
|
|
530
530
|
fpmm: OmenMarket
|
531
531
|
|
532
532
|
@property
|
533
|
-
def collateral_amount_token(self) ->
|
533
|
+
def collateral_amount_token(self) -> CollateralToken:
|
534
534
|
return self.collateralAmount.as_token
|
535
535
|
|
536
536
|
@property
|
@@ -560,7 +560,7 @@ class OmenBet(BaseModel):
|
|
560
560
|
self.collateral_amount_token, self.collateral_token_checksummed
|
561
561
|
)
|
562
562
|
|
563
|
-
def get_profit(self) ->
|
563
|
+
def get_profit(self) -> CollateralToken:
|
564
564
|
bet_amount = self.collateral_amount_token
|
565
565
|
profit = (
|
566
566
|
self.outcomeTokensTraded.as_outcome_token.as_token - bet_amount
|
@@ -8,13 +8,13 @@ from prediction_market_agent_tooling.config import APIKeys
|
|
8
8
|
from prediction_market_agent_tooling.gtypes import (
|
9
9
|
USD,
|
10
10
|
ChecksumAddress,
|
11
|
+
CollateralToken,
|
11
12
|
HexAddress,
|
12
13
|
HexStr,
|
13
14
|
OutcomeStr,
|
14
15
|
OutcomeToken,
|
15
16
|
OutcomeWei,
|
16
17
|
Probability,
|
17
|
-
Token,
|
18
18
|
Wei,
|
19
19
|
xDai,
|
20
20
|
)
|
@@ -145,16 +145,16 @@ class OmenAgentMarket(AgentMarket):
|
|
145
145
|
def get_liquidity_in_wei(self, web3: Web3 | None = None) -> Wei:
|
146
146
|
return self.get_contract().totalSupply(web3)
|
147
147
|
|
148
|
-
def get_liquidity(self, web3: Web3 | None = None) ->
|
148
|
+
def get_liquidity(self, web3: Web3 | None = None) -> CollateralToken:
|
149
149
|
return self.get_liquidity_in_wei(web3).as_token
|
150
150
|
|
151
|
-
def get_tiny_bet_amount(self) ->
|
151
|
+
def get_tiny_bet_amount(self) -> CollateralToken:
|
152
152
|
return self.get_in_token(OMEN_TINY_BET_AMOUNT)
|
153
153
|
|
154
|
-
def get_token_in_usd(self, x:
|
154
|
+
def get_token_in_usd(self, x: CollateralToken) -> USD:
|
155
155
|
return get_token_in_usd(x, self.collateral_token_contract_address_checksummed)
|
156
156
|
|
157
|
-
def get_usd_in_token(self, x: USD) ->
|
157
|
+
def get_usd_in_token(self, x: USD) -> CollateralToken:
|
158
158
|
return get_usd_in_token(x, self.collateral_token_contract_address_checksummed)
|
159
159
|
|
160
160
|
def liquidate_existing_positions(
|
@@ -226,7 +226,7 @@ class OmenAgentMarket(AgentMarket):
|
|
226
226
|
|
227
227
|
def get_sell_value_of_outcome_token(
|
228
228
|
self, outcome: str, amount: OutcomeToken, web3: Web3 | None = None
|
229
|
-
) ->
|
229
|
+
) -> CollateralToken:
|
230
230
|
"""
|
231
231
|
Market can have as collateral token GNO for example.
|
232
232
|
When you place bet, you buy shares with GNO. For example, you get 10 shares for 1 GNO.
|
@@ -593,7 +593,7 @@ class OmenAgentMarket(AgentMarket):
|
|
593
593
|
return get_omen_user_url(keys.bet_from_address)
|
594
594
|
|
595
595
|
def get_buy_token_amount(
|
596
|
-
self, bet_amount: USD |
|
596
|
+
self, bet_amount: USD | CollateralToken, direction: bool
|
597
597
|
) -> OutcomeToken:
|
598
598
|
"""
|
599
599
|
Note: this is only valid if the market instance's token pool is
|
@@ -709,7 +709,7 @@ def pick_binary_market(
|
|
709
709
|
)
|
710
710
|
def omen_buy_outcome_tx(
|
711
711
|
api_keys: APIKeys,
|
712
|
-
amount: USD |
|
712
|
+
amount: USD | CollateralToken,
|
713
713
|
market: OmenAgentMarket,
|
714
714
|
outcome: str,
|
715
715
|
auto_deposit: bool,
|
@@ -761,7 +761,7 @@ def omen_buy_outcome_tx(
|
|
761
761
|
|
762
762
|
def binary_omen_buy_outcome_tx(
|
763
763
|
api_keys: APIKeys,
|
764
|
-
amount: USD |
|
764
|
+
amount: USD | CollateralToken,
|
765
765
|
market: OmenAgentMarket,
|
766
766
|
binary_outcome: bool,
|
767
767
|
auto_deposit: bool,
|
@@ -779,7 +779,7 @@ def binary_omen_buy_outcome_tx(
|
|
779
779
|
|
780
780
|
def omen_sell_outcome_tx(
|
781
781
|
api_keys: APIKeys,
|
782
|
-
amount: OutcomeToken |
|
782
|
+
amount: OutcomeToken | CollateralToken | USD,
|
783
783
|
market: OmenAgentMarket,
|
784
784
|
outcome: str,
|
785
785
|
auto_withdraw: bool,
|
@@ -852,7 +852,7 @@ def omen_sell_outcome_tx(
|
|
852
852
|
|
853
853
|
def binary_omen_sell_outcome_tx(
|
854
854
|
api_keys: APIKeys,
|
855
|
-
amount: OutcomeToken |
|
855
|
+
amount: OutcomeToken | CollateralToken | USD,
|
856
856
|
market: OmenAgentMarket,
|
857
857
|
binary_outcome: bool,
|
858
858
|
auto_withdraw: bool,
|
@@ -870,7 +870,7 @@ def binary_omen_sell_outcome_tx(
|
|
870
870
|
|
871
871
|
def omen_create_market_tx(
|
872
872
|
api_keys: APIKeys,
|
873
|
-
initial_funds: USD |
|
873
|
+
initial_funds: USD | CollateralToken,
|
874
874
|
question: str,
|
875
875
|
closing_time: DatetimeUTC,
|
876
876
|
category: str,
|
@@ -964,7 +964,7 @@ def omen_create_market_tx(
|
|
964
964
|
)
|
965
965
|
|
966
966
|
# Create the market.
|
967
|
-
fee =
|
967
|
+
fee = CollateralToken(fee_perc).as_wei
|
968
968
|
(
|
969
969
|
market_event,
|
970
970
|
funding_event,
|
@@ -1000,7 +1000,7 @@ def omen_create_market_tx(
|
|
1000
1000
|
def omen_fund_market_tx(
|
1001
1001
|
api_keys: APIKeys,
|
1002
1002
|
market: OmenAgentMarket,
|
1003
|
-
funds: USD |
|
1003
|
+
funds: USD | CollateralToken,
|
1004
1004
|
auto_deposit: bool,
|
1005
1005
|
web3: Web3 | None = None,
|
1006
1006
|
) -> None:
|
@@ -1350,7 +1350,7 @@ def send_keeping_token_to_eoa_xdai(
|
|
1350
1350
|
|
1351
1351
|
|
1352
1352
|
def get_buy_outcome_token_amount(
|
1353
|
-
investment_amount:
|
1353
|
+
investment_amount: CollateralToken,
|
1354
1354
|
buy_direction: bool,
|
1355
1355
|
yes_outcome_pool_size: OutcomeToken,
|
1356
1356
|
no_outcome_pool_size: OutcomeToken,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import typing as t
|
2
2
|
|
3
|
-
from prediction_market_agent_tooling.gtypes import USD,
|
3
|
+
from prediction_market_agent_tooling.gtypes import USD, CollateralToken
|
4
4
|
from prediction_market_agent_tooling.markets.agent_market import (
|
5
5
|
AgentMarket,
|
6
6
|
FilterBy,
|
@@ -48,7 +48,7 @@ class PolymarketAgentMarket(AgentMarket):
|
|
48
48
|
outcome_token_pool=None,
|
49
49
|
)
|
50
50
|
|
51
|
-
def get_tiny_bet_amount(self) ->
|
51
|
+
def get_tiny_bet_amount(self) -> CollateralToken:
|
52
52
|
raise NotImplementedError("TODO: Implement to allow betting on Polymarket.")
|
53
53
|
|
54
54
|
def place_bet(self, outcome: bool, amount: USD) -> str:
|
@@ -10,11 +10,11 @@ from web3.constants import ADDRESS_ZERO
|
|
10
10
|
from prediction_market_agent_tooling.config import RPCConfig
|
11
11
|
from prediction_market_agent_tooling.gtypes import (
|
12
12
|
ChecksumAddress,
|
13
|
+
CollateralToken,
|
13
14
|
HexAddress,
|
14
15
|
HexBytes,
|
15
16
|
OutcomeStr,
|
16
17
|
Probability,
|
17
|
-
Token,
|
18
18
|
Web3Wei,
|
19
19
|
)
|
20
20
|
from prediction_market_agent_tooling.loggers import logger
|
@@ -207,7 +207,7 @@ class SeerMarket(BaseModel):
|
|
207
207
|
return Probability(price_yes)
|
208
208
|
|
209
209
|
def _get_price_for_token(self, token: ChecksumAddress) -> float:
|
210
|
-
collateral_exchange_amount =
|
210
|
+
collateral_exchange_amount = CollateralToken(1).as_wei
|
211
211
|
try:
|
212
212
|
quote = CowManager().get_quote(
|
213
213
|
collateral_token=self.collateral_token_contract_address_checksummed,
|
@@ -7,12 +7,12 @@ from web3.types import TxReceipt
|
|
7
7
|
from prediction_market_agent_tooling.config import APIKeys, RPCConfig
|
8
8
|
from prediction_market_agent_tooling.gtypes import (
|
9
9
|
USD,
|
10
|
+
CollateralToken,
|
10
11
|
HexAddress,
|
11
12
|
HexBytes,
|
12
13
|
OutcomeStr,
|
13
14
|
OutcomeToken,
|
14
15
|
OutcomeWei,
|
15
|
-
Token,
|
16
16
|
xDai,
|
17
17
|
)
|
18
18
|
from prediction_market_agent_tooling.loggers import logger
|
@@ -101,14 +101,14 @@ class SeerAgentMarket(AgentMarket):
|
|
101
101
|
agent_name=agent_name,
|
102
102
|
)
|
103
103
|
|
104
|
-
def get_token_in_usd(self, x:
|
104
|
+
def get_token_in_usd(self, x: CollateralToken) -> USD:
|
105
105
|
return get_token_in_usd(x, self.collateral_token_contract_address_checksummed)
|
106
106
|
|
107
|
-
def get_usd_in_token(self, x: USD) ->
|
107
|
+
def get_usd_in_token(self, x: USD) -> CollateralToken:
|
108
108
|
return get_usd_in_token(x, self.collateral_token_contract_address_checksummed)
|
109
109
|
|
110
110
|
def get_buy_token_amount(
|
111
|
-
self, bet_amount: USD |
|
111
|
+
self, bet_amount: USD | CollateralToken, direction: bool
|
112
112
|
) -> OutcomeToken:
|
113
113
|
"""Returns number of outcome tokens returned for a given bet expressed in collateral units."""
|
114
114
|
|
@@ -133,7 +133,7 @@ class SeerAgentMarket(AgentMarket):
|
|
133
133
|
def get_trade_balance(api_keys: APIKeys) -> USD:
|
134
134
|
return OmenAgentMarket.get_trade_balance(api_keys=api_keys)
|
135
135
|
|
136
|
-
def get_tiny_bet_amount(self) ->
|
136
|
+
def get_tiny_bet_amount(self) -> CollateralToken:
|
137
137
|
return self.get_in_token(SEER_TINY_BET_AMOUNT)
|
138
138
|
|
139
139
|
def get_position(
|
@@ -228,7 +228,7 @@ class SeerAgentMarket(AgentMarket):
|
|
228
228
|
CowManager().get_quote(
|
229
229
|
collateral_token=self.collateral_token_contract_address_checksummed,
|
230
230
|
buy_token=outcome_token,
|
231
|
-
sell_amount=
|
231
|
+
sell_amount=CollateralToken(
|
232
232
|
1
|
233
233
|
).as_wei, # we take 1 as a baseline value for common trades the agents take.
|
234
234
|
)
|
@@ -295,7 +295,7 @@ class SeerAgentMarket(AgentMarket):
|
|
295
295
|
|
296
296
|
def seer_create_market_tx(
|
297
297
|
api_keys: APIKeys,
|
298
|
-
initial_funds: USD |
|
298
|
+
initial_funds: USD | CollateralToken,
|
299
299
|
question: str,
|
300
300
|
opening_time: DatetimeUTC,
|
301
301
|
language: str,
|
@@ -2,7 +2,12 @@ from pydantic import BaseModel
|
|
2
2
|
from tenacity import retry, stop_after_attempt, wait_fixed
|
3
3
|
from web3 import Web3
|
4
4
|
|
5
|
-
from prediction_market_agent_tooling.gtypes import
|
5
|
+
from prediction_market_agent_tooling.gtypes import (
|
6
|
+
ChecksumAddress,
|
7
|
+
CollateralToken,
|
8
|
+
xDai,
|
9
|
+
xDaiWei,
|
10
|
+
)
|
6
11
|
from prediction_market_agent_tooling.markets.omen.omen_contracts import (
|
7
12
|
WrappedxDaiContract,
|
8
13
|
sDaiContract,
|
@@ -11,11 +16,11 @@ from prediction_market_agent_tooling.markets.omen.omen_contracts import (
|
|
11
16
|
|
12
17
|
class Balances(BaseModel):
|
13
18
|
xdai: xDai
|
14
|
-
wxdai:
|
15
|
-
sdai:
|
19
|
+
wxdai: CollateralToken
|
20
|
+
sdai: CollateralToken
|
16
21
|
|
17
22
|
@property
|
18
|
-
def total(self) ->
|
23
|
+
def total(self) -> CollateralToken:
|
19
24
|
return self.xdai.as_token + self.wxdai + self.sdai
|
20
25
|
|
21
26
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from prediction_market_agent_tooling.gtypes import
|
1
|
+
from prediction_market_agent_tooling.gtypes import CollateralToken, OutcomeToken
|
2
2
|
from prediction_market_agent_tooling.markets.market_fees import MarketFees
|
3
3
|
from prediction_market_agent_tooling.tools.betting_strategies.utils import SimpleBet
|
4
4
|
|
@@ -9,7 +9,7 @@ def check_is_valid_probability(probability: float) -> None:
|
|
9
9
|
|
10
10
|
|
11
11
|
def get_kelly_bet_simplified(
|
12
|
-
max_bet:
|
12
|
+
max_bet: CollateralToken,
|
13
13
|
market_p_yes: float,
|
14
14
|
estimated_p_yes: float,
|
15
15
|
confidence: float,
|
@@ -52,7 +52,7 @@ def get_kelly_bet_simplified(
|
|
52
52
|
kelly_fraction = edge / odds
|
53
53
|
|
54
54
|
# Ensure bet size is non-negative does not exceed the wallet balance
|
55
|
-
bet_size =
|
55
|
+
bet_size = CollateralToken(min(kelly_fraction * max_bet.value, max_bet.value))
|
56
56
|
|
57
57
|
return SimpleBet(direction=bet_direction, size=bet_size)
|
58
58
|
|
@@ -62,7 +62,7 @@ def get_kelly_bet_full(
|
|
62
62
|
no_outcome_pool_size: OutcomeToken,
|
63
63
|
estimated_p_yes: float,
|
64
64
|
confidence: float,
|
65
|
-
max_bet:
|
65
|
+
max_bet: CollateralToken,
|
66
66
|
fees: MarketFees,
|
67
67
|
) -> SimpleBet:
|
68
68
|
"""
|
@@ -98,7 +98,7 @@ def get_kelly_bet_full(
|
|
98
98
|
check_is_valid_probability(confidence)
|
99
99
|
|
100
100
|
if max_bet == 0:
|
101
|
-
return SimpleBet(direction=True, size=
|
101
|
+
return SimpleBet(direction=True, size=CollateralToken(0))
|
102
102
|
|
103
103
|
x = yes_outcome_pool_size.value
|
104
104
|
y = no_outcome_pool_size.value
|
@@ -146,5 +146,5 @@ def get_kelly_bet_full(
|
|
146
146
|
# Clip the bet size to max_bet to account for rounding errors.
|
147
147
|
return SimpleBet(
|
148
148
|
direction=kelly_bet_amount > 0,
|
149
|
-
size=
|
149
|
+
size=CollateralToken(min(max_bet.value, abs(kelly_bet_amount))),
|
150
150
|
)
|
@@ -2,7 +2,11 @@ from functools import reduce
|
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
|
5
|
-
from prediction_market_agent_tooling.gtypes import
|
5
|
+
from prediction_market_agent_tooling.gtypes import (
|
6
|
+
CollateralToken,
|
7
|
+
OutcomeToken,
|
8
|
+
Probability,
|
9
|
+
)
|
6
10
|
from prediction_market_agent_tooling.markets.omen.omen import (
|
7
11
|
MarketFees,
|
8
12
|
OmenAgentMarket,
|
@@ -41,7 +45,7 @@ def get_market_moving_bet(
|
|
41
45
|
fixed_product = yes_outcome_pool_size * no_outcome_pool_size
|
42
46
|
bet_direction: bool = target_p_yes > market_p_yes
|
43
47
|
|
44
|
-
min_bet_amount =
|
48
|
+
min_bet_amount = CollateralToken(0.0)
|
45
49
|
max_bet_amount = (
|
46
50
|
yes_outcome_pool_size + no_outcome_pool_size
|
47
51
|
).as_token * 100 # TODO set a better upper bound
|
@@ -14,8 +14,8 @@ from prediction_market_agent_tooling.gtypes import (
|
|
14
14
|
ABI,
|
15
15
|
ChainID,
|
16
16
|
ChecksumAddress,
|
17
|
+
CollateralToken,
|
17
18
|
Nonce,
|
18
|
-
Token,
|
19
19
|
TxParams,
|
20
20
|
TxReceipt,
|
21
21
|
Wei,
|
@@ -249,7 +249,7 @@ class ContractERC20BaseClass(ContractBaseClass):
|
|
249
249
|
|
250
250
|
def balance_of_in_tokens(
|
251
251
|
self, for_address: ChecksumAddress, web3: Web3 | None = None
|
252
|
-
) ->
|
252
|
+
) -> CollateralToken:
|
253
253
|
return self.balanceOf(for_address, web3=web3).as_token
|
254
254
|
|
255
255
|
|
@@ -19,7 +19,7 @@ from web3 import Web3
|
|
19
19
|
from web3.constants import ADDRESS_ZERO
|
20
20
|
|
21
21
|
from prediction_market_agent_tooling.config import APIKeys
|
22
|
-
from prediction_market_agent_tooling.gtypes import ChecksumAddress,
|
22
|
+
from prediction_market_agent_tooling.gtypes import ChecksumAddress, CollateralToken, Wei
|
23
23
|
from prediction_market_agent_tooling.loggers import logger
|
24
24
|
from prediction_market_agent_tooling.tools.cow.cow_order import swap_tokens_waiting
|
25
25
|
|
@@ -93,7 +93,7 @@ class CowManager:
|
|
93
93
|
|
94
94
|
@staticmethod
|
95
95
|
def swap(
|
96
|
-
amount:
|
96
|
+
amount: CollateralToken,
|
97
97
|
sell_token: ChecksumAddress,
|
98
98
|
buy_token: ChecksumAddress,
|
99
99
|
api_keys: APIKeys,
|
@@ -36,6 +36,11 @@ def get_order_book_api(env: Envs, chain: Chain) -> OrderBookApi:
|
|
36
36
|
return OrderBookApi(OrderBookAPIConfigFactory.get_config(env, chain_id))
|
37
37
|
|
38
38
|
|
39
|
+
@tenacity.retry(
|
40
|
+
stop=tenacity.stop_after_attempt(3),
|
41
|
+
wait=tenacity.wait_fixed(1),
|
42
|
+
after=lambda x: logger.debug(f"get_sell_token_amount failed, {x.attempt_number=}."),
|
43
|
+
)
|
39
44
|
def get_sell_token_amount(
|
40
45
|
buy_amount: Wei,
|
41
46
|
sell_token: ChecksumAddress,
|
@@ -4,8 +4,8 @@ from eth_typing.evm import ChecksumAddress
|
|
4
4
|
from prediction_market_agent_tooling.gtypes import (
|
5
5
|
USD,
|
6
6
|
ChecksumAddress,
|
7
|
+
CollateralToken,
|
7
8
|
OutcomeToken,
|
8
|
-
Token,
|
9
9
|
xDai,
|
10
10
|
)
|
11
11
|
from prediction_market_agent_tooling.markets.omen.omen_constants import (
|
@@ -26,13 +26,13 @@ def get_xdai_in_usd(amount: xDai) -> USD:
|
|
26
26
|
return USD(amount.value)
|
27
27
|
|
28
28
|
|
29
|
-
def get_usd_in_token(amount: USD, token_address: ChecksumAddress) ->
|
29
|
+
def get_usd_in_token(amount: USD, token_address: ChecksumAddress) -> CollateralToken:
|
30
30
|
rate = get_single_token_unit_to_usd_rate(token_address)
|
31
|
-
return
|
31
|
+
return CollateralToken(amount.value / rate.value)
|
32
32
|
|
33
33
|
|
34
34
|
def get_token_in_usd(
|
35
|
-
amount:
|
35
|
+
amount: CollateralToken | OutcomeToken, token_address: ChecksumAddress
|
36
36
|
) -> USD:
|
37
37
|
rate = get_single_token_unit_to_usd_rate(token_address)
|
38
38
|
return USD(amount.value * rate.value)
|
@@ -51,11 +51,11 @@ def get_single_token_unit_to_usd_rate(token_address: ChecksumAddress) -> USD:
|
|
51
51
|
if SDAI_CONTRACT_ADDRESS == token_address:
|
52
52
|
return USD(
|
53
53
|
ContractERC4626OnGnosisChain(address=SDAI_CONTRACT_ADDRESS)
|
54
|
-
.convertToAssets(
|
54
|
+
.convertToAssets(CollateralToken(1).as_wei)
|
55
55
|
.as_token.value
|
56
56
|
)
|
57
57
|
in_wei = get_buy_token_amount(
|
58
|
-
sell_amount=
|
58
|
+
sell_amount=CollateralToken(1).as_wei,
|
59
59
|
sell_token=token_address,
|
60
60
|
buy_token=WRAPPED_XDAI_CONTRACT_ADDRESS,
|
61
61
|
)
|
@@ -10,11 +10,11 @@ from scipy.optimize import newton
|
|
10
10
|
from scipy.stats import entropy
|
11
11
|
|
12
12
|
from prediction_market_agent_tooling.gtypes import (
|
13
|
+
CollateralToken,
|
13
14
|
DatetimeUTC,
|
14
15
|
OutcomeToken,
|
15
16
|
Probability,
|
16
17
|
SecretStr,
|
17
|
-
Token,
|
18
18
|
)
|
19
19
|
from prediction_market_agent_tooling.loggers import logger
|
20
20
|
from prediction_market_agent_tooling.markets.market_fees import MarketFees
|
@@ -192,7 +192,7 @@ def calculate_sell_amount_in_collateral(
|
|
192
192
|
holdings: OutcomeToken,
|
193
193
|
other_holdings: OutcomeToken,
|
194
194
|
fees: MarketFees,
|
195
|
-
) ->
|
195
|
+
) -> CollateralToken:
|
196
196
|
"""
|
197
197
|
Computes the amount of collateral that needs to be sold to get `shares`
|
198
198
|
amount of shares. Returns None if the amount can't be computed.
|
@@ -212,4 +212,4 @@ def calculate_sell_amount_in_collateral(
|
|
212
212
|
return ((first_term * second_term) - third_term).value
|
213
213
|
|
214
214
|
amount_to_sell = newton(f, 0)
|
215
|
-
return
|
215
|
+
return CollateralToken(float(amount_to_sell) * 0.999999) # Avoid rounding errors
|
@@ -23,35 +23,35 @@ prediction_market_agent_tooling/benchmark/utils.py,sha256=D0MfUkVZllmvcU0VOurk9t
|
|
23
23
|
prediction_market_agent_tooling/config.py,sha256=So5l8KbgmzcCpxzzf13TNrEJPu_4iQnUDhzus6XRvSc,10151
|
24
24
|
prediction_market_agent_tooling/deploy/agent.py,sha256=DW9edzHDX7QVURMGyOoIHTIvl3Itpbi8i0l5XPrEkbk,24974
|
25
25
|
prediction_market_agent_tooling/deploy/agent_example.py,sha256=dIIdZashExWk9tOdyDjw87AuUcGyM7jYxNChYrVK2dM,1001
|
26
|
-
prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=
|
26
|
+
prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=iU-D7cdcwiCOWbjDt8hin3ZpL633pQbw9GIKRnIR3FY,12494
|
27
27
|
prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
|
28
28
|
prediction_market_agent_tooling/deploy/gcp/deploy.py,sha256=CYUgnfy-9XVk04kkxA_5yp0GE9Mw5caYqlFUZQ2j3ks,3739
|
29
29
|
prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py,sha256=OsPboCFGiZKsvGyntGZHwdqPlLTthITkNF5rJFvGgU8,2582
|
30
30
|
prediction_market_agent_tooling/deploy/gcp/utils.py,sha256=WI2ycX1X-IlTRoNoG4ggFlRwPL28kwM9VGDFD2fePLo,5699
|
31
31
|
prediction_market_agent_tooling/deploy/trade_interval.py,sha256=Xk9j45alQ_vrasGvsNyuW70XHIQ7wfvjoxNR3F6HYCw,1155
|
32
|
-
prediction_market_agent_tooling/gtypes.py,sha256=
|
32
|
+
prediction_market_agent_tooling/gtypes.py,sha256=DaerVkKVqhIhTwCB9A8piwCR97ZMnd8nSTSOlI9XcLM,5549
|
33
33
|
prediction_market_agent_tooling/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
34
34
|
prediction_market_agent_tooling/jobs/jobs_models.py,sha256=8vYafsK1cqMWQtjBoq9rruroF84xAVD00vBTMWH6QMg,2166
|
35
35
|
prediction_market_agent_tooling/jobs/omen/omen_jobs.py,sha256=Pf6QxPXGyie-2l_wZUjaGPTjZTlpv50_JhP40mULBaU,5048
|
36
36
|
prediction_market_agent_tooling/loggers.py,sha256=MvCkQSJL2_0yErNatqr81sJlc4aOgPzDp9VNrIhKUcc,4140
|
37
|
-
prediction_market_agent_tooling/markets/agent_market.py,sha256=
|
37
|
+
prediction_market_agent_tooling/markets/agent_market.py,sha256=A8eHhV68RIBUE1eIxVchp3QstzpnAYdZxaANyS6vg68,14866
|
38
38
|
prediction_market_agent_tooling/markets/base_subgraph_handler.py,sha256=7RaYO_4qAmQ6ZGM8oPK2-CkiJfKmV9MxM-rJlduaecU,1971
|
39
39
|
prediction_market_agent_tooling/markets/blockchain_utils.py,sha256=1iTU_D-Uof0E442qVUhSBCfc1rJNQpDcd3UjSnilYZg,2129
|
40
40
|
prediction_market_agent_tooling/markets/categorize.py,sha256=jsoHWvZk9pU6n17oWSCcCxNNYVwlb_NXsZxKRI7vmsk,1301
|
41
|
-
prediction_market_agent_tooling/markets/data_models.py,sha256=
|
41
|
+
prediction_market_agent_tooling/markets/data_models.py,sha256=_R9Hr5zwGLpZLPXq0Jo2wZRNRQyOnSi3WVQJZ81syuk,4541
|
42
42
|
prediction_market_agent_tooling/markets/manifold/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
43
43
|
prediction_market_agent_tooling/markets/manifold/api.py,sha256=ih92UTZdSbmy6tTUgSCps_HqYQXpMSsfne5Np5znVEM,7217
|
44
|
-
prediction_market_agent_tooling/markets/manifold/data_models.py,sha256=
|
45
|
-
prediction_market_agent_tooling/markets/manifold/manifold.py,sha256=
|
44
|
+
prediction_market_agent_tooling/markets/manifold/data_models.py,sha256=DWNvK6Qdxz7Lxqpe-qQE4X-mw8GFGpukGfnjT_ohcZA,6364
|
45
|
+
prediction_market_agent_tooling/markets/manifold/manifold.py,sha256=TakZ0SqyDFal0QECKCkKkuqqeUm1o3mTpesQIuYInig,4800
|
46
46
|
prediction_market_agent_tooling/markets/manifold/utils.py,sha256=_gGlWid0sPF127Omx5qQ1fq17frLInv0wdyXJBMGVzM,670
|
47
|
-
prediction_market_agent_tooling/markets/market_fees.py,sha256=
|
47
|
+
prediction_market_agent_tooling/markets/market_fees.py,sha256=YeK3ynjYIguB0xf6sO5iyg9lOdW_HD4C6nbJfiGyRCU,1351
|
48
48
|
prediction_market_agent_tooling/markets/markets.py,sha256=OMADWd1C5wD7sVdcY_GVdxAFDndkU9kn6Ble4GXCw0c,4045
|
49
49
|
prediction_market_agent_tooling/markets/metaculus/api.py,sha256=4TRPGytQQbSdf42DCg2M_JWYPAuNjqZ3eBqaQBLkNks,2736
|
50
50
|
prediction_market_agent_tooling/markets/metaculus/data_models.py,sha256=FaBCTPPezXbBwZ9p791CiVgQ4vB696xnMbz9XVXmiVI,3267
|
51
51
|
prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=86TIx6cavEWc8Cv4KpZxSvwiSw9oFybXE3YB49pg-CA,4377
|
52
52
|
prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
53
|
-
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=
|
54
|
-
prediction_market_agent_tooling/markets/omen/omen.py,sha256=
|
53
|
+
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=URvplDcTLeL6vfpkSgi8ln2iEKxt8w5qf6mTZkSyrCo,29189
|
54
|
+
prediction_market_agent_tooling/markets/omen/omen.py,sha256=F_TUNkiwmZqmURYTbA0204gbBqQ6gZzCq5DFzM0w_CA,51578
|
55
55
|
prediction_market_agent_tooling/markets/omen/omen_constants.py,sha256=D9oflYKafLQiHYtB5sScMHqmXyzM8JP8J0yATmc4SQQ,233
|
56
56
|
prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=bCC9A7ZTJxMDJcPbl3jof6HcAGGHv1BrFq3RRWbkQ_c,28739
|
57
57
|
prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=Cyi9Ci-Z-K8WCZWVLs9oSuJC6qRobi_CpqDCno_5F-0,10238
|
@@ -59,10 +59,10 @@ prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=6N6
|
|
59
59
|
prediction_market_agent_tooling/markets/polymarket/api.py,sha256=UZ4_TG8ceb9Y-qgsOKs8Qiv8zDt957QkT8IX2c83yqo,4800
|
60
60
|
prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=utGN-Lhjsa-RHX5WW_jcqgWXtRkEZn0JemwYZkt3Lng,4344
|
61
61
|
prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=LVEsNw2nUx5poiU1m803NNqG5-fs8-MODQRyGLqy4mE,12585
|
62
|
-
prediction_market_agent_tooling/markets/polymarket/polymarket.py,sha256=
|
62
|
+
prediction_market_agent_tooling/markets/polymarket/polymarket.py,sha256=6rc9qulPl90MxXKB55XiiWKLhjfAyG_eUzAlqpq1UIE,3339
|
63
63
|
prediction_market_agent_tooling/markets/polymarket/utils.py,sha256=8kTeVjXPcXC6DkDvWYsZQLY7x8DS6CEp_yznSEazsNU,2037
|
64
|
-
prediction_market_agent_tooling/markets/seer/data_models.py,sha256=
|
65
|
-
prediction_market_agent_tooling/markets/seer/seer.py,sha256=
|
64
|
+
prediction_market_agent_tooling/markets/seer/data_models.py,sha256=qo8qH-3j0czH8zrgHnaYyB5-f38zZcl9MNtQfXi_JZM,8192
|
65
|
+
prediction_market_agent_tooling/markets/seer/seer.py,sha256=l9H7AYRje4bEXMdVzw83cseY46BLgOAgiJarE_8faHk,13189
|
66
66
|
prediction_market_agent_tooling/markets/seer/seer_contracts.py,sha256=XOEhaL5wrKEg7P-xg1mW5mJXVfeALuflJOvqAeuwrWM,2717
|
67
67
|
prediction_market_agent_tooling/markets/seer/seer_subgraph_handler.py,sha256=o5Sh_6bpiJQb1KnW3rf4cBqN2PM8IdggQARdBeDMvIE,8725
|
68
68
|
prediction_market_agent_tooling/monitor/financial_metrics/financial_metrics.py,sha256=fjIgjDIx5MhH5mwf7S0cspLOOSU3elYLhGYoIiM26mU,2746
|
@@ -75,19 +75,19 @@ prediction_market_agent_tooling/monitor/monitor_app.py,sha256=-_6w_ZvQ-Ad5qaeuo7
|
|
75
75
|
prediction_market_agent_tooling/monitor/monitor_settings.py,sha256=Xiozs3AsufuJ04JOe1vjUri-IAMWHjjmc2ugGGiHNH4,947
|
76
76
|
prediction_market_agent_tooling/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
77
77
|
prediction_market_agent_tooling/tools/_generic_value.py,sha256=0_EDybTsr3iXqPPqy2U1WMw4st_SlYaCrf2p1MZhED4,10511
|
78
|
-
prediction_market_agent_tooling/tools/balances.py,sha256=
|
79
|
-
prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py,sha256=
|
80
|
-
prediction_market_agent_tooling/tools/betting_strategies/market_moving.py,sha256=
|
78
|
+
prediction_market_agent_tooling/tools/balances.py,sha256=Osab21btfJDw2Y-jT_TV-KHGrseCRxcsYeW6WcOMB8E,1050
|
79
|
+
prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py,sha256=L9yp3m_81i-y85dGZH1rYRv9YXYYt1w3RGroFAAYSbw,4873
|
80
|
+
prediction_market_agent_tooling/tools/betting_strategies/market_moving.py,sha256=36ucOuF38bdB4rnSPNjC1qpidBo30Ff4P5Kb-7emKEQ,5469
|
81
81
|
prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py,sha256=-FUSuQQgjcWSSnoFxnlAyTeilY6raJABJVM2QKkFqAY,438
|
82
82
|
prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py,sha256=THMXwFlskvzbjnX_OiYtDSzI8XVFyULWfP2525_9UGc,429
|
83
|
-
prediction_market_agent_tooling/tools/betting_strategies/utils.py,sha256=
|
83
|
+
prediction_market_agent_tooling/tools/betting_strategies/utils.py,sha256=68zFWUj43GUaSpOPowVrbI-t6qbCE29RsVHNzCVuJ9U,175
|
84
84
|
prediction_market_agent_tooling/tools/caches/db_cache.py,sha256=dB8LNs2JvVRaFCeAKRmIQRwiirsMgtL31he8051wM-g,11431
|
85
85
|
prediction_market_agent_tooling/tools/caches/inmemory_cache.py,sha256=ZW5iI5rmjqeAebu5T7ftRnlkxiL02IC-MxCfDB80x7w,1506
|
86
86
|
prediction_market_agent_tooling/tools/caches/serializers.py,sha256=vFDx4fsPxclXp2q0sv27j4al_M_Tj9aR2JJP-xNHQXA,2151
|
87
|
-
prediction_market_agent_tooling/tools/contract.py,sha256=
|
87
|
+
prediction_market_agent_tooling/tools/contract.py,sha256=PJaC_Mc06vowyHD6f4MNQuEfo-h0H-Lh741YzRuemUk,21018
|
88
88
|
prediction_market_agent_tooling/tools/costs.py,sha256=EaAJ7v9laD4VEV3d8B44M4u3_oEO_H16jRVCdoZ93Uw,954
|
89
|
-
prediction_market_agent_tooling/tools/cow/cow_manager.py,sha256=
|
90
|
-
prediction_market_agent_tooling/tools/cow/cow_order.py,sha256=
|
89
|
+
prediction_market_agent_tooling/tools/cow/cow_manager.py,sha256=ZX6K0ZKMpcgiDsIrv4wtZAPg-LTozIbvOyQFyVgDpMA,3812
|
90
|
+
prediction_market_agent_tooling/tools/cow/cow_order.py,sha256=RdbIUlE7ssQAXKDYEWK1twrt57pWCdYCqdlzrAGFI_k,5523
|
91
91
|
prediction_market_agent_tooling/tools/custom_exceptions.py,sha256=Fh8z1fbwONvP4-j7AmV_PuEcoqb6-QXa9PJ9m7guMcM,93
|
92
92
|
prediction_market_agent_tooling/tools/datetime_utc.py,sha256=8_WackjtjC8zHXrhQFTGQ6e6Fz_6llWoKR4CSFvIv9I,2766
|
93
93
|
prediction_market_agent_tooling/tools/db/db_manager.py,sha256=GtzHH1NLl8HwqC8Z7s6eTlIQXuV0blxfaV2PeQrBnfQ,3013
|
@@ -116,12 +116,12 @@ prediction_market_agent_tooling/tools/tokens/auto_deposit.py,sha256=ZKGJPoRhch7Q
|
|
116
116
|
prediction_market_agent_tooling/tools/tokens/auto_withdraw.py,sha256=nV9jSUt1ydceDj03cTwdyrJs8kFGqz9z6YcvTVUaNg4,2682
|
117
117
|
prediction_market_agent_tooling/tools/tokens/main_token.py,sha256=1rbwpdCusPgQIVFuo3m00nBZ_b2lCAoFVm67i-YDcEw,812
|
118
118
|
prediction_market_agent_tooling/tools/tokens/token_utils.py,sha256=zwV-jGFkPJu4-IslXOUqnsNQjzh_9CrfkruDQL0dq0c,1381
|
119
|
-
prediction_market_agent_tooling/tools/tokens/usd.py,sha256=
|
119
|
+
prediction_market_agent_tooling/tools/tokens/usd.py,sha256=FmQUfrkLvN8cI_6vw9QNhOXdaqYlw-DxevP39VA8hmQ,2240
|
120
120
|
prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
|
121
|
-
prediction_market_agent_tooling/tools/utils.py,sha256=
|
121
|
+
prediction_market_agent_tooling/tools/utils.py,sha256=1xsyBBJfiEdSoMlceB2F8o2sCb6Z8-qNz11pEJFrdyE,6566
|
122
122
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=eYCc1iWAVtqDKUPTwnMUHuYolPdwh_OTiM3-AdRgDp4,12198
|
123
|
-
prediction_market_agent_tooling-0.62.0.
|
124
|
-
prediction_market_agent_tooling-0.62.0.
|
125
|
-
prediction_market_agent_tooling-0.62.0.
|
126
|
-
prediction_market_agent_tooling-0.62.0.
|
127
|
-
prediction_market_agent_tooling-0.62.0.
|
123
|
+
prediction_market_agent_tooling-0.62.0.dev471.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
124
|
+
prediction_market_agent_tooling-0.62.0.dev471.dist-info/METADATA,sha256=FXFhBtPJQo1TxlIC6xUlEPE0W0mLj2lscAchC1IiQk0,8696
|
125
|
+
prediction_market_agent_tooling-0.62.0.dev471.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
126
|
+
prediction_market_agent_tooling-0.62.0.dev471.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
127
|
+
prediction_market_agent_tooling-0.62.0.dev471.dist-info/RECORD,,
|
File without changes
|
File without changes
|