Added default type none to price argument in OHLCV methods

This commit is contained in:
Sam Germain 2021-10-13 18:39:49 -06:00
parent 48470e33ec
commit 06dea121fd
4 changed files with 26 additions and 18 deletions

View File

@ -219,13 +219,15 @@ class Binance(Exchange):
raise OperationalException(e) from e
def _get_mark_price(self, pair: str, date: datetime) -> float:
# TODO-lev: implement
raise OperationalException(f'_get_mark_price has not been implemented on {self.name}')
def _get_funding_rate(self, pair: str, premium_index: float) -> Optional[float]:
def _get_funding_rate(self, pair: str, when: datetime):
"""
Get's the funding_rate for a pair at a specific date and time in the past
"""
raise OperationalException(f'_get_mark_price has not been implemented on {self.name}')
# TODO-lev: implement
raise OperationalException(f"get_funding_rate has not been implemented for {self.name}")
def _get_funding_fee(
self,
@ -253,7 +255,7 @@ class Binance(Exchange):
timeframe: str,
since_ms: int,
is_new_pair: bool,
price: Optional[str]
price: Optional[str] = None
) -> List:
"""
Overwrite to introduce "fast new pair" functionality by detecting the pair's listing date

View File

@ -1296,7 +1296,7 @@ class Exchange:
pair: str,
timeframe: str,
since_ms: int,
price: Optional[str]
price: Optional[str] = None
) -> DataFrame:
"""
Minimal wrapper around get_historic_ohlcv - converting the result into a dataframe
@ -1306,14 +1306,13 @@ class Exchange:
:param price: "mark" if retrieving the mark price cnadles, "index" for index price candles
:return: OHLCV DataFrame
"""
ticks = self.get_historic_ohlcv(pair, timeframe, since_ms=since_ms)
ticks = self.get_historic_ohlcv(pair, timeframe, since_ms=since_ms, price=price)
return ohlcv_to_dataframe(
ticks,
timeframe,
pair=pair,
fill_missing=True,
drop_incomplete=self._ohlcv_partial_candle,
price=price
drop_incomplete=self._ohlcv_partial_candle
)
async def _async_get_historic_ohlcv(
@ -1322,7 +1321,7 @@ class Exchange:
timeframe: str,
since_ms: int,
is_new_pair: bool,
price: Optional[str]
price: Optional[str] = None
) -> List:
"""
Download historic ohlcv
@ -1368,7 +1367,7 @@ class Exchange:
pair_list: ListPairsWithTimeframes, *,
since_ms: Optional[int] = None,
cache: bool = True,
price: Optional[str]
price: Optional[str] = None
) -> Dict[Tuple[str, str], DataFrame]:
"""
Refresh in-memory OHLCV asynchronously and set `_klines` with the result

View File

@ -1557,15 +1557,18 @@ def test_get_historic_ohlcv(default_conf, mocker, caplog, exchange_name):
]
pair = 'ETH/BTC'
async def mock_candle_hist(pair, timeframe, since_ms):
async def mock_candle_hist(pair, timeframe, since_ms, price=None):
return pair, timeframe, ohlcv
exchange._async_get_candle_history = Mock(wraps=mock_candle_hist)
# one_call calculation * 1.8 should do 2 calls
since = 5 * 60 * exchange.ohlcv_candle_limit('5m') * 1.8
ret = exchange.get_historic_ohlcv(pair, "5m", int((
arrow.utcnow().int_timestamp - since) * 1000))
ret = exchange.get_historic_ohlcv(
pair,
"5m",
int((arrow.utcnow().int_timestamp - since) * 1000)
)
assert exchange._async_get_candle_history.call_count == 2
# Returns twice the above OHLCV data
@ -1577,8 +1580,11 @@ def test_get_historic_ohlcv(default_conf, mocker, caplog, exchange_name):
raise TimeoutError()
exchange._async_get_candle_history = MagicMock(side_effect=mock_get_candle_hist_error)
ret = exchange.get_historic_ohlcv(pair, "5m", int(
(arrow.utcnow().int_timestamp - since) * 1000))
ret = exchange.get_historic_ohlcv(
pair,
"5m",
int((arrow.utcnow().int_timestamp - since) * 1000)
)
assert log_has_re(r"Async code raised an exception: .*", caplog)
@ -1613,7 +1619,7 @@ def test_get_historic_ohlcv_as_df(default_conf, mocker, exchange_name):
]
pair = 'ETH/BTC'
async def mock_candle_hist(pair, timeframe, since_ms):
async def mock_candle_hist(pair, timeframe, since_ms, price=None):
return pair, timeframe, ohlcv
exchange._async_get_candle_history = Mock(wraps=mock_candle_hist)

View File

@ -276,9 +276,10 @@ def test_fill_leverage_brackets_ftx(default_conf, mocker):
('XRP/USDT', datetime.utcnow() - timedelta(hours=30)),
])
def test__get_funding_rate(default_conf, mocker, pair, when):
api_mock = MagicMock()
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="ftx")
assert exchange._get_funding_rate(pair, when) is None
# api_mock = MagicMock()
# exchange = get_patched_exchange(mocker, default_conf, api_mock, id="ftx")
# assert exchange._get_funding_rate(pair, when) is None
return
def test__get_funding_fee():