package jforex.strategies; 
  
import java.util.Currency;
import java.util.HashSet;
import java.util.Set;

import com.dukascopy.api.*;
  
public class ErrorDemo4 implements IStrategy {
    private JFUtils utils;
    private IHistory history;
    private IConsole console;
    private IAccount account;
      
    public void onStart(IContext context) throws JFException {
        this.utils = context.getUtils();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.account = context.getAccount();
        
        Set<Currency> currencies = new HashSet<Currency>();
        currencies.add(account.getCurrency());
        currencies.add(Currency.getInstance("USD"));
        currencies.add(Currency.getInstance("EUR"));
        currencies.add(Currency.getInstance("JPY"));
        
        for(Currency currency: currencies){
            for(Instrument instrument : context.getSubscribedInstruments()){
                ITick tick = history.getLastTick(instrument);
                try{
                    double pipCost = utils.convertPipToCurrency(instrument, currency);
                    double rate = pipCost /instrument.getPipValue();
                    console.getOut().println(String.format("%s -> %s pipCost=%.8f, rate=%.5f, last tick: %s", instrument, currency, pipCost, rate, tick));
                } catch (JFException e){
                    console.getErr().println(e + " for " + instrument + " -> " + currency);
                }
            }   
        }
        console.getOut().println("account currency: " + account.getCurrency());
    }
  
    public void onAccount(IAccount account) throws JFException {    } 
    public void onMessage(IMessage message) throws JFException {    } 
    public void onStop() throws JFException {    } 
    public void onTick(Instrument instrument, ITick tick) throws JFException {    }     
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {    }
}