Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- Fix MarketUtils.is_opening
- Fix Transaction.get_cn_type
- Support config runner interval
- More logs
  • Loading branch information
sinall committed Dec 6, 2016
1 parent 04d1b82 commit 8c7e59d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ ShiPanE-Python-SDK
先决条件
^^^^^^^^

- 部署实盘易成功
- 手动测试通过
- 聚宽(公网)可访问实盘易
- 部署实盘易成功
- 手动测试通过
- 聚宽(公网)可访问实盘易

步骤
^^^^
Expand All @@ -40,8 +40,8 @@ ShiPanE-Python-SDK
先决条件
^^^^^^^^

- 部署实盘易成功
- 手动测试通过
- 部署实盘易成功
- 手动测试通过

步骤
^^^^
Expand Down
4 changes: 3 additions & 1 deletion examples/joinquant/config/config.ini.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ key=
[JoinQuant]
username=
password=
backtestId=
backtest_id=
interval=10
idle_interval=60
6 changes: 4 additions & 2 deletions examples/joinquant/simple_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
key=config.get('ShiPanE', 'key'))
jq_client = JoinQuantClient(username=config.get('JoinQuant', 'username'),
password=config.get('JoinQuant', 'password'),
backtest_id=config.get('JoinQuant', 'backtestId'))
backtest_id=config.get('JoinQuant', 'backtest_id'))
jq_client.login()
runner = JoinQuantRunner(shipane_client, jq_client, interval=15)
runner = JoinQuantRunner(shipane_client, jq_client,
interval=config.getint('JoinQuant', 'interval'),
idle_interval=config.getint('JoinQuant', 'idle_interval'))

runner.run()
7 changes: 4 additions & 3 deletions shipane_sdk/joinquant/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, shipane_client, jq_client, **kwargs):
self._start_datatime = datetime.now()
self._processed_transactions = []
self._interval = kwargs.pop('interval', 10)
self._idle_interval = kwargs.pop('idle_interval', 60)

def run(self):
while (True):
Expand All @@ -24,15 +25,15 @@ def run(self):
if self._processed_transactions:
del self._processed_transactions[:]

time.sleep(self._interval)
time.sleep(self._idle_interval)
continue

self._log.info("********** 开始跟单 **********")

try:
transaction_detail = self._jq_client.query()
raw_transactions = transaction_detail['data']['transaction']
self._log.info("抓取到 {} 条委托".format(len(raw_transactions)))
self._log.info("获取到 {} 条委托".format(len(raw_transactions)))

transactions = []
for raw_transaction in raw_transactions:
Expand All @@ -52,7 +53,7 @@ def run(self):
else:
self._log.error('实盘易未回复')
except Exception as e:
self._log.error("跟单异常:" + str(e))
self._log.exception("跟单异常")

self._log.info("********** 结束跟单 **********\n")
time.sleep(self._interval)
Expand Down
2 changes: 1 addition & 1 deletion shipane_sdk/market_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def is_opening(cls, datetime_=None):
if datetime_ is None:
datetime_ = datetime.now()

if datetime_.isoweekday() not in range(1, 5):
if datetime_.isoweekday() not in range(1, 6):
return False
if datetime_.time() <= cls.OPEN_TIME or datetime_.time() >= cls.CLOSE_TIME:
return False
Expand Down
3 changes: 2 additions & 1 deletion shipane_sdk/transaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-


class Transaction(object):
def __init__(self, **kwargs):
self._completed_at = kwargs.get('completed_at')
Expand All @@ -22,7 +23,7 @@ def __eq__(self, other):
return True

def get_cn_type(self):
return '买入' if type == 'BUY' else '卖出'
return u'买入' if self.type == 'BUY' else u'卖出'

@property
def completed_at(self):
Expand Down

0 comments on commit 8c7e59d

Please sign in to comment.