• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MarketDataEventArgs.ToString() method culture specific?

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

    MarketDataEventArgs.ToString() method culture specific?

    Question is whether the string generated by calling MarketDataEventArgs.ToString() is culture specific. I will explain by an example.
    code snippet handling OnMarketData event:
    protected override void OnMarketData(MarketDataEventArgs e)
    {
    string exampleString = e.ToString();
    }
    Running this method in US may result in the following 'exampleString':
    Instrument='CL 12-13 Nymex' Type=Last Price=94.88 Volume=1 Time=11/6/2013 1:28:13

    The question is whether this string, in particular its price portion, will be formatted differently in Europe, for example French culture ( CultureInfo("fr-FR") ) will format decimal point separation with a comma instead. and thus it might be that the string could look like this
    Instrument='CL 12-13 Nymex' Type=Last Price=94,88 Volume=1 Time=11/6/2013 1:28:13
    This would be the case if the 'ToString()' method internally used a call to 'Price.ToString()' as Double.ToString() is culture specific and would return 94.88 in US and 94,88 in most european cultures.

    It is important to know the answer to this question for anyone who develops applications for NinjaTrader with international audience in mind.

    #2
    Hello JQuant,

    Thank you for your post.

    This should be dependent on your region settings for Windows.
    http://windows.microsoft.com/en-us/w...#1TC=windows-7
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your answer. Could you post an example of an update entry in a non-us region?
      Even better, could you confirm that the following is the case:
      in the price portion of the string, the only difference across regions will be that some use '.' as decimal point separator and others use ',' as separator. Everything else (regarding price entry) will be the same. Therefore to correctly parse a price 'double' from an entry would be to find if it contains a '.' and in that case use 'en-US' culture or if it contains ',' then use 'fr-FR' culture. So, in pseudo code, assuming one first separates the correct portion of price string as 'priceString', we could handle it as follows:

      double price = 0;
      if(priceString.Contains("."))
      {
      price = Convert.ToDouble(priceString, usCulture);
      }
      else if(priceString.Contains(","))
      {
      price = Convert.ToDouble(priceString, frenchCulture);
      }
      else
      {
      price = Convert.ToDouble(priceString);//here it doesn't matter what region we are in...
      }
      where usCulture is 'en-US' instance of CultureInfo and frenchCulture is 'fr-FR' instance of CultureInfo class.

      Comment


        #4
        Hello JQuant,

        You actually have the example right there. That will check the priceString if it does contain a , or ar . for the value
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by darkgreen, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post darkgreen  
        Started by GTBrooks, Today, 02:44 PM
        2 responses
        14 views
        0 likes
        Last Post GTBrooks  
        Started by GLFX005, Today, 12:22 PM
        4 responses
        41 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by AspenHiker, Today, 08:37 AM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by MartinT, Yesterday, 01:12 PM
        3 responses
        17 views
        0 likes
        Last Post MartinT
        by MartinT
         
        Working...
        X