Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

财富证券同花顺客户端grid里的数据无法复制 #270

Closed
ocdman opened this issue Mar 9, 2018 · 5 comments
Closed

财富证券同花顺客户端grid里的数据无法复制 #270

ocdman opened this issue Mar 9, 2018 · 5 comments

Comments

@ocdman
Copy link

ocdman commented Mar 9, 2018

env

OS: win10
PYTHON_VERSION: 3.6.4
EASYTRADER_VERSION: 0.13.5

problem

我的券商客户端是##财富证券##的[同花顺新一代]独立委托,使用easytrader获取资金状况(balance)ok,但是获取持仓(position)就显示为空数组。

查看源代码后发现,_get_grid_data方法里的grid.type_keys('^A^C')这行代码是复制grid里的所有行数据,但是我的客户端grid不支持复制,只能保存为.xls文件。

难道每次查看持仓,都要保存为一个xls文件吗?然后再从xls文件中去复制?有没有好的办法推荐呢?

@nladuo
Copy link

nladuo commented Mar 23, 2018

我也发现了这个问题,我用的是同花顺免费版v8.70.32版本。发现模拟Ctrl+A 然后Ctrl+C并不能复制。必须要模拟鼠标右键然后输入C才行。输入完c之后还要输入验证码。

代码大概这样:

from captcha_recognize import captcha_recognize  #引入验证码破解模块
from pywinauto import clipboard

grid = main.window(
    control_id=0x417,
    class_name='CVirtualGridCtrl'
)  # 获取grid
grid.set_focus().right_click()  #模拟右键
pywinauto.keyboard.SendKeys('c')  # 输入C

file_path = "./captchas/" + str(uuid.uuid4()) + ".png"
app.top_window().window(
    control_id=0x965,
    class_name='Static'
).CaptureAsImage().save(file_path)  #保存验证码

captcha_num = captcha_recognize(file_path) # 识别验证码

print(captcha_num)

app.top_window().window(
    control_id=0x964,
    class_name='Edit'
).set_text(captcha_num)  # 输入验证码

app.top_window().window(
    control_id=0x1,
    class_name='Button'
).click()  # 点击提交确认

print(clipboard.GetData())  # 显示剪切板数据

@ocdman
Copy link
Author

ocdman commented Mar 26, 2018

@nladuo
确实没有更好的办法了。我的客户端只能快捷键保存为.xls文件,然后再读取,修改了一下源代码,不影响使用。

def _get_grid_data(self, control_id):
        grid = self._main.window(
            control_id=control_id,
            class_name='CVirtualGridCtrl'
        )
        # grid.type_keys('^A^C')
        # return self._format_grid_data(
            # self._get_clipboard_data()
        # )
        grid.type_keys('^s')
        self._wait(0.2)
        """
        保存为table.xls文件,如果已存在,则替换
        alt+s保存,alt+y替换已存在的文件
        """
        self._app.top_window().type_keys('%{s}%{y}')
        origination = self._config.DEFAULT_XLS_PATH
        destination = self._config.DEFAULT_CSV_PATH
        """
        将xls文件重命名为csv文件
        """
        if os.path.exists(destination):
            os.remove(destination)
        os.rename(origination, destination)
        return self._format_grid_data(destination)

def _format_grid_data(self, data):
        # df = pd.read_csv(io.StringIO(data),
        df = pd.read_csv(data,
                         encoding='gbk',
                         delimiter='\t',
                         dtype=self._config.GRID_DTYPE,
                         na_filter=False,
                         )
        return df.to_dict('records')

@shidenggui
Copy link
Owner

#272 提供我开发用的客户端版本

@shidenggui
Copy link
Owner

shidenggui commented Jun 26, 2018

我提供的版本也不行了,这个目前没有想到特别好的办法

@shidenggui
Copy link
Owner

shidenggui commented Jul 1, 2018

close by e273e3f

实现了 @ocdmanGrid 数据存为文件再读取的策略,
使用方式如下:

from easytrader import grid_data_get_strategy

user.grid_data_get_strategy = grid_data_get_strategy.XlsStrategy
# 后面获取 balance 、position 都会使用新的策略

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants