Capital Markets Adapters 10.15 | Apama Capital Markets Adapters Documentation 10.15 | EBS Spot Ai FIX Adapter | Connecting to CME EBS Ai | Subscription sample
 
Subscription sample
using com.apama.session.SessionHandler;
using com.apama.session.SessionHandlerFactory;

using com.apama.md.DepthSubscriberFactory;
using com.apama.md.DepthSubscriber;

using com.apama.utils.Params;

monitor test_sub_mon {

context mainContext := context.current();
string session := "FIX";
string transport := "CME_EBSAi_DATA";

action onload() {

SessionHandler sessionHandler := (new SessionHandlerFactory).connectCb(
mainContext, session, transport,onSessionConnected );
}

action onSessionConnected(SessionHandler sessionHandler) {
log "Session Connected" at INFO;
on all com.apama.fix.SessionLoggedOn(connection = transport){
senduserRequest(sessionHandler);
}
}

action senduserRequest(SessionHandler sessionHandler) {

/** Send UserLogonRequest **/

/*for an example:
dictionary <integer, string> userDatadict := new dictionary <integer, string>;
route com.apama.fix.ebs.UserLogonRequest(transport, "123", "USER", PSSWD", [
com.apama.fix.ebs.UserData("AllowNDFSwapInfo","Y",userDatadict),
com.apama.fix.ebs.UserData("AllowFixingInfo","Y",userDatadict),
com.apama.fix.ebs.UserData("AllowFixPointsInfo","Y",userDatadict)], {"1129":"1.6"});
*/

/**On user success logon handle subscription **/
on com.apama.fix.ebs.UserResponse() as userResponse {
if userResponse.__payload.hasKey("926") and userResponse.__payload["926"] = "1" {
handle_depth_subscription(sessionHandler);
}
}
}

action handle_depth_subscription(SessionHandler sessionHandler) {
DepthSubscriber depthSubscriber := (new DepthSubscriberFactory).create(sessionHandler);
Params controlParams := new Params;
controlParams.addParam("461"," RCSXXX ");
controlParams.addParam("63","0");
controlParams.addParam("1300","USD");
controlParams.addParam("1021","2");

depthSubscriber.setParams(controlParams);
integer retVal := depthSubscriber.addSubscribedCallback(onDepthSubscribed);
depthSubscriber.subscribeCb("EUR/USD" , onDepthUpdate);
}

action onDepthSubscribed(com.apama.md.DepthSubscriber handler,
com.apama.md.adapter.ConnectionKey connKey)
{log "Successfully Depth subscribed for symbol: " + connKey.getSymbol() at INFO ;}

action onDepthUpdate(com.apama.md.client.CurrentDepthInterface depth) {
log "depth : Bid : " + depth.getRawBids().toString() at INFO;
log "depth : Ask : " + depth.getRawAsks().toString() at INFO;
log "depth : EP : " + depth.getEPValuesInterface().getRaw().toString() at INFO;
}
}