DAApi.Net is a .NET library for the DAApi Futures API which is popular worldwide future market trade api in China. This project is a wrapper of the DAApi C++ API using swig.
Please read FAQ before using this library.FAQ
- Support DAApi Trade API
- Support .Net framework 4.5 and .Net Standard 2.0 and Modern .Net6 and .Net8
- Auto copy the native dlls to the output directory
- Native AOT support
- Solved the GB2312 encoding problem
dotnet add package DAApi.Net
using System.Threading.Tasks;
using DAApi.Net;
Console.WriteLine($"ITapTradeAPIVersion:{CMarketApi.GetVersion()}");
int ret = 0;
var api = CMarketApi.CreateMarketApi(false);
var spi = new SpiImpl(api);
api.RegisterSpi(spi);
api.RegisterNameServer("tcp://127.0.0.1:1234");
api.Init();
await Task.Delay(100000);
public class SpiImpl : IMarketEvent
{
public SpiImpl(CMarketApi api)
{
Api = api;
}
public CMarketApi Api { get; }
public override void OnFrontConnected()
{
Console.WriteLine("OnFrontConnected");
var ret = Api.ReqUserLogin(
new CMarketReqUserLoginField
{
UserId = "UserId",
UserPwd = "Password",
SoftwareName = "SoftwareName",
SoftwareVersion = "SoftwareVersion",
AuthorCode = "AuthCode",
BrokerIDForMarketPrice = "BrokerIdForMarketPrice",
},
0
);
Console.WriteLine($"ReqUserLogin ret:{ret}");
}
public override void OnRspUserLogin(CMarketRspInfoField pRspInfo, int iRequestID, bool bIsLast)
{
Console.WriteLine($"OnRspUserLogin pRspInfo:{pRspInfo} iRequestID:{iRequestID} bIsLast:{bIsLast}");
}
public override void OnFrontDisconnected(int iReason)
{
Console.WriteLine($"OnFrontDisconnected iReason:{iReason}");
}
public override void OnRspMarketData(
CMarketRspMarketDataField pRspMarketData,
CMarketRspInfoField pRspInfo,
int iRequestID,
bool bIsLast
)
{
Console.WriteLine($"OnRspMarketData pRspMarketData:{pRspMarketData} pRspInfo:{pRspInfo} iRequestID:{iRequestID} bIsLast:{bIsLast}");
}
}
- dotnet sdk 8.0 or later
- swig 4.3.0 or later, use
scoop install swig
to install swig on windows, do not usewinget
. - cmake 3.31.3 or later.
- Clone the repository and open the solution file
DAApi.Net.sln
with Visual Studio 2022. - run the command in
DAApiApi/SwigGenerator.sh
to generate the cpp and C# wrapper code. - run
win-build.sh
for windows native build orlinux-build.sh
for linux native build. - Build the
DAApi.Net
C# project.
ApiVersion:1.18.2.0
set RuntimeIdentifier
to win-x64
in the project file.
MIT License