Dukascopy
 
 
Wiki JStore Search Login

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.

Easy solution to get tick data from multiple currencies; help, please.
 Post subject: Easy solution to get tick data from multiple currencies; help, please. Post rating: 0   New post Posted: Mon 04 Jun, 2018, 06:54 

User rating: 4
Joined: Wed 23 May, 2018, 20:08
Posts: 44
Location: FinlandFinland
Hello,

As title says I would like a easy solution to get tick data from multiple currencies, please?

Thank you!


 
 Post subject: Re: Easy solution to get tick data from multiple currencies; help, please. Post rating: 0   New post Posted: Tue 05 Jun, 2018, 10:11 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
If I understand you correctly, you can implement something like this.

public class TickMultipleCurrency implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    HashSet<Instrument> myInstruments;
    Instrument firstCurrency = Instrument.EURUSD;
    Instrument secondCurrency = Instrument.USDCHF;
    Instrument thirdCurrency = Instrument.GBPJPY;

    ITick firstCurrencyLastTick, secondCurrencyLastTick, thirdCurrencyLastTick;

    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();

        myInstruments = new HashSet<>(Arrays.asList(firstCurrency, secondCurrency, thirdCurrency));
        context.setSubscribedInstruments(myInstruments);
    }

    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 {
        if (!myInstruments.contains(instrument)) {
            return;
        }

        if (instrument.equals(firstCurrency)) {
            firstCurrencyLastTick = tick;
        }
        else if (instrument.equals(secondCurrency)) {
            secondCurrencyLastTick = tick;
        }
        else if (instrument.equals(thirdCurrency)) {
            thirdCurrencyLastTick = tick;
        }

       
    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


 
 Post subject: Re: Easy solution to get tick data from multiple currencies; help, please. Post rating: 0   New post Posted: Tue 05 Jun, 2018, 11:32 

User rating: 4
Joined: Wed 23 May, 2018, 20:08
Posts: 44
Location: FinlandFinland
Hello,

Thank you so much for the code you provide! I was trying to do multiple currencies with the default set of just not filtering out any currencies, but then the tick.getTotalAskVolume(); is not correct.
Hopefully this will work for the better!

I am so greatfull for the work you do!
Thank you many times!


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com