-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Curve Prices API for pool volume #277
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dff0508
Use Curve Prices API for pool volume
nagakingg 98a6f81
Remove PoolDataCache
nagakingg 048c0e8
Move get_pool_volume() to pool_data
nagakingg f3c1904
Commit data for CI test - GH run ID: 6670341442
github-actions[bot] 10b1a16
Use token wrapper addresses for lending pool volume
nagakingg 03e03d2
Commit data for CI test - GH run ID: 6672156480
github-actions[bot] 6637750
Correct adress order, use checksum addresses in get_pool_pair_volume
nagakingg ac070fe
Commit data for CI test - GH run ID: 6721414119
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
changelog.d/20231025_203748_nagakingg_curve_prices_volume.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Removed | ||
------- | ||
- Removed volume multiplier modes | ||
- Removed pipelines.utils | ||
- Removed PriceVolume.total_volumes() | ||
- Removed volume from PoolDataCache | ||
- Removed convex subgraph volume query | ||
- Removed PoolDataCache | ||
|
||
Added | ||
----- | ||
- Added Curve Prices API volume query (network.curve_prices) | ||
- Added pool_data.get_pool_volume() to fetch historical pool volume from | ||
Curve Prices API | ||
|
||
Changed | ||
------- | ||
- Volume multipliers now computed individually for each asset pair | ||
- Replaced pool_data.queries with folder | ||
- Pool volume and volume limiting are only supported for Ethereum pools | ||
pending updates to Curve Prices API | ||
|
||
Deprecated | ||
---------- | ||
- RAI3CRV pool is currently unsupported by simulation pipelines. It will | ||
be reimplemented along with Stableswap-NG pools. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
""" | ||
Network connector for Curve Prices API. | ||
""" | ||
|
||
from typing import List | ||
|
||
from eth_utils import to_checksum_address | ||
from pandas import DataFrame, to_datetime | ||
|
||
from curvesim.exceptions import ApiResultError, CurvesimValueError | ||
|
||
from .http import HTTP | ||
from .utils import sync | ||
|
||
URL = "https://prices.curve.fi/v1/" | ||
|
||
CHAIN_ALIASES = {"mainnet": "ethereum"} | ||
|
||
|
||
async def _get_pool_pair_volume( | ||
pool_address, | ||
main_token_address, | ||
reference_token_address, | ||
start_ts, | ||
end_ts, | ||
*, | ||
chain="ethereum", | ||
interval="day", | ||
): | ||
chain = _chain_from_alias(chain) | ||
pool_address = to_checksum_address(pool_address) | ||
main_token_address = to_checksum_address(main_token_address) | ||
reference_token_address = to_checksum_address(reference_token_address) | ||
|
||
url = URL + f"volume/{chain}/{pool_address}" | ||
params = { | ||
"main_token": main_token_address, | ||
"reference_token": reference_token_address, | ||
"start": start_ts, | ||
"end": end_ts, | ||
"interval": interval, | ||
} | ||
r = await HTTP.get(url, params=params) | ||
|
||
try: | ||
data = r["data"] | ||
except KeyError as e: | ||
raise ApiResultError( | ||
"No historical volume returned for\n" | ||
f"Pool: '{pool_address}', Chain: '{chain}',\n" | ||
f"Tokens: (main: {main_token_address}, " | ||
f"reference: {reference_token_address}),\n" | ||
f"Timestamps: (start: {start_ts}, end: {end_ts})" | ||
) from e | ||
|
||
return data | ||
|
||
|
||
async def get_pool_pair_volume( | ||
pool_address: str, | ||
main_token_address: str, | ||
reference_token_address: str, | ||
start_ts: int, | ||
end_ts: int, | ||
*, | ||
chain: str = "ethereum", | ||
interval: str = "day", | ||
) -> DataFrame: | ||
""" | ||
Gets historical daily volume for a pair of coins traded in a Curve pool. | ||
|
||
Parameters | ||
---------- | ||
pool_address: str | ||
The Curve pool's address. | ||
|
||
main_token_address: str | ||
Address for the token volume will be denominated in. | ||
|
||
reference_token_address: str | ||
Address for the second token in the trading pair. | ||
|
||
start_ts: int | ||
Posix timestamp (UTC) for start of query period. | ||
|
||
end_ts: int | ||
Posix timestamp (UTC) for end of query period. | ||
|
||
chain: str, default "ethereum" | ||
The pool's blockchain (note: currently only "ethereum" supported) | ||
|
||
interval: str, default "day" | ||
The sampling interval for the data. Available values: week, day, hour | ||
|
||
Returns | ||
------- | ||
DataFrame | ||
Rows: DateTimeIndex; Columns: volume, fees | ||
|
||
""" | ||
data: List[dict] = await _get_pool_pair_volume( | ||
pool_address, | ||
main_token_address, | ||
reference_token_address, | ||
start_ts, | ||
end_ts, | ||
chain=chain, | ||
interval=interval, | ||
) | ||
|
||
df = DataFrame(data, columns=["timestamp", "volume", "fees"]) | ||
df["timestamp"] = to_datetime(df["timestamp"], unit="s") | ||
df.set_index("timestamp", inplace=True) | ||
return df | ||
|
||
|
||
def _chain_from_alias(chain): | ||
if chain in CHAIN_ALIASES: # pylint: disable=consider-using-get | ||
chain = CHAIN_ALIASES[chain] | ||
|
||
if chain != "ethereum": | ||
raise CurvesimValueError( | ||
"Curve Prices API currently only supports Ethereum chain." | ||
) | ||
|
||
return chain | ||
|
||
|
||
get_pool_pair_volume_sync = sync(get_pool_pair_volume) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention we've removed volume support for chains other Mainnet (pending future support from the curve-prices API) and sims for the RAI pool are no longer supported.