Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

NTDirect.dll memory leak

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    NTDirect.dll memory leak

    I am using the NtDirect.dll with Tradestation and it appears to be the source of a memory leak. I say this because a second TS platform not using the dll does not leak memory.
    Since this dll was developed by a third party and not supported by Ninjatrader, can you put me in touch with the developer so I can ask to have the problem addressed?

    #2
    Hello Atomic,

    To confirm, the NinjaTrader process is growing in memory in the Task Manager?

    Do you have all workspaces closed and a blank workspace open?

    Below is a link to a demonstration project.
    https://ninjatrader.com/support/foru...626#post793626

    May I confirm you are able to reproduce the behavior with the demonstration project without making any modifications to it?

    Unfortunately, I cannot provide you direct contact with the development team. If there is an issue we can make a report as we do for all NinjaTrader issues.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Atomic,

      To confirm, the NinjaTrader process is growing in memory in the Task Manager?

      Do you have all workspaces closed and a blank workspace open?

      Below is a link to a demonstration project.
      https://ninjatrader.com/support/foru...626#post793626

      May I confirm you are able to reproduce the behavior with the demonstration project without making any modifications to it?

      Unfortunately, I cannot provide you direct contact with the development team. If there is an issue we can make a report as we do for all NinjaTrader issues.
      I was unable to locate the example project you referred to. Can you be more specific as to what I should be looking for.

      Comment


        #4
        Hello Atomic,

        I have outlined a red square around the download link on that forum page.

        If you are not able to download files from the forum, this may indicate you have not completed clicking the registration link sent to your email when creating a forum user account.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello Atomic,

          I have outlined a red square around the download link on that forum page.

          If you are not able to download files from the forum, this may indicate you have not completed clicking the registration link sent to your email when creating a forum user account.

          I do not see a highlight link such as you described. I have no problem download files.

          Comment


            #6
            Hello Atomic,

            I've edited the post to add additional links at the bottom.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello Atomic,

              I've edited the post to add additional links at the bottom.
              I do not see any posts here which have been edited today.

              Comment


                #8
                Hello Atomic,

                Ctrl + F5 to refresh and clear cache.

                Attached is a screenshot showing the post was edited.

                Click image for larger version

Name:	2022-11-16_8-47-26.png
Views:	195
Size:	27.5 KB
ID:	1223868
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello Atomic,

                  Ctrl + F5 to refresh and clear cache.

                  Attached is a screenshot showing the post was edited.

                  Click image for larger version

