update add_external_candle returns

This commit is contained in:
Timothy Pogue 2022-11-27 12:17:26 -07:00
parent 4cbb3341d7
commit 36a00e8de0
2 changed files with 11 additions and 9 deletions

View File

@ -7,7 +7,7 @@ Common Interface for bot and strategy to access data.
import logging import logging
from collections import deque from collections import deque
from datetime import datetime, timezone from datetime import datetime, timezone
from typing import Any, Dict, List, Optional, Tuple, Union from typing import Any, Dict, List, Optional, Tuple
from pandas import DataFrame, concat from pandas import DataFrame, concat
@ -165,7 +165,7 @@ class DataProvider:
timeframe: str, timeframe: str,
candle_type: CandleType, candle_type: CandleType,
producer_name: str = "default" producer_name: str = "default"
) -> Union[bool, int]: ) -> Tuple[bool, int]:
""" """
Append a candle to the existing external dataframe Append a candle to the existing external dataframe
@ -179,22 +179,22 @@ class DataProvider:
if producer_name not in self.__producer_pairs_df: if producer_name not in self.__producer_pairs_df:
# We don't have data from this producer yet, # We don't have data from this producer yet,
# so we can't append a candle # so we can't append a candle
return False return (False, 0)
if pair_key not in self.__producer_pairs_df[producer_name]: if pair_key not in self.__producer_pairs_df[producer_name]:
# We don't have data for this pair_key, # We don't have data for this pair_key,
# so we can't append a candle # so we can't append a candle
return False return (False, 0)
# CHECK FOR MISSING CANDLES # CHECK FOR MISSING CANDLES
# return int # return (False, int > 0)
existing_df, _ = self.__producer_pairs_df[producer_name][pair_key] existing_df, _ = self.__producer_pairs_df[producer_name][pair_key]
appended_df = self._append_candle_to_dataframe(existing_df, dataframe) appended_df = self._append_candle_to_dataframe(existing_df, dataframe)
# Everything is good, we appended # Everything is good, we appended
self.__producer_pairs_df[producer_name][pair_key] = appended_df, last_analyzed self.__producer_pairs_df[producer_name][pair_key] = appended_df, last_analyzed
return True return (True, 0)
def _append_candle_to_dataframe(self, existing: DataFrame, new: DataFrame) -> DataFrame: def _append_candle_to_dataframe(self, existing: DataFrame, new: DataFrame) -> DataFrame:
""" """

View File

@ -393,14 +393,16 @@ class ExternalMessageConsumer:
# Have dataprovider append it to # Have dataprovider append it to
# the full datafame. If it can't, # the full datafame. If it can't,
# request the missing candles # request the missing candles
if not self._dp._add_external_candle( did_append, n_missing = self._dp._add_external_candle(
pair, pair,
df, df,
last_analyzed=la, last_analyzed=la,
timeframe=timeframe, timeframe=timeframe,
candle_type=candle_type, candle_type=candle_type,
producer_name=producer_name producer_name=producer_name
): )
if not did_append:
logger.info("Holes in data or no existing df, " logger.info("Holes in data or no existing df, "
f"requesting data for {key} from `{producer_name}`") f"requesting data for {key} from `{producer_name}`")
@ -408,7 +410,7 @@ class ExternalMessageConsumer:
producer_name, producer_name,
WSAnalyzedDFRequest( WSAnalyzedDFRequest(
data={ data={
"limit": 1000, "limit": n_missing if n_missing > 0 else 1000,
"pair": pair "pair": pair
} }
) )