Exemplo n.º 1
0
def test_mongo_date_range_query_asserts():
    self = create_autospec(TickStore)
    self._collection = create_autospec(Collection)
    self._collection.find_one.return_value = {'s': sentinel.start}
    with pytest.raises(AssertionError):
        TickStore._mongo_date_range_query(self, 'sym', DateRange(None, None, CLOSED_OPEN))

    with pytest.raises(AssertionError):
        TickStore._mongo_date_range_query(self, 'sym', DateRange(dt(2014, 1, 1), None))

    with pytest.raises(AssertionError):
        TickStore._mongo_date_range_query(self, 'sym', DateRange(None, dt(2014, 1, 1)))
Exemplo n.º 2
0
def test_mongo_date_range_query():
    self = create_autospec(TickStore)
    self._collection = create_autospec(Collection)
    self._collection.find_one.return_value = {'s': sentinel.start}
    self._symbol_query = partial(TickStore._symbol_query, self)
    query = TickStore._mongo_date_range_query(
        self, 'sym',
        DateRange(dt(2014, 1, 1, 0, 0, tzinfo=mktz()),
                  dt(2014, 1, 2, 0, 0, tzinfo=mktz())))
    assert self._collection.find_one.call_args_list == [
        call({
            'sy': 'sym',
            's': {
                '$lte': dt(2014, 1, 1, 0, 0, tzinfo=mktz())
            }
        },
             sort=[('s', -1)],
             projection={
                 's': 1,
                 '_id': 0
             }),
        call({
            'sy': 'sym',
            's': {
                '$gt': dt(2014, 1, 2, 0, 0, tzinfo=mktz())
            }
        },
             sort=[('s', 1)],
             projection={
                 's': 1,
                 '_id': 0
             })
    ]
    assert query == {'s': {'$gte': sentinel.start, '$lt': sentinel.start}}
Exemplo n.º 3
0
def test_mongo_date_range_query():
    self = create_autospec(TickStore)
    self._collection = create_autospec(Collection)
    self._symbol_query.return_value = {"sy": { "$in" : [ "s1" , "s2"]}}
    self._collection.aggregate.return_value = iter([{"_id": "s1", "start": dt(2014, 1, 1, 0, 0, tzinfo=mktz())},
                                                    {"_id": "s2", "start": dt(2014, 1, 1, 12, 0, tzinfo=mktz())}])
    
    self._collection.find_one.side_effect = [
        {'e': dt(2014, 1, 1, 15, 0, tzinfo=mktz())},
        {'e': dt(2014, 1, 2, 12, 0, tzinfo=mktz())}]

    query = TickStore._mongo_date_range_query(self, 'sym', DateRange(dt(2014, 1, 2, 0, 0, tzinfo=mktz()),
                                                                     dt(2014, 1, 3, 0, 0, tzinfo=mktz())))

    assert self._collection.aggregate.call_args_list == [call([
     {"$match": {"s": {"$lte": dt(2014, 1, 2, 0, 0, tzinfo=mktz())}, "sy": { "$in" : [ "s1" , "s2"]}}},
     {"$project": {"_id": 0, "s": 1, "sy": 1}},
     {"$group": {"_id": "$sy", "start": {"$max": "$s"}}},
     {"$sort": {"start": 1}}])]

    assert self._collection.find_one.call_args_list == [
        call({'sy': 's1', 's': dt(2014, 1, 1, 0, 0, tzinfo=mktz())}, {'e': 1}),
        call({'sy': 's2', 's': dt(2014, 1, 1, 12, 0, tzinfo=mktz())}, {'e': 1})]

    assert query == {'s': {'$gte': dt(2014, 1, 1, 12, 0, tzinfo=mktz()), '$lte': dt(2014, 1, 3, 0, 0, tzinfo=mktz())}}
Exemplo n.º 4
0
def setPWD(user=None, passwd=None):
    if user is not None:
        auth = lambda: None
        auth.user = user
        auth.password = passwd
        register_get_auth_hook(lambda *x, **y: auth)
    else:
        register_get_auth_hook(lambda *x, **y: None)


arctic.Arctic("192.168.1.135:19931")
setPWD("liangxuanshuo", "}[;.KLJI*(%^5g6")
client = arctic.Arctic("192.168.1.135:19931")
lib = client['liangxuanshuo.demoFuture']
data = lib.read("rb1901", )
data = lib.read(symbol='rb1901', date_range=DateRange(start='2018-09-10', end='2018-11-13'))
data.sort_index()
# 将数据按每天分类,并将前一天的夜盘并到当天
da = {}  # type: Dict[str, data]
days = []
starttime = pd.to_datetime(range(60), unit='D', origin=pd.Timestamp('2018-09-27'))


def f(x):
    return x.strftime("%m%d")


# f = lambda x: x.strftime("%m%d")
tmp = 0
for _date in starttime:  # type: daytime
    try: