|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
JForex API getCaptchaImage - using the latest JForex API with Live Accounts |
yoursong
|
Post subject: JForex API getCaptchaImage - using the latest JForex API with Live Accounts |
Post rating: 0
|
Posted: Wed 01 Feb, 2012, 10:07
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
Hi, i need to use the latest API in live mode but pin bypass is only available for static IPs which is unsuitable for me. I remember seeing an example somewhere on how to use the IClient getCaptchaImage to use standalone API with pin verification and then start a strategy. I can't find it anymore though  Is there an example available or can you please provide a simple one? Just to get a connection with pin verification running to start a strategy. No other gui needed. Thanks a lot
|
|
|
|
 |
yoursong
|
Post subject: Re: JForex API getCaptchaImage |
Post rating: 0
|
Posted: Wed 01 Feb, 2012, 12:32
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
Probably very bad code but it works  JForex API Main.java Example: the changed lines are: ... PinDialog test=new PinDialog(null,client,jnlpUrl); LOGGER.info("Connecting..."); //connect to the server using jnlp, user name and password client.connect(jnlpUrl, userName, password,test.pinfield.getText()); ... /* * Copyright (c) 2009 Dukascopy (Suisse) SA. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * -Redistribution of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * -Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Dukascopy (Suisse) SA or the names of contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. DUKASCOPY (SUISSE) SA ("DUKASCOPY") * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL DUKASCOPY OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, * EVEN IF DUKASCOPY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ package singlejartest;
import com.dukascopy.api.system.ISystemListener; import com.dukascopy.api.system.IClient; import com.dukascopy.api.system.ClientFactory; import com.dukascopy.api.Instrument;
import java.util.HashSet; import java.util.Set;
import org.slf4j.LoggerFactory; import org.slf4j.Logger;
/** * This small program demonstrates how to initialize Dukascopy client and start a strategy */ public class Main { private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
//url of the DEMO jnlp private static String jnlpUrl = "https://www.dukascopy.com/client/live/jclient/jforex.jnlp"; //user name private static String userName = ""; //password private static String password = "";
public static void main(String[] args) throws Exception { //get the instance of the IClient interface final IClient client = ClientFactory.getDefaultInstance(); //set the listener that will 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) { client.reconnect(); --lightReconnects; } else { try { //sleep for 10 seconds before attempting to reconnect Thread.sleep(10000); } catch (InterruptedException e) { //ignore } try { client.connect(jnlpUrl, userName, password); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } } });
PinDialog test=new PinDialog(null,client,jnlpUrl); LOGGER.info("Connecting..."); //connect to the server using jnlp, user name and password client.connect(jnlpUrl, userName, password,test.pinfield.getText());
//wait for it to connect int i = 10; //wait max ten seconds while (i > 0 && !client.isConnected()) { Thread.sleep(1000); i--; } if (!client.isConnected()) { LOGGER.error("Failed to connect Dukascopy servers"); System.exit(1); }
//subscribe to the instruments Set<Instrument> instruments = new HashSet<Instrument>(); instruments.add(Instrument.EURUSD); LOGGER.info("Subscribing instruments..."); client.setSubscribedInstruments(instruments); //start the strategy LOGGER.info("Starting strategy"); // client.startStrategy(new MA_Play()); //now it's running } }
The captcha dialog: package singlejartest;
import java.awt.BorderLayout; import javax.swing.BoxLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.ImageIcon; import javax.swing.JTextField;
import com.dukascopy.api.system.ClientFactory; import com.dukascopy.api.system.IClient;
public class PinDialog extends JDialog implements ActionListener { public JTextField pinfield; private JButton button_login = new JButton("Login"); private JButton button_reload = new JButton("Reload"); private JLabel captcha_image=new JLabel(); private IClient client; private String jnlpUrl; public PinDialog(JFrame parent, IClient client, String jnlpUrl) { super(parent, "JForex PIN Dialog", true); this.client=client; this.jnlpUrl=jnlpUrl; try{ captcha_image.setIcon(new ImageIcon(client.getCaptchaImage(jnlpUrl))); pinfield = new JTextField(); JPanel messagePane = new JPanel(); messagePane.setLayout(new BoxLayout(messagePane,BoxLayout.Y_AXIS)); messagePane.add( captcha_image); messagePane.add(pinfield); getContentPane().add(messagePane); JPanel buttonPane = new JPanel(); buttonPane.add(button_login); button_login.addActionListener(this); buttonPane.add(button_reload); button_reload.addActionListener(this); getContentPane().add(buttonPane, BorderLayout.SOUTH); setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); setVisible(true); } catch(Exception ex) { } } public void actionPerformed(ActionEvent e) { if(e.getSource()==button_login) { setVisible(false); dispose(); } else if(e.getSource()==button_reload) { try { IClient client = ClientFactory.getDefaultInstance(); captcha_image.setIcon(new ImageIcon(client.getCaptchaImage(jnlpUrl))); }catch(Exception ex) { } } } }
|
|
|
|
 |
yoursong
|
Post subject: Re: JForex API getCaptchaImage - using the latest JForex API with Live Accounts |
Post rating: 0
|
Posted: Wed 01 Feb, 2012, 23:36
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
Maybe Dukascopy can post their Pin/Captcha Dialog source?
|
|
|
|
 |
API Support
|
Post subject: Re: JForex API getCaptchaImage - using the latest JForex API with Live Accounts |
Post rating: 0
|
Posted: Fri 03 Feb, 2012, 09:59
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Your example already successfully uses the captcha, what additional information do you need?
|
|
|
|
 |
yoursong
|
Post subject: Re: JForex API getCaptchaImage - using the latest JForex API with Live Accounts |
Post rating: 0
|
Posted: Fri 03 Feb, 2012, 11:03
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
I dont need anymore information. I only thought it would make a nice addition to the wiki and my code is not what i would call well written.
|
|
|
|
 |
tfangz888
|
Post subject: Re: JForex API getCaptchaImage - using the latest JForex API with Live Accounts |
Post rating: 0
|
Posted: Fri 16 Mar, 2012, 02:43
|
|
User rating: 0
Joined: Fri 16 Mar, 2012, 02:38 Posts: 1
|
this method is good. but it needs to input PIN code manually everytime.
how can I do not input PIN code by hand? it is useful to create an automatic trade system.
I have no static IP. I believe most of us have no static IP. could Duk create a new policy to disable PIN under the condition that one requests???
|
|
|
|
 |
hyperscalper
|
Post subject: Re: JForex API getCaptchaImage - using the latest JForex API with Live Accounts |
Post rating: 0
|
Posted: Sun 09 Sep, 2012, 21:15
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
The Captcha image itself includes an image of a "Reload" and a "Cancel" as part of the rectangular image. I'm sure there's a way to somehow put an "image map" type of event handler which will allow users to click on the lower left portion of the image and generate a Reload event, and on the lower right to generate a Cancel event, but I'd rather not have to work out that logic.
If someone has logic to manage the Captcha image, then please make a contribution.
It is confusing to a user to have this "Reload" and "Cancel" part of the image (which does not naturally respond to a click), and also to have additional real JButton controls which implement Reload and Cancel operations.
Yes, I know I could blank out portions of the image, etc., and I could also enhance the captcha image myself, etc., but please post some proper handling code so everyone will benefit.
Attachments: |
File comment: Image of sample captcha showing images of button like areas for Reload and Cancel
CaptchaImage.PNG [9.41 KiB]
Downloaded 424 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
 |
hyperscalper
|
Post subject: Re: JForex API getCaptchaImage - using the latest JForex API with Live Accounts |
Post rating: 0
|
Posted: Sun 09 Sep, 2012, 22:20
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
By adding a mouse listener as shown below, simple click handler functions can be achieved. Here is a simple "hack" based upon the dimensions of the image I've seen: captcha_image.setIcon(new ImageIcon(client.getCaptchaImage(jnlpUrl))); captcha_image.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { int x = me.getX(); int y = me.getY(); //System.out.println("CLICKED x: "+x+" y: "+y); if (y>=94) { if (x<=75) { //System.out.println("RELOAD"); myReload(); // you must implement } else if (x>=164) { //System.out.println("CANCEL"); myCancel(); // you must implement } } } });
Hope this helps someone. It's not much, but it works.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|