def test_get_gains_losses(self): res = { 'gains': [g for g in EXPECTED_CHANGES if g >= 0], 'losses': [l for l in EXPECTED_CHANGES if l < 0] } self.assertEqual( poloniex.get_gains_losses(poloniex.parse_changes(HTTP_RESPONSE)), res)
def from_poloniex(json): """ Gets RSI from a JSON of market data Args: json: List of dates where each entry is a dict of raw market data. Returns: Float between 0 and 100, momentum indicator of a market measuring the speed and change of price movements. """ changes = poloniex.get_gains_losses(poloniex.parse_changes(json)) return eval_algorithm(changes['gains'], changes['losses'])
def eval_from_json(json): """ Evaluates RSI from JSON (typically Poloniex API response) Args: json: List of dates where each entry is a dict of raw market data. Returns: Float between 0 and 100, momentum indicator of a market measuring the speed and change of price movements. """ changes = poloniex.get_gains_losses(poloniex.parse_changes(json)) return RSI.eval_algorithm(changes['gains'], changes['losses'])
def test_get_gains_losses(self): res = { 'gains': [g for g in EXPECTED_CHANGES if g >= 0], 'losses': [l for l in EXPECTED_CHANGES if l < 0] } self.assertEqual(poloniex.get_gains_losses(EXPECTED_CHANGES), res)