Пример #1
0
    def test_batch_historical_pandas(self):

        f = get_historical_data(["AMZN", "TSLA"], self.good_start,
                                self.good_end, output_format="pandas")

        assert isinstance(f, dict)
        assert len(f) == 2
        assert sorted(list(f)) == ["AMZN", "TSLA"]

        a = f["AMZN"]
        t = f["TSLA"]

        assert len(a) == 73
        assert len(t) == 73

        expected1 = a.loc["2017-02-09"]
        assert expected1["close"] == pytest.approx(821.36, 3)
        assert expected1["high"] == pytest.approx(825.0, 3)

        expected2 = a.loc["2017-05-24"]
        assert expected2["close"] == pytest.approx(980.35, 3)
        assert expected2["high"] == pytest.approx(981.0, 3)

        expected1 = t.loc["2017-02-09"]
        assert expected1["close"] == pytest.approx(269.20, 3)
        assert expected1["high"] == pytest.approx(271.18, 3)

        expected2 = t.loc["2017-05-24"]
        assert expected2["close"] == pytest.approx(310.22, 3)
        assert expected2["high"] == pytest.approx(311.0, 3)
Пример #2
0
def import_chart():
    apple = Company.objects.filter(symbol='AAPL')[0]
    chart = iex.get_historical_data(symbols='AAPL')
    data = chart['AAPL']

    try:
        iex_provider = Provider.objects.filter(name="iex")[0]
    except IndexError:
        iex_provider = Provider.objects.create(name="iex")
        iex_provider.save()

    for date_tick in data.keys():
        date = string_to_date(date_tick)

        try:
            tick_db = Tick.objects.filter(company=apple,
                                          provider=iex_provider,
                                          date=date)[0]
        except IndexError:
            tick_db = Tick.objects.create(company=apple,
                                          provider=iex_provider,
                                          date=date,
                                          open=data[date_tick]['open'],
                                          high=data[date_tick]['high'],
                                          low=data[date_tick]['low'],
                                          close=data[date_tick]['close'],
                                          volume=data[date_tick]['volume'])
            tick_db.save()

    ticks = serializers.json.Deserializer(chart)
    print("ticks", ticks)
Пример #3
0
    def test_single_historical_json(self):

        f = get_historical_data("AMZN", self.good_start, self.good_end)
        assert isinstance(f, dict)
        assert len(f["AMZN"]) == 73

        expected1 = f["AMZN"]["2017-02-09"]
        assert expected1["close"] == pytest.approx(821.36, 3)
        assert expected1["high"] == pytest.approx(825.0, 3)

        expected2 = f["AMZN"]["2017-05-24"]
        assert expected2["close"] == pytest.approx(980.35, 3)
        assert expected2["high"] == pytest.approx(981.0, 3)
Пример #4
0
    def test_single_historical_pandas(self):

        f = get_historical_data("AMZN", self.good_start, self.good_end,
                                output_format="pandas")

        assert isinstance(f, pd.DataFrame)
        assert len(f) == 73

        expected1 = f.loc["2017-02-09"]
        assert expected1["close"] == pytest.approx(821.36, 3)
        assert expected1["high"] == pytest.approx(825.0, 3)

        expected2 = f.loc["2017-05-24"]
        assert expected2["close"] == pytest.approx(980.35, 3)
        assert expected2["high"] == pytest.approx(981.0, 3)
Пример #5
0
 def test_invalid_dates_batch(self):
     start = datetime(2010, 5, 9)
     end = datetime(2017, 5, 9)
     with pytest.raises(ValueError):
         get_historical_data(["AAPL", "TSLA"], start, end)
Пример #6
0
 def test_invalid_symbol_batch(self):
     start = datetime(2017, 2, 9)
     end = datetime(2017, 5, 24)
     with pytest.raises(IEXSymbolError):
         get_historical_data(["BADSYMBOL", "TSLA"], start, end)