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.

Flatlined data after pc standby / suspend
 Post subject: Flatlined data after pc standby / suspend Post rating: 0   New post Posted: Fri 15 Dec, 2017, 11:32 

User rating: 0
Joined: Mon 29 May, 2017, 17:19
Posts: 21
Location: Germany,
Hey everyone,

I have a problem with the data after waking up from pc standby:
for the time of the standby from standby start to the end (wakeup), I am automatically getting new bars that each have the same open, high, low, close as the last close value. How can I make jforex stop generating those bars and wait for a reconnect and then automatically get the missing values?

I *think* I would have to unsubscribe and then subscribe again, then request the history, but I am not sure if this is the best way to do it.

Any help is greatly appreciated!


 
 Post subject: Re: Flatlined data after pc standby / suspend Post rating: 0   New post Posted: Thu 21 Dec, 2017, 17:15 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You can implement something like this:
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConnectionStatusMessage;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IMessage.Type;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import java.text.SimpleDateFormat;
import java.util.List;

public class SimleBarGettingStrategy implements IStrategy {
  IContext context;
  IConsole console;

  boolean isConnected;

  long connectionLosingTime;
  long connectionReturningTime;

  Instrument instrument = Instrument.EURUSD;
  Period period = Period.ONE_MIN;

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  @Override
  public void onStart(IContext context) throws JFException {
    this.context = context;
    this.console = context.getConsole();
    isConnected = true;
  }

  @Override
  public void onTick(Instrument instrument, ITick tick) throws JFException {
  }

  @Override
  public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar)
      throws JFException {
    if (instrument != this.instrument || period != this.period || !isConnected) return;
    console.getOut().println("Time: " + sdf.format(askBar.getTime()) + " O: " + askBar.getOpen() + " C: " + askBar.getClose() + " H: " +
    askBar.getHigh() + " L: " + askBar.getLow());
  }

  @Override
  public void onMessage(IMessage message) throws JFException {
    if (message.getType() == Type.CONNECTION_STATUS) {
      IConnectionStatusMessage iConnectionStatusMessage = (IConnectionStatusMessage) message;
      if (!iConnectionStatusMessage.isConnected()) {
        connectionLosingTime = message.getCreationTime();
        isConnected = iConnectionStatusMessage.isConnected();
      } else {
        connectionReturningTime = message.getCreationTime();
        isConnected = iConnectionStatusMessage.isConnected();
        if (connectionLosingTime != 0 && connectionReturningTime != 0 && isConnected) {
          getLostBars();
        }
      }
    }
  }

  private void getLostBars() throws JFException {
    IHistory history = context.getHistory();
    List<IBar> lostBars = history.getBars(instrument, period, OfferSide.BID, history.getBarStart(period, connectionLosingTime),
        history.getBarStart(period, connectionReturningTime));
    for (int i = 0; i < lostBars.size(); i++) {
      console.getOut().println("Bar No " + i + " Time: " + sdf.format(lostBars.get(i).getTime()) + " O: " + lostBars.get(i).getOpen()
      + " C: " + lostBars.get(i).getClose() + " H: " + lostBars.get(i).getHigh() + " L: " + lostBars.get(i).getLow());
    }
  }

  @Override
  public void onAccount(IAccount account) throws JFException {

  }

  @Override
  public void onStop() throws JFException {

  }
}


 

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