NexusFi: Find Your Edge


Home Menu

 





NinjaTrader WebSocket client


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one pixel with 2 posts (5 thanks)
    2. looks_two eldee with 1 posts (1 thanks)
    3. looks_3 alhakeem with 1 posts (0 thanks)
    4. looks_4 rolexrsp with 1 posts (0 thanks)
    1. trending_up 4,189 views
    2. thumb_up 6 thanks given
    3. group 10 followers
    1. forum 4 posts
    2. attach_file 2 attachments




 
Search this Thread
  #1 (permalink)
 pixel 
Arkansas/US
 
Experience: Intermediate
Platform: NinjaTrader
Trading: E-mini S&P 500
Posts: 13 since Jul 2020
Thanks Given: 6
Thanks Received: 23

Here's a WebSocket client for NinjaTrader 8 to facilitate communication between programming languages that support the WebSocket protocol. I've attached the indicator and a Python example .

I created this indicator to integrate with Ninjatrader and leverage AI tools such as Langchain, Microsoft Semantic Kernel, Autogen, and more.

If allowed, here's the source code
https://github.com/mattalford/ninja-socket

 
Code
git clone https://github.com/mattalford/ninja-socket.git
cd python_example
pip install -r requirements.txt
uvicorn main:app --reload
 
Code
NinjaScript Output:
Data: Sent data - Hello Word!


Attached Files
Elite Membership required to download: NinjaSocket.zip
Elite Membership required to download: python_example.zip
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Five Days Until the Gap Dies -- CME Goes 24/7 on All Dig …
Traders Hideout
Q1 2026 Shatters All Derivatives Volume Records -- CME H …
Traders Hideout
Wood Mackenzie Drops $200 Oil Forecast -- Airspace Expir …
Prediction Markets & Event Contracts
Hormuz Surges From 14% to 26.5% Intraday as Irans Answer …
Prediction Markets & Event Contracts
Energy Futures Shatter All-Time Daily Volume: 8.3 Millio …
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
22 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
5 thanks
  #2 (permalink)
 rolexrsp 
boca ratón
 
Experience: Advanced
Platform: NT8
Trading: futures
Posts: 3 since May 2021
Thanks Given: 4
Thanks Received: 1


pixel View Post
Here's a WebSocket client for NinjaTrader 8 to facilitate communication between programming languages that support the WebSocket protocol. I've attached the indicator and a Python example .

I created this indicator to integrate with Ninjatrader and leverage AI tools such as Langchain, Microsoft Semantic Kernel, Autogen, and more.

If allowed, here's the source code
https://github.com/mattalford/ninja-socket

 
Code
git clone https://github.com/mattalford/ninja-socket.git
cd python_example
pip install -r requirements.txt
uvicorn main:app --reload
 
Code
NinjaScript Output:
Data: Sent data - Hello Word!

How this should be implemented into the NT8 ?


Reply With Quote
  #3 (permalink)
 pixel 
Arkansas/US
 
Experience: Intermediate
Platform: NinjaTrader
Trading: E-mini S&P 500
Posts: 13 since Jul 2020
Thanks Given: 6
Thanks Received: 23



rolexrsp View Post
How this should be implemented into the NT8 ?

This is for developers and individuals interested in bi-directional data communication using WebSocket in their preferred programming language. You can utilize the NinjaSocket source code in your own indicators or strategies. For instance, if you wish to send OHLC data from NinjaTrader to Python for analysis

Here's a short code snippet
NinjaScript
 
Code
string data = "";  
  
for (int i = 0; i < Bars.Count; i++)  
{  
double open = Bars.GetOpen(i); double high = Bars.GetHigh(i); double low = Bars.GetLow(i); double close = Bars.GetClose(i); double volume = Bars.GetVolume(i); DateTime time = Bars.GetTime(i); data += string.Format("{0}|{1}|{2}|{3}|{4}|{5};", open, high, low, close, volume, time);
} // Send the data SendDataAsync(data);
Python
 
Code
data = await websocket.receive_text()
bars = data.decode('utf-8').split(';')  
for bar in bars:  
open, high, low, close, volume, time = bar.split('|') open, high, low, close, volume = map(float, [open, high, low, close, volume]) time = datetime.datetime.strptime(time, "%m/%d/%Y %H:%M:%S") print(f"Open: {open}, High: {high}, Low: {low}, Close: {close}, Volume: {volume}, Time: {time}")


Started this thread Reply With Quote
  #4 (permalink)
eldee
Vancouver BC Canada
 
Posts: 1 since Aug 2024
Thanks Given: 0
Thanks Received: 1


pixel View Post
This is for developers and individuals interested in bi-directional data communication using WebSocket in their preferred programming language. You can utilize the NinjaSocket source code in your own indicators or strategies. For instance, if you wish to send OHLC data from NinjaTrader to Python for analysis

Here's a short code snippet
NinjaScript
 
Code
string data = "";  
  
for (int i = 0; i < Bars.Count; i++)  
{  
double open = Bars.GetOpen(i); double high = Bars.GetHigh(i); double low = Bars.GetLow(i); double close = Bars.GetClose(i); double volume = Bars.GetVolume(i); DateTime time = Bars.GetTime(i); data += string.Format("{0}|{1}|{2}|{3}|{4}|{5};", open, high, low, close, volume, time);
} // Send the data SendDataAsync(data);
Python
 
Code
data = await websocket.receive_text()
bars = data.decode('utf-8').split(';')  
for bar in bars:  
open, high, low, close, volume, time = bar.split('|') open, high, low, close, volume = map(float, [open, high, low, close, volume]) time = datetime.datetime.strptime(time, "%m/%d/%Y %H:%M:%S") print(f"Open: {open}, High: {high}, Low: {low}, Close: {close}, Volume: {volume}, Time: {time}")

@pixel Do I need to modify the file inside Protechy/NinjaSocket to add this code, or do I need to create a new NinjaScript?

Secondly, I would like to send the realtime tick data from NinjaTrader to my script (NodeJS) outside of NinjaTrader. How do I go about sending this data via websockets?


Reply With Quote
Thanked by:
  #5 (permalink)
 alhakeem 
Harlow
 
Experience: Advanced
Platform: TWS
Trading: Gold, Bonds,Currencies
Posts: 39 since Feb 2017
Thanks Given: 21
Thanks Received: 19

Hello Eldee,

Is there any way to modify this code the other-way around ?.
For example, stream data via a 3rd party REST based API into NT8 for charting.


Reply With Quote




Last Updated on October 16, 2024


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts