java - JFOREX SDK - How to send HTTPS GET request to www server ssl connection -


how add this

public class javahttpsexample {  public static void main(string[] args)    throws exception   {     string httpsurl = "https://localhost/send.php&json=somevalue";     url myurl = new url(httpsurl);     httpsurlconnection con = (httpsurlconnection)myurl.openconnection();     inputstream ins = con.getinputstream();     inputstreamreader isr = new inputstreamreader(ins);     bufferedreader in = new bufferedreader(isr);      string inputline;      while ((inputline = in.readline()) != null)     {       system.out.println(inputline);     }      in.close();   } } 

to

jforex maven sdk eclipse: http://www.dukascopy.com/client/jforexlib/jforex-sdk.zip

and http://www.dukascopy.com/wiki/#iclient_functionality

package singlejartest_old;  import com.dukascopy.api.system.isystemlistener; import com.dukascopy.api.system.iclient; import com.dukascopy.api.system.clientfactory; import com.dukascopy.api.*; import java.util.hashset; import java.util.scanner; import java.util.set;  import org.slf4j.loggerfactory; import org.slf4j.logger;  /**  * small program demonstrates how initialize dukascopy client , start strategy  */ public class mainstopfromconsole {      private static final logger logger = loggerfactory.getlogger(mainstopfromconsole.class);     private static string jnlpurl = "https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";     private static string username = "";     private static string password = "";      public static void main(string[] args) throws exception {         //get instance of iclient interface         final iclient client = clientfactory.getdefaultinstance();         //set listener receive system events         client.setsystemlistener(new isystemlistener() {             private int lightreconnects = 3;             @override            public void onstart(long processid) {                 logger.info("strategy started: " + processid);            }           @override          public void onstop(long processid) {                 logger.info("strategy stopped: " + processid);                    if (client.getstartedstrategies().size() == 0) {                     system.exit(0);                 }          }           @override          public void onconnect() {                 logger.info("connected");                 lightreconnects = 3;          }           @override          public void ondisconnect() {                 logger.warn("disconnected");                 if (lightreconnects > 0) {                    logger.error("try reconnect, reconnects left: " + lightreconnects);                     client.reconnect();                     --lightreconnects;                 } else {                     try {                         //sleep 10 seconds before attempting reconnect                         thread.sleep(10000);                     } catch (interruptedexception e) {                         //ignore                     }                     try {                         client.connect(jnlpurl, username, password);                     } catch (exception e) {                         logger.error(e.getmessage(), e);                     }                 }          }       });          logger.info("connecting...");         //connect server using jnlp, user name , password         client.connect(jnlpurl, username, password);          //wait connect         int = 10; //wait max ten seconds         while (i > 0 && !client.isconnected()) {             thread.sleep(1000);             i--;         }         if (!client.isconnected()) {             logger.error("failed connect dukascopy servers");             system.exit(1);         }          //subscribe instruments         set<instrument> instruments = new hashset<instrument>();         instruments.add(instrument.eurusd);         logger.info("subscribing instruments...");         client.setsubscribedinstruments(instruments);           //start strategy         logger.info("starting strategy");         final long strategyid = client.startstrategy(new istrategy(){             public instrument instrument = instrument.eurusd;             private iconsole console;              public void onstart(icontext context) throws jfexception {                        console = context.getconsole();                }             public void onbar(instrument instrument, period period, ibar askbar, ibar bidbar) throws jfexception {                 if ( instrument == this.instrument){                    console.getout().println(" bar: " + period  + " " + askbar);                 }             }             public void ontick(instrument instrument, itick tick) throws jfexception {    }             public void onmessage(imessage message) throws jfexception {    }             public void onaccount(iaccount account) throws jfexception {    }             public void onstop() throws jfexception {    }         });         //now it's running          //every second check if "stop" had been typed in console - if - stop strategy         thread thread = new thread(new runnable() {             @override             public void run() {                               scanner s = new scanner(system.in);                               while(true){                   while(s.hasnext()){                      string str = s.next();                      if(str.equalsignorecase("stop")){                         system.out.println("strategy stop console command.");                         client.stopstrategy(strategyid);                      }                   }                   try {                   thread.sleep(1000);                } catch (interruptedexception e) {                   e.printstacktrace();                }                }             }             });         thread.start();      } } 

i need send values(account balance or open positions) www serwer strategy

thanks zix

package master;  import com.dukascopy.api.system.isystemlistener; import com.dukascopy.api.system.iclient; import com.dukascopy.api.system.clientfactory; import com.dukascopy.api.*;  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.net.url; import java.nio.file.files; 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 javax.swing.jframe;  import org.slf4j.loggerfactory; import org.slf4j.logger;  import singlejartest.javahttpsexample;   public class mainstopfromconsole {      private static final logger logger = loggerfactory.getlogger(mainstopfromconsole.class);     private static string jnlpurl = "https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";     private static string username = "demo2prfwj";     private static string password = "prfwj";      //static string[] columns = {"open time", "id", "label", "comment", "instrument", "side", "amount", "original amount", "open price", "stop loss", "take profit", "profit (pips)", "profit currency", "profit in usd", "commission", "commission usd"};     static string[] columns = {"id", "instrument", "side", "amount", "open price", "stop loss", "take profit"};     //static string[][] data = {{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"},      static string[][] data = new string[50][11];     //static string[][] data = null;     //static jframe jf = new jframe();      public static void main(string[] args) throws exception {                  //get instance of iclient interface         final iclient client = clientfactory.getdefaultinstance();         //set listener receive system events         client.setsystemlistener(new isystemlistener() {             private int lightreconnects = 3;              public void onstart(long procid) {                 //iconsole console = context.getconsole();                 logger.info("strategy started: ");               }              public void onstop(long processid) {                 logger.info("strategy stopped: " + processid);                   if (client.getstartedstrategies().size() == 0) {                     system.exit(0);                 }             }              @override             public void onconnect() {                 logger.info("connected");                 lightreconnects = 3;             }              @override             public void ondisconnect() {                 logger.warn("disconnected");                 if (lightreconnects > 0) {                     logger.error("try reconnect, reconnects left: " + lightreconnects);                     client.reconnect();                     --lightreconnects;                 } else {                     try {                         //sleep 10 seconds before attempting reconnect                         thread.sleep(10000);                     } catch (interruptedexception e) {                         //ignore                     }                     try {                         client.connect(jnlpurl, username, password);                     } catch (exception e) {                         logger.error(e.getmessage(), e);                     }                 }             }         });          logger.info("connecting...");         //connect server using jnlp, user name , password         client.connect(jnlpurl, username, password);          //wait connect         int = 10; //wait max ten seconds         while (i > 0 && !client.isconnected()) {             thread.sleep(1000);             i--;         }         if (!client.isconnected()) {             logger.error("failed connect dukascopy servers");             system.exit(1);         }          //subscribe instruments         set<instrument> instruments = new hashset<instrument>();         instruments.add(instrument.eurusd);         logger.info("subscribing instruments...");         client.setsubscribedinstruments(instruments);          //start strategy         logger.info("starting strategy");         final long strategyid = client.startstrategy(new istrategy(){             public instrument instrument = instrument.eurusd;             private iconsole console;             private iengine engine;               public void onstart(icontext context) throws jfexception {                         console = context.getconsole();                     engine = context.getengine();              }             public void onbar(instrument instrument, period period, ibar askbar, ibar bidbar) throws jfexception {                 if ( instrument == this.instrument){                     //console.getout().println(" bar: " + period  + " " + askbar);                 }              }              public void ontick(instrument instrument, itick tick) throws jfexception {                   try {                                     int xx = 0;                 //data[0][1] = "1";                 for(iorder o : engine.getorders()){                     if(o.getprofitlossinusd() != 987654231){                         console.getout().println("order: " + o.getinstrument() + " " + o.getprofitlossinpips() + " " + o.getordercommand());                          // copy orders array                         string userhash = "1";                         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();                          data[xx][0] = userhash;                         data[xx][1] = positionopentime;                         data[xx][2] = positionid;                         data[xx][3] = positioninstrument;                         data[xx][4] = positionisbuy;                         data[xx][5] = positionvolume;                         data[xx][6] = positionopen;                         data[xx][7] = positionsl;                         data[xx][8] = positiontp;                         data[xx][9] = positioncomment;                         xx++;                     }                 }                 xx=0;                 /*                 int = 0;                 int j = 0;                 string string = "";                 for(j = 0; j<10; j++){                 for(i = 0; i<10; i++){                     string += data[j][i] + "#";                   }                 string += "$$";                 }                   }                   console.getout().println("=====================================================================================" );                 console.getout().println(string);                 */                  console.getout().println("=====================================================================================" );                 string txt ="";                 txt = arrays.deeptostring(data);                 txt = txt.replaceall(",", "aa");                 txt = txt.replaceall(" ", "zz");                 system.out.println(txt);                 console.getout().println("=====================================================================================" );                  //=================================================================== send == need commerciall ssl startssl.com , serveralias , servername in virtualhost                 url hp = new url("https://breakermind.com/index.php?line="+txt);                 httpsurlconnection hpcon = (httpsurlconnection) hp.openconnection();                  boolean isproxy = hpcon.usingproxy();                 system.out.println("is using proxy " + isproxy);                 inputstream obj = hpcon.getinputstream();                 bufferedreader br = new bufferedreader(new inputstreamreader(obj));                  string s;                 while ((s = br.readline()) != null) {                     s = s.replaceall("zz", " ");                     s = s.replaceall("aa", ",");                  system.out.println(">>>" + s);                 }                 //===================================================================== end                         } catch (exception e) {                   console.geterr().println(e.getmessage());                   e.printstacktrace(console.geterr());                  // context.stop();               }              console.getout().println("=====================================================================================" );              }             public void onmessage(imessage message) throws jfexception {    }             public void onaccount(iaccount account) throws jfexception {    }             public void onstop() throws jfexception {    }         });         //now it's running          //every second check if "stop" had been typed in console - if - stop strategy         thread thread = new thread(new runnable() {             @override             public void run() {                      scanner s = new scanner(system.in);                              while(true){                     while(s.hasnext()){                         string str = s.next();                         if(str.equalsignorecase("stop")){                             system.out.println("strategy stop console command.");                             client.stopstrategy(strategyid);                         }                     }                     try {                         thread.sleep(1000);                     } catch (interruptedexception e) {                         e.printstacktrace();                     }                 }             }             });         thread.start();      } } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -