-
-
Save nlinker/ee6af9b5caae1365e6c522327397cc03 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct OrderBook { | |
pair_name: String, | |
pair_id: u64, | |
bids: HashMap<String, String>, | |
asks: HashMap<String, String>, | |
} | |
fn parse_poloniex_full_order_book(msg: &str) -> OrderBook{ | |
let f:Value = serde_json::from_str(msg).unwrap(); | |
let pair_id = f[0].as_u64().unwrap(); | |
let pair_name = f[2][0][1]["currencyPair"].as_str().unwrap(); | |
let asks = &f[2][0][1]["orderBook"][0].as_object().unwrap(); | |
let bids = &f[2][0][1]["orderBook"][1].as_object().unwrap(); | |
//println!("{:?}", asks); | |
let asks: HashMap<String, String>= asks.iter().map(|(price, vol)|{ | |
(price.clone(), vol.as_str().unwrap().to_string()) | |
}).collect(); | |
let bids: HashMap<String, String>= bids.iter().map(|(price, vol)|{ | |
(price.clone(), vol.as_str().unwrap().to_string()) | |
}).collect(); | |
OrderBook { | |
pair_name: pair_name.to_string(), | |
pair_id, | |
asks, | |
bids, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment