Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

History readFeedData() / readBars() return no volume with feedData/bars?
 Post subject: History readFeedData() / readBars() return no volume with feedData/bars? Post rating: 0   New post Posted: Tue 22 Jul, 2014, 10:56 
User avatar

User rating: 8
Joined: Tue 25 Oct, 2011, 23:02
Posts: 74
Location: Australia, Melbourne
I'm unable to get volume values back from history calls to DEMO. The IStrategy implementation below happily returns 30 Minute Bars via either an readFeedData or readBars call, and the 30M bars have OHLC but Volume is always 0.
Am I missing something or is this a bug?

import org.apache.log4j.Logger;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Minutes;

import com.dukascopy.api.Filter;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.ITimedData;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFCurrency;
import com.dukascopy.api.JFException;
import com.dukascopy.api.LoadingDataListener;
import com.dukascopy.api.LoadingProgressListener;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.IFeedListener;
import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor;
import com.dukascopy.charts.data.datacache.CandleData;


public class JForexHistoryNoVolume implements IStrategy
{
    private static final Logger LOGGER = Logger.getLogger(JForexHistoryNoVolume.class);
   
   private Instrument _instrument;
   private IContext _context = null;
   DateTime _startDate = null;
   DateTime _endDate = null;

   public JForexHistoryNoVolume(DateTime startDate, DateTime endDate)
   {
      _startDate = startDate;
      _endDate = endDate;
   }
   

   ////////////////////////////////////////////////////
   // IStrategy implementation.
   ////////////////////////////////////////////////////

   private IHistory _history;
   private int _progressCount;
   private Period _timeFrame = null;

   public void onStart(IContext context) throws JFException
   {
      LOGGER.info("Strategy now started");

      IFeedDescriptor feedDescriptor = null;
      _history = context.getHistory();
      IBar lastFeedBar;
      DateTime toDate;
      int count;
      
      _history = context.getHistory();
      lastFeedBar = _history.getBar(_instrument, Period.THIRTY_MINS, OfferSide.BID, 0);

      toDate = new DateTime(lastFeedBar.getTime(), DateTimeZone.UTC);
      feedDescriptor = new TimePeriodAggregationFeedDescriptor(_instrument, Period.THIRTY_MINS, OfferSide.BID, Filter.WEEKENDS);
      LOGGER.info(String.format("Retrieving Data from %s to %s", _startDate.toString("dd/MM/yyyy"), toDate.toString("dd/MM/yyyy")));
      count = Minutes.minutesBetween(_startDate, toDate).getMinutes() / 30;

      getHistoryData(feedDescriptor, count, toDate);
      
   }

   private void getHistoryData(final IFeedDescriptor feedDescriptor, int count, DateTime to)
   {
      try
      {
         _progressCount = 0;
            
/*         long lastTickTime = _history.getLastTick(feedDescriptor.getInstrument()).getTime();
           final long end = _history.getTimeForNBarsBack(feedDescriptor.getPeriod(), lastTickTime, 2);

           _history.readBars(feedDescriptor.getInstrument(), feedDescriptor.getPeriod(), feedDescriptor.getOfferSide(), feedDescriptor.getFilter(), count, end, 0,
                        
           new LoadingDataListener()
           {
               @Override
               public void newTick(Instrument instrument, long time, double ask, double bid, double askVol, double bidVol) {} 
      
               @Override
               public void newBar(Instrument instrument, Period period, OfferSide side, long time, double open, double close, double low, double high, double vol)
               {
                  Object timeBar = null;
               
               if (feedDescriptor.getPeriod() == Period.THIRTY_MINS)
               {
                   LOGGER.debug("Bar" + new DateTime(bar.getTime()).toString() + ", Volume = " + bar.getVolume());
               }
               }
           },
          new LoadingProgressListener()
          {      
               @Override
               public void loadingFinished(boolean allDataLoaded, long start, long end, long currentPosition)
               {
               
               if (allDataLoaded == false)
               {
                  LOGGER.warn("More data available");
               }
               }
               
               @Override
               public void dataLoaded(long start, long end, long currentPosition, String information)
               {
               }
      
               @Override
               public boolean stopJob()
               {
                   return false;
               }
          });      
          */   
         
         _history.readFeedData(feedDescriptor, _startDate.getMillis(), to.getMillis(), new IFeedListener()
         {
            
            public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData)
            {
               CandleData bar = (CandleData) feedData;
               Object timeBar = null;
               
               if (feedDescriptor.getPeriod() == Period.THIRTY_MINS)
               {
                  LOGGER.debug("Bar" + new DateTime(bar.getTime()).toString() + ", Volume = " + bar.getVolume());
               }
            }
         },
         
         new LoadingProgressListener()
         {

            public boolean stopJob()
            {
               return false;
            }
            
            public void loadingFinished(boolean allDataLoaded, long start, long end, long currentPosition)
            {
               
               if (allDataLoaded == false)
               {
                  LOGGER.warn("More data available");
               }
            }
         
            public void dataLoaded(long start, long end, long currentPosition, String information)
            {
            }
         });
      } 
      catch (JFException e)
      {
         LOGGER.error("JFException: " + e.getMessage());
      }
   }


   public void onTick(Instrument instrument, ITick tick) throws JFException
   {
   }
   
   public void onStop() throws JFException
   {
      // Not used.
   }

   public void onAccount(IAccount arg0) throws JFException
   {
      // Not used.
   }
   
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException
   {
      // Not used.
   }

   public void onMessage(IMessage arg0) throws JFException
   {
      // Not used.
   }
}



 
 Post subject: Re: History readFeedData() / readBars() return no volume with feedData/bars? Post rating: 0   New post Posted: Fri 25 Jul, 2014, 02:48 