Name:	2022-11-16_8-47-26.png
Views:	195
Size:	27.5 KB
ID:	1223868
                  I found it, but I realize I may have miscommunicated my problem. The memory leak is in Tradestation, not Ninjatrader.
                  Sorry for the trouble.

                  Comment


                    #10
                    Hello Atomic,

                    This would indicate an issue with TradeStation.

                    If the sample project application accessing the NTDirect.dll is not able to reproduce, this would indicate this is not an issue with the NinjaTrader API.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello Atomic,

                      This would indicate an issue with TradeStation.

                      If the sample project application accessing the NTDirect.dll is not able to reproduce, this would indicate this is not an issue with the NinjaTrader API.
                      Are you saying that the C# project to which you referred me, can be used to generate the same NTDirect dll that you provide to NinjaTrader users?

                      I believe you suggest that if I have questions about the dll, that you would pass them on to the developer. Can I put them in an email to you?

                      Comment


                        #12
                        Hello Atomic,

                        The NTDirect.dll is the file NinjaTrader provides for access to the API.

                        No, the project I have provided does not generate the NTDirect.dll. This uses the existing NTDirect.dll that NinjaTrader provides to interface with the API and send and receive data.

                        Have a look a look at the project and test it.

                        What questions can we assist with?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          Hello Atomic,

                          The NTDirect.dll is the file NinjaTrader provides for access to the API.

                          No, the project I have provided does not generate the NTDirect.dll. This uses the existing NTDirect.dll that NinjaTrader provides to interface with the API and send and receive data.

                          Have a look a look at the project and test it.

                          What questions can we assist with?
                          I believe that my memory leak problem results from using this dll function:
                          string OrderStatus(string orderId)
                          Gets the order state (see definitions) for the orderId. Returns an empty string if the order ID value provided does not return an order.

                          ​That is from the NT8 help guide.

                          When I first started using the dll, I was using NT7 and that version cames with some Easylanguage functions to make it simpler
                          for EL programmers to access the dll functions. This is what the NTOrderStatus Easylanguage function looked like:
                          Code:
                          { ** Copyright (c) 2005, NinjaTrader LLC [email protected] }
                          DefineDLLFunc: "NtDirect.dll", int, "Connected", int;
                          DefineDLLFunc: "NtDirect.dll", lpstr, "OrderStatus", lpstr;
                          DefineDLLFunc: "NtDirect.dll", int, "SetAllocReturnString", int;
                          DefineDLLFunc: "NtDirect.dll", int, "SetMaxReturnStringLength", int;
                          
                          inputs: OrderId(string);
                          
                          once begin
                          SetAllocReturnString(1); { alloc memory for returned string, TS will free that memory }
                          SetMaxReturnStringLength(500); { limit the max length of return string to 500 }
                          end;
                          
                          if Connected(0) = 0 then
                          NTOrderStatus = OrderStatus(OrderId);
                          I determined early on that this was causing a memory leak, and my solution was to reduce the length of the return string
                          and to call the funciton less frequently. I was able to prove this by calling the function at a very high rate. When I reduced the
                          size of the return string and the calling frequency, the memory leak growth was mitigated.

                          Fast forward ten years, better computers, I'm using NT8 and TS10, and I had rather put the memory leak problem out of my mind. However,
                          lately I have dramatically increased my use of the dll, and I begain to notice the memory leak problem again. At first, I didn't
                          attribute it to the NTOrderStatus function, but I'm convinced that is what it is. As a way to minimize the memory leak, I have
                          experimented with reducing the return string length to as short as possible. To that end, I created this Easylanguage function:
                          Code:
                          { ** Copyright (c) 2005, NinjaTrader LLC [email protected] }
                          DefineDLLFunc: "NtDirect.dll", int, "Connected", int;
                          DefineDLLFunc: "NtDirect.dll", lpstr, "OrderStatus", lpstr;
                          DefineDLLFunc: "NtDirect.dll", int, "SetAllocReturnString", int;
                          DefineDLLFunc: "NtDirect.dll", int, "SetMaxReturnStringLength", int;
                          using tsdata.common;
                          
                          //POSSIBLE ORDER STATES
                          //InitializedPendingSubmitAcceptedWorkingPendingChan gePendingCancelCancelledRejectedPartFilledFilled
                          //10.10.22 Revised to return only "Working" if status is "Accepted"
                          inputs: OrderId(stringsimple);
                          
                          var:
                          TokenList ReturnStrings(null),
                          int Chars(6),
                          intrabarpersist string OS(""),
                          intrabarpersist Res1(""),
                          intrabarpersist Res2(""),
                          intrabarpersist Res3(""),
                          intrabarpersist Res4(""),
                          intrabarpersist Res5(""),
                          intrabarpersist Res6(""),
                          intrabarpersist Res7(""),
                          intrabarpersist Res8(""),
                          intrabarpersist Res9(""),
                          intrabarpersist Res10(""),
                          intrabarpersist Res11(""),
                          intrabarpersist Res12("");
                          
                          once begin
                          ReturnStrings = TokenList.Create("Initialized,Submitted,Accepted,W orking,Change Submitted,Cancel Pending,Cancelled,Rejected,Partially Filled,Filled,Trigger Pending");
                          SetAllocReturnString(1); { alloc memory for returned string, TS will free that memory }
                          SetMaxReturnStringLength(Chars); { limit the max length of return string to 500 }
                          Res1 = leftstr(ReturnStrings[0],Chars).tolower();
                          Res2 = leftstr(ReturnStrings[1],Chars).tolower();
                          Res3 = leftstr(ReturnStrings[2],Chars).tolower();
                          Res4 = leftstr(ReturnStrings[3],Chars).tolower();
                          Res5 = leftstr(ReturnStrings[4],Chars).tolower();
                          Res6 = leftstr(ReturnStrings[5],Chars).tolower();
                          Res7 = leftstr(ReturnStrings[6],Chars).tolower();
                          Res8 = leftstr(ReturnStrings[7],Chars).tolower();
                          Res9 = leftstr(ReturnStrings[8],Chars).tolower();
                          Res10 = leftstr(ReturnStrings[9],Chars).tolower();
                          Res11 = leftstr(ReturnStrings[10],Chars).tolower();
                          end;
                          
                          if Connected(0) = 0 then begin
                          OS = OrderStatus(OrderID).tolower();
                          //print(OS);
                          switch(OS)
                          begin
                          case Res1 :NTOSy = "Initialized";
                          case Res2 :NTOSy = "Submitted";
                          case Res3 :NTOSy = "Accepted";
                          case Res4 :NTOSy = "Working";
                          case Res5 :NTOSy = "Change Submitted";
                          case Res6 :NTOSy = "Cancel Pending";
                          case Res7 :NTOSy = "Cancelled";
                          case Res8 :NTOSy = "Rejected";
                          case Res9 :NTOSy = "Partially Filled";
                          case Res10 :NTOSy = "Filled";
                          case Res11 :NTOSy = "Trigger Pending";
                          default :NTOSy = "No Order";
                          end;
                          end;
                          This allows me to easily change the return string length and to examine the results.

                          I run this Easylanguage code on a chart that is running every tick, and what I see is that the
                          returns are not reliable when I make the return string too short. When I am statusing a filled
                          order, it will usually return "Filled", but if the orderstatus function return string length is set too
                          short, it will often return "No Order".

                          Why does the dll orderstatus function behave in this way, and is there anything to be done in
                          the dll that will mitigate the memory use (I am speaking of the Tradestation process ORPlat.exe)?

                          What I find is that if I set the return string length to a minimum of 6 characters, then I do not get any incorrect
                          returns from my code.






                          Last edited by Atomic; 11-17-2022, 02:21 PM.

                          Comment


                            #14
                            Hello Atomic,

                            The EasyLanguage that was made for NinjaTrader 7 is deprecated and is not supported by NinjaTrader for NinjaTrader 8.
                            (Basically, we have removed support for this as its for another platform and requires our technicians to be able to code EasyLanguage)

                            We directly support the API, but no longer support the EasyLanguage files and we do not support using the ones for NinjaTrader 7 in NinjaTrader 8 even though some users are making the decision to do so, knowing it is not supported.

                            However, I will happily test calling OrderStatus(string orderId) from the project application directly to the API.

                            I'll set a timer that calls this every 10 seconds or so and assigning the value to the same class level string (so as to not stack objects in memory) and i'll check to see if the project application starts growing memory. I will let you know what find.

                            I also recommend you give this a try as well.
                            Last edited by NinjaTrader_ChelseaB; 11-17-2022, 03:03 PM.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello Atomic,

                              I was seeing the application close when using the NTDirect.dll. I will look further into this.

                              Using the NinjaTrader.Client.dll was successful, and after running this method 3 times a second for 4 minutes I was not seeing any uncontrolled memory growth.

                              Below is a link to a video of the test.


                              Testing the same on your end are you getting different behavior?
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              15 responses
                              3,269 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Taddypole  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              4 responses
                              51 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              10 responses
                              402 views
                              1 like
                              Last Post beobast
                              by beobast
                               
                              Working...
                              X