Skip to content

zhengdanwei/easytrader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easytrader

  • 进行简单的 web 股票交易
  • 目前还很不完善,仅供测试

开发环境 : Ubuntu 15.10 / Python 3.4

TODO

  • 支持更多券商
  • 实现自动登录
  • 优化速度

支持券商

  • 佣金宝
  • 华泰(支持自动登录,还在测试阶段)

requirements

Python 3.4+

pip install -r requirements.txt

华泰的自动登录需要安装以下二者之一:

  • JAVA : 推荐, 识别率高,安装简单, 需要命令行下 java -version 可用 (感谢空中园的贡献)
  • tesseract : 保证在命令行下 tesseract 可用

用法

引入:

import easytrader

设置账户:

佣金宝
user = easytrader.use('yjb') # 佣金宝支持 ['yjb', 'YJB', '佣金宝']
华泰
user = easytrader.use('ht') # 华泰支持 ['ht', 'HT', '华泰']

登录

佣金宝
user.token = 'ABC...CBA'

如何获取 token, 即文章中的 JSESSIONID

华泰
user.read_config('me.json')

: 华泰需要配置 me.json 填入相关信息, trdpwd 加密后的密码首次需要登录后查看登录 POSTtrdpwd 值确定

如何获取 trdpwd, 可参考此文章

自动登录

华泰
user.autologin()

交易相关

以下用法以佣金宝为例,华泰类似

获取资金状况:

user.balance

return

[{ 'asset_balance': '资产总值',
   'current_balance': '当前余额',
   'enable_balance': '可用金额',
   'market_value': '证券市值',
   'money_type': '币种',
   'pre_interest': '预计利息' ]}

获取持仓:

user.position

return

[{'cost_price': '摊薄成本价',
   'current_amount': '当前数量',
   'enable_amount': '可卖数量',
   'income_balance': '摊薄浮动盈亏',
   'keep_cost_price': '保本价',
   'last_price': '最新价',
   'market_value': '证券市值',
   'position_str': '定位串',
   'stock_code': '证券代码',
   'stock_name': '证券名称'}]

获取今日委托单

user.entrust

return

[{'business_amount': '成交数量',
  'business_price': '成交价格',
  'entrust_amount': '委托数量',
  'entrust_bs': '买卖方向',
  'entrust_no': '委托编号',
  'entrust_price': '委托价格',
  'entrust_status': '�委托状态',  # 废单 / 已报
  'report_time': '申报时间',
  'stock_code': '证券代码',
  'stock_name': '证券名称'}]

买入:

user.buy('162411', price=0.55, amount=100)

return

[{'entrust_no': '委托编号',
  'init_date': '发生日期',
  'batch_no': '委托批号',
  'report_no': '申报号',
  'seat_no': '席位编号',
  'entrust_time': '委托时间',
  'entrust_price': '委托价格',
  'entrust_amount': '委托数量',
  'stock_code': '证券代码',
  'entrust_bs': '买卖方向',
  'entrust_type': '委托类别',
  'entrust_status': '委托状态',
  'fund_account': '资金帐号',
  'error_no': '错误号',
  'error_info': '错误原因'}]

卖出:

user.sell('162411', price=0.55, amount=100)

撤单(华泰特有)

user.cancel_entrust('委托单号')

掉线(佣金宝特有)

后台开了一个进程 30 秒请求一次维持 token 的有效性,理论上是不会掉线的。 如果掉线了,请求会返回

{'error_info': '登陆已经超时,请重新登陆!', 'error_no': '-1'}

这时只需要重新设置token就可以了

user.token='valid token'

其他

其他可参考下面链接

佣金宝

About

提供华泰/佣金宝的股票自动交易

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%