Esempio n. 1
0
async def async_get_board_candles(ticker: Ticker, cache_dir: Optional[str], start: str, end: Optional[str], interval: int):
    cache_file = f'moex_candles_{ticker.symbol}_{start}_{end if end else "now"}_{interval}.cache'
    ttl = datetime.timedelta(days=1)

    cache = DataFrameCache(cache_dir, cache_file, ttl)
    df = cache.get()
    if df is not None:
        return df

    async with aiomoex.ISSClientSession():
        engine, market, board = '', '', ''

        resp = await aiomoex.find_securities(ticker.symbol, columns=('secid', 'name', 'group', 'primary_boardid'))
        for x in resp:
            if x['secid'] != ticker.symbol:
                continue
            engine, market = x['group'].split('_')
            board = x['primary_boardid']

        if engine == '':
            raise Exception(f'unknown ticker {ticker}')

        rdata = await aiomoex.get_board_candles(ticker.symbol, start=start, end=end, interval=interval, engine=engine, market=market, board=board)
        df = pandas.DataFrame(rdata)
        df.set_index('begin', inplace=True)
        df.drop(['value'], axis=1, inplace=True)

        cache.put(df)
        return df
Esempio n. 2
0
async def test_update_timestamp(path, monkeypatch):
    monkeypatch.setattr(config, "DATA_PATH", path)
    async with aiomoex.ISSClientSession():
        with lmbd.DataStore(path, MAX_SIZE, MAX_DBS) as db:
            date = await utils.update_timestamp(db)
            date_web = await utils.download_last_history()
            date_store = db[utils.LAST_HISTORY].value
    assert date == date_web == date_store
Esempio n. 3
0
async def test_download_last_history():
    async with aiomoex.ISSClientSession():
        date = await utils.download_last_history()
    assert isinstance(date, pd.Timestamp)
    assert date.hour == 19
    assert date.minute == 45
    assert date.second == 0
    assert date.microsecond == 0
    assert date.nanosecond == 0
    now = pd.Timestamp.now("Europe/Moscow")
    assert date < pd.Timestamp.now("Europe/Moscow")
    # noinspection PyUnresolvedReferences
    assert date.tz == now.tz
Esempio n. 4
0
async def test_update_timestamp_after_end_of_trading_day(path, monkeypatch):
    monkeypatch.setattr(config, "DATA_PATH", path)
    fake_end_of_trading = dict(hour=0,
                               minute=0,
                               second=0,
                               microsecond=0,
                               nanosecond=0)
    async with aiomoex.ISSClientSession():
        with lmbd.DataStore(path, MAX_SIZE, MAX_DBS) as db:
            date_web = await utils.download_last_history()
            monkeypatch.setattr(utils, "END_OF_TRADING", fake_end_of_trading)
            date = await utils.update_timestamp(db)
            date_store = db[utils.LAST_HISTORY].value
    assert date == date_web == date_store
Esempio n. 5
0
async def fake_data_path(path):
    async with aiomoex.ISSClientSession() as session:
        with lmbd.DataStore(path, MAX_SIZE, MAX_DBS) as db:
            manager.AbstractManager.ISS_SESSION = session
            manager.AbstractManager.STORE = db
            yield
Esempio n. 6
0
 def __init__(self):
     self._session = aiomoex.ISSClientSession()
     self._store = open_store()