Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shidenggui committed Apr 7, 2016
1 parent 1f69a58 commit 9150fca
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 64 deletions.
33 changes: 0 additions & 33 deletions autogf.py

This file was deleted.

2 changes: 1 addition & 1 deletion easytrader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
from .yjbtrader import YJBTrader
from .gftrader import GFTrader

__version__ = '0.5.10'
__version__ = '0.6.0'
__author__ = 'shidenggui'
4 changes: 2 additions & 2 deletions easytrader/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding=utf-8
from .gftrader import GFTrader
from .helpers import disable_log
from .httrader import HTTrader
from .xqtrader import XueQiuTrader
from .yhtrader import YHTrader
from .yjbtrader import YJBTrader
from .xqtrader import XueQiuTrader
from .gftrader import GFTrader


def use(broker, debug=True, **kwargs):
Expand Down
50 changes: 24 additions & 26 deletions easytrader/gftrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@

import json
import os
import random
import re
import demjson
import urllib

import requests
import urllib

from . import helpers
from .webtrader import WebTrader, NotLoginError
from requests import Request, Session
from .webtrader import WebTrader

log = helpers.get_logger(__file__)

Expand All @@ -23,6 +20,7 @@
SH = 0
SZ = 1


class GFTrader(WebTrader):
config_path = os.path.dirname(__file__) + '/config/gf.json'

Expand Down Expand Up @@ -64,15 +62,15 @@ def __go_login_page(self):
def login(self, throw=False):
"""实现广发证券的自动登录"""
self.__go_login_page()

verify_code = self.__handle_recognize_code()

if not verify_code:
return False

login_status, result = self.post_login_data(verify_code)
if login_status is False:
return False
return False
return True

def post_login_data(self, verify_code):
Expand All @@ -94,14 +92,14 @@ def post_login_data(self, verify_code):

def create_basic_params(self):
basic_params = dict(
dse_sessionId = self.sessionid
dse_sessionId=self.sessionid
)
return basic_params

def request(self, params):
params_str = urllib.parse.urlencode(params)
unquote_str = urllib.parse.unquote(params_str)
url = self.trade_prefix + '?' + unquote_str
url = self.trade_prefix + '?' + unquote_str
r = self.s.post(url)
return r.content

Expand All @@ -117,20 +115,20 @@ def __set_trade_need_info(self):
"""设置交易所需的一些基本参数
"""
account_params = dict(
self.config['accountinfo']
)
self.config['accountinfo']
)
params_str = urllib.parse.urlencode(account_params)
unquote_str = urllib.parse.unquote(params_str)
url = self.trade_prefix + '?' + unquote_str
log.debug('get account info: %s' % unquote_str)
r = self.s.get(url)
jslist = r.text.split(';')
jsholder = jslist[HOLDER_POS]
jsholder = re.findall(r'\[(.*)\]',jsholder)
jsholder = re.findall(r'\[(.*)\]', jsholder)
jsholder = jsholder[0].split('},{')
self.holdername.append(json.loads(jsholder[0] + '}'))
self.holdername.append(json.loads('{' + jsholder[1]))

def __get_trade_need_info(self, stock_code):
"""获取股票对应的证券市场和帐号"""
# 获取股票对应的证券市场
Expand All @@ -143,7 +141,7 @@ def __get_trade_need_info(self, stock_code):
exchange_type=exchange_type,
stock_account=stock_account
)

def buy(self, stock_code, price, amount=0, volume=0, entrust_prop=0):
"""买入
:param stock_code: 股票代码
Expand Down Expand Up @@ -174,29 +172,29 @@ def sell(self, stock_code, price, amount=0, volume=0, entrust_prop=0):
)
return self.__trade(stock_code, price, other=params)

def fund_subscribe(self, stock_code, price=0, entrust_prop='LFS'):
def fund_subscribe(self, stock_code, price=0, entrust_prop='LFS'):
"""基金认购
:param stock_code: 基金代码
:param price: 认购金额
"""
params = dict(
self.config['fundsubscribe'],
entrust_amount=1,
entrust_prop=entrust_prop
self.config['fundsubscribe'],
entrust_amount=1,
entrust_prop=entrust_prop
)
return self.__trade(stock_code, price, other=params)
return self.__trade(stock_code, price, other=params)

def fund_purchase(self, stock_code, price=0, entrust_prop='LFC'):
"""基金申购
:param stock_code: 基金代码
:param amount: 申购金额
"""
params = dict(
self.config['fundpurchase'],
entrust_amount=1,
entrust_prop=entrust_prop
self.config['fundpurchase'],
entrust_amount=1,
entrust_prop=entrust_prop
)
return self.__trade(stock_code, price, other=params)
return self.__trade(stock_code, price, other=params)

def fund_redemption(self, stock_code, amount=0, entrust_prop='LFR'):
"""基金赎回
Expand Down Expand Up @@ -250,8 +248,8 @@ def cancel_entrust(self, entrust_no):
"""撤单
:param entrust_no: 委单号"""
cancel_params = dict(
self.config['cancel_entrust'],
entrust_no=entrust_no,
dse_sessionId = self.sessionid
self.config['cancel_entrust'],
entrust_no=entrust_no,
dse_sessionId=self.sessionid
)
return self.do(cancel_params)
4 changes: 2 additions & 2 deletions gf.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"username": "加密的客户号",
"password": "加密的密码"
"username": "加密的客户号",
"password": "加密的密码"
}

0 comments on commit 9150fca

Please sign in to comment.