-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
151 additions
and
112 deletions.
There are no files selected for viewing
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
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,22 @@ | ||
from datetime import datetime, timedelta, timezone | ||
|
||
from curvesim.pool_data import get_pool_assets | ||
from curvesim.price_data import get_price_data | ||
from curvesim.templates import DateTimeSequence | ||
|
||
|
||
def get_asset_data(pool_metadata, time_sequence, data_source): | ||
sim_assets = get_pool_assets(pool_metadata) | ||
time_sequence = time_sequence or _make_default_time_sequence() | ||
asset_data = get_price_data( | ||
sim_assets, time_sequence, data_source=data_source | ||
) # allow DataSource to be passed | ||
return asset_data, time_sequence | ||
|
||
|
||
def _make_default_time_sequence(): | ||
t_end = datetime.now(timezone.utc) - timedelta(days=1) | ||
t_end = t_end.replace(hour=23, minute=0, second=0, microsecond=0) | ||
t_start = t_end - timedelta(days=60) + timedelta(hours=1) | ||
time_sequence = DateTimeSequence.from_range(start=t_start, end=t_end, freq="1h") | ||
return time_sequence |
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,44 @@ | ||
from datetime import datetime | ||
|
||
from curvesim.exceptions import CurvesimTypeError | ||
from curvesim.pool import get_sim_pool | ||
from curvesim.pool_data import get_metadata | ||
from curvesim.pool_data.metadata import PoolMetaDataInterface | ||
|
||
|
||
def get_pool_data(metadata_or_address, chain, env, pool_ts): | ||
pool_metadata = _parse_metadata_or_address(metadata_or_address, chain) | ||
end_ts = _parse_timestamp(pool_ts) | ||
pool = get_sim_pool(pool_metadata, env=env, end_ts=end_ts) | ||
|
||
return pool, pool_metadata | ||
|
||
|
||
def _parse_timestamp(timestamp) -> int: | ||
if not timestamp: | ||
return timestamp | ||
|
||
if isinstance(timestamp, datetime): | ||
timestamp = int(timestamp.timestamp()) | ||
|
||
if not isinstance(timestamp, int): | ||
_type = type(timestamp).__name__ | ||
raise CurvesimTypeError(f"'Pool_ts' must be 'int' or 'timestamp', not {_type}.") | ||
|
||
return timestamp | ||
|
||
|
||
def _parse_metadata_or_address(metadata_or_address, chain): | ||
if isinstance(metadata_or_address, str): | ||
pool_metadata: PoolMetaDataInterface = get_metadata(metadata_or_address, chain) | ||
|
||
elif isinstance(metadata_or_address, PoolMetaDataInterface): | ||
pool_metadata = metadata_or_address | ||
|
||
else: | ||
_type = type(metadata_or_address).__name__ | ||
raise CurvesimTypeError( | ||
f"'Metadata_or_address' must be 'PoolMetaDataInterface' or 'str', not {_type}." | ||
) | ||
|
||
return pool_metadata |
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
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.