Skip to content

Commit

Permalink
#
Browse files Browse the repository at this point in the history
  • Loading branch information
yutiansut committed Dec 22, 2021
1 parent a6bfaf7 commit 9cb1d9b
Show file tree
Hide file tree
Showing 15 changed files with 1,327 additions and 502 deletions.
1,311 changes: 976 additions & 335 deletions qapro-rs/Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions qapro-rs/cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ log4rs = "0.13"

lazy_static = "1.4.0"


reqwest = "0.9.22"
csv = "1.1.3"
clap = "2.33"
toml = "0.5"
redis = "0.18.0"
amiquip = "0.4.0"

redis-async = "0.6.3"
actix-redis = "0.9.2"

bson = "0.13.0"
mongodb = {version = "1.1.1", default-features = false, features = ["sync"]}

actix = "0.10.0"
actix-rt = "1.0.0"
actix-web = "3.0.0"
actix-cors = "0.3"
actix-web-actors="3.0.0"

redis-async = { version = "0.8", default-features = false, features = ["tokio10"] }
actix-web-actors="4.0.0-beta.8"
actix-redis = "0.10.0-beta.4"
actix = "0.12.0"
actix-rt = "2.5.0"
actix-web = "4.0.0-beta.5"
actix-cors = "0.6.0-beta.7"

futures="0.3.5"
futures-executor = "^0.3"
Expand Down
65 changes: 65 additions & 0 deletions qapro-rs/database.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: "2.1"
services:

redis:
image: 'daocloud.io/quantaxis/qaredis:latest'
ports:
- "6379:6379"
environment:
- TZ=Asia/Shanghai
command: ['redis-server']
restart: always
networks:
qanetwork_db:
ipv4_address: 172.19.11.2
mgdb:
image: daocloud.io/quantaxis/qamongo_single:latest
ports:
- "27017:27017"
environment:
- TZ=Asia/Shanghai
- MONGO_INITDB_DATABASE=quantaxis
volumes:
- qamg:/data/db
networks:
qanetwork_db:
ipv4_address: 172.19.11.3
restart: always

qaclickhouse:
image: daocloud.io/quantaxis/qa-clickhouse
ports:
- "9000:9000"
- "8123:8123"
- "9009:9009"
environment:
- TZ=Asia/Shanghai
networks:
qanetwork_db:
ipv4_address: 172.19.11.4

qaeventmq:
image: daocloud.io/quantaxis/qaeventmq:latest
ports:
- "15672:15672"
- "5672:5672"
- "4369:4369"
environment:
- TZ=Asia/Shanghai
networks:
qanetwork_db:
ipv4_address: 172.19.11.5
restart: always


volumes:
qamg:
external:
name: qamg

networks:
qanetwork_db:
ipam:
config:
- subnet: 172.19.11.0/24
gateway: 172.19.11.1
34 changes: 34 additions & 0 deletions qapro-rs/examples/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use actix::Actor;
use actix_cors::Cors;
use actix_redis::RedisActor;
use actix_rt::Arbiter;


use actix_web::{middleware,http::header, web, App, HttpResponse, HttpServer};
use qapro_rs::qahandlers::websocket::websocket_router;
use qapro_rs::qaenv::localenv::CONFIG;
use qapro_rs::qahandlers::realtime::Realtime;


use qapro_rs::qalog::log4::init_log4;

use qapro_rs::qahandlers::wshandle::index;
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
init_log4("log/qarealtimepro_rs.log");
println!("{:#?}", &CONFIG.common.addr);
let redis_addr = RedisActor::start(&CONFIG.redis.uri);
let realtime_addr = Realtime::new(redis_addr.clone()).start();

HttpServer::new(move || {
App::new()
.data(realtime_addr.clone())
.route("/ws/", web::get().to(index))
//.service(web::scope("/ws").route("/", web::get().to(index)))
.route("/ws2/",web::get().to(websocket_router))

})
.bind(&CONFIG.common.addr)?
.run()
.await
}
25 changes: 25 additions & 0 deletions qapro-rs/examples/factorlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use qapro_rs::qaconnector::clickhouse::ckclient;
use qapro_rs::qaconnector::clickhouse::ckclient::DataConnector;
use actix_web::{middleware, web, App, HttpResponse, HttpServer};


use actix::Actor;
use actix_cors::Cors;
use actix_redis::RedisActor;
use actix_rt::Arbiter;

use log4rs;

