Hi,
Please remove all my posts from this forum !
Regards
Quote:
package jforex;
import java.util.*;
import java.awt.Color;
import java.awt.List;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Array;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;
import javax.net.ssl.HttpsURLConnection;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.net.MalformedURLException;
import java.io.IOException;
import java.io.*;
import java.sql.Timestamp;
import java.util.Date;
import javax.swing.JFrame;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import com.dukascopy.api.*;
@RequiresFullAccess
public class Copyhttp implements IStrategy {
private final String USER_AGENT = "Mozilla/5.0";
public String logFilePath = "/root/Pulpit/jfxlog.db";
public String pathToServerFile = "https://breakermind.com/z.php";
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
static String[][] out = new String[100][10];
public String line = "";
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
this.userInterface = context.getUserInterface();
console.getOut().println("========================================================");
console.getOut().println("Robot start ...");
console.getOut().println("========================================================");
}
public void onAccount(IAccount account) throws JFException {
}
@Override
public void onMessage(IMessage message) throws JFException {
String[][] data = new String[100][10];
try {
int xx = 0;
//data[0][1] = "1";
for(IOrder o : engine.getOrders()){
if(o.getProfitLossInUSD() != 987654231){
// open orders
console.getOut().println("Order: " + o.getInstrument() + " " + o.getProfitLossInPips() + " " + o.getOrderCommand());
// Copy orders to array
String positionOpenTime = "" + o.getFillTime();
String positionId = "" + o.getId();
String positionInstrument = "" + o.getInstrument();
String positionIsbuy = "" + o.getOrderCommand().isLong();
String positionVolume = "" + o.getAmount();
String positionOpen = "" + o.getOpenPrice();
String positionSl = "" + o.getStopLossPrice();
String positionTp = "" + o.getTakeProfitPrice();
String positionComment = "" + o.getComment();
String positionLabel = "" + o.getLabel();
data[xx][0] = positionOpenTime;
data[xx][1] = positionId;
data[xx][2] = positionInstrument;
data[xx][3] = positionIsbuy;
data[xx][4] = positionVolume;
data[xx][5] = positionOpen;
data[xx][6] = positionSl;
data[xx][7] = positionTp;
data[xx][8] = positionLabel;
data[xx][9] = positionComment;
xx++;
}
}
xx=0;
// convert array to string
line = "";
int k = 0;
for(int i =0; i< 100; i++){
for(int j =0; j< 10; j++){
if(data[i][j] != null){
line += data[i][j] + ",";
}else{k = 1;}
}
if(k == 0){
line += "ZZZ";
}
}
line = "START"+line+"STOP";
console.getOut().println("========================================================");
sendPost("line="+line+"&dd=hsdjkahdkjashk");
console.getOut().println("\nSend positions to server: "+ line);
console.getOut().println("========================================================");
line="";
} catch (Exception e) {
console.getOut().println(e.getMessage());
// context.stop();
}
}
public void onStop() throws JFException {
console.getOut().println("========================================================");
console.getOut().println("Robot stop!");
console.getOut().println("========================================================");
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
// SENT HTTP POST request and log to file
private void sendPost(String txt){
try{
String url = pathToServerFile;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add reuqest header
boolean isProxy = con.usingProxy();
if(isProxy){
System.out.println("System using proxy: " + isProxy);
}
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
String urlParameters = txt;
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
//console.getOut().println("\nSending 'POST' request to URL : " + url);
//console.getOut().println("Post parameters : " + urlParameters);
//console.getOut().println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
// read one line
break;
}
in.close();
// log file operation get timestamp
java.util.Date date= new java.util.Date();
//System.out.println(new Timestamp(date.getTime()));
// time to string
String time = new Timestamp(date.getTime()).toString();
// log file catch all response
PrintWriter log = new PrintWriter(new BufferedWriter(new FileWriter(logFilePath, true)));
log.println("Copyhttp: " + time + " " + response.toString());
log.close();
//print result
console.getOut().println("Server response: " + response.toString());
}catch(Exception ss)
{
///
}
}
}