Skip to content

Commit

Permalink
support context_vars with dict input
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWang committed Mar 30, 2017
1 parent 2d7dc02 commit 9c1bd1b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions rqalpha/mod/rqalpha_mod_sys_stock_realtime/event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from rqalpha.environment import Environment
from rqalpha.utils.logger import system_log
from rqalpha.events import Event, EVENT
from rqalpha.utils import json as json_utils
from rqalpha.utils import rq_json
from .utils import get_realtime_quotes, order_book_id_2_tushare_code, is_holiday_today, is_tradetime_now


Expand All @@ -45,12 +45,12 @@ def __init__(self, fps):
self.quotation_engine_thread.daemon = True

def set_state(self, state):
persist_dict = json_utils.convert_json_to_dict(state.decode('utf-8'))
persist_dict = rq_json.convert_json_to_dict(state.decode('utf-8'))
self.before_trading_fire_date = persist_dict['before_trading_fire_date']
self.after_trading_fire_date = persist_dict['after_trading_fire_date']

def get_state(self):
return json_utils.convert_dict_to_json({
return rq_json.convert_dict_to_json({
"before_trading_fire_date": self.before_trading_fire_date,
"after_trading_fire_date": self.after_trading_fire_date,
}).encode('utf-8')
Expand Down
8 changes: 5 additions & 3 deletions rqalpha/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ def parse_config(config_args, config_path=None, click_type=True, source_code=Non
user_system_log.handlers.append(user_std_handler)

if extra_config.context_vars:
import base64
import json
extra_config.context_vars = json.loads(base64.b64decode(extra_config.context_vars).decode('utf-8'))
import simplejson as json
print(extra_config.context_vars, type(extra_config.context_vars))
if isinstance(extra_config.context_vars, six.string_types):
print(to_utf8(extra_config.context_vars))
extra_config.context_vars = json.loads(to_utf8(extra_config.context_vars))

if base_config.stock_starting_cash < 0:
raise patch_user_exc(ValueError(_('invalid stock starting cash: {}').format(base_config.stock_starting_cash)))
Expand Down
File renamed without changes.

0 comments on commit 9c1bd1b

Please sign in to comment.