User avatar

User rating: 8
Joined: Tue 25 Oct, 2011, 23:02
Posts: 74
Location: Australia, Melbourne
Volume is a really useful part of the historical data feed, so it would be good to be able to access it.


 
 Post subject: Re: History readFeedData() / readBars() return no volume with feedData/bars? Post rating: 0   New post Posted: Fri 25 Jul, 2014, 11:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We could not replicate this, consider the following strategy:
package jforex.requests;

import java.util.Calendar;
import java.util.Collections;

import com.dukascopy.api.Configurable;
import com.dukascopy.api.Filter;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.ITimedData;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.LoadingProgressListener;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.IFeedListener;
import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor;
import com.dukascopy.api.util.DateUtils;

public class JForexHistoryNoVolume2 implements IStrategy {
   
    private static Calendar calFrom;
    static {
        calFrom = Calendar.getInstance();
        calFrom.set(2014, Calendar.JULY, 17, 12, 00, 00);
        calFrom.set(Calendar.MILLISECOND, 0);
    }
    private static Calendar calTo;
    static {
        calTo = Calendar.getInstance();
        calTo.set(2014, Calendar.JULY, 24, 12, 00, 00);
        calTo.set(Calendar.MILLISECOND, 0);
    }

    @Configurable(value = "time from", datetimeAsLong = true)
    public long from = calFrom.getTimeInMillis();
    @Configurable(value = "time to", datetimeAsLong = true)
    public long to = calTo.getTimeInMillis();
    @Configurable("")
    public IFeedDescriptor feedDescriptor = new TimePeriodAggregationFeedDescriptor(Instrument.EURUSD, Period.THIRTY_MINS, OfferSide.BID, Filter.WEEKENDS);

    private IHistory history;
    private IConsole console;
    private int itemCount;
    private Instrument instrument;

    @Override
    public void onStart(final IContext context) throws JFException {
        history = context.getHistory();
        console = context.getConsole();
        instrument = feedDescriptor.getInstrument();
        context.setSubscribedInstruments(Collections.singleton(instrument), true);
        console.getOut().println("Feed reading started");
        history.readFeedData(feedDescriptor, from, to, new IFeedListener(){
     
             @Override
             public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
                 itemCount++;
                 console.getOut().println("volume " + ((IBar)feedData).getVolume());
             }
         },
         new LoadingProgressListener() {
     
             @Override
             public void dataLoaded(long start, long end, long currentPosition, String information) {
             }
     
             @Override
             public void loadingFinished(boolean allDataLoaded, long start, long end, long currentPosition) { 
                 console.getOut().format("Loaded %s %s %s  - %s    feed descriptor=%s",
                         itemCount,
                         feedDescriptor.getDataType(),
                         DateUtils.format(from),
                         DateUtils.format(to),
                         feedDescriptor
                 ).println();
                 context.stop();
             }
       
             @Override
             public boolean stopJob() {
                 return false;
             }
         });
     }


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

    public void onStop() throws JFException {}

    public void onAccount(IAccount arg0) throws JFException {}

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

    public void onMessage(IMessage arg0) throws JFException {}
}


Attachments:
JForexHistoryNoVolume2.java [3.69 KiB]
Downloaded 98 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: History readFeedData() / readBars() return no volume with feedData/bars? Post rating: 0   New post Posted: Tue 29 Jul, 2014, 12:46 
User avatar

User rating: 8
Joined: Tue 25 Oct, 2011, 23:02
Posts: 74
Location: Australia, Melbourne
Thanks. Ran that and helped figure out what I was doing wrong. Problem fixed.


 

Jump to:  

cron
  © 1998-2024 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