トップ  >  リファレンス  >  ストラテジーAPI  >  コンソール
コンソール


IConsoleインターフェースはJForexAPIコンソールへのアクセスを提供します。
IConsoleインターフェースにはPrintStreamクラスオブジェクトを返す5つのメソッドがあります。
  • getOut() - 白色のバックグラウンドに情報表示する
  • getErr() - 赤色のバックグラウンドに情報表示する
  • getWarn() - 黄色のバックグラウンドに情報表示する
  • getInfo() - 緑色のバックグラウンドに情報表示する
  • getNotif() - 青色のバックグラウンドに情報表示する

最後のAsk価格を表示

以下サンプルは、通貨ペア名とAsk価格を表示します。



private IConsole console;
public void onStart(IContext context) throws JFException {
    this.console = context.getConsole();
}

public void onTick(Instrument instrument, ITick tick) throws JFException {
    console.getOut().println("通貨ペア:" + instrument + " Ask価格:" + tick.getAsk());
}







書式化した数値で表示

PrintStream.formatを使用して、指定した精度で十進数の数値をログ出力します。
以下例は、価格差を絶対値とピップス単位の両方でログ出力します。



private Instrument instrument = Instrument.EURUSD;
public  IHistory history;
public  IConsole console;

public void onStart(IContext context) throws JFException {
    this.history = context.getHistory();
    this.console = context.getConsole();

    ITick tick0  = history.getLastTick(instrument);
    ITick tick10 = history.getTick(instrument, 10);
    double priceDiff     = tick0.getBid() - tick10.getBid();
    double spread0       = tick0.getAsk() - tick0.getBid();
    double priceDiffPips = priceDiff      / instrument.getPipValue();
    double spreadPips    = priceDiff      / instrument.getPipValue();
    
    console.getOut().format(
            "最新のtick           =%s\n" +
            "10個前のtick         =%s\n" +
            "tickの価格差         =%.5f (%.1f pips) \n"+
            "最新tickのスプレッド =%.5f (%.1f pips)"
            ,tick0
            ,tick10
            ,priceDiff, priceDiffPips
            ,spread0, spreadPips
    ).println();
}









異なるコンソールカラーを使用する



public void onStart(IContext context) throws JFException {
    IConsole c = context.getConsole();
    c.getOut().println(  "out test");
    c.getErr().println(  "err test");
    c.getInfo().println( "info test");
    c.getWarn().println( "warn test");
    c.getNotif().println("notif test");
    System.out.println(  "System.out test");
}






注意:jClientプラットフォーム外でgetInfo(), getWarn(), getNotif()を実行した場合、getOut()と同じスタイルになります。


HTMLとCSSと使用する



console = context.getConsole();

console.getOut().println("<html><font bgcolor=\"red\" color=\"yellow\" ><b>HTML test output</b></font>");
console.getOut().println("<html><div style=\"background-color:yellow;width:200px;text-decoration:underline\">CSS test output</div>");






注意:jClientプラットフォームでのみスタイル適用されます。


各値のログ出力

以下サンプルは、JForesAPIで良く使用される値と配列をログ出力します。
例えば、
  • 単一のdouble値
  • 単一のtime値
  • オブジェクト
  • オブジェクト配列
  • doubleの2次元配列
  • doubleの1次元配列


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




スポンサーリンク

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


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


Top

inserted by FC2 system