def test_leakage_limit_nrecords():
    data = np.array(
        [(pd.Timestamp("2019-01-01 01:02:03").value / 10**9, 1, 2, 0)],
        dtype=[("Epoch", "i8"), ("Bid", "f4"), ("Ask", "f4"),
               ("Nanoseconds", "i4")],
    )
    data2 = np.array(
        [(pd.Timestamp("2019-01-01 01:02:03").value / 10**9, 3, 4, 100_000_000)
         ],
        dtype=[("Epoch", "i8"), ("Bid", "f4"), ("Ask", "f4"),
               ("Nanoseconds", "i4")],
    )
    client.write(data, "DEBUG/1Sec/TICK", isvariablelength=True)
    client.write(data2, "DEBUG/1Sec/TICK", isvariablelength=True)

    param = pymkts.Param(
        "DEBUG",
        "1Sec",
        "TICK",
        start=pd.Timestamp("2019-01-01 01:02:03.100000000"),
        limit=1,
        limit_from_start=True,
    )
    reply = client.query(param)
    df = reply.first().df()
    print(df)
    # if wrong, it means the first tick leaks outside of the interval starting within
    # `start` parameter
    cond1 = ((df.shape[0] == 1) and (df.Bid[0] == 3)
             and (df.Nanoseconds[0] == 100_000_000))

    assert cond1

    param = pymkts.Param(
        "DEBUG",
        "1Sec",
        "TICK",
        end=pd.Timestamp("2019-01-01 01:02:03.000000000"),
        limit=1,
        limit_from_start=False,
    )
    reply = client.query(param)
    df = reply.first().df()
    print(df)
    # if wrong, it means the second tick leaks outside of the interval ending within
    # `end` parameter
    cond2 = (df.shape[0] == 1) and (df.Bid[0] == 1) and (df.Nanoseconds[0]
                                                         == 0)

    assert cond2
Пример #2
0
    def random_query(self, symbol: str, timeframe: str, attribute_group: str,
                     size: int, num: int, limit_from_start: bool,
                     time_range: str, limit: str) -> int:
        # TODO: add start, end, limit, limit_from_start options
        if num <= 0:
            return 0

        params = []
        for k in range(num):
            start, end = get_range(time_range)
            params.append(
                pymkts.Param(symbol,
                             timeframe,
                             attribute_group,
                             start=start,
                             end=end,
                             limit=get_limit(limit, size),
                             limit_from_start=limit_from_start))

        now = time.time_ns()
        for k in range(num):
            self.cli.query(params[k])
            # reply = self.cli.query(params[k])
            # print(reply.first().df())
        elapsed = time.time_ns() - now

        return elapsed
Пример #3
0
    def random_query(self, symbol: str, timeframe: str, attribute_group: str,
                     size: int, num: int, limit_from_start: bool,
                     time_range: str, limit: str, grpc: bool) -> int:
        if num <= 0:
            return 0

        params = []
        for k in range(num):
            start, end = get_range(time_range)
            params.append(
                pymkts.Param(symbols=symbol,
                             timeframe=timeframe,
                             attrgroup=attribute_group,
                             start=start,
                             end=end,
                             limit=get_limit(limit, size),
                             limit_from_start=limit_from_start))

        c = self.get_client(grpc)

        # first query takes a lot of time compared to the following queries.
        # query once to remove the effect.
        if num > 0:
            c.query(params=params[0])

        now = time.time_ns()
        for k in range(num):
            c.query(params=params[k])
            # reply = self.cli.query(params[k])
            # print(reply.first().df())
        elapsed = time.time_ns() - now

        return elapsed
Пример #4
0
    def get_bulk_history(self, symbols, timeframe, attrgroup='OHLCV',
                         start=None, end=None,
                         limit=None, limit_from_start=False):
        if isinstance(symbols, str):
            symbols = [symbols]

        p = pymkts.Param(','.join(symbols), get_timeframe(timeframe), attrgroup,
                         start=start, end=end,
                         limit=limit, limit_from_start=limit_from_start)
        r = self.client.query(p)
        return {symbol: ds.df() for symbol, ds in r.by_symbols().items()}
Пример #5
0
 def get_history(self, symbol, timeframe, attrgroup='OHLCV',
                 start=None, end=None,
                 limit=None, limit_from_start=False):
     p = pymkts.Param(symbol, get_timeframe(timeframe), attrgroup,
                      start=start, end=end,
                      limit=limit, limit_from_start=limit_from_start)
     try:
         return self.client.query(p).first().df()
     except Exception as e:
         if 'No files returned from query parse' in e.args[0]:
             return None
         raise e
Пример #6
0
def get_df(symbol, timeframe='1D', attrgroup='OHLCV'):
    client = pymkts.Client()
    p = pymkts.Param(symbol, timeframe, attrgroup, start='2015-01-01')
    return client.query(p).first().df()