Skip to content

Commit

Permalink
Merge commit '90af0b615fcca3cf87917e6fdb044f6baff16a49' into easyquot…
Browse files Browse the repository at this point in the history
…ation

* commit '90af0b615fcca3cf87917e6fdb044f6baff16a49':
  fix(jsl): 修复集思路分级套利接口的错误
  fix(sina): fix coroutines cant except error
  fix(jsl): fix fundarb func
  • Loading branch information
lamter committed Mar 19, 2016
2 parents 310bf64 + 90af0b6 commit 7fb5fb8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion easyquotation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .api import *
from .helpers import get_stock_codes, update_stock_codes

__version__ = '0.3.4'
__version__ = '0.3.8'
__author__ = 'shidenggui'
36 changes: 19 additions & 17 deletions easyquotation/jsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class Jsl(object):
__fundb_url = 'http://www.jisilu.cn/data/sfnew/fundb_list/?___t={ctime:d}'

# 分级套利的接口
_fundarb_url = 'http://www.jisilu.cn/data/sfnew/arbitrage_vip_list/?___t={ctime:d}'
__fundarb_url = 'http://www.jisilu.cn/data/sfnew/arbitrage_vip_list/?___t={ctime:d}'

# 集思录登录接口
__jxl_login_url = 'http://www.jisilu.cn/account/ajax/login_process/'
__jsl_login_url = 'https://www.jisilu.cn/account/ajax/login_process/'

# 集思录 ETF 接口
__etf_index_url = "https://www.jisilu.cn/jisiludata/etf.php?___t={ctime:d}"
Expand Down Expand Up @@ -102,7 +102,6 @@ def formatetfindexjson(fundbjson):
d[fundb_id] = cell
return d


@staticmethod
def percentage2float(per):
"""
Expand Down Expand Up @@ -180,7 +179,7 @@ def fundarb(self, jsl_username, jsl_password, avolume=100, bvolume=100, ptype='p
"""
s = requests.session()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko',
}
s.headers.update(headers)

Expand All @@ -189,21 +188,23 @@ def fundarb(self, jsl_username, jsl_password, avolume=100, bvolume=100, ptype='p
password=jsl_password,
net_auto_login='1',
_post_type='ajax')
rep = s.post(self.__jxl_login_url, data=logindata)

if rep.status_code != 200: return {}
rep = s.post(self.__jsl_login_url, data=logindata)

if rep.json()['err'] is not None:
return rep.json()

# 添加当前的ctime
self.__fundarb_url = self.__fundarb_url.format(ctime=int(time.time()))
fundarb_url = self.__fundarb_url.format(ctime=int(time.time()))

pdata = dict(avolume=avolume,
bvolume=bvolume,
ptype=ptype,
is_search='1',
market=['sh', 'sz'],
rp='100')
rp='50')
# 请求数据
rep = s.post(self.__fundarb_url, data=pdata)
rep = s.post(fundarb_url, data=pdata)

# 获取返回的json字符串
fundajson = json.loads(rep.text)
Expand All @@ -213,7 +214,6 @@ def fundarb(self, jsl_username, jsl_password, avolume=100, bvolume=100, ptype='p
self.__fundarb = data
return self.__fundarb


def etfindex(self, index_id="", min_volume=0, max_discount=None, min_discount=None):
"""
以字典形式返回 指数ETF 数据
Expand Down Expand Up @@ -248,7 +248,8 @@ def etfindex(self, index_id="", min_volume=0, max_discount=None, min_discount=No
min_discount = self.percentage2float(min_discount)
else:
min_discount = float(min_discount) / 100.
data = {fund_id: cell for fund_id, cell in data.items() if self.percentage2float(cell["discount_rt"]) >= min_discount}
data = {fund_id: cell for fund_id, cell in data.items() if
self.percentage2float(cell["discount_rt"]) >= min_discount}
if max_discount is not None:
# 指定最大溢价率
if isinstance(max_discount, str):
Expand All @@ -257,16 +258,17 @@ def etfindex(self, index_id="", min_volume=0, max_discount=None, min_discount=No
max_discount = self.percentage2float(max_discount)
else:
max_discount = float(max_discount) / 100.
data = {fund_id: cell for fund_id, cell in data.items() if self.percentage2float(cell["discount_rt"]) <= max_discount}
data = {fund_id: cell for fund_id, cell in data.items() if
self.percentage2float(cell["discount_rt"]) <= max_discount}

self.__etfindex = data
return self.__etfindex


if __name__ == "__main__":
Jsl().etfindex(
index_id="000016",
min_volume=0,
max_discount="-0.4",
min_discount="-1.3%"
)
index_id="000016",
min_volume=0,
max_discount="-0.4",
min_discount="-1.3%"
)
2 changes: 1 addition & 1 deletion easyquotation/sina.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_stock_data(self):
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(asyncio.wait(threads))
loop.run_until_complete(asyncio.gather(*threads))

return self.format_response_data()

Expand Down

0 comments on commit 7fb5fb8

Please sign in to comment.