3 个不稳定版本
使用旧的 Rust 2015
0.2.1 | 2016 年 10 月 8 日 |
---|---|
0.2.0 | 2016 年 8 月 14 日 |
0.1.0 | 2016 年 8 月 7 日 |
#147 in #http-api
31KB
549 代码行
wd40
Rust 中 Stockfighter 的 HTTP API 包装器。
覆盖了 Stockfighter API 文档中所有内容(除 websockets 外),假设测试通过。
需要 nightly Rust。
cargo doc --open
查看文档和示例。
Master 分支文档在 https://kittenspace.github.io/stockfighter/wd40。
示例
您可以使用以下命令运行以下示例: env API_KEY=your_key_here cargo run --example first_level
一次您获得了 Stockfighter 账户。
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);
}
}
上述示例的输出应该类似于以下内容
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.
待办事项
查看 GitHub 里程碑和问题。
依赖关系
~7.5MB
~172K SLoC