The third example extend the second one adding a query facility.
To use this example you have to compile both second and third examples.
/*
Description
===========
This simple application example open a connection with a MetaMarket service
using YAS service manager, and then it subscribe orders
of some securities using EntityFilter.
*/
// Effective source-code Example3 starts here.
import java.io.*;
import it.list.jft.*; // to use the JFT/Api library
import it.list.jft.event.*; // to use the JFT/Api library
import metamarket.*; // to use MetaMarket, FT_C_ORDER, FT_C_TRADING_STATE, etc...
public class Example3 implements ConnectionListener, SubscriptionListener, FilterListener
{
Context context;
Connection connection;
EntityFilter filter;
public Example3(){
JFT.THIS.init(JFT.MODE_MULTI_THREAD);
System.out.println("Starting...");
JFT.THIS.setTrace(true);
JFT.THIS.setTraceLevel(JFT.TRACE_LEVEL_DEBUG);// uncomment this line for debug trace on system out
// JFT.THIS.setTraceMode(true, new PrintWriter(System.out));
// use this if you want to print trace on a file
// JFT.THIS.setTraceMode(true, new File("C:\\TRACE_Test.txt"));
// register MetaMarket order class
JFT.THIS.register(new FT_C_ORDER());
JFT.THIS.start();context = JFT.THIS.makeContext();
ConnectionParam p = context.makeConnectionParam();// change following parameters to fit your configuration
p.setHost("194.91.195.36");
p.setPort(37000);
p.setUserName("marco");
p.setPassword("*");
p.setClientID(12345);
p.setUserType(ConnectionParam.USER_TYPE_TRADER);p.setService("METAMARKET");
connection = context.makeConnection(p, this);
System.out.println("Open connection result: " + connection.open());
}
public static void main(String[] args)
{Example3 test = new Example3();
}
// connection listener interface
public void onConnectionOpen(ConnectionOpenEvent event)
{
System.out.println(event);// crete EntityFilter
FilterParam filterparam = context.makeFilterParam();filterparam.setEntityClassID(MetaMarket.FT_C_ORDER_ID);
filterparam.setType(EntityFilter.TYPE_ENTITYFILTER);filter = (EntityFilter)context.makeFilter(connection, filterparam, this);
System.out.println("Filter Create Result: " + filter.create());
}
public void onConnectionClose(ConnectionCloseEvent event)
{
System.out.println(event);
}public void onConnectionLost(ConnectionLostEvent event)
{
System.out.println(event);
}// filter listener interface
public void onFilterCreate(FilterCreateEvent event)
{
System.out.println(event);if (event.getResult() == FilterCreateEvent.RESULT_OK)
{
FT_C_ORDER order = new FT_C_ORDER();SubscriptionParam param = context.makeSubscriptionParam();
param.setEntityClassID(MetaMarket.FT_C_ORDER_ID);
param.setFilter(filter);
param.setEntityKey(order.getFullEntityKey(MetaMarket.FT_C_ORDERKey));Subscription sub = context.makeSubscription(connection, param, this);
System.out.println("Subscribing Result FT_C_ORDER: " + sub.start());
}
}public void onFilterSet(FilterSetEvent event)
{
System.out.println(event);
}public void onFilterDestroy(FilterDestroyEvent event)
{
System.out.println(event);
}// subscription listener interface
public void onSubscriptionStart(SubscriptionStartEvent event)
{System.out.println(event);
if (event.getResult()==SubscriptionStartEvent.RESULT_OK)
{FT_C_ORDER order = new FT_C_ORDER();
order.FTSecID = "BITMTAACE";
filter.add(order.getPartialEntityKey(MetaMarket.FT_C_ORDERKey,1));
order.FTSecID = "BITMTAF";
filter.add(order.getPartialEntityKey(MetaMarket.FT_C_ORDERKey,1));
order.FTSecID = "BITMTACSP";
filter.add(order.getPartialEntityKey(MetaMarket.FT_C_ORDERKey,1));
filter.flush();// now you will receive the order of this three security only
}
}
public void onSubscriptionStop(SubscriptionStopEvent event)
{System.out.println(event);
}
public void onSubscriptionIdle(SubscriptionIdleEvent event)
{System.out.println(event);
}
public void onSubscriptionNotify(SubscriptionNotifyEvent event)
{System.out.println(event);
}
}