Tickevent

43 views
Skip to first unread message

mdja...@gmail.com

unread,
Oct 23, 2014, 3:27:07 PM10/23/14
to tbg-quant...@googlegroups.com
Dear all. How can i publish a tickevent ir a candle event (fakemarketfeed)

Alberto Sfolcini

unread,
Oct 24, 2014, 3:16:33 AM10/24/14
to tbg-Quant-community
Hello,

What do you need to do exactly ?

Do you need to work on Ticks or Candles event?

If you receive ticks, you can create a CandleEvent using the service shown below:
// Services
TickToCandleEventService candle1min = new TickToCandleEventService(TimeFrame.TIMEFRAME_1min,this);


If you are using the BogusMarketDataFeed you can just subscribe the CandleEvent instead of Ticks:

private final IMarketDataFeed marketDataFeed = new BogusMarketDataFeed();
{
marketDataFeed.setMarketDataEvent(MarketDataEventType.CANDLE_EVENT);
}


Please let me know what do you need so I can help in a better way.
Thank you



On Thu, Oct 23, 2014 at 9:27 PM, <mdja...@gmail.com> wrote:
Dear all. How can i publish a tickevent ir a candle event (fakemarketfeed)

--
www.thebonnotgang.com
---
You received this message because you are subscribed to the Google Groups "tbg-Quant-community" group.
To post to this group, send email to tbg-quant...@googlegroups.com.



--
Alberto Sfolcini

mdja...@gmail.com

unread,
Oct 24, 2014, 7:33:44 AM10/24/14
to tbg-quant...@googlegroups.com
After Having collected market data, I publish à tick event. When i send an order (paper account), I encounter an error. Do not know how to debug or if sending à tick is enough. Help or an example would be appreciated.

Alberto Sfolcini

unread,
Oct 24, 2014, 10:54:23 AM10/24/14
to tbg-Quant-community
Hi,

Which MarketDataFeed are you using ?
Can you please send me your skeleton source code in order to reproduce this issue ?

 
thank you

On Fri, Oct 24, 2014 at 1:33 PM, <mdja...@gmail.com> wrote:
After Having collected market data, I publish à tick event. When i send an order (paper account), I encounter an error. Do not know how to debug or if sending à tick is enough. Help or an example would be appreciated.
--
www.thebonnotgang.com
---
You received this message because you are subscribed to the Google Groups "tbg-Quant-community" group.
To post to this group, send email to tbg-quant...@googlegroups.com.



--
Alberto Sfolcini

mdjam...@gmail.com

unread,
Oct 25, 2014, 6:54:22 PM10/25/14
to tbg-quant...@googlegroups.com
public void onEvent(Object event) {
Order order = new Order();
order.setSecurity(new Security(new Symbol("EPA:AI")));
order.setOrderSide(OrderSide.BUY);
order.setOrderType(OrderType.LIMIT);
order.setLimitPrice(1);;
order.setQuantity(100);
broker.sendOrder(order);


This generate the error below. The line "TestOnEvent.java:149" of the stack trace refers to code line "broker.sendOrder(order);"


2014-10-26 00:39:30,225 [AWT-EventQueue-0] INFO [com.tbg.strategy.TradingSystem] - TICK_EVENT => TimeStamp: Thu Jan 01 01:23:34 CET 1970 Symbol: EPA:AI Price: 92.66000366210938 Size: 0.0 Volume: 0 AskPrice: 0.0 BidPrice: 0.0 askSize: 0.0 bidSize: 0.0

2014-10-26 00:39:30,225 [AWT-EventQueue-0] INFO [com.tbg.adapter.paper.broker.PaperBroker] - sendOrder(): OID=null, type=MARKET, security=null, side=BUY, quantity=-1.0, orderTimeStamp=null, executionTragetTimeStamp=null, expirationTimeStamp=null, timeInForce=DAY, stopPrice=-1.0, limitPrice=-1.0, trailingDistance=-1.0, orderStatus=NEW

2014-10-26 00:39:30,225 [AWT-EventQueue-0] WARN [org.bushe.swing.event.EventService] - Exception thrown by;EventService subscriber:com.tbg.core.model.strategy.StrategyBase$MarketDataSubscriber@325c62c0. Subscriber class:class com.tbg.core.model.strategy.StrategyBase$MarketDataSubscriber

org.bushe.swing.exception.SwingException: Exception handling event topic event class=com.tbg.core.model.types.event.TickEvent, event=TICK_EVENT => TimeStamp: Thu Jan 01 01:23:34 CET 1970 Symbol: EPA:AI Price: 92.66000366210938 Size: 0.0 Volume: 0 AskPrice: 0.0 BidPrice: 0.0 askSize: 0.0 bidSize: 0.0, topic=null, eventObj=null

org.bushe.swing.exception.SwingException: Exception handling event topic event class=com.tbg.core.model.types.event.TickEvent, event=TICK_EVENT => TimeStamp: Thu Jan 01 01:23:34 CET 1970 Symbol: EPA:AI Price: 92.66000366210938 Size: 0.0 Volume: 0 AskPrice: 0.0 BidPrice: 0.0 askSize: 0.0 bidSize: 0.0, topic=null, eventObj=null
at org.bushe.swing.event.ThreadSafeEventService.handleException(ThreadSafeEventService.java:2021)
at org.bushe.swing.event.ThreadSafeEventService.handleException(ThreadSafeEventService.java:2009)
at org.bushe.swing.event.ThreadSafeEventService.publish(ThreadSafeEventService.java:975)
at org.bushe.swing.event.SwingEventService.access$001(SwingEventService.java:31)
at org.bushe.swing.event.SwingEventService$1.run(SwingEventService.java:88)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:702)
at java.awt.EventQueue$3.run(EventQueue.java:696)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:719)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.NullPointerException
at com.tbg.adapter.paper.broker.PaperBroker.getLastMarketTickEvent(PaperBroker.java:419)
at com.tbg.adapter.paper.broker.PaperBroker.sendOrder(PaperBroker.java:80)
at examples.test.TestOnEvent.onEvent(TestOnEvent.java:149)
at com.tbg.service.cep.PassThroughProvider.sendEvent(PassThroughProvider.java:34)
at com.tbg.core.model.strategy.StrategyBase$MarketDataSubscriber.onEvent(StrategyBase.java:93)
at org.bushe.swing.event.ThreadSafeEventService.publish(ThreadSafeEventService.java:971)
... 16 more


