additional informations for VolumeCounter

Custom indicators, trading strategies, data export and recording and more...
mdtrader
Posts: 39
Joined: Sat Oct 27, 2018 4:05 pm
Location: germany
Has thanked: 12 times
Been thanked: 41 times

additional informations for VolumeCounter

Post by mdtrader » Wed Nov 14, 2018 8:17 am

Hi
I try to understand how to get bid ask volume in the simple-example "VolumeTracker" but I need more informations about

Code: Select all

 volumeCounter = new VolumeCounter(interval, volumeCounterType);
Where can I find it? I searched in javadoc but couldn't find something.
Another thing, is it possible to show bars instead lines in the bottom chart like the volume in the main chart?

Thanks
Mario

Serg
Posts: 113
Joined: Mon Jun 11, 2018 12:40 pm
Has thanked: 15 times
Been thanked: 35 times

Re: additional informations for VolumeCounter

Post by Serg » Wed Nov 14, 2018 9:44 am

Please note that this project is a demo of how to use the API, not the API itself, this is why there is no javadoc for it. But you can use these helper classes like VolumeCounter in your code.
mdtrader wrote:
Wed Nov 14, 2018 8:17 am
how to get bid ask volume
The trading terminology is somewhat confusing because being used in different ways. Can you please clarify what do you mean by bid ask volume? Is it sizes of best bid/ask, or sizes of entire order book, or executed volume (i.e. at bid by sellers, at ask by buyers)?
mdtrader wrote:
Wed Nov 14, 2018 8:17 am
Another thing, is it possible to show bars instead lines in the bottom chart like the volume in the main chart?
Yes, it's in our roadmap. However, since you can use Indicator#addPoint() at any moment, you can make the indicator lines look like steps (not bars, but similar).

mdtrader
Posts: 39
Joined: Sat Oct 27, 2018 4:05 pm
Location: germany
Has thanked: 12 times
Been thanked: 41 times

Re: additional informations for VolumeCounter

Post by mdtrader » Wed Nov 14, 2018 2:55 pm

Hi Serg,

sorry for the confusion...
I mean the executed volume on the bid and on the ask so I can calculate the delta.
I found the VolumeCounter.java now and saw that the calculation is done for the time I choose in the settings, right?
I ask because I developed some delta indicators with C++ in Sierra and in Sierra you always calculate within the cycle of the chart timeframe say 1min. here in Bookmap you have a continous flow of executions, is this the reason you need this "nanoseconds-variable" to cummulate the volume within this selected time?

Mario

PS: right now I'm not so fit in Java, so maybe some questions are a little "easy" :)

Serg
Posts: 113
Joined: Mon Jun 11, 2018 12:40 pm
Has thanked: 15 times
Been thanked: 35 times

Re: additional informations for VolumeCounter

Post by Serg » Thu Nov 15, 2018 11:46 am

Thanks for clarification. Right, the actual market data is a continuous very non-uniform timeseries. If you wish to receive trades in such continuous Times & Sales form, all you need to do is to include in the list of implemented interfaces TradeDataListener and implement onTrade(), for instance:

Code: Select all

@Layer1SimpleAttachable
@Layer1StrategyName("My Custom Module")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class MyCustomModule implements CustomModule, TradeDataListener {
	
	int lastTradeSizeOnBid;
	int lastTradeSizeOnAsk;
	
	@Override
	public void onTrade(double price, int size, TradeInfo tradeInfo) {
		if (tradeInfo.isBidAggressor) {
			lastTradeSizeOnAsk = size;
		} else {
			lastTradeSizeOnBid = size;	
		}
	}

	@Override
	public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
	}

	@Override
	public void stop() {
	}
}
mdtrader wrote:
Wed Nov 14, 2018 2:55 pm
...here in Bookmap you have a continous flow of executions, is this the reason you need this "nanoseconds-variable" to cummulate the volume within
Well, there may be many thousands trades per second and dozens of thousands market depth updates per second. But even that doesn't require the granularity of nanoseconds. The simplest answer is this: whether you use milliseconds, microseconds, or nanoseconds, it still requires 64-bit integer (long). Even seconds resolution will require 64-bit in several years )). So, there is no any downside of using nanoseconds by default. But there are definitely some advantages. Here is a more detailed answer: https://bookmap.com/wiki/Market_Mechani ... in_Bookmap.

Serg
Posts: 113
Joined: Mon Jun 11, 2018 12:40 pm
Has thanked: 15 times
Been thanked: 35 times

Re: additional informations for VolumeCounter

Post by Serg » Thu Nov 15, 2018 12:38 pm

Alternatively, you can easily aggregate trades data into bars yourself with any interval:

Code: Select all

@Layer1SimpleAttachable
@Layer1StrategyName("My Custom Module")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class MyCustomModule implements CustomModule, TradeDataListener, IntervalListener {

	Bar bar = new Bar();
	
	@Override
	public void onTrade(double price, int size, TradeInfo tradeInfo) {
		bar.addTrade(tradeInfo.isBidAggressor, size, price);
	}

	@Override
	public long getInterval() {
		return Intervals.INTERVAL_1_SECOND;
	}

	@Override
	public void onInterval() {
		double vwapBuyers = bar.getVwapBuy();
		double vwapSellers = bar.getVwapSell();
		 // there is much more info in the Bar object including OHLCV
		bar.startNext(); // reset the bar and init its Open as current Close
	}

	@Override
	public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
	}

	@Override
	public void stop() {
	}
}

Serg
Posts: 113
Joined: Mon Jun 11, 2018 12:40 pm
Has thanked: 15 times
Been thanked: 35 times

Re: additional informations for VolumeCounter

Post by Serg » Thu Nov 15, 2018 12:46 pm

Even simpler, if you want Bookmap to aggregate the data into bars with any resolution:

Code: Select all

@Layer1SimpleAttachable
@Layer1StrategyName("My Custom Module")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class MyCustomModule implements CustomModule, BarDataListener {

	@Override
	public long getInterval() {
		return Intervals.INTERVAL_100_MILLISECONDS; // tell Bookmap how frequently to call onBar()
	}

	@Override
	public void onBar(OrderBook orderBook, Bar bar) { // do something with bar and/or the order book 
		long buyVolume = bar.getVolumeBuy();
		long sellVolume = bar.getVolumeSell();
	}

	@Override
	public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
	}

	@Override
	public void stop() {
	}
}


mdtrader
Posts: 39
Joined: Sat Oct 27, 2018 4:05 pm
Location: germany
Has thanked: 12 times
Been thanked: 41 times

Re: additional informations for VolumeCounter

Post by mdtrader » Mon Nov 19, 2018 8:52 am

Hi Serg,

these are very,very helpful informations for me

Thanks

Post Reply