8个版本
0.2.9 | 2020年10月13日 |
---|---|
0.2.8 | 2020年10月12日 |
0.2.7 | 2020年9月28日 |
0.2.6 | 2020年6月22日 |
0.1.0 | 2018年1月12日 |
#9 in #ticker
每月下载 30次
620KB
2K SLoC
包含 (WOFF字体, 120KB) doc/Heuristica-Italic.woff, (WOFF字体, 90KB) doc/FiraSans-Medium.woff, (WOFF字体, 92KB) doc/FiraSans-Regular.woff, (WOFF字体, 56KB) doc/SourceCodePro-Regular.woff, (WOFF字体, 56KB) doc/SourceCodePro-Semibold.woff, (WOFF字体, 49KB) doc/SourceSerifPro-Bold.woff 和更多.
kiteconnect-rs
Rust中风筝连接的API包装器
文档
用法
前往 https://crates.io/crates/kiteconnect
将 kiteconnect = "<VERSION>"
依赖项复制到 Cargo.toml 文件
风筝连接REST API
extern crate kiteconnect;
extern crate serde_json as json;
use kiteconnect::connect::KiteConnect;
fn main() {
let mut kiteconnect = KiteConnect::new("<API-KEY>", "");
// Open browser with this URL and get the request token from the callback
let loginurl = kiteconnect.login_url();
println!("{:?}", loginurl);
// Generate access token with the above request token
let resp = kiteconnect.generate_session("<REQUEST-TOKEN>", "<API-SECRET>");
// `generate_session` internally sets the access token from the response
println!("{:?}", resp);
let holdings: json::Value = kiteconnect.holdings().unwrap();
println!("{:?}", holdings);
}
风筝Ticker Websocket
extern crate kiteconnect;
extern crate serde_json as json;
use kiteconnect::ticker::{KiteTicker, KiteTickerHandler, WebSocketHandler}
#[derive(Debug)]
struct CustomHandler {
count: u32
}
impl KiteTickerHandler for CustomHandler {
fn on_open<T>(&mut self, ws: &mut WebSocketHandler<T>)
where T: KiteTickerHandler {
// Subscribe to a list of tokens on opening the websocket connection
ws.subscribe(vec![123456]);
println!("Fellow on_open callback");
}
fn on_ticks<T>(&mut self, ws: &mut WebSocketHandler<T>, tick: Vec<json::Value>)
where T: KiteTickerHandler {
println!("{:?}", tick);
println!("Fellow on_ticks callback");
}
fn on_close<T>(&mut self, ws: &mut WebSocketHandler<T>)
where T: KiteTickerHandler {
println!("Fellow on_close callback");
}
fn on_error<T>(&mut self, ws: &mut WebSocketHandler<T>)
where T: KiteTickerHandler {
println!("Fellow on_error callback");
}
}
fn main() {
let mut ticker = KiteTicker::new("<API-KEY>", "<ACCESS-TOKEN>");
let custom_handler = CustomHandler {
count: 0
};
ticker.connect(custom_handler, None);
loop {}
}
运行示例
风筝连接REST API示例
cargo run --example connect_sample
风筝连接Websocket示例
cargo run --example ticker_sample
待办事项
- 为所有风筝连接返回的数据结构添加序列化结构体
- 重连机制
依赖项
~25MB
~516K SLoC