#-*-coding:utf-8-*-importctypes#引入ctypes调用dll的支持库importjsonimportsysfromctypesimportc_char_pfromctypesimportc_intfromctypesimportc_intdll=ctypes.WinDLL#加载DLL#以下为定义参数类型dll.readid.argtypes=[c_char_p]dll.signin.argtypes=[c_char_p,c_char_p,c_char_p]dll.transaction.argtypes=[c_char_p,c_char_p,c_int,c_char_p,c_char_p,c_char_p]dll.query.argtypes=[c_char_p,c_char_p,ctypes.c_int]#以下为定义返回值类型dll.readid.restype=ctypes.c_char_pdll.signin.restype=ctypes.c_char_pdll.transaction.restype=ctypes.c_char_pdll.query.restype=ctypes.c_char_pqsmc=ctypes.create_string_buffer)#券商名称改成自己的qsid=ctypes.string_at)#readid参数1券商名称返回券商idifqsid==b"":printsys.exitqszh=ctypes.create_string_buffer#账号改成自己的qsmm=ctypes.create_string_buffer#密码改成自己的str=ctypes.string_at).decode#signin的参数券商id账号密码返回登录结果Title=json.loads["Title"]ifTitle!="登录成功":printsys.exitprint#打印登录结果str=ctypes.string_at).decode#query函数是查询参数4是查询类型0查持仓及资产1查成交2查委托print#打印查询结果gpdm=ctypes.create_string_buffer#股票代码mmjg=ctypes.create_string_buffer#买卖价格mmsl=ctypes.create_string_buffer#买卖数量#下面是下单函数str=ctypes.string_at).decode#参数40为买1为卖print#打印下单结果。执行接口程序出现的情况有这两方面:
非正常交易时间段容易出现登录失败,这是券商服务器维护造成的;如果调用函数返回数据都是JSON,这里只是简单演示,没有做详细处理;不过以上这些功能只是暂时只支持,也有的加入了大新股和定投的接口数据。
文章为作者独立观点,不代表股票交易接口观点