wd40

HTTP API wrapper for Stockfighter in Rust.

Covers everything in the Stockfighter API docs as of latest commit (excepting websockets), assuming tests pass.

Needs nightly Rust.

cargo doc --open to see docs and examples.

Master branch docs at https://kittenspace.github.io/stockfighter/wd40.

Example

You can run the below example with the command env API_KEY=your_key_here cargo run --example first_level once you've got a Stockfighter account.

```rust extern crate wd40;

use wd40::game::{Level, startlevel, stoplevel}; use wd40::account::{OrderReceipt, placeorder}; use wd40::stock::{Quote, lastquote, order_status}; use wd40::{Direction, Order, OrderType};

use std::time::Duration; use std::thread::sleep;

fn main() { let firstlevel: Level = startlevel("firststeps").unwrap().unwrap(); if firstlevel.ok { // Instructions for this level should be something like: find out what the // first stock is going for, then buy a hundred. firstlevel.instructions .get("Instructions") .andthen(|info| { println!("Instructions: {}", info); Some(info) });

// We'll use last_quote, since this level is simple. I'll have what he's
// having.

let stock_quote: Quote = last_quote(&first_level.venues[0],
                                    &first_level.tickers[0])
  .unwrap().unwrap();

let our_ask: i32 = stock_quote.last.unwrap_or(1);

let hundo: OrderReceipt = place_order(&first_level.venues[0],
                                      &first_level.account,
                                      &first_level.tickers[0],
                                      100,
                                      our_ask,
                                      Direction::Buy,
                                      OrderType::Limit)
  .unwrap().unwrap();

let mut order_ok: bool = false;
while !order_ok {
  println!("Checking to see if the order we placed (id {}) for a hundred \
            shares of {} in venue {} was filled...",
           &hundo.id,
           &first_level.venues[0],
           &first_level.tickers[0]);

  let our_order: Order = order_status(&first_level.venues[0],
                                      &first_level.tickers[0],
                                      hundo.id)
    .unwrap().unwrap();

  order_ok = !our_order.open.unwrap_or(true);
  // don't hammer the API
  sleep(Duration::from_secs(2));
}

println!("All done. You won the level.");
// close the level, since we're done
stop_level(first_level.instance_id);

} } ```

The output of the above example should look something like this:

`` Runningtarget/debug/examples/first_level` Instructions: # Welcome to Your New Job

These instructions are always available under the Instructions tab if you need to see them again.

Congrats on being employed at Taylor & Collins. We're sure you'll love it here. You have been granted control over account TAC17772961 and have full authority to conduct trades on it... subject to the not-so-watchful eye of our risk management desk, naturally.

First order of business: This is a blotter interface. It connects your terminal to MysteriousRock Calcutta Board of Exchange (MRCBEX), a well-regarded stock exchange. We've pre-loaded it to track your first assignment, the shares of YVR Corp. (YVR).

Your Goal

You'll Be Fired If

TODO

See github milestones and issues.