Introducing FSX Trader: Automated Fantasy Stock Trading in Ruby

Posted on August 23, 2007

The Fantasy Stock Exchange app on Facebook gives you up to $50 million in play money to trade securities on the major market indices (NYSE, Nasdaq, etc) using a combination of buy/sells and short/covers.

One thing the FSX app does not currently offer is a way to place stop loss orders. Say you’ve purchased 500 shares of the el Goog at $510. You think it’ll go up, but don’t want to hold on if the stock drops off precipitously, say to $500 or less. So you place a stop loss order with your broker or automated trading system to automatically sell your GOOG shares if the price hits $500.

With FSX Trader you can do the following (all automated if run using a cron job):

  • sell a stock when it reaches a high of $X
  • cover a stock if it reaches a low of $X
  • short a stock if it reaches a specified high
  • buy a stock if it reaches a pre-determined low

It’s a simple ruby command-line app configured via a YAML file on your localhost. (target audience would definitely have to be a bit geeky + into stocks)

How to Install the App on OSX or Linux (command-line based)

If you want to tinker around with the command-line client app itself, grab the gem using:

sudo gem install fsxtrader

Documentation is located at fsxtrader.rubyforge.org (rdoc).

Settuping up FSX Trader

Once installed, to setup the config file which by default is located at ~/.fsx_config.yml:

fsxtrader setup

Next, edit that file by hand or using your system editor with:

fsxtrader edit

To see if it actually works, you might place an order to buy AAPL if it’s price is greater than $1, or some other kind of trade that will always execute.

Next to actually kick off FSX Trader and potentially make trades for you (if your trading conditions are met), do a:

fsxtrader

To get more help on the various command-line options:

fsxtrader --help

Making it Useful

If this is to actually be useful, you’ll need to setup some kind of cron job for it and then remember to enter your stop-loss, etc orders into the YAML file as you trade. See the documentation for more on this.

Inspect the Code

If you want to see how I’m automating interaction with Facebook using WWW::Mechanize, stay tuned for future posts or visit the download page and grab the fsxtrader-1.0.0.tgz file.

The following should work on OSX/linux:

wget http://rubyforge.org/frs/download.php/24414/fsxtrader-1.0.0.tgz
tar xvzf fsxtrader-1.0.0.tgz 
cd fsxtrader-1.0.0

And open in your favorite text editor. The files to look at are: lib/fsxtrader.rb and all those in lib/fsxtrader/.

Anyway, I don’t expect this to be a massively popular Ruby gem, but if you’re a stock geek like me, check it out and let me know what you think!

Comments
  1. fsxtradaAugust 23, 2007 @ 01:58 PM
    Cool, great idea. One hitch: on Ubuntu, directly after installing, I get the following... fsxtrader setup /usr/lib/ruby/gems/1.8/gems/fsxtrader-1.0.0/lib/fsxtrader/application.rb:19:in `run': private method `default_config_path' called for #<fsxtrader::application:0xb7857fe8> (NoMethodError) from /usr/lib/ruby/gems/1.8/gems/cooloptions-1.1.1/lib/cooloptions.rb:26:in `parse!' from /usr/lib/ruby/gems/1.8/gems/fsxtrader-1.0.0/lib/fsxtrader/application.rb:16:in `run' from /usr/lib/ruby/gems/1.8/gems/fsxtrader-1.0.0/bin/fsxtrader:7 from /usr/bin/fsxtrader:16:in `load' from /usr/bin/fsxtrader:16 Here's the install log... gem install fsxtrader -y Successfully installed fsxtrader-1.0.0 Successfully installed cooloptions-1.1.1 Successfully installed hoe-1.3.0 Successfully installed rubyforge-0.4.4 Installing ri documentation for fsxtrader-1.0.0... Installing ri documentation for cooloptions-1.1.1... Installing ri documentation for hoe-1.3.0... Installing ri documentation for rubyforge-0.4.4... Installing RDoc documentation for fsxtrader-1.0.0... Installing RDoc documentation for cooloptions-1.1.1... Installing RDoc documentation for hoe-1.3.0... Installing RDoc documentation for rubyforge-0.4.4...
  2. Shanti BrafordAugust 30, 2007 @ 04:05 PM
    fsxtrada - I honestly haven't tried installing it yet on Ubuntu / some flavors of Linux. I'll have to give it a whirl and post an update. Thanks for the heads up! - Shanti