shidenggui / easytrader Goto Github PK
View Code? Open in Web Editor NEW提供同花顺客户端/国金/华泰客户端/雪球的基金、股票自动程序化交易以及自动打新,支持跟踪 joinquant /ricequant 模拟交易 和 实盘雪球组合, 量化交易组件
License: MIT License
提供同花顺客户端/国金/华泰客户端/雪球的基金、股票自动程序化交易以及自动打新,支持跟踪 joinquant /ricequant 模拟交易 和 实盘雪球组合, 量化交易组件
License: MIT License
我想问一下,我在执行user = easytrader.use('yjb') 和 user.prepare('yjb.json') ,登录之后,多长时间不操作,session会失效,能否在你的程序中,直接加入维持登陆状态的功能。因为有时候策略需要运行几个月时间,万一被服务器踢出了,程序执行就会出现不可预见的错误,这个很麻烦。
盼回复!
user.prepare('ht.json')
Traceback (most recent call last):
File "", line 1, in
File "easytrader/webtrader.py", line 55, in prepare
self.autologin()
File "easytrader/webtrader.py", line 59, in autologin
is_login_ok = self.login()
File "easytrader/httrader.py", line 74, in login
self.__go_login_page()
File "easytrader/httrader.py", line 97, in __go_login_page
self.s.get(self.config['logout_api'])
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 480, in get
return self.request('GET', url, *_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, *_send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 447, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)
华泰的能不能增加查询当日成交这个功能?方便记录已经成交的信息,目前好像没法使用。。
我用vmware装的Redhat 5.2调试,发现即使强制easytrader.use('yh',debug=True),也不可以使调试信息出来。也不知道保持在线是否正确。可否确认该现象是否正常,谢谢
修改代码使得在yhtrader.py的request函数里打印log:
def request(self, params):
url = self.trade_prefix + params['service_jsp']
print ("seeeeeeeeeeeeeeeeee: cookies={}".format(self.cookie))
.......
....
..
会发现,cookies=None . 所有的后端,比如yjbtrader.py等,都是一样。
顺着查找(搜索self.cookie),发现token函数没有被调用. 似乎应该算bug。。
easytrader用于雪球模拟若股票数量超过15、16只样子,就会出现错误。如目前我的雪球账户中大概有18只股票,买卖都不再能执行了,必须手工先卖出几只股票后,才能用easytrader操作。买入也是如此,当一个空账户,最多能买入15-6只股票,后面的就不行了。请帮助解决。谢谢!
你好!
我昨天在我的windows机器上的anaconda python命令行环境下,运行了 user = easytrader.use('yjb') 和 user.prepare('yjb.json') ,然后隔一段时间执行一次 user.balance,刚开始每次都能返回正确结果,后来间隔时间拉大,早上起来运行了 user.balance就出现错误了,马上接着运行一次 user.balance,又返回正确结果。今天下午再运行一次 user.balance的时候,又出现同样的错误,截图出来了,根据提示,线程只能被started 一次,好像是作者的命令有逻辑错误,请作者检查一下。可能是在检查出掉线后,试图再次登陆,然后又调用了一次 self.heart_thread.start(),然后导致的出错。
如题 在广发证券web交易系统页面 F12 Console
document.getElementById("SecurePassword")
结果是null
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/test_easy_trader/main.py", line 6, in
user.buy(stock_code='000876',price=7.88,amount=100)
File "C:\Anaconda2\lib\site-packages\easytrader\httrader.py", line 209, in buy
return self.__trade(stock_code, price, entrust_prop=entrust_prop, other=params)
File "C:\Anaconda2\lib\site-packages\easytrader\httrader.py", line 226, in __trade
need_info = self.__get_trade_need_info(stock_code)
File "C:\Anaconda2\lib\site-packages\easytrader\httrader.py", line 242, in __get_trade_need_info
stock_account = self.__sh_stock_account if exchange_type == self.__sh_exchange_type
AttributeError: 'HTTrader' object has no attribute '_HTTrader__sh_exchange_type'
namemap={'参考市值':'market_value'
,'可用资金':'enable_balance'
,'总资产':'asset_balance'
,'资金余额':'current_balance'
,'币种':'money_type'
,'证券名称':'stock_name'
,'证券代码':'stock_code'
,'股份可用':'enable_amount'
,'当前持仓':'current_amount'
,'参考市价':'last_price'
,'参考盈亏':'income_balance'
,'委托时间':'report_time'
,'状态说明':'entrust_status'
,'委托序号':'entrust_no'
}
类似这样
这样以后不同的券商返回的字段就可以统一了
如果不同的券商,前端调用就比较方便了,
__set_trade_need_info函数之中self.holdername.append(jsholder[2])错误:IndexError: tuple index out of range。我debug了下,看到url是https://trade.gf.com.cn/entry?classname=com.gf.etrade.control.FrameWorkControl&method=getMainJS, 执行self.s.get(url)之后,结果是,显然这个不是程序预期的返回。那么这个url对吗?如果url对的话为何返回的结果不对呢?
I have tested it with below code change.
I have not right to check in.
Please check in the below diff file in order to support the SH IPO stock number.
diff --git a/easytrader/helpers.py b/easytrader/helpers.py
index 577c989..4639f20 100644
--- a/easytrader/helpers.py
+++ b/easytrader/helpers.py
@@ -61,7 +61,7 @@ def get_stock_type(stock_code):
assert type(stock_code) is str, 'stock code need str type'
if stock_code.startswith(('sh', 'sz')):
return stock_code[:2]
设置一个登录失败重试的次数,超过就抛出异常,避免无限的重试
怎么获得接口?
雪球组合是比例调仓,按仓位管理,实时成交,基本跟price和amount无关。也就是说接口暴露出weight足矣,price和amount都没用,代码里面weight 是计算来的,还round四舍五入,太容易导致仓位不足,出错,建议考虑修改一下。
用华泰进行交易,不能登录,提示一下错误:
File "E:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\easytrader\httrader.py", line 113, in __handle_recognize_code
verify_code = helpers.recognize_verify_code(image_path)
File "E:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\easytrader\helpers.py", line 128, in recognize_verify_code
with open(verify_code_result) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'result.txt'
反复测试了几天,情况都是如此
佣金宝支持多进程vcode
On running
import easytrader
easytrader.use('yjb')
pop up this error message:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in
easytrader.use('yjb')
File "C:\python35\Lib\site-packages\easytrader\api.py", line 27, in use
return YJBTrader()
File "C:\python35\Lib\site-packages\easytrader\yjbtrader.py", line 24, in init
super(YJBTrader, self).init()
File "C:\python35\Lib\site-packages\easytrader\webtrader.py", line 31, in init
self.read_config()
File "C:\python35\Lib\site-packages\easytrader\webtrader.py", line 99, in __read_config
self.global_config = helpers.file2dict(self.global_config_path)
File "C:\python35\Lib\site-packages\easytrader\helpers.py", line 42, in file2dict
return json.load(f)
File "C:\python35\Lib\json__init.py", line 265, in load
return loads(fp.read(),
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 190: illegal multibyte sequence
I run sys.getdefaultencoding(), it returns 'utf-8'.
How to fix this error?
Thanks!
我的账户, 股东列表页面, 内容有3行, 最底一行最后一列内容为设为主股东, 这样为导致登陆失败, 也不能下单
在 yhtrader.py 文件的第300行.
我修改为:
data = data.replace('\r','').replace('\n','').replace('\t','').replace(' ','')
search_result_content = re.findall(r'<td nowrap=\"nowrap\">(.*?)</td>', data)
user.check_available_cancels()
Traceback (most recent call last):
File "<ipython-input-52-d6a9f31533d3>", line 1, in <module>
user.check_available_cancels()
File "/home/wenjian/anaconda3/lib/python3.5/site-packages/easytrader-0.7.2-py3.5.egg/easytrader/yhtrader.py", line 150, in check_available_cancels
, "canceled_vol": int(item[9])
ValueError: invalid literal for int() with base 10: 'A**********'
A*********为A股账号,我隐去了
如题
对于华泰,买卖单成交后:
1、成交的委托会从entrust中删除,entrust中始终只有“未报”、“已报”、 “废单”,没有“已成”
2、在交易时段内user.get_exchangebill('开始日期', '截止日期') 查不到当天已经成交了的买卖单
目前看起来只能通过position的current_amount变化的方式确认成交。
而对于佣金宝,买卖单成交后:
1、成交后在entrust有记录,显示为“已成”
2、user.current_deal有显示刚刚的成交
所以佣金宝用于确认委托成交的方法较方便。
不知是否能添加华泰可用的,更便捷的委托单成交确认方式?
user.buy('sh510050', price=2.100, amount=100)
Out[21]:
{'cssweb_code': 'error',
'cssweb_msg': '证券代码长度不对',
'cssweb_type': 'STOCK_BUY',
'item': None}
[2016-04-02 23:14:15.176473] DEBUG: yhtrader.py: login response: {"result_type":"error","result_msg":"90002trdpwd项数据缓冲区太小"}
user.buy(510050, price=2.278, amount=3600)
user.buy(150019, price=0.885, amount=6300)
同时发出买入指令,510050没有委托记录,其他都能成交。试了一下其他510开头的etf都没有委托记录。
直接在命令行使用是没问题的,一旦加入到 crontab 里,代码就无法正常执行。
主要问题在于 os.path.dirname(__file__)
在 crontab 下并没有得到预期的文件路径,从而导致 json 配置文件无法被正常读取。
我目前的解决办法是把里面的路径全部替换成了绝对路径。
如题
在官方上,每次登陆都都会在POST抓到不同的动态密码,因此通过easytrader无法连接,总是报密码不对的错。
另外,readme里的需要看hardinfo是什么意思?怎么使用hardinfo?
2016-08-11 08:21:33,239 [DEBUG] yhtrader.py 83: verify code detect result: erro
2016-08-11 08:21:33,240 [DEBUG] yhtrader.py 99: login params: {'checkword': 'erro'
'inputtype': 'C', 'Authplain9320': '', 'logintype_rzrq': 0, 'certdata9322': '', 'isonlytrade': 1, 'ftype': 'bsn', 'Authsign9321': '', 'trdpwdjtws': '',
2016-08-11 08:21:33,249 [DEBUG] yhtrader.py 101: login response: {"result_type":"error","result_msg":"系统超时请重新登录"}
大家能成功吗?
code = i['stock_code']
TypeError: string indices must be integers
我写的程序自动跑的,基本上10次会出现1次这样的错误,没搞懂为什么?
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/90/bnqnyd2j2c70x1tb013tlff40000gn/T/pip-build-RBH8hv/easytrader
請問是什麼意思呢?謝謝
m.load_strategy()
m.start()
load_strategy() 这里可不可以调入指定的策略
抓包不到密码的地方啊。
user = easytrader.use('xq')
user.prepare('xq.json')
提示该邮箱尚未注册
webtrader.py 里有以下一段代码:
except json.JSONDecodeError:
但实际默认的 json 模块并没有 JSONDecodeError
只有 simplejson 才有
github不熟悉,没法提交我的修改,见谅
华泰的当日成交无法获取? 无法取当前的 成效情况.
现在登入券商失败,虽然会打log但是程序无法拿到错误的信息。
错误已知的原因有可能是券商暂停端口、验证码识别错误,仅供参考。
--- Logging error ---
Traceback (most recent call last):
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 595, in urlopen
chunked=chunked)
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 393, in _make_request
six.raise_from(e, None)
File "", line 2, in raise_from
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 389, in _make_request
httplib_response = conn.getresponse()
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\http\client.py", line 1227, in getresponse
response.begin()
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\http\client.py", line 386, in begin
version, status, reason = self._read_status()
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\http\client.py", line 348, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\socket.py", line 378, in readinto
return self._sock.recv_into(b)
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\ssl.py", line 748, in recv_into
return self.read(nbytes, buffer)
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\ssl.py", line 620, in read
v = self._sslobj.read(len, buffer)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\adapters.py", line 417, in send
timeout=timeout
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 640, in urlopen
_stacktrace=sys.exc_info()[2])
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\util\retry.py", line 261, in increment
raise six.reraise(type(error), error, _stacktrace)
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 595, in urlopen
chunked=chunked)
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 393, in _make_request
six.raise_from(e, None)
File "", line 2, in raise_from
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 389, in _make_request
httplib_response = conn.getresponse()
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\http\client.py", line 1227, in getresponse
response.begin()
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\http\client.py", line 386, in begin
version, status, reason = self._read_status()
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\http\client.py", line 348, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\socket.py", line 378, in readinto
return self._sock.recv_into(b)
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\ssl.py", line 748, in recv_into
return self.read(nbytes, buffer)
File "D:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\ssl.py", line 620, in read
v = self._sslobj.read(len, buffer)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None))
百度了无数次解决无果,期待作者您能知道是什么问题?
我咨询了群内一些成功的朋友,他们都可以正常查询,而我在win与ubuntu下均提示这个错误。
[2016-07-14 16:30:29.654315] DEBUG: xqtrader.py: login status: SUCCESS
Traceback (most recent call last):
File "F:\Program Files\JetBrains\PyCharm 5.0.3\helpers\pycharm\utrunner.py", line 129, in
module = loadSource(a[0])
File "F:\Program Files\JetBrains\PyCharm 5.0.3\helpers\pycharm\utrunner.py", line 41, in loadSource
module = imp.load_source(moduleName, fileName)
File "E:\Python35\lib\imp.py", line 172, in load_source
module = _load(spec)
File "", line 693, in _load
File "", line 673, in _load_unlocked
File "", line 662, in exec_module
File "", line 222, in _call_with_frames_removed
File "F:\py\easytrader\test.py", line 9, in
user.balance
File "F:\py\easytrader\easytrader\webtrader.py", line 113, in balance
return self.get_balance()
File "F:\py\easytrader\easytrader\xqtrader.py", line 161, in get_balance
portfolio_info = self.__get_portfolio_info(portfolio_code) # 组合信息
File "F:\py\easytrader\easytrader\xqtrader.py", line 148, in __get_portfolio_info
html = self.__get_html(url)
File "F:\py\easytrader\easytrader\xqtrader.py", line 114, in __get_html
resp = urllib.request.urlopen(req)
File "E:\Python35\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "E:\Python35\lib\urllib\request.py", line 465, in open
response = self._open(req, data)
File "E:\Python35\lib\urllib\request.py", line 483, in _open
'_open', req)
File "E:\Python35\lib\urllib\request.py", line 443, in _call_chain
result = func(_args)
File "E:\Python35\lib\urllib\request.py", line 1283, in https_open
context=self._context, check_hostname=self._check_hostname)
File "E:\Python35\lib\urllib\request.py", line 1240, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "E:\Python35\lib\http\client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "E:\Python35\lib\http\client.py", line 1118, in _send_request
self.putrequest(method, url, *_skips)
File "E:\Python35\lib\http\client.py", line 960, in putrequest
self._output(request.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-12: ordinal not in range(128)
#-*- coding: utf-8 -*-
import easytrader
if __name__ == '__main__':
user=easytrader.use('yh')
user.prepare('yh.json')
执行到yhtrader.login的exchangeinfo = list((self.do(dict(self.config['account4stock']))))
进一步,webtrader.do的format_json_data = self.format_response_data(response_data)
时抛出这个错误ERROR: yhtrader.pyc: Can not fetch balance info,请问是什么原因呢。
环境win8 x64, python2.7,谢谢。。
[2016-03-23 14:32:54.621000] DEBUG: yhtrader.pyc: login params: {'……
[2016-03-23 14:32:54.849000] DEBUG: yhtrader.pyc: login response:……
[2016-03-23 14:34:01.540000] ERROR: yhtrader.pyc: Can not fetch balance info
如果继续运行就是这样了:
File "C:\Users\ccw\Desktop\arbitrage\stock.py", line 7, in <module>
user.prepare('yh.json')
File "c:\Users\ccw\AppData\Local\Enthought\Canopy\User\Lib\site-packages\easytrader\webtrader.py", line 54, in prepare
self.autologin()
File "c:\Users\ccw\AppData\Local\Enthought\Canopy\User\Lib\site-packages\easytrader\webtrader.py", line 58, in autologin
is_login_ok = self.login()
File "c:\Users\ccw\AppData\Local\Enthought\Canopy\User\Lib\site-packages\easytrader\yhtrader.py", line 59, in login
if exchangeinfo[i][TRADE_MARKET]['浜ゆ槗甯傚満'] == '娣盇':
TypeError: string indices must be integers
exchangeinfo的值是
[u'股东代码', u'交易市场', u'股东姓名', u'客户代码', u'设为主股东']
File "xqtrader.py", line 299, in __trade
stock = self.__search_stock_info(stock_code)
{ 'code': u'600132',
'data': { 'code': '600132',
'key': '47bce5c74f',
'market': 'cn',
'size': '300'},
'r': ,
'self': ,
'stocks': { u'error_code': u'400016',
u'error_description': u'\u9047\u5230\u9519\u8bef\uff0c\u8bf7\u5237\u65b0\u9875\u9762\u6216\u8005\u91cd\u65b0\u767b\u5f55\u5e10\u53f7\u540e\u518d\u8bd5',
你好,shidenggui,我在使用easytrader的时候,登录雪球后,查看组合的资金状况和持仓状况都没有问题,但是调用查看今日委托单接口,买、卖接口的时候都会报错。上面是买接口所报的错,对应的中文错误信息是:遇到错误,请刷新页面或者重新登录帐号后再试
我想知道是否是cookie有问题,我要怎么才能解决这个问题?
如题,谢谢
提供对广发证券的交易接口支持
user.buy(sh510050, price=2.100, amount=100)
Traceback (most recent call last):
File "", line 1, in
user.buy(sh510050, price=2.100, amount=100)
NameError: name 'sh510050' is not defined
加上“”sh“”还是有问题
sell不起作用的
2016-08-29 09:25:04,796 [DEBUG] httrader.py 272: response data before format: {"cssweb_code":"error","cssweb_type":"GET_STOCK_POSITION","cssweb_msg":"UID无效,请退出重新登录","item":[]
Hi,
When I use
user.prepare('ht.json')
It shows
[2016-03-29 11:05:25.947000] DEBUG: helpers.pyc: java detect result: '{' is not recognized as an internal or external command,
operable program or batch file.
'tesseract' is not recognized as an internal or external command,
operable program or batch file.
'export' is not recognized as an internal or external command,
operable program or batch file.
IOError: [Errno 2] No such file or directory: 'result.txt'
Is there any file I miss? I install easytrader through pyCharm. Is that okay? Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.