示例#1
0
def test_quotes():
    inst = instrument.Instrument(isin="FR0011665280",
                                 type=instrument.InstrumentType.STOCK,
                                 name="Figeac Aero",
                                 symbol="FGA",
                                 currency="EUR",
                                 exchange_mic="XPAR",
                                 pea=None,
                                 pea_pme=None,
                                 ttf=None)
    inst.refresh_quotes()
    quotes = inst.quotes.values()
    assert instrument.Quote(date=datetime.date(2017, 12, 20),
                            open=16.73,
                            close=17.69,
                            high=17.69,
                            low=16.25,
                            volume=179707) in quotes
    inst = instrument.Instrument(isin="FR0011665281",
                                 type=instrument.InstrumentType.STOCK,
                                 name="Invalid",
                                 symbol="FGAXX",
                                 currency="EUR",
                                 exchange_mic="XPAR",
                                 pea=None,
                                 pea_pme=None,
                                 ttf=None)
    inst.refresh_quotes()
    quotes = inst.quotes.values()
    assert list(quotes) == []
示例#2
0
def test_quotes_list():
    q1 = instrument.Quote(date=datetime.date(2016, 12, 12),
                          low=None,
                          high=None,
                          open=None,
                          close=None,
                          volume=None)
    q2 = instrument.Quote(date=datetime.date(2016, 12, 18),
                          low=None,
                          high=None,
                          open=None,
                          close=None,
                          volume=None)
    q3 = instrument.Quote(date=datetime.date(2016, 12, 19),
                          low=None,
                          high=None,
                          open=None,
                          close=None,
                          volume=None)
    q4 = instrument.Quote(date=datetime.date(2016, 12, 21),
                          low=None,
                          high=None,
                          open=None,
                          close=None,
                          volume=None)
    ql = instrument.QuoteList([q1, q2, q4, q3])
    assert ql[0] == q1
    assert ql[1] == q2
    assert ql[2] == q3
    assert ql[3] == q4
    assert ql[q3.date] == q3
    assert ql[q2.date] == q2
    assert ql[:q3.date] == [q1, q2, q3]
    assert ql[q1.date:q3.date] == [q1, q2, q3]
    assert ql[q2.date:] == [q2, q3, q4]
    assert ql[datetime.date(2017, 1, 1):] == []
    assert ql[:datetime.date(2015, 1, 1)] == []
    assert ql[:datetime.date(2016, 12, 13)] == [q1]
    assert ql[datetime.date(2016, 12, 13):] == [q2, q3, q4]