3 unstable releases
Uses old Rust 2015
0.2.1 | Oct 8, 2016 |
---|---|
0.2.0 | Aug 14, 2016 |
0.1.0 | Aug 7, 2016 |
#160 in #http-api
31KB
549 lines
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.
extern crate wd40;
use wd40::game::{Level, start_level, stop_level};
use wd40::account::{OrderReceipt, place_order};
use wd40::stock::{Quote, last_quote, order_status};
use wd40::{Direction, Order, OrderType};
use std::time::Duration;
use std::thread::sleep;
fn main() {
let first_level: Level = start_level("first_steps").unwrap().unwrap();
if first_level.ok {
// Instructions for this level should be something like: find out what the
// first stock is going for, then buy a hundred.
first_level.instructions
.get("Instructions")
.and_then(|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:
Running `target/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
* Get acquainted with this interface.
* Watch the market participants trade a bit.
* When you're ready, purchase 100 shares. (Try using a market order. Not sure about what that means? Read about Order Types in the instructions menu.)
## You'll Be Fired If
* The risk management desk is at an offsite today. Parachuting into a volcano, apparently. No rules until Monday!
Checking to see if the order we placed (id 817) for a hundred shares of MRCBEX in venue YVR was filled...
Checking to see if the order we placed (id 817) for a hundred shares of MRCBEX in venue YVR was filled...
Checking to see if the order we placed (id 817) for a hundred shares of MRCBEX in venue YVR was filled...
Checking to see if the order we placed (id 817) for a hundred shares of MRCBEX in venue YVR was filled...
All done. You won the level.
TODO
See github milestones and issues.
Dependencies
~8MB
~160K SLoC