Skip to content

Commit

Permalink
Added NinjaTrader External Test piloting
Browse files Browse the repository at this point in the history
  • Loading branch information
bleunguts committed Jan 29, 2024
1 parent 83c0f37 commit 929a69e
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
Binary file added 3rdParty/NinjaTrader.Client.dll
Binary file not shown.
63 changes: 63 additions & 0 deletions ProjectX.MarketData.NinjaTrader.Tests/NinjaTraderExternalTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using NUnit.Framework;
using System.Threading.Tasks;
using System;
using NinjaTrader.Client;

namespace ProjectX.MarketData.NinjaTrader.Tests
{
public class NinjaTraderExternalTests
{
/*
* An external project using the NinjaTrader.Client.dll should target .NET 4.8 for compatibility with NT8 8.0.23.0 and later.
* To test the Ninja8API, you must enable the AT Interface option in NinjaTrader 8 by opening NInjaTrader and going to the Tools > Options > Automated Trading Interface tab. Enable the 'AT Interface' checkbox option and click OK.
* After enabling the 'AT Interface' option, restart NinjaTrader.
* https://forum.ninjatrader.com/forum/ninjatrader-8/add-on-development/1260152-nt8-api-ninjatrader-client-dll-demo
*/
private Client _client = new Client();

[Test]
public async Task SubscribeTo()
{
const string instrumentReceive = "BTCUSD";
try
{
//int setup = _client.SetUp("localhost", 36973);
//Console.WriteLine($"{DateTime.Now} | setup: {setup}");

int connect = _client.Connected(1);
Console.WriteLine($"{DateTime.Now} | connect: {connect}");

var mdSubscribed = _client.SubscribeMarketData(instrumentReceive);
Console.WriteLine($"{DateTime.Now} | subscribed: {instrumentReceive}");

if (mdSubscribed != 0)
{
throw new Exception($"Subscription error to {instrumentReceive}, error code:{mdSubscribed}");
}

for (int i = 0; i < 3; i++)
{
var askPriceReceive = _client.MarketData(instrumentReceive, 2);
var bidPriceReceive = _client.MarketData(instrumentReceive, 1);
var lastPriceReceive = _client.MarketData(instrumentReceive, 0);

Console.WriteLine($"{DateTime.Now} | {instrumentReceive} | Last: {lastPriceReceive}, Ask: {askPriceReceive}, Bid: {bidPriceReceive}");
await Task.Delay(1000);
}
}
catch (Exception exp)
{
Console.WriteLine($"Error occurred {exp.Message}");
}
finally
{
var mdSubscribed = _client.UnsubscribeMarketData(instrumentReceive);
if (mdSubscribed != 0)
{
Console.WriteLine($"Unsubscription error to {instrumentReceive}, error code:{mdSubscribed}");
}
_client.TearDown();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="NinjaTrader.Client">
<HintPath>..\3rdParty\NinjaTrader.Client.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions ProjectX.sln
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{406DF674-C57
ProjectX.AnalyticsLibNative\src\CMakeLists.txt = ProjectX.AnalyticsLibNative\src\CMakeLists.txt
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectX.MarketData.NinjaTrader.Tests", "ProjectX.MarketData.NinjaTrader.Tests\ProjectX.MarketData.NinjaTrader.Tests.csproj", "{31FE4683-7334-48FC-9642-628F4FA7F821}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectX.MarketData.NinjaTraderApi.Tests", "ProjectX.MarketData.NinjaTraderApi.Tests\ProjectX.MarketData.NinjaTraderApi.Tests.csproj", "{31A7F96A-31E5-4B88-80E5-DC04329B880F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -242,6 +246,30 @@ Global
{976A2B6C-D76E-46E9-BD5D-C5FAC69B8509}.Release|x64.Build.0 = Release|Any CPU
{976A2B6C-D76E-46E9-BD5D-C5FAC69B8509}.Release|x86.ActiveCfg = Release|Any CPU
{976A2B6C-D76E-46E9-BD5D-C5FAC69B8509}.Release|x86.Build.0 = Release|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Debug|x64.ActiveCfg = Debug|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Debug|x64.Build.0 = Debug|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Debug|x86.ActiveCfg = Debug|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Debug|x86.Build.0 = Debug|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Release|Any CPU.Build.0 = Release|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Release|x64.ActiveCfg = Release|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Release|x64.Build.0 = Release|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Release|x86.ActiveCfg = Release|Any CPU
{31FE4683-7334-48FC-9642-628F4FA7F821}.Release|x86.Build.0 = Release|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Debug|x64.ActiveCfg = Debug|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Debug|x64.Build.0 = Debug|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Debug|x86.ActiveCfg = Debug|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Debug|x86.Build.0 = Debug|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Release|Any CPU.Build.0 = Release|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Release|x64.ActiveCfg = Release|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Release|x64.Build.0 = Release|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Release|x86.ActiveCfg = Release|Any CPU
{31A7F96A-31E5-4B88-80E5-DC04329B880F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -254,6 +282,8 @@ Global
{A91A79D7-55B1-4D85-B500-6B53D0C42886} = {291F2E1A-D783-4A45-955B-6C39A801C658}
{66D0F4A6-3505-4275-90AA-8B95E76EFB41} = {291F2E1A-D783-4A45-955B-6C39A801C658}
{406DF674-C576-4678-9B50-630275B73318} = {CB887621-9DE5-49ED-BE4C-7B170A43F062}
{31FE4683-7334-48FC-9642-628F4FA7F821} = {291F2E1A-D783-4A45-955B-6C39A801C658}
{31A7F96A-31E5-4B88-80E5-DC04329B880F} = {291F2E1A-D783-4A45-955B-6C39A801C658}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8123A31C-36EE-481E-9ED7-0EB9D36F17CD}
Expand Down

0 comments on commit 929a69e

Please sign in to comment.