Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yutiansut committed Dec 8, 2019
1 parent 67a99fd commit 689aecf
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 483 deletions.
10 changes: 1 addition & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,4 @@ serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] } # 序列化
rayon = "1.1" # 多线程
ndarray = "0.13.0" # ndarray
actix-web = "2.0.0-alpha.1"
actix = "0.8.2"
actix-codec = "0.1.2"
actix-web-actors = "1.0.0"
actix-files = "0.1.1"
awc = "0.2.8"
json = "*"
bytes = "0.4"
tokio = "*"
ws = "0.7.8"
130 changes: 34 additions & 96 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,50 @@ pub mod qawebsocket;
pub mod qaeventmq;

extern crate ndarray;

use ws::{connect};
extern crate chrono;
use chrono::prelude::*;
use ndarray::array;

use std::time::Duration;
use std::sync::mpsc::channel;
use std::thread;

use crate::qaeventmq::{Publisher,Subscriber, Callback};


fn main() {

// qamongo::query_account("192.168.2.24".to_string(), "288870".to_string());
// let mut puber = qaeventmq::QAEventMQ{
// amqp: "amqp:https://admin:[email protected]:5672/".to_string(),
// exchange: "tick".to_string(),
// model: "direct".to_string(),
// routing_key: "rb2001".to_string()
// };
//
//
// let mut i = 1;
// thread::spawn(move|| {
// while i<1000 {
// puber.publish_routing("s".to_string());
// i+=1;
// thread::sleep(Duration::from_secs(1));
// }
// });
//
// impl Callback for qaeventmq::QAEventMQ{
// fn callback(&mut self, message:String) -> Option<i32>{
// println!("receive x! {}",message);
// Some(1)
// }
//}
// let mut client = qaeventmq::QAEventMQ{
// amqp: "amqp:https://admin:[email protected]:5672/".to_string(),
// exchange: "tick".to_string(),
// model: "direct".to_string(),
// routing_key: "rb2001".to_string()
// };
// client.subscribe_routing();
// println!("12212");
for mut ix in 0..20000 {

let (ws_event_tx, ws_event_rx) = channel();
let user_name = "000001".to_string();

{
let event_tx = ws_event_tx.clone();
thread::spawn(move || {
println!("xxxx{}", ix);
qawebsocket::QAtradeR(
format!("000{}", ix),format!("000{}", ix), "QUANTAXIS".to_string(), "192.168.2.118".to_string(),
"ws:https://192.168.2.118:7788".to_string(), "amqp:https://admin:[email protected]:5672/".to_string());
ix += 1;
let mut client = qaeventmq::QAEventMQ{
amqp: "amqp:https://admin:[email protected]:5672/".to_string(),
exchange: "QAORDER_ROUTER".to_string(),
model: "direct".to_string(),
routing_key: user_name.clone(),
};
println!("xxx");
qaeventmq::QAEventMQ::consume(client, event_tx).unwrap();
});
thread::sleep(Duration::from_millis(200));
};

qawebsocket::QAtradeR(
format!("000{}", 8888),format!("000{}",8888), "QUANTAXIS".to_string(), "192.168.2.118".to_string(),
"ws:https://192.168.2.118:7788".to_string(), "amqp:https://admin:[email protected]:5672/".to_string());

// thread::sleep(Duration::from_secs(200));
// thread::spawn(move || {
// client.subscribe_routing();
//
// });
// let ix = 0;
// for mut ix in 0..300 {
// thread::spawn(move || {
//
// println!("xxxx{}",ix);
// qawebsocket::wsmain(
// "ws:https://192.168.2.118:7988".to_string(),
// format!("s0{}", ix), format!("s0{}", ix));
// ix +=1;
//
// });
// thread::sleep(Duration::from_millis(200));
//
// };
// qawebsocket::wsmain(
// "ws:https://192.168.2.118:7988".to_string(),
// format!("sw0{}", ix), format!("sw0{}", ix));
////
////
}
let user_name = "000001".to_string();
thread::spawn(|| {
connect("ws:https://www.yutiansut.com:7788", move |out| {
qawebsocket::QAtradeR{
user_name: user_name.clone(),
password: user_name.clone(),
broker:"QUANTAXIS".to_string(),
out:out
}

}).unwrap()
});
qawebsocket::QAtradeR::start(ws_event_rx);
println!("trader");


test_ndarray();
test_datetime();
test_timeseries();
Expand Down Expand Up @@ -148,29 +109,6 @@ fn test_datetime() {
}


// fn test_pyo3() -> Result<(), ()> {
// let gil = Python::acquire_gil();
// test_pyo3_(gil.python()).map_err(|e| {
// eprintln!("error! :{:?}", e);
// // we can't display python error type via ::std::fmt::Display
// // so print error here manually
// e.print_and_set_sys_last_vars(gil.python());
// })
// }

// fn test_pyo3_<'py>(py: Python<'py>) -> PyResult<()> {
// let np = py.import("numpy")?;
// let dict = PyDict::new(py);
// dict.set_item("np", np)?;
// let pyarray: &PyArray1<i32> = py
// .eval("np.absolute(np.array([-1, -2, -3], dtype='int32'))", Some(&dict), None)?
// .extract()?;
// let slice = pyarray.as_slice()?;
// assert_eq!(slice, &[1, 2, 3]);
// Ok(())
// }




fn test_timeseries() {
Expand Down
Loading

0 comments on commit 689aecf

Please sign in to comment.