/AlgoPlus

AlgoPlus 2.0是使用c++语言开发的用于全市场交易的SDK,提供c++/python/java接口。

Primary LanguagePython

官网

http://algo.plus


股票现货API

  • 安装方法

pip install AlgoPlusTORAStockV3x

操作系统:win_amd64,linux

Python版本:>=3.7,<3.9

如果无法安装,可以下载安装包,然后尝试离线安装:

https://pypi.tuna.tsinghua.edu.cn/simple/algoplustorastockv3x/

  • 业务柜台

AlgoPlusTORAStockV3x封装的是华鑫证券奇点柜台的API。对在N视界官网(http://n-sight.com.cn)注册的现货仿真交易账户开放测试,支持普通股债交易、查询等业务。

  • 仿真交易测试
  1. 同步仿真环境
TraderFrontAddress = "tcp://210.14.72.11:4400"
MdFrontAddress = "tcp://210.14.72.11:4402"
  1. 7*24仿真环境
TraderFrontAddress = "tcp://210.14.72.15:4400"
MdFrontAddress = "tcp://210.14.72.15:4402"
  • 客户端

下载链接: https://pan.baidu.com/s/1jQCjl3eGAUf41HO4lPyD5g 提取码: 6aye


期货API

  • 安装方法

pip install AlgoPlusCTPV6315

操作系统:win_amd64,linux

Python版本:>=3.7,<3.9

如果无法安装,可以下载安装包,然后尝试离线安装:

https://pypi.tuna.tsinghua.edu.cn/simple/algoplusctpv6315/

  • 业务柜台

AlgoPlusCTPV6315封装的是上期技术CTP柜台的API。对在N视界(http://n-sight.com.cn)和SimNow(http://simnow.com.cn)注册的期货仿真交易账户开放测试,支持期货交易、查询等相关业务。

  • 仿真交易测试
  1. NSight同步仿真环境
BrokerID = "10010"
TraderFrontAddress = "tcp://210.14.72.15:4600"
MdFrontAddress = "tcp://210.14.72.15:4602"
AppID = ""
AuthCode = ""
  1. SimNow同步仿真环境
BrokerID = "9999"
TraderFrontAddress = "tcp://180.168.146.187:10201"
MdFrontAddress = "tcp://180.168.146.187:10211"
AppID = "simnow_client_test"
AuthCode = "0000000000000000"
  1. SimNow同步仿真环境
BrokerID = "9999"
TraderFrontAddress = tcp://180.168.146.187:10202
MdFrontAddress = 180.168.146.187:10212
AppID = "simnow_client_test"
AuthCode = "0000000000000000"
  1. SimNow同步仿真环境
BrokerID = "9999"
TraderFrontAddress = "tcp://218.202.237.33:10203"
MdFrontAddress = "tcp://218.202.237.33:10213"
AppID = "simnow_client_test"
AuthCode = "0000000000000000"
  1. SimNow7*24仿真环境
BrokerID = "9999"
TraderFrontAddress = "tcp://180.168.146.187:10130"
MdFrontAddress = "tcp://180.168.146.187:10131"
AppID = "simnow_client_test"
AuthCode = "0000000000000000"
  • 客户端

下载链接: https://pan.baidu.com/s/1VSza3McX-Dyy33YLr8pBMg 提取码:f5ni


方法列表

/// 版本号
const char* getVersion();

/// 初始化
CBaseTrader* init(int nRunID, CAPLoginField* pLoginField, PyObject* pOrderEventCallback = Py_None, PyObject* pFlexibleEventCallback = Py_None, PyObject* pLoopEventCallback = Py_None, PyObject* pSnapDataEventCallback = Py_None);
/// 查询初始化错误
int getInitError();
/// 查询错误信息
const char* getMessageByErrorID(TAPErrorIDType nErrorID);
/// 轮询
void loop();

/// 设置运行模式。默认Debug模式:将事件相关结构体转为字符串,调用EventTextProcessor处理。
int setRunMode(TAPRunModeType chRunMode);
/// 设置处理事件字符串的方法。默认输出到屏幕。
int setEventTextProcessor(PyObject* pTextProcessor);

/// 订阅行情
int subscribeOne(CBaseTrader* pAPTrader, const char* szStandardID, const char* szExchangeID = NULL);
/// 批量订阅行情
int subscribe(CBaseTrader* pAPTrader, char** ppStandardID, int nCount, const char* szExchangeID = NULL);
/// 退订行情
int unsubscribeOne(CBaseTrader* pAPTrader, const char* szStandardID, const char* szExchangeID = NULL);
/// 批量退订行情
int unsubscribe(CBaseTrader* pAPTrader, char** ppStandardID, int nCount, const char* szExchangeID = NULL);

/// 买开数量
CAPOrderField* buyOpen(CBaseTrader* pAPTrader, const char* szStandardID, int nOrderVolume, char chOrderType, double dOrderPrice, const char* szExchangeID = NULL, char chDirection = ENUM_Direction_Buy);
/// 卖平数量
CAPOrderField* sellClose(CBaseTrader* pAPTrader, const char* szStandardID, int nOrderVolume, char chOrderType, double dOrderPrice, const char* szExchangeID = NULL, char chDirection = ENUM_Direction_Sell, char chOffsetFlag = '\0', const char* szCreditDebtID = NULL);
/// 卖开数量
CAPOrderField* sellOpen(CBaseTrader* pAPTrader, const char* szStandardID, int nOrderVolume, char chOrderType, double dOrderPrice, const char* szExchangeID = NULL, char chDirection = '\0', char chCreditQuotaType = '\0');
/// 买平数量
CAPOrderField* buyClose(CBaseTrader* pAPTrader, const char* szStandardID, int nOrderVolume, char chOrderType, double dOrderPrice, const char* szExchangeID = NULL, char chDirection = '\0', char chOffsetFlag = '\0', const char* szCreditDebtID = NULL);
/// 报单
CAPOrderField* insertOrder(CBaseTrader* pAPTrader, const char* szExchangeID, const char* szStandardID, char chDirection, char chOffsetFlag, int nVolume, const char* szCombineOrderType, double dPrice, char chCreditQuotaType = '\0', const char* szCreditDebtID = NULL);

/// 撤单
int cancelOrder(CBaseTrader* pAPTrader, const char* szExchangeID, const char* szStandardID, const char* szOrderSysID, int nOrderID, int nFrontID = 0, int nSessionID = 0);
/// 撤单
int cancelOrderByOrderID(CBaseTrader* pAPTrader, int nOrderID);
/// 以标的撤单
int cancelOrderByStandardID(CBaseTrader* pAPTrader, const char* szExchangeID = NULL, const char* szStandardID = NULL);

/// 划转资金
CAPTransferAssetField* transferCash(CBaseTrader* pAPTrader, char chTransferFlag, double dAmount, const char* szAccountPassword, const char* szBankID, const char* szBankPassword, const char* szNodeID = NULL, const char* szCreditDebtID = NULL);
/// 划转持仓
CAPTransferAssetField* transferPosition(CBaseTrader* pAPTrader, char chTransferFlag, int nVolume, const char* szStandardID, const char* szNodeID = NULL, const char* szCreditDebtID = NULL, const char* szExchangeID = NULL);
/// 查询银行卡余额
TAPErrorIDType queryBankAccountCash(CBaseTrader* pAPTrader, const char* szAccountPassword, const char* szBankID, const char* szBankPassword);
/// 修改密码
TAPErrorIDType updatePassword(CBaseTrader* pAPTrader, char chPasswordFlag, const char* szOldPassword, const char* szNewPassword);

/// 添加任务
int addTask(CBaseTrader* pAPTrader, TAPEventIDType nEventID, CAPQueryCommandField* pQueryCommandField = NULL, int nMaxExecuteCount = 1, TAPTimeAnchorType nExecuteGap = -1, TAPTimeAnchorType nFailedGap = -1, bool bRefuseError = false, TAPTimeAnchorType nExecuteTimeout = -1);

/// 退出
void exitX(CBaseTrader* pAPTrader = NULL);

/// 事件响应结构体域名
const char* getFields(TAPEventIDType nEventID, void* pEventStruct);
/// 事件响应结构体转字符串
const char* toText(TAPEventIDType nEventID, void* pEventStruct, bool bWithFieldName = false, const char* szSeparator = ",", int nPrecision = 2);

/// 设置时间锚
long long setTimeAnchor();
/// 计算时间差
long long getTimeElapse(TAPTimeAnchorType nTimeAnchor = 0);

回调函数类型

/// 切片行情事件回调
typedef void(*FAPSnapDataEventCallbackType)(TAPEventIDType, CAPMarketDataField*);

/// 订单事件回调
typedef void(*FAPOrderEventCallbackType)(TAPEventIDType, CAPOrderField*);

/// 其他事件回调
typedef void(*FAPFlexibleEventCallbackType)(TAPEventIDType, void*, bool, TAPErrorIDType, const char*, const char*);

/// 线程轮询事件回调
typedef void(*FAPLoopEventCallbackType)();

结构体

class APLoginField:
    _fields_ = [
        ('License', ctypes.c_char*256), #///许可证
        ('UserType', ctypes.c_int), #///客户类型
        ('UserID', ctypes.c_char*16), #///客户号
        ('Password', ctypes.c_char*41), #///密码
        ('InvestorID', ctypes.c_char*16), #///投资者代码,如果未设置则使用UserID
        ('AccountID', ctypes.c_char*21), #///资金账户,无需设置
        ('DepartmentID', ctypes.c_char*11), #///部门代码,无需设置
        ('TraderFrontType', ctypes.c_int), #///交易前置类型
        ('TraderFrontAddress', ctypes.c_char*32), #///交易前置地址(tcp://127.0.0.1:22222)
        ('MdFrontType', ctypes.c_int), #///行情前置类型
        ('MdFrontAddress', ctypes.c_char*32), #///行情前置地址(tcp://127.0.0.1:22222)
        ('ConnectTimeout', ctypes.c_longlong), #///初始化超时退出(微秒)
        ('TaskExecuteGap', ctypes.c_longlong), #///账户任务执行间隔(微秒)
        ('TaskFailedGap', ctypes.c_longlong), #///任务失败执行间隔(微秒)
        ('TaskExecuteTimeout', ctypes.c_longlong), #///账户任务执行超时(微秒),未设置或者小于10秒时以10秒阈值
        ('LoopGap', ctypes.c_longlong), #///Loop线程间隔(微秒)
        ('IDRange', ctypes.c_int), #///管理标识
        ('BasePath', ctypes.c_char*128), #///文件路径
        ('BrokerID', ctypes.c_char*11), #///BrokerID(期货专用)
        ('AppID', ctypes.c_char*33), #///AppID(期货专用)
        ('AuthCode', ctypes.c_char*17), #///AuthCode(期货专用)
        ('HDSerial', ctypes.c_char*33), #///硬盘序列号
        ('MacAddress', ctypes.c_char*21), #///Mac地址
        ('OuterIPAddress', ctypes.c_char*16), #///公网IP地址
        ('OuterPort', ctypes.c_int), #///公网IP端口号
        ('InnerIPAddress', ctypes.c_char*16), #///内网IP地址
        ('UserProductInfo', ctypes.c_char*11), #///产品信息
        ('TerminalInfo', ctypes.c_char*256), #///终端信息
    ]

class APMarketDataField:
    _fields_ = [
        ('TradingDay', ctypes.c_char*9), #///交易日
        ('ExchangeID', ctypes.c_char*9), #///交易所
        ('StandardID', ctypes.c_char*81), #///标准交易代码
        ('MarketDataStatus', ctypes.c_char*1), #///行情状态
        ('UpdateTime', ctypes.c_char*9), #///更新时间
        ('UpdateMillisec', ctypes.c_int), #///更新毫秒
        ('LastPrice', ctypes.c_double), #///最新价
        ('PreClosePrice', ctypes.c_double), #///昨收盘价
        ('PreSettlementPrice', ctypes.c_double), #///昨结算价
        ('OpenPrice', ctypes.c_double), #///今开盘价
        ('HighestPrice', ctypes.c_double), #///最高价
        ('LowestPrice', ctypes.c_double), #///最低价
        ('BidPrice1', ctypes.c_double), #///买1价
        ('BidVolume1', ctypes.c_int), #///买1量
        ('AskPrice1', ctypes.c_double), #///卖1价
        ('AskVolume1', ctypes.c_int), #///卖1量
        ('UpperLimitPrice', ctypes.c_double), #///涨停价
        ('LowerLimitPrice', ctypes.c_double), #///跌停价
        ('OpenInterest', ctypes.c_double), #///持仓量
        ('PreOpenInterest', ctypes.c_double), #///昨持仓量
        ('Volume', ctypes.c_longlong), #///成交量
        ('Turnover', ctypes.c_double), #///成交金额
        ('AveragePrice', ctypes.c_double), #///当日均价
        ('BidPrice2', ctypes.c_double), #///买2价
        ('BidVolume2', ctypes.c_int), #///买2量
        ('AskPrice2', ctypes.c_double), #///卖2价
        ('AskVolume2', ctypes.c_int), #///卖2量
        ('BidPrice3', ctypes.c_double), #///买3价
        ('BidVolume3', ctypes.c_int), #///买3量
        ('AskPrice3', ctypes.c_double), #///卖3价
        ('AskVolume3', ctypes.c_int), #///卖3量
        ('BidPrice4', ctypes.c_double), #///买4价
        ('BidVolume4', ctypes.c_int), #///买4量
        ('AskPrice4', ctypes.c_double), #///卖4价
        ('AskVolume4', ctypes.c_int), #///卖4量
        ('BidPrice5', ctypes.c_double), #///买5价
        ('BidVolume5', ctypes.c_int), #///买5量
        ('AskPrice5', ctypes.c_double), #///卖5价
        ('AskVolume5', ctypes.c_int), #///卖5量
    ]

class APOrderField:
    _fields_ = [
        ('TradingDay', ctypes.c_char*9), #///交易日
        ('UserID', ctypes.c_char*16), #///客户号
        ('ShareholderID', ctypes.c_char*11), #///股东账户代码
        ('SessionID', ctypes.c_int), #///会话号
        ('FrontID', ctypes.c_int), #///前置号
        ('OrderID', ctypes.c_int), #///报单引用
        ('OrderMark', ctypes.c_int), #///订单备注
        ('ExchangeID', ctypes.c_char*9), #///交易所
        ('StandardID', ctypes.c_char*81), #///标准交易代码
        ('Direction', ctypes.c_char*1), #///订单方向
        ('OffsetFlag', ctypes.c_char*1), #///开平标志
        ('OrderType', ctypes.c_char*1), #///订单类型
        ('IsBuyFromMarket', ctypes.c_bool), #///是否是买入
        ('IsLimitOrder', ctypes.c_bool), #///是否是限价单
        ('CombineOrderType', ctypes.c_char*5),
        ('CreditQuotaType', ctypes.c_char*1), #///头寸类型(两融专用)
        ('CreditDebtID', ctypes.c_char*21), #///信用负债编号(两融专用)
        ('OriginalVolume', ctypes.c_int), #///报单数量
        ('OriginalPrice', ctypes.c_double), #///报单价格
        ('OrderLocalTime', ctypes.c_longlong), #///本地报单时间
        ('OrderSysID', ctypes.c_char*21), #///系统编号
        ('InsertTime', ctypes.c_char*9), #///申报时间
        ('UpdateTime', ctypes.c_char*9), #///交易所接收时间
        ('OrderStatus', ctypes.c_char*1), #///订单状态
        ('TradedVolumeChange', ctypes.c_int), #///成交数量变化
        ('TradedVolume', ctypes.c_int), #///全部成交数量
        ('CanceledVolume', ctypes.c_int), #///全部撤单数量
        ('LastTradedPrice', ctypes.c_double), #///最近一次成交价
        ('TradedVolumeChangeOfTurnover', ctypes.c_int), #///与成交额对应的成交数量变化
        ('TradedVolumeOfTurnover', ctypes.c_int), #///与成交额对应的全部成交数量
        ('TurnoverChange', ctypes.c_double), #///成交额
        ('Turnover', ctypes.c_double), #///成交额
        ('AverageCost', ctypes.c_double), #///平均成本
        ('UsableVolume', ctypes.c_int), #///可用持仓
        ('UseableCash', ctypes.c_double), #///可用资金
        ('ErrorID', ctypes.c_int), #///错误代码
        ('Message', ctypes.c_char*256), #///信息
    ]

class APTransferAssetField:
    _fields_ = [
        ('TradingDay', ctypes.c_char*9), #///交易日
        ('UserID', ctypes.c_char*16), #///客户号
        ('TransferID', ctypes.c_int), #///资产划转编号
        ('TransferStatus', ctypes.c_char*1), #///转移状态
        ('TransferFlag', ctypes.c_char*1), #///转移方向
        ('Amount', ctypes.c_double), #///转移金额
        ('Volume', ctypes.c_int), #///转移数量
        ('ExchangeID', ctypes.c_char*9), #///交易所
        ('StandardID', ctypes.c_char*81), #///标准交易代码
        ('TransferPositionType', ctypes.c_char*1), #///转移持仓类型
        ('CreditDebtID', ctypes.c_char*21), #///负债编号
        ('BankID', ctypes.c_char*4), #///银行代码(银证转账时必填)
        ('ExternalNodeID', ctypes.c_char*32), #///外部节点编号
        ('FrontID', ctypes.c_int), #///前置编号
        ('SessionID', ctypes.c_int), #///会话编号
        ('BusinessID', ctypes.c_char*32), #///转移流水号
        ('ErrorID', ctypes.c_int), #///错误代码
        ('Message', ctypes.c_char*256), #///信息
    ]

class APQueryCommandField:
    _fields_ = [
        ('TradingDay', ctypes.c_char*9), #///交易日
        ('UserID', ctypes.c_char*16), #///客户号
        ('RequestID', ctypes.c_int), #///请求编号
        ('ExchangeID', ctypes.c_char*9), #///交易所
        ('StandardID', ctypes.c_char*81), #///标准交易代码
        ('BusinessID', ctypes.c_char*32), #///业务流水号
        ('CombineBusinessFlag', ctypes.c_char*3), #///业务标志组合
        ('FloatValue', ctypes.c_double), #///浮点型
        ('IntValue', ctypes.c_int), #///整形
        ('StartTime', ctypes.c_char*9), #///开始时间
        ('EndTime', ctypes.c_char*9), #///结束时间
        ('StartDate', ctypes.c_char*9), #///开始日期
        ('EndDate', ctypes.c_char*9), #///结束日期
        ('BankID', ctypes.c_char*4), #///银行代码
        ('BankPassword', ctypes.c_char*41), #///银行账户密码
        ('AccountPassword', ctypes.c_char*41), #///资金账户密码
        ('NodeID', ctypes.c_char*32), #///柜台节点号
    ]

联系

  • 微信公众号: AlgoPlus
  • QQ群: 866469866(加群注明AlgoPlus)