Skip to content

Commit

Permalink
last fix
Browse files Browse the repository at this point in the history
  • Loading branch information
traderpedroso committed May 20, 2023
1 parent 0c0ed67 commit a921bf6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
12 changes: 5 additions & 7 deletions ejtradermtrust/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use zmq::{Context, REQ, PULL};
use serde::{Serialize, Deserialize};
use serde_json::{Value, from_str};

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct Command {
pub action: String,
pub action_type: Option<String>,
Expand Down Expand Up @@ -34,17 +34,15 @@ pub struct Functions {


impl Functions {
pub fn new(host: Option<String>) -> Self {
let host = host.unwrap_or_else(|| String::from("192.168.1.153"));

pub fn new(host: String) -> Self {
let context = Context::new();
let sys_socket = context.socket(REQ).unwrap();
let sys_socket = context.socket(REQ).expect("Failed to create subscriber socket");
sys_socket
.connect(&format!("tcp:https://{}:{}", host, 15555))
.connect(&format!("tcp:https://{}:{}", &host, 15555))
.unwrap();
let data_socket = context.socket(PULL).unwrap();
data_socket
.connect(&format!("tcp:https://{}:{}", host, 15556))
.connect(&format!("tcp:https://{}:{}", &host, 15556))
.unwrap();

Functions {
Expand Down
37 changes: 10 additions & 27 deletions ejtradermtrust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
mod connection;
use connection::Functions;
use connection::Command;

use connection::{Command, Functions};
use std::env;

fn main() {
let mut functions = Functions::new(None);
let args: Vec<String> = env::args().collect();
let host = args.get(1).cloned().unwrap_or_else(|| String::from("192.168.1.153"));

let mut functions = Functions::new(host);
let mut command = Command::default();
command.action = "ACCOUNT".to_string();

let command = Command {
action: "ACCOUNT".to_string(),
action_type: None,
symbol: None,
chart_tf: None,
from_date: None,
to_date: None,
id: None,
magic: None,
volume: None,
price: None,
stoploss: None,
takeprofit: None,
expiration: None,
deviation: None,
comment: None,
chart_id: None,
indicator_chart_id: None,
chart_indicator_sub_window: None,
style: None,
};


match functions.command(command) {
Ok(value) => println!("Value: {}", value),
Err(e) => println!("Error: {}", e),
}
}
}

0 comments on commit a921bf6

Please sign in to comment.