JForex SDK ライブモード

他のJForex SDKプロジェクトのサンプルプログラムは全てデモモードで動作するようにソースコードが書かれていました。
ライブモードで使用する為には、以下の調整を行う必要があります。
  1. 接続するURLを lhttp://platform.dukascopy.com/live/jforex.jnlp に変更します。
  2. PINコード認証のバイパス登録がされていない場合は、キャプチャイメージ処理を追加する必要があります。

(PINコード認証のバイパス登録は、固定グローバルIPアドレスが必要になります。GIPが変動する場合は使えません。)


キャプチャイメージ処理

ユーザーがキャプチャイメージに従って入力出来る処理のサンプルプログラム



public class MainPin {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(MainPin.class);

    // url of the LIVE 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 = "";
    
    private static IClient client;

    public static void main(String[] args) throws Exception {
        // IClientインターフェースのインスタンスを取得
        client = ClientFactory.getDefaultInstance();
        
        LOGGER.info("接続中...");
        // jnlp, user , passwordでサーバーに接続します
        client.connect(jnlpUrl, userName, password, PinDialog.showAndGetPin());

        // client.isConnected()での接続待ちを追加
        // 通貨ペア登録とストラテジー起動を追加
    }
    
    @SuppressWarnings("serial")
    private static class PinDialog extends JDialog {
        
        private final JTextField pinfield = new JTextField();
        private final static JFrame noParentFrame = null;
        
        static String showAndGetPin() throws Exception{
            return new PinDialog().pinfield.getText();
        }

        public PinDialog() throws Exception {            
            super(noParentFrame, "PIN Dialog", true);
            
            JPanel captchaPanel = new JPanel();
            captchaPanel.setLayout(new BoxLayout(captchaPanel, BoxLayout.Y_AXIS));
            
            final JLabel captchaImage = new JLabel();
            captchaImage.setIcon(new ImageIcon(client.getCaptchaImage(jnlpUrl)));
            captchaPanel.add(captchaImage);
            
            
            captchaPanel.add(pinfield);
            getContentPane().add(captchaPanel);
            
            JPanel buttonPane = new JPanel();
            
            JButton btnLogin = new JButton("Login");
            buttonPane.add(btnLogin);
            btnLogin.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                    dispose();
                }
            });
            
            JButton btnReload = new JButton("Reload");
            buttonPane.add(btnReload);
            btnReload.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        captchaImage.setIcon(new ImageIcon(client.getCaptchaImage(jnlpUrl)));
                    } catch (Exception ex) {
                        LOGGER.info(ex.getMessage(), ex);
                    }
                }
            });
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            pack();
            setVisible(true);
        }        
    }
}


サンプルソースコード:MainPin.java



スポンサーリンク

スポンサーリンク
検索
リファレンスツリー


Copyright ©2016 JForexAPIで自動売買させ隊! All Rights Reserved.


Top

inserted by FC2 system