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.
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 { // Find out what the first stock is going for, then buy a hundred.
// 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 {
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);
} } ```
See github milestones and issues.