def from_poloniex(json): """ Gets SO from a JSON of market data Args: json: List of dates where each entry is a dict of raw market data. Returns: Float SO between 0 and 100. """ close = json[-1]['close'] # Latest closing price low = min(poloniex.get_attribute(json, 'low')) # Lowest low high = max(poloniex.get_attribute(json, 'high')) # Highest high return eval_algorithm(close, low, high)
def eval_from_json(json): """ Evaluates OBV from JSON (typically Poloniex API response) Args: json: List of dates where each entry is a dict of raw market data. Returns: Float of OBV """ closes = poloniex.get_attribute(json, 'close') volumes = poloniex.get_attribute(json, 'volume') obv = 0 for date in range(1, len(json)): curr = {'close': closes[date], 'volume': volumes[date]} prev = {'close': closes[date - 1], 'obv': obv} obv = OBV.eval_algorithm(curr, prev) return obv
def from_poloniex(json): """ Gets OBV from a JSON of market data Args: json: List of dates where each entry is a dict of raw market data. Returns: Float of OBV """ closes = poloniex.get_attribute(json, 'close') volumes = poloniex.get_attribute(json, 'volume') for date, _ in enumerate(json): if date == 0: obv = 0 continue curr = {'close': closes[date], 'volume': volumes[date]} prev = {'close': closes[date - 1], 'obv': obv} obv = eval_algorithm(curr, prev) return obv
def test_get_attribute(self): res = [attribute['quoteVolume'] for attribute in HTTP_RESPONSE] attr = 'quoteVolume' self.assertEqual(poloniex.get_attribute(HTTP_RESPONSE, attr), res)