def load_json(self): """ Gets market chart data from today to a previous date """ today = dt.now() DIRECTION = 'last' epochs = date.get_end_start_epochs(today.year, today.month, today.day, DIRECTION, self.unit, self.count) self.json = poloniex.chart_json(epochs['shifted'], epochs['initial'], self.period, self.symbol)[0]
}] EXPECTED_CHANGES = ([ EXPECTED_RESPONSE[1]['close'] - EXPECTED_RESPONSE[0]['close'] ]) YEAR = 2017 MONTH = 1 DAY = 1 UNIT = 'day' COUNT = 3 PERIOD = 86400 SYMBOL = 'USDT_BTC' EPOCH1 = 1483228800 # 01/01/2017, 00:00 epoch EPOCH2 = 1483315200 # 01/02/2017, 00:00 epoch HTTP_RESPONSE = poloniex.chart_json(EPOCH1, EPOCH2, PERIOD, SYMBOL)[0] class PoloniexIntegrationTest(unittest.TestCase): def test_parse_changes(self): self.assertEqual(poloniex.parse_changes(HTTP_RESPONSE), EXPECTED_CHANGES) 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 test_chart_json(self): http_response = poloniex.chart_json(EPOCH1, EPOCH2, PERIOD, SYMBOL)[0] self.assertEqual(http_response, EXPECTED_RESPONSE)