Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirEven committed Oct 9, 2024
1 parent 43341da commit 53cc63f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 18 deletions.
3 changes: 1 addition & 2 deletions locast/candle/candle_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ def amount_of_candles_in_range(
range_seconds = (end_date - start_date).total_seconds()
return int(range_seconds / resolution.seconds)

# TODO: Rename this func
@classmethod
def amount_of_candles_missing_inbetween(
def amount_missing(
cls,
start_date: datetime,
end_date: datetime,
Expand Down
14 changes: 1 addition & 13 deletions locast/candle_fetcher/dydx/candle_fetcher/dydx_candle_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ def __init__(self, api_fetcher: DydxFetcher, log_progress: bool = False) -> None
def exchange(self) -> Exchange:
return self._exchange

# TODO: This function contains violation detection and reporting code, that is not covering edge cases (where a gap exists in between two batches).
# Also i would like to refactor that code out of here to make fetch_candles really only call violoation and logging specific code.
# Idea:
# - Run violation detection not on batch, but on candles collected so far (where batches are incrementally added to)
# - Problem: We run detection over the same candles many times which is more expensive and forces us to handle duplicate detections.
# - The simpler apporach would be, to feed overlapping portions into detection func, by not strictly passing a batch,
# but rather passing a candle range reaching from previous batch end to current batch end. This way, if a gap exists inbetween batches
# it would still detect it.
async def fetch_candles(
self,
market: str,
Expand Down Expand Up @@ -163,10 +155,6 @@ def _violations_in_batch(

def _count_missing(self, batch_violations: List[Tuple[Candle, Candle]]):
return sum(
cu.amount_of_candles_missing_inbetween(
vi[0].started_at,
vi[1].started_at,
vi[0].resolution,
)
cu.amount_missing(vi[0].started_at, vi[1].started_at, vi[0].resolution)
for vi in batch_violations
)
2 changes: 1 addition & 1 deletion locast/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def log_integrity_violations(
detail = f"{market}, {resolution.notation}"
print(f"{emoji} Attention: {exchange.name} delivered {n} {vi} for {detail} {emoji}")
for v in violations:
n_missing = cu.amount_of_candles_missing_inbetween(
n_missing = cu.amount_missing(
v[0].started_at,
v[1].started_at,
resolution,
Expand Down
2 changes: 1 addition & 1 deletion notebooks/example_dydx_v3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion tests/candle/test_candle_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_amount_of_candles_missing_intbetween_returns_correctly(amount: int) ->
start = candles[-1].started_at
end = candles[0].started_at
res = candles[0].resolution
missing = uc.amount_of_candles_missing_inbetween(start, end, res)
missing = uc.amount_missing(start, end, res)

# then
expected_missing = amount - 2
Expand Down

0 comments on commit 53cc63f

Please sign in to comment.