NexusFi: Find Your Edge


Home Menu

 





NinjaTrader WebSocket client


Discussion in NinjaTrader

Updated
    1. trending_up 286 views
    2. thumb_up 5 thanks given
    3. group 7 followers
    1. forum 2 posts
    2. attach_file 2 attachments




 
Search this Thread

NinjaTrader WebSocket client

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

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?
Better Renko Gaps
The Elite Circle
Deepmoney LLM
Elite Quantitative GenAI/LLM
Futures True Range Report
The Elite Circle
ZombieSqueeze
Platforms and Indicators
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 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: 12 since Jul 2020
Thanks Given: 6
Thanks Received: 19



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




Last Updated on October 28, 2023


© 2024 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 - Privacy Policy - Downloads - Top
no new posts