[Del] 去除代码中多余的输出

This commit is contained in:
nanoric 2019-04-23 04:18:23 -04:00
parent e34781e6b4
commit d8d05e4da9
11 changed files with 192 additions and 188 deletions

View File

@ -53,7 +53,6 @@ void MdApi::OnRspUserLogin(CUstpFtdcRspUserLoginField *pRspUserLogin, CUstpFtdcR
}
if (pRspInfo)
{
cout << "md OnRspUserLogin pRspInfo" << endl;
CUstpFtdcRspInfoField *task_error = new CUstpFtdcRspInfoField();
*task_error = *pRspInfo;
task.task_error = task_error;
@ -314,7 +313,6 @@ void MdApi::processRspUserLogin(Task *task)
dict error;
if (task->task_error)
{
cout << "md processRspUserLogin task_error" << endl;
CUstpFtdcRspInfoField *task_error = (CUstpFtdcRspInfoField*)task->task_error;
error["ErrorID"] = task_error->ErrorID;
error["ErrorMsg"] = toUtf(task_error->ErrorMsg);

View File

@ -80,8 +80,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\ProgramData\VNConda\include;$(SolutionDir);$(SolutionDir)..\include;$(SolutionDir)..\include\femas;$(IncludePath)</IncludePath>
<LibraryPath>C:\ProgramData\VNConda\libs;$(SolutionDir)..\libs;$(LibraryPath)</LibraryPath>
<IncludePath>C:\Python37\include;$(SolutionDir);$(SolutionDir)..\include;$(SolutionDir)..\include\femas;$(IncludePath)</IncludePath>
<LibraryPath>C:\Python37\libs;$(SolutionDir)..\libs;$(LibraryPath)</LibraryPath>
<TargetExt>.pyd</TargetExt>
<OutDir>$(SolutionDir)..\</OutDir>
</PropertyGroup>
@ -95,10 +95,10 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>C:\ProgramData\VNConda\include;$(SolutionDir);$(SolutionDir)..\include;$(SolutionDir)..\include\femas;$(IncludePath)</IncludePath>
<IncludePath>C:\Python37\include;$(SolutionDir);$(SolutionDir)..\include;$(SolutionDir)..\include\femas;$(IncludePath)</IncludePath>
<ReferencePath>$(ReferencePath)</ReferencePath>
<TargetExt>.pyd</TargetExt>
<LibraryPath>C:\ProgramData\VNConda\libs;$(SolutionDir)..\libs;$(LibraryPath)</LibraryPath>
<LibraryPath>C:\Python37\libs;$(SolutionDir)..\libs;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)..\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -110,6 +110,7 @@
<PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;NOMINMAX;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;VNFEMASMD_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -125,6 +126,7 @@
<PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_DEBUG;VNFEMASMD_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -145,6 +147,9 @@
<ConformanceMode>true</ConformanceMode>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -167,6 +172,9 @@
</AdditionalIncludeDirectories>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@ -21,24 +21,24 @@
<ClInclude Include="targetver.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ctp\USTPFtdcMduserApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ctp\USTPFtdcTraderApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ctp\USTPFtdcUserApiDataType.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ctp\USTPFtdcUserApiStruct.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="vnfemasmd.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\vnfemas.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\femas\USTPFtdcMduserApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\femas\USTPFtdcTraderApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\femas\USTPFtdcUserApiDataType.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\femas\USTPFtdcUserApiStruct.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>

View File

@ -91,11 +91,8 @@ void TdApi::OnRspUserLogin(CUstpFtdcRspUserLoginField *pRspUserLogin, CUstpFtdcR
}
if (pRspInfo)
{
cout << "td OnRspUserLogin pRspInfo" << endl;
CUstpFtdcRspInfoField *task_error = new CUstpFtdcRspInfoField();
*task_error = *pRspInfo;
cout << "td OnRspUserLogin pRspInfo errorid" <<endl;
cout << pRspInfo->ErrorID << endl;
task.task_error = task_error;
}
task.task_id = nRequestID;
@ -630,15 +627,12 @@ void TdApi::OnRspQryInvestorAccount(CUstpFtdcRspInvestorAccountField *pRspInvest
task.task_name = ONRSPQRYINVESTORACCOUNT;
if (pRspInvestorAccount)
{
cout << "OnRspQryInvestorAccount" << endl;
cout << pRspInvestorAccount->AccountID << endl;
CUstpFtdcRspInvestorAccountField *task_data = new CUstpFtdcRspInvestorAccountField();
*task_data = *pRspInvestorAccount;
task.task_data = task_data;
}
if (pRspInfo)
{
cout << pRspInfo->ErrorMsg << endl;
CUstpFtdcRspInfoField *task_error = new CUstpFtdcRspInfoField();
*task_error = *pRspInfo;
task.task_error = task_error;
@ -1427,7 +1421,6 @@ void TdApi::processRspUserLogin(Task *task)
dict error;
if (task->task_error)
{
cout << "td processRspUserLogin task_error" << endl;
CUstpFtdcRspInfoField *task_error = (CUstpFtdcRspInfoField*)task->task_error;
error["ErrorID"] = task_error->ErrorID;
error["ErrorMsg"] = toUtf(task_error->ErrorMsg);

View File

@ -80,8 +80,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\ProgramData\VNConda\include;$(SolutionDir);$(SolutionDir)..\include;$(SolutionDir)..\include\femas;$(IncludePath)</IncludePath>
<LibraryPath>C:\ProgramData\VNConda\libs;$(SolutionDir)..\libs;$(LibraryPath)</LibraryPath>
<IncludePath>C:\Python37\include;$(SolutionDir);$(SolutionDir)..\include;$(SolutionDir)..\include\femas;$(IncludePath)</IncludePath>
<LibraryPath>C:\Python37\libs;$(SolutionDir)..\libs;$(LibraryPath)</LibraryPath>
<TargetExt>.pyd</TargetExt>
<OutDir>$(SolutionDir)..\</OutDir>
</PropertyGroup>
@ -95,8 +95,8 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.pyd</TargetExt>
<IncludePath>C:\ProgramData\VNConda\include;$(SolutionDir);$(SolutionDir)..\include;$(SolutionDir)..\include\femas;$(IncludePath)</IncludePath>
<LibraryPath>C:\ProgramData\VNConda\libs;$(SolutionDir)..\libs;$(LibraryPath)</LibraryPath>
<IncludePath>C:\Python37\include;$(SolutionDir);$(SolutionDir)..\include;$(SolutionDir)..\include\femas;$(IncludePath)</IncludePath>
<LibraryPath>C:\Python37\libs;$(SolutionDir)..\libs;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)..\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -108,6 +108,7 @@
<PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;VNFEMASTD_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -123,6 +124,7 @@
<PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;_DEBUG;VNFEMASTD_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -142,6 +144,9 @@
<ConformanceMode>true</ConformanceMode>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -164,6 +169,9 @@
</AdditionalIncludeDirectories>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@ -21,21 +21,21 @@
<ClInclude Include="targetver.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ctp\USTPFtdcMduserApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ctp\USTPFtdcTraderApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ctp\USTPFtdcUserApiDataType.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ctp\USTPFtdcUserApiStruct.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="vnfemastd.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\femas\USTPFtdcMduserApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\femas\USTPFtdcTraderApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\femas\USTPFtdcUserApiDataType.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\include\femas\USTPFtdcUserApiStruct.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>

Binary file not shown.

Binary file not shown.

View File

@ -30,7 +30,7 @@ from vnpy.api.femas import (
USTP_FTDC_VC_AV,
USTP_FTDC_TC_IOC,
USTP_FTDC_VC_CV,
USTP_FTDC_AF_Delete
USTP_FTDC_AF_Delete,
)
from vnpy.trader.constant import (
Direction,
@ -39,7 +39,7 @@ from vnpy.trader.constant import (
OrderType,
Product,
Status,
OptionType
OptionType,
)
from vnpy.trader.gateway import BaseGateway
from vnpy.trader.object import (
@ -56,8 +56,8 @@ from vnpy.trader.object import (
from vnpy.trader.utility import get_folder_path
from vnpy.trader.event import EVENT_TIMER
USTP_FTDC_PD_Long = '2'
USTP_FTDC_PD_Short = '3'
USTP_FTDC_PD_Long = "2"
USTP_FTDC_PD_Short = "3"
STATUS_FEMAS2VT = {
USTP_FTDC_CAS_Submitted: Status.SUBMITTING,
@ -66,17 +66,17 @@ STATUS_FEMAS2VT = {
USTP_FTDC_OS_NoTradeQueueing: Status.NOTTRADED,
USTP_FTDC_OS_PartTradedQueueing: Status.PARTTRADED,
USTP_FTDC_OS_AllTraded: Status.ALLTRADED,
USTP_FTDC_OS_Canceled: Status.CANCELLED
USTP_FTDC_OS_Canceled: Status.CANCELLED,
}
DIRECTION_VT2FEMAS = {
Direction.LONG: USTP_FTDC_D_Buy,
Direction.SHORT: USTP_FTDC_D_Sell
Direction.SHORT: USTP_FTDC_D_Sell,
}
ORDERTYPE_VT2FEMAS = {
OrderType.LIMIT: USTP_FTDC_OPT_LimitPrice,
OrderType.MARKET: USTP_FTDC_OPT_AnyPrice
OrderType.MARKET: USTP_FTDC_OPT_AnyPrice,
}
OFFSET_VT2FEMAS = {
@ -92,18 +92,17 @@ DIRECTION_FEMAS2VT[USTP_FTDC_PD_Long] = Direction.LONG
DIRECTION_FEMAS2VT[USTP_FTDC_PD_Short] = Direction.SHORT
EXCHANGE_FEMAS2VT = {
"CFFEX": Exchange.CFFEX,
"SHFE": Exchange.SHFE,
"CZCE": Exchange.CZCE,
"DCE": Exchange.DCE,
"INE": Exchange.INE
"INE": Exchange.INE,
}
OPTIONTYPE_FEMAS2VT = {
USTP_FTDC_OT_CallOptions: OptionType.CALL,
USTP_FTDC_OT_PutOptions: OptionType.PUT
USTP_FTDC_OT_PutOptions: OptionType.PUT,
}
@ -122,7 +121,7 @@ class FemasGateway(BaseGateway):
"password": "",
"brokerid": "",
"td_address": "",
"md_address": ""
"md_address": "",
}
def __init__(self, event_engine):
@ -140,7 +139,6 @@ class FemasGateway(BaseGateway):
td_address = setting["td_address"]
md_address = setting["md_address"]
if not td_address.startswith("tcp://"):
td_address = "tcp://" + td_address
if not md_address.startswith("tcp://"):
@ -176,13 +174,20 @@ class FemasGateway(BaseGateway):
self.td_api.close()
self.md_api.close()
def write_error(self, msg: str, error: dict):
""""""
error_id = error["ErrorID"]
error_msg = error["ErrorMsg"]
def write_error(self, msg: str, error_id: int, error_msg: str):
msg = f"{msg},代码:{error_id},信息:{error_msg}"
self.write_log(msg)
def if_error_write_error(self, msg: str, error: dict):
"""
当有错误的时候就输出错误并返回True
"""
error_id = error["ErrorID"]
if error_id:
error_msg = error["ErrorMsg"]
self.write_error(msg, error_id, error_msg)
return True
def process_timer_event(self, event):
""""""
self.count += 1
@ -241,29 +246,26 @@ class FemasMdApi(MdApi):
"""
Callback when user is logged in.
"""
if not error["ErrorID"]:
self.login_status = True
self.gateway.write_log("onRspUserLogin行情服务器登录成功")
self.gateway.write_log("行情服务器登录成功")
if self.gateway.if_error_write_error("行情登录失败", error):
return
self.login_status = True
self.gateway.write_log("onRspUserLogin行情服务器登录成功")
self.gateway.write_log("行情服务器登录成功")
for symbol in self.subscribed:
self.subMarketData(symbol)
else:
self.gateway.write_error("行情登录失败", error)
for symbol in self.subscribed:
self.subMarketData(symbol)
def onRspError(self, error: dict, reqid: int, last: bool):
"""
Callback when error occured.
"""
self.gateway.write_error("行情接口报错", error)
self.gateway.if_error_write_error("行情接口报错", error)
def onRspSubMarketData(self, data: dict, error: dict, reqid: int, last: bool):
""""""
if not error or not error["ErrorID"]:
if self.gateway.if_error_write_error("行情订阅失败", error):
return
self.gateway.write_error("行情订阅失败", error)
def onRtnDepthMarketData(self, data: dict):
"""
Callback of tick data update.
@ -292,7 +294,7 @@ class FemasMdApi(MdApi):
ask_price_1=data["AskPrice1"],
bid_volume_1=data["BidVolume1"],
ask_volume_1=data["AskVolume1"],
gateway_name=self.gateway_name
gateway_name=self.gateway_name,
)
self.gateway.on_tick(tick)
@ -323,7 +325,7 @@ class FemasMdApi(MdApi):
req = {
"UserID": self.userid,
"Password": self.password,
"BrokerID": self.brokerid
"BrokerID": self.brokerid,
}
self.reqid += 1
@ -355,8 +357,8 @@ class FemasTdApi(TdApi):
self.gateway = gateway
self.gateway_name = gateway.gateway_name
self.reqid = 0
self.localID = 0
self.reqid = int(10e5)
self.localID = int(10e5 + 8888)
self.connect_status = False
self.login_status = False
@ -387,11 +389,10 @@ class FemasTdApi(TdApi):
def onRspUserLogin(self, data: dict, error: dict, reqid: int, last: bool):
""""""
if not error["ErrorID"]:
for k, v in data.items():
print(k, ':', v)
if data['MaxOrderLocalID']:
self.localID = int(data['MaxOrderLocalID']) # 目前最大本地报单号
if data["MaxOrderLocalID"]:
self.localID = max(
self.localID, int(data["MaxOrderLocalID"])
) # 目前最大本地报单号
self.login_status = True
self.gateway.write_log("onRspUserLogin交易登录成功")
self.reqid += 1
@ -399,10 +400,12 @@ class FemasTdApi(TdApi):
else:
self.login_failed = True
self.gateway.write_error("交易登录失败", error)
self.gateway.if_error_write_error("交易登录失败", error)
def onRspOrderInsert(self, data: dict, error: dict, reqid: int, last: bool):
""""""
if self.gateway.if_error_write_error("交易委托失败", error):
return
orderid = data["UserOrderLocalID"]
symbol = data["InstrumentID"]
@ -416,21 +419,22 @@ class FemasTdApi(TdApi):
price=data["LimitPrice"],
volume=data["Volume"],
status=Status.REJECTED,
gateway_name=self.gateway_name
gateway_name=self.gateway_name,
)
self.gateway.on_order(order)
self.gateway.write_error("交易委托失败", error)
def onRspOrderAction(self, data: dict, error: dict, reqid: int, last: bool):
""""""
self.gateway.write_error("交易撤单失败", error)
if self.gateway.if_error_write_error("交易撤单失败", error):
return
def onRspQueryMaxOrderVolume(self, data: dict, error: dict, reqid: int, last: bool):
""""""
pass
def onRspSettlementInfoConfirm(self, data: dict, error: dict, reqid: int, last: bool):
def onRspSettlementInfoConfirm(
self, data: dict, error: dict, reqid: int, last: bool
):
"""
Callback of settlment info confimation.
"""
@ -452,7 +456,7 @@ class FemasTdApi(TdApi):
symbol=data["InstrumentID"],
exchange=symbol_exchange_map[data["InstrumentID"]],
direction=DIRECTION_FEMAS2VT[data["Direction"]],
gateway_name=self.gateway_name
gateway_name=self.gateway_name,
)
self.positions[key] = position
@ -479,14 +483,13 @@ class FemasTdApi(TdApi):
def onRspQryInvestorAccount(self, data: dict, error: dict, reqid: int, last: bool):
""""""
print ("onRspQryInvestorAccount")
account = AccountData(
accountid=data["AccountID"],
frozen = data['LongMargin']+data['ShortMargin'],
balance= data['PreBalance'],
gateway_name=self.gateway_name
frozen=data["LongMargin"] + data["ShortMargin"],
balance=data["PreBalance"],
gateway_name=self.gateway_name,
)
# todo: check for error
self.gateway.on_account(account)
def onRspQryInstrument(self, data: dict, error: dict, reqid: int, last: bool):
@ -495,7 +498,7 @@ class FemasTdApi(TdApi):
"""
contract = ContractData(
product = data["ProductID"],
product=data["ProductID"],
symbol=data["InstrumentID"],
exchange=EXCHANGE_FEMAS2VT[data["ExchangeID"]],
name=data["InstrumentName"],
@ -505,7 +508,7 @@ class FemasTdApi(TdApi):
option_type=OPTIONTYPE_FEMAS2VT.get(data["OptionsType"], None),
option_strike=data["StrikePrice"],
option_expiry=datetime.strptime(data["ExpireDate"], "%Y%m%d"),
gateway_name=self.gateway_name
gateway_name=self.gateway_name,
)
self.gateway.on_contract(contract)
@ -522,7 +525,7 @@ class FemasTdApi(TdApi):
Callback of order status update.
"""
# 更新最大报单编号
self.localID = max(self.localID, int(data['UserOrderLocalID'])) # 检查并增加本地报单编号
self.localID = max(self.localID, int(data["UserOrderLocalID"])) # 检查并增加本地报单编号
symbol = data["InstrumentID"]
exchange = symbol_exchange_map.get(symbol, "")
@ -530,8 +533,7 @@ class FemasTdApi(TdApi):
self.order_data.append(data)
return
orderid = data['UserOrderLocalID']
print ("---------onRtnOrder-----------")
orderid = data["UserOrderLocalID"]
order = OrderData(
symbol=symbol,
exchange=exchange,
@ -543,7 +545,7 @@ class FemasTdApi(TdApi):
traded=data["VolumeTraded"],
status=STATUS_FEMAS2VT[data["OrderStatus"]],
time=data["InsertTime"],
gateway_name=self.gateway_name
gateway_name=self.gateway_name,
)
self.gateway.on_order(order)
@ -571,7 +573,7 @@ class FemasTdApi(TdApi):
price=data["TradePrice"],
volume=data["TradeVolume"],
time=data["TradeTime"],
gateway_name=self.gateway_name
gateway_name=self.gateway_name,
)
self.gateway.on_trade(trade)
@ -584,7 +586,6 @@ class FemasTdApi(TdApi):
self.brokerid = brokerid
self.address = address
if not self.connect_status:
path = get_folder_path(self.gateway_name.lower())
self.createFtdcTraderApi(str(path) + "\\Td")
@ -609,7 +610,7 @@ class FemasTdApi(TdApi):
req = {
"UserID": self.userid,
"Password": self.password,
"BrokerID": self.brokerid
"BrokerID": self.brokerid,
}
self.reqid += 1
@ -620,11 +621,10 @@ class FemasTdApi(TdApi):
Send new order.
"""
self.localID += 1
strLocalID = str(self.localID)
print ('----femasgateway type' + str(req.type))
strLocalID = str(self.localID).rjust(12, "0")
femas_req = {
"InstrumentID": req.symbol,
"ExchangeID": str(req.exchange).split('.')[1],
"ExchangeID": str(req.exchange).split(".")[1],
"BrokerID": self.brokerid,
"InvestorID": self.userid,
"UserID": self.userid,
@ -639,22 +639,17 @@ class FemasTdApi(TdApi):
"IsAutoSuspend": 0,
"TimeCondition": USTP_FTDC_TC_GFD,
"VolumeCondition": USTP_FTDC_VC_AV,
"MinVolume": 1
"MinVolume": 1,
}
if req.type == OrderType.FAK:
femas_req["OrderPriceType"] = USTP_FTDC_OPT_LimitPrice
femas_req["TimeCondition"] = USTP_FTDC_TC_IOC
femas_req["VolumeCondition"] = USTP_FTDC_VC_AV
print ("------------fak")
elif req.type == OrderType.FOK:
femas_req["OrderPriceType"] = USTP_FTDC_OPT_LimitPrice
femas_req["TimeCondition"] = USTP_FTDC_TC_IOC
femas_req["VolumeCondition"] = USTP_FTDC_VC_CV
print ("------------fok")
for key in femas_req:
print(key + ':' + str(femas_req[key]))
self.reqid += 1
self.reqOrderInsert(femas_req, self.reqid)
@ -672,17 +667,15 @@ class FemasTdApi(TdApi):
"""
self.localID += 1
strLocalID = str(self.localID)
print ('--cancel exchange--' + str(req.exchange).split('.')[1])
print ('--cancel orderid--' + req.orderid)
femas_req = {
"InstrumentID": req.symbol,
"ExchangeID": str(req.exchange).split('.')[1],
"ExchangeID": str(req.exchange).split(".")[1],
"UserOrderLocalID": req.orderid,
"UserOrderActionLocalID": strLocalID,
"ActionFlag": USTP_FTDC_AF_Delete,
"BrokerID": self.brokerid,
"InvestorID": self.userid,
"UserID": self.userid
"UserID": self.userid,
}
self.reqid += 1
@ -695,7 +688,7 @@ class FemasTdApi(TdApi):
req = {
"BrokerID": self.brokerid,
"InvestorID": self.userid,
"UserID": self.userid
"UserID": self.userid,
}
self.reqid += 1
self.reqQryInvestorAccount(req, self.reqid)
@ -710,7 +703,7 @@ class FemasTdApi(TdApi):
req = {
"BrokerID": self.brokerid,
"InvestorID": self.userid,
"UserID": self.userid
"UserID": self.userid,
}
self.reqid += 1