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

View File

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

View File

@ -21,24 +21,24 @@
<ClInclude Include="targetver.h"> <ClInclude Include="targetver.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </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"> <ClInclude Include="vnfemasmd.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\vnfemas.h"> <ClInclude Include="..\vnfemas.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </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>
<ItemGroup> <ItemGroup>
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">

View File

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

View File

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

View File

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

View File

@ -21,21 +21,21 @@
<ClInclude Include="targetver.h"> <ClInclude Include="targetver.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </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"> <ClInclude Include="vnfemastd.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </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>
<ItemGroup> <ItemGroup>
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">

View File

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