Skip to content

Commit

Permalink
Merge pull request #356 from valory-xyz/develop
Browse files Browse the repository at this point in the history
Release `v0.20.0`
  • Loading branch information
jmoreira-valory authored Oct 3, 2024
2 parents 1f733bf + 3d52b6c commit 90f938c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ chmod +x run_service.sh
./run_service.sh
```

Answer 'No' when prompted:
Answer `1) No staking` when prompted:

```text
Do you want to use staking in this service? (yes/no): n
Please, select your staking program preference
```

### For Stakers
Expand Down Expand Up @@ -77,6 +77,8 @@ Please, select your staking program preference
running Olas Predict agents with the quickstart. It is designed for
professional agent operators, requiring 1000 OLAS for staking. The rewards
are proportional to the Quickstart Beta - Hobbyist.
...
```

Find below a diagram of the possible status a service can be in the staking program:
Expand Down
56 changes: 52 additions & 4 deletions report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import time
import traceback
from argparse import ArgumentParser
from collections import Counter

from dotenv import dotenv_values
from enum import Enum
from pathlib import Path
import requests
import sys
from typing import Any, List
from typing import Any

import docker
import trades
Expand Down Expand Up @@ -107,6 +107,8 @@
OPERATOR_XDAI_BALANCE_THRESHOLD = 50000000000000000
MECH_REQUESTS_PER_EPOCH_THRESHOLD = 10
TRADES_LOOKBACK_DAYS = 3
MULTI_TRADE_LOOKBACK_DAYS = TRADES_LOOKBACK_DAYS
SECONDS_PER_DAY = 60 * 60 * 24

OUTPUT_WIDTH = 80

Expand Down Expand Up @@ -158,6 +160,44 @@ def _trades_since_message(trades_json: dict[str, Any], utc_ts: float = 0) -> str
return f"{trades_count} trades on {markets_count} markets"


def _calculate_retrades_since(trades_json: dict[str, Any], utc_ts: float = 0) -> tuple[Counter[Any], int, int, int]:
filtered_trades = Counter((
trade.get("fpmm", {}).get("id", None)
for trade in trades_json.get("data", {}).get("fpmmTrades", [])
if float(trade.get("creationTimestamp", 0)) >= utc_ts
))

if None in filtered_trades:
raise ValueError(
f"Unexpected format in trades_json: {filtered_trades[None]} trades have no associated market ID.")

unique_markets = set(filtered_trades)
n_unique_markets = len(unique_markets)
n_trades = sum(filtered_trades.values())
n_retrades = sum(n_bets - 1 for n_bets in filtered_trades.values() if n_bets > 1)

return filtered_trades, n_unique_markets, n_trades, n_retrades

def _retrades_since_message(n_unique_markets: int, n_trades: int, n_retrades: int) -> str:
return f"{n_retrades} re-trades on total {n_trades} trades in {n_unique_markets} markets"

def _average_trades_since_message(n_trades: int, n_markets: int) -> str:
if not n_markets:
average_trades = 0
else:
average_trades = round(n_trades / n_markets, 2)

return f"{average_trades} trades per market"

def _max_trades_per_market_since_message(filtered_trades: Counter[Any]) -> str:
if not filtered_trades:
max_trades = 0
else:
max_trades = max(filtered_trades.values())

return f"{max_trades} trades per market"


def _get_mech_requests_count(
mech_requests: dict[str, Any], timestamp: float = 0
) -> int:
Expand Down Expand Up @@ -395,12 +435,20 @@ def _parse_args() -> Any:
_color_percent(statistics_table[MarketAttribute.ROI][MarketState.CLOSED]),
)

since_ts = time.time() - 60 * 60 * 24 * TRADES_LOOKBACK_DAYS
since_ts = time.time() - SECONDS_PER_DAY * TRADES_LOOKBACK_DAYS
_print_status(
f"Trades on last {TRADES_LOOKBACK_DAYS} days",
_trades_since_message(trades_json, since_ts),
)

#Multi trade strategy
retrades_since_ts = time.time() - SECONDS_PER_DAY * MULTI_TRADE_LOOKBACK_DAYS
filtered_trades, n_unique_markets, n_trades, n_retrades = _calculate_retrades_since(trades_json, retrades_since_ts)
_print_subsection_header(f"Multi-trade markets in previous {MULTI_TRADE_LOOKBACK_DAYS} days")
_print_status(f"Multi-trade markets", _retrades_since_message(n_unique_markets, n_trades, n_retrades))
_print_status(f"Average trades per market", _average_trades_since_message(n_trades, n_unique_markets))
_print_status(f"Max trades per market", _max_trades_per_market_since_message(filtered_trades))

# Service
_print_section_header("Service")
_print_status("ID", str(service_id))
Expand Down
2 changes: 1 addition & 1 deletion run_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ directory="trader"
service_repo=https://github.com/$org_name/$directory.git
# This is a tested version that works well.
# Feel free to replace this with a different version of the repo, but be careful as there might be breaking changes
service_version="v0.18.2"
service_version="v0.19.0"

# Define constants for on-chain interaction
gnosis_chain_id=100
Expand Down
2 changes: 2 additions & 0 deletions scripts/choose_staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"quickstart_beta_expert": "0x5344B7DD311e5d3DdDd46A4f71481bD7b05AAA3e",
"quickstart_beta_expert_2": "0xb964e44c126410df341ae04B13aB10A985fE3513",
"quickstart_beta_expert_3": "0x80faD33Cadb5F53f9D29F02Db97D682E8b101618",
"quickstart_beta_expert_4": "0xaD9d891134443B443D7F30013c7e14Fe27F2E029",
"quickstart_beta_expert_5": "0xE56dF1E563De1B10715cB313D514af350D207212",
}

DEPRECATED_STAKING_PROGRAMS = {
Expand Down

0 comments on commit 90f938c

Please sign in to comment.