mdjam...@gmail.com

unread,
Oct 26, 2014, 1:22:36 PM10/26/14
to tbg-quant...@googlegroups.com, mdjam...@gmail.com
I forgot to mention that i was using 'fakemarketfeed".

ps : having the source code would have been helpful...

best regards.

Alberto Sfolcini

unread,
Oct 27, 2014, 5:39:37 AM10/27/14
to tbg-Quant-community, mdjam...@gmail.com
Hi James,

You cannot do that.
FakeMarketDataFeed is used to produce a fake market event in order to trigger the onEvent method. In the examples package it is used to implements a orderRouter, thus the event it produces it's a fake TickEvent. If you want a "real" continuous fake market  you  need to use the BogusMarketDataFeed.

Check this source:

/**
 * FakeEventMarketDataFeed <br>
 * <br>
 * <b>History:</b><br>
 *  - [03/feb/2012] Created. (sfl)<br>
 *
 *  @author sfl
 */
public class FakeEventMarketDataFeed implements IMarketDataFeed {

private long SLEEP_TIME = 1000;
protected final static Logger log = Logger.getLogger(FakeEventMarketDataFeed.class);
private boolean debug = false;
private int marketDataFeedId = 0;
private MarketDataEventType marketDataEventType;
private IAlarmService alarmService;
@Override
public void setMarketDataFeedId(int marketDataFeedId) {
this.marketDataFeedId = marketDataFeedId;
}

@Override
public int getMarketDataFeedId() {
return this.marketDataFeedId;
}

@Override
public void connectToMarketFeed() {
log.info("Connected to EventMarketDataFeeder.");
}

@Override
public boolean isConnected() {
return true;
}

@Override
public void setDebug(boolean debug) {
this.debug = debug;
}

@Override
public void disconnectFromMarketDataFeed() {
log.info("Connection to EventMarketDataFeeder closed.");
}

@Override
public void subscribeMarketData(Security security) {
log.info(security.getSymbol()+" subscribed.");
}

@Override
public void activeMarketDataSubscription(){

while (true){
try {
Thread.sleep(this.SLEEP_TIME);
} catch (InterruptedException e) {}
EventBus.publish(new TickEvent("XXX", 1, 0, 0, 0));
}
}
public void setEventTime(long millisecs){
this.SLEEP_TIME = millisecs;
}
@Override
public void setAlarmService(IAlarmService alarmService) {
this.alarmService = alarmService;
}


@Override
public void setMarketDataEvent(MarketDataEventType marketDataEventType) {
this.marketDataEventType = marketDataEventType;
}

@Override
public MarketDataEventType getMarketDataEvent() {
return this.marketDataEventType;
}


}



I dont know what are you trying to do but I think you should work on this method:

@Override
public void activeMarketDataSubscription(){

Read your datasource and push it into EventBus.publish();
                                You can push TickEvent or CandleEvent as you prefer.
                                
In the FakeMarketEvent I push an empty TickEvent (EventBus.publish(new TickEvent("XXX", 1, 0, 0, 0));) because my only goal was to fire up the onEvent() method on TradeSystem class, this is the reason you got the exception. If you push the right symbol event (tick or candle) you will be able to feed the TradeSystem class and fullfill the order thro the paperbroker.

}


Hope this helps, 

Try to replace the FakeMarketDataFeed with BogusMarketDataFeed, it produces continuos bogus market data and you can chose between Candle or Tick events.


What is your datasource ? is it a CSV file ?
Hope that the sourcecode above is useful, pleasde give me feedback.

thank you
Alberto




--
www.thebonnotgang.com
---
You received this message because you are subscribed to the Google Groups "tbg-Quant-community" group.
To post to this group, send email to tbg-quant...@googlegroups.com.



--
Alberto Sfolcini

mdjam...@gmail.com

unread,
Oct 30, 2014, 2:45:59 AM10/30/14
to tbg-quant...@googlegroups.com
Thank you.

if we suscribe for a security using the constructor with new symbol only generate an exception when you try to send an order. So the steps
1 susbscribesecurity(new security(new symbol("ibm")))
2 ordersend....
Generate an exception.

To avoid this bug/error, One need to subscribesecurity with a complete constructor ie susbscribesecurity(new security(new symbol("ibm", "", "smart",currency, ...)))

Best regards.

mdjam...@gmail.com

unread,
Oct 31, 2014, 1:35:59 PM10/31/14
to tbg-quant...@googlegroups.com, mdja...@gmail.com
Thank you.

An exception occurs when an order is sent on a security subscribed with the most simple constructor. One need to subscribe a security filling all requested parameter (ticker, vendor, type, currency, market, etc) to avoid the exception when sending an order.

Best regards.

Reply all
Reply to author
Forward
0 new messages