本文整理汇总了Python中util.config.Config.get_config方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get_config方法的具体用法?Python Config.get_config怎么用?Python Config.get_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.config.Config
的用法示例。
在下文中一共展示了Config.get_config方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StrategyEngine
# 需要导入模块: from util.config import Config [as 别名]
# 或者: from util.config.Config import get_config [as 别名]
class StrategyEngine(object):
DEFAULT_STRATEGY = 'macd_strategy'
DEFAULT_BAR_PERIOD = 30
def __init__(self):
self.__mq_server = None
self.__data_db = DB(Constants.HIST_DATA_DB_NAME)
self.__config = Config()
self.__tick_db = FileDB(self.__config.get_config('persistent', 'hist_tick_dir'))
self.__trading_strategy = None
self.__tick_collector = None
def start(self):
Util.set_token()
self.__mq_server = MqServer()
self.__mq_server.set_callback(self.__process)
self.__mq_server.start()
def __process(self, msg, server):
content = json.loads(msg)
if not content:
_logger.warn("request msg(%r) is illegal." % msg)
return
stock_code = content.get('stock', None)
if not stock_code:
_logger.warn("stock code(%r) is invalid." % stock_code)
return
start = content.get('start', None)
end = content.get('end', None)
if not start or not end:
_logger.warn("start date(%r) or end date(%r) is null." % (start, end))
return
strategy = content.get('strategy', self.DEFAULT_STRATEGY)
buy_percent = content.get('buy_ratio', 0.5)
sell_percent = content.get('sell_ratio', 1)
context = Context()
history_data = self.__get_data(stock_code, start, end)
context.set_history_data(stock_code, history_data)
self.__tick_collector = HistTickCollector(stock_code, self.__tick_db)
self.__trading_strategy = StrategyFactory.create_strategy(strategy, self.__price_generator)
deal_strategy = DealStrategy()
sugestions = self.__trading_strategy.decide(context, stock_code, start)
_logger.info(sugestions)
deals = deal_strategy.deal(context, stock_code, sugestions)
_logger.info(deals)
server.send(json.dumps(deals))
def __get_data(self, stock_code, start, end):
collection = Collection(stock_code, self.__data_db)
start_date = datetime.strptime(start, '%Y-%m-%d')
end_date = datetime.strptime(end, '%Y-%m-%d')
result = {}
for record in collection.find().sort('date', pymongo.ASCENDING):
record_date = datetime.strptime(record['date'], '%Y-%m-%d')
if record_date >= (start_date - timedelta(days=self.DEFAULT_BAR_PERIOD)) and record_date <= end_date :
result[record['date']] = record
if record_date > end_date:
break
return OrderedDict(sorted(result.items(), key= lambda t: t[0]))
def __price_generator(self, date):
return self.__tick_collector.get_middle_price(date)
def stop(self):
self.__mq_server.stop()