#[actix_rt::main]
async fn main() {
let c = ckclient::QACKClient::init();

let codelist = ["600010.XSHG", "300002.XSHE"];
let hisdata = c
.exectue(Vec::from(codelist), "2021-07-11", "2021-12-22", "1min")
.await
.unwrap();
println!("{:#?}", hisdata.to_kline());


}
40 changes: 40 additions & 0 deletions qapro-rs/examples/wsserver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use actix::{Actor, StreamHandler};
use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer};
use actix_web_actors::ws;

/// Define HTTP actor
struct MyWs;

impl Actor for MyWs {
type Context = ws::WebsocketContext<Self>;
}

/// Handler for ws::Message message
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
fn handle(
&mut self,
msg: Result<ws::Message, ws::ProtocolError>,
ctx: &mut Self::Context,
) {
match msg {
Ok(ws::Message::Ping(msg)) => ctx.pong(&msg),
Ok(ws::Message::Text(text)) => ctx.text(text),
Ok(ws::Message::Binary(bin)) => ctx.binary(bin),
_ => (),
}
}
}

async fn index(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
let resp = ws::start(MyWs {}, &req, stream);
println!("{:?}", resp);
resp
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().route("/ws/", web::get().to(index)))
.bind("127.0.0.1:8080")?
.run()
.await
}
2 changes: 2 additions & 0 deletions qapro-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ pub mod qalog;
pub mod qamacros;
pub mod qapraser;

pub mod qafactor;
pub mod qahandlers;
10 changes: 5 additions & 5 deletions qapro-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io::{BufRead, BufReader, Error, Write};

use actix::Actor;
use actix_rt;
use actix_rt::Arbiter;
use actix_rt::{ArbiterHandle, Arbiter};
use chrono::{Date, Local};
use chrono_tz::{Tz, UTC};
use serde_json::Value;
Expand Down Expand Up @@ -35,10 +35,10 @@ async fn main() {

let codelist = ["600010.XSHG", "300002.XSHE"];
let hisdata = c
.exectue(Vec::from(codelist), "2021-07-11", "2021-08-05", "day")
.exectue(Vec::from(codelist), "2021-07-11", "2021-12-22", "day")
.await
.unwrap();
println!("{:#?}",hisdata.to_kline());
//println!("{:#?}",hisdata.to_kline());

println!(
"QARUNTIME Start: {}",
Expand Down Expand Up @@ -73,7 +73,7 @@ async fn main() {
let morm = morm_addr.clone();
let arb = Arbiter::new();

InstructMQ::start_in_arbiter(&arb, move |_| InstructMQ {
InstructMQ::start_in_arbiter(&arb.handle(), move |_| InstructMQ {
amqp: CONFIG.instruct.uri.clone(),
exchange: CONFIG.instruct.exchange.clone(),
routing_key: CONFIG.instruct.routing_key.clone(),
Expand All @@ -86,7 +86,7 @@ async fn main() {
let mc = code.clone();
let arc = Arbiter::new();

MarketMQ::start_in_arbiter(&arc, move |_| {
MarketMQ::start_in_arbiter(&arc.handle(), move |_| {
MarketMQ::new(
CONFIG.realtime.uri.clone(),
CONFIG.realtime.exchange.clone(),
Expand Down
23 changes: 22 additions & 1 deletion qapro-rs/src/qaenv/localenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct Config {
pub backtest: Backtest,
pub instruct: MQConfig,
pub ack: MQConfig,
pub common: Common,
}

impl Config {
Expand Down Expand Up @@ -118,7 +119,7 @@ pub struct RedisConfig {
impl Default for RedisConfig {
fn default() -> Self {
Self {
uri: "redis://localhost:6379".to_owned(),
uri: "redis://localhost:6379/0".to_owned(),
}
}
}
Expand All @@ -137,6 +138,26 @@ impl Default for ClickhouseConfig {
}
}

#[derive(Clone, Debug, Deserialize)]
#[serde(default)]
pub struct Common {
pub addr: String,
pub log_level: String,
pub key: String,
pub qifi_gap: u64,
}

impl Default for Common {
fn default() -> Self {
Self {
addr: "0.0.0.0:5000".to_string(),
log_level: "info".to_string(),
key: "quantaxis".to_string(),
qifi_gap: 5,
}
}
}

#[derive(Clone, Debug, Deserialize)]
#[serde(default)]
pub struct AccountConfig {
Expand Down
4 changes: 4 additions & 0 deletions qapro-rs/src/qahandlers/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod realtime;
pub mod websocket;
pub mod state;
pub mod wshandle;
Loading

0 comments on commit 9cb1d9b

Please sign in to comment.