forked from QuantFans/quantdigger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.py
More file actions
36 lines (27 loc) · 955 Bytes
/
Copy pathsource.py
File metadata and controls
36 lines (27 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
class SourceWrapper(object):
""" 数据源包装器,使相关数据源支持逐步读取操作 """
def __init__(self, pcontract, data, max_length):
self.data = data
self.curbar = -1
self.pcontract = pcontract
self._max_length = max_length
def __len__(self):
return self._max_length
def rolling_forward(self):
""" 读取下一个数据"""
self.curbar += 1
if self.curbar == self._max_length:
return False, self.curbar
else:
return True, self.curbar
class DatasourceAbstract(object):
'''数据源抽象基类'''
def get_bars(self, pcontract, dt_start, dt_end):
raise NotImplementedError
def get_last_bars(self, pcontract, n):
raise NotImplementedError
def get_contracts(self):
raise NotImplementedError
def get_code2strpcon(self):
raise NotImplementedError