From 592c480936da1c297a18198f789142b220300e34 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Mon, 19 Feb 2024 16:55:00 +0100 Subject: [PATCH 1/2] chore: fix duplicate mech calls --- trades.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/trades.py b/trades.py index 011f5408..dd8ac8bc 100644 --- a/trades.py +++ b/trades.py @@ -622,6 +622,7 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements ) -> tuple[str, dict[Any, Any]]: """Parse the trades from the response.""" + _mech_statistics = dict(mech_statistics) user_json = _query_conditional_tokens_gc_subgraph(creator) statistics_table = { @@ -670,10 +671,11 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements market_status ] += collateral_amount statistics_table[MarketAttribute.FEES][market_status] += fee_amount + mech_data = _mech_statistics.pop(fpmmTrade["title"], {}) statistics_table[MarketAttribute.MECH_CALLS][ market_status - ] += mech_statistics.get(fpmmTrade["title"], {}).get("count", 0) - mech_fees = mech_statistics.get(fpmmTrade["title"], {}).get("fees", 0) + ] += mech_data.get("count", 0) + mech_fees = mech_data.get("fees", 0) statistics_table[MarketAttribute.MECH_FEES][market_status] += mech_fees output += f" Market status: {market_status}\n" From c25175f0ded8380f3b9c7c7525b5fcbcfb99256e Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Mon, 19 Feb 2024 17:15:52 +0100 Subject: [PATCH 2/2] chore: fix dict type --- trades.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/trades.py b/trades.py index dd8ac8bc..05d30fc8 100644 --- a/trades.py +++ b/trades.py @@ -304,7 +304,7 @@ def _parse_args() -> Any: return args -def _to_content(q: str) -> dict[str, Any]: +def _to_content(q: str) -> Dict[str, Any]: """Convert the given query string to payload content, i.e., add it under a `queries` key and convert it to bytes.""" finalized_query = { "query": q, @@ -320,7 +320,7 @@ def _query_omen_xdai_subgraph( # pylint: disable=too-many-locals to_timestamp: float = DEFAULT_TO_TIMESTAMP, fpmm_from_timestamp: float = DEFAULT_FROM_TIMESTAMP, fpmm_to_timestamp: float = DEFAULT_TO_TIMESTAMP, -) -> dict[str, Any]: +) -> Dict[str, Any]: """Query the subgraph.""" url = "https://api.thegraph.com/subgraphs/name/protofire/omen-xdai" @@ -365,11 +365,11 @@ def _query_omen_xdai_subgraph( # pylint: disable=too-many-locals return all_results -def _query_conditional_tokens_gc_subgraph(creator: str) -> dict[str, Any]: +def _query_conditional_tokens_gc_subgraph(creator: str) -> Dict[str, Any]: """Query the subgraph.""" url = "https://api.thegraph.com/subgraphs/name/gnosis/conditional-tokens-gc" - all_results: dict[str, Any] = {"data": {"user": {"userPositions": []}}} + all_results: Dict[str, Any] = {"data": {"user": {"userPositions": []}}} userPositions_id_gt = "" while True: query = conditional_tokens_gc_user_query.substitute( @@ -419,7 +419,7 @@ def wei_to_olas(wei: int) -> str: return "{:.2f} OLAS".format(wei_to_unit(wei)) -def _is_redeemed(user_json: dict[str, Any], fpmmTrade: dict[str, Any]) -> bool: +def _is_redeemed(user_json: Dict[str, Any], fpmmTrade: Dict[str, Any]) -> bool: user_positions = user_json["data"]["user"]["userPositions"] outcomes_tokens_traded = int(fpmmTrade["outcomeTokensTraded"]) condition_id = fpmmTrade["fpmm"]["condition"]["id"] @@ -451,7 +451,7 @@ def _compute_roi(initial_value: int, final_value: int) -> float: def _compute_totals( - table: dict[Any, dict[Any, Any]], mech_statistics: dict[str, Any] + table: Dict[Any, Dict[Any, Any]], mech_statistics: Dict[str, Any] ) -> None: for row in table.keys(): total = sum(table[row][c] for c in table[row]) @@ -489,7 +489,7 @@ def _compute_totals( ) -def _format_table(table: dict[Any, dict[Any, Any]]) -> str: +def _format_table(table: Dict[Any, Dict[Any, Any]]) -> str: column_width = 14 table_str = " " * column_width @@ -617,9 +617,9 @@ def _format_table(table: dict[Any, dict[Any, Any]]) -> str: def parse_user( # pylint: disable=too-many-locals,too-many-statements rpc: str, creator: str, - creator_trades_json: dict[str, Any], - mech_statistics: dict[str, Any], -) -> tuple[str, dict[Any, Any]]: + creator_trades_json: Dict[str, Any], + mech_statistics: Dict[str, Any], +) -> tuple[str, Dict[Any, Any]]: """Parse the trades from the response.""" _mech_statistics = dict(mech_statistics)