NexusFi: Find Your Edge


Home Menu

 





Posting to Twitter


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one josh with 6 posts (1 thanks)
    2. looks_two bukkan with 5 posts (3 thanks)
    3. looks_3 shodson with 4 posts (13 thanks)
    4. looks_4 Flexer with 3 posts (0 thanks)
      Best Posters
    1. looks_one shodson with 3.3 thanks per post
    2. looks_two Beljevina with 2 thanks per post
    3. looks_3 gregid with 1.5 thanks per post
    4. looks_4 bukkan with 0.6 thanks per post
    1. trending_up 11,296 views
    2. thumb_up 24 thanks given
    3. group 13 followers
    1. forum 29 posts
    2. attach_file 1 attachments




 
Search this Thread

Posting to Twitter

  #1 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

I just coded my automated strategy to post trades, entries, exits, and daily P/L summaries to a Twitter account. I tried using some of the 3rd-part .NET Twitter APIs but I couldn't get one to work (Twitteroo) so I just used the command-line API. You need to have a working copy of curl.exe on your machine and set it's path in the "cmd" string. I've attached a ZIP with the curl.exe I'm using on Vista Ultimate. The "user" and "password" parameters are your Twitter username and password you want to post to.

 
Code
        private void PostToTwitter(string msg, string user, string password)
        {
            try
            {
                string cmd = "C:\\Windows\\System32\\curl.exe";
                string args = "-u " + user + ":" + password -d status=\"" 
                    + msg + "\" http://twitter.com/statuses/update.xml";    
                
                System.Diagnostics.Process.Start(cmd, args);
            }
            catch (Exception ex)
            {
                Print(ex.Message);
            }
        }
You can follow my strategy's Twitter account at @uberBOT1.

Attached Files
Elite Membership required to download: curl.zip
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
ZombieSqueeze
Platforms and Indicators
Are there any eval firms that allow you to sink to your …
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
  #2 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

Actually, this one is probably better, it doesn't require the curl library, just uses the built-in .NET libraries. Props to this page for helping me fine-tune it.
 
Code
private void PostToTwitter(string msg, string username, string password)
{
    System.IO.Stream os = null;
    try
    {
         string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
         string url = "http://twitter.com/statuses/update.xml";
         System.Net.HttpWebRequest req = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(url);
         req.Headers.Add("Authorization", "Basic " + user);
         req.ContentType = "application/x-www-form-urlencoded";
         req.Method = "POST";
         req.ServicePoint.Expect100Continue = false;

         byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + msg);

         req.ContentLength = bytes.Length;
         os = req.GetRequestStream();
         os.Write(bytes, 0, bytes.Length);

         System.Net.WebResponse resp = req.GetResponse();
         if (resp == null) return;

         System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
         string response = sr.ReadToEnd().Trim();
    }
    catch (Exception ex)
    {
        Print("Error in PostToTwitter: " + ex.Message);
    }
    if (os != null) os.Close();
}

Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #3 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623


Thanks shodson for posting this.

Also, may I ask you a question of what is the advantage of using API over using service like TwitterMail?

Doesn't TwitterMail allow you to post updates by sending email to your Twitter account?

Reply With Quote
  #4 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

Not sure, I've never used TwitterMail

Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


gregid View Post
Thanks shodson for posting this.

Also, may I ask you a question of what is the advantage of using API over using service like TwitterMail?

Doesn't TwitterMail allow you to post updates by sending email to your Twitter account?

I'm not a Twitter user, but I think it's the easy way to do it, just a mailto() to your TwitterMail.

Follow me on Twitter Reply With Quote
  #6 (permalink)
 Treggs 
Working on my LCD tan
 
Experience: Advanced
Platform: NinjaTrader
Posts: 127 since Jun 2009
Thanks Given: 25
Thanks Received: 52


shodson View Post
Actually, this one is probably better, it doesn't require the curl library, just uses the built-in .NET libraries. Props to this page for helping me fine-tune it.
 
Code
private void PostToTwitter(string msg, string username, string password)
{
    System.IO.Stream os = null;
    try
    {
         string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
         string url = "http://twitter.com/statuses/update.xml";
         System.Net.HttpWebRequest req = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(url);
         req.Headers.Add("Authorization", "Basic " + user);
         req.ContentType = "application/x-www-form-urlencoded";
         req.Method = "POST";
         req.ServicePoint.Expect100Continue = false;

         byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + msg);

         req.ContentLength = bytes.Length;
         os = req.GetRequestStream();
         os.Write(bytes, 0, bytes.Length);

         System.Net.WebResponse resp = req.GetResponse();
         if (resp == null) return;

         System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
         string response = sr.ReadToEnd().Trim();
    }
    catch (Exception ex)
    {
        Print("Error in PostToTwitter: " + ex.Message);
    }
    if (os != null) os.Close();
}

Apologies for the grave dig but I'm curious how you implemented this code. I tried pasting the code into a strategy and calling it in "OnBarUpdate" and it locked up NT7. Never managed to break NT so easily and consistently lol.

Reply With Quote
  #7 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 278 since Jun 2009
Thanks Given: 161
Thanks Received: 271

have a look at TwitterVB - A .NET Twitter Library

Reply With Quote
Thanked by:
  #8 (permalink)
 
josh's Avatar
 josh 
Georgia, US
Legendary Market Wizard
 
Experience: None
Platform: SC
Broker: Denali+Rithmic
Trading: ES, NQ, YM
Posts: 6,216 since Jan 2011
Thanks Given: 6,752
Thanks Received: 18,136

I've asked over at the NT forum but thought it wouldn't hurt to double post here.

Is it possible to use something like TwitterVB or another library to post twitter updates if I place a manual trade, as opposed to calling the code from an automated strategy? Like, if I place a stop order in the DOM, is there some mechanism to detect that and immediately post that an order is placed, and then when the order is filled, and then when the stop loss is moved, etc.?

Reply With Quote
Thanked by:
  #9 (permalink)
 
josh's Avatar
 josh 
Georgia, US
Legendary Market Wizard
 
Experience: None
Platform: SC
Broker: Denali+Rithmic
Trading: ES, NQ, YM
Posts: 6,216 since Jan 2011
Thanks Given: 6,752
Thanks Received: 18,136

I tried using a strategy and it seems that a strategy will not detect orders placed outside of the strategy.

After researching, one way I can see to implement this is to read from the log file, and read each line and then just determine the order information from that text file.

Reply With Quote
  #10 (permalink)
 
josh's Avatar
 josh 
Georgia, US
Legendary Market Wizard
 
Experience: None
Platform: SC
Broker: Denali+Rithmic
Trading: ES, NQ, YM
Posts: 6,216 since Jan 2011
Thanks Given: 6,752
Thanks Received: 18,136


As an update to this, I am reading from the log file and doing what I needed to do, this is the only way to get info for manually placed trades according to NT. Parsing the info and using SendMail() via twittermail.

Reply With Quote




Last Updated on March 28, 2017


© 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