How to know if the trepEmaClient has retrieved the rate file completely?
Currently when we connect with the trep server to retrieve files, we set the thread to sleep one minute to let the treoEmaClient downloads the rate file completely because the rate file is big, around 1-2MB.
Is there any way to avoid the thread sleep, or make the sleep a bit shorter? Such as 15 seconds? See below for our code.
Because we are using the default operation model: API_DISPATCH where EMA manages the dispatching of events within a background thread, we must block and wait on our application thread for a short period to capture our market data events.
Thank you.
public TrepResult retrieveRatesXml(String baseCurrency) throws InterruptedException {
OmmConsumer consumer = getOmmConsumer();
if (consumer == null) {
LOGGER.error("Can not connect to any TREP server.");
return null;
}
try {
ElementList batch = EmaFactory.createElementList();
OmmArray array = EmaFactory.createOmmArray();
for (String currency : TrepCurrency.getTrepRevertCurrencies().get(baseCurrency)) {
//EmaFactory.createOmmArrayEntry() must be inside the loop, otherwise only the last currency will be requested.
array.add(EmaFactory.createOmmArrayEntry().ascii("ky" + currency + baseCurrency + BFIX_CURNCY));
}
for (String currency : TrepCurrency.getTrepCurrencies().get(baseCurrency)) {
array.add(EmaFactory.createOmmArrayEntry().ascii("ky" + baseCurrency + currency + BFIX_CURNCY));
}
batch.add(EmaFactory.createElementEntry().array(EmaRdm.ENAME_BATCH_ITEM_LIST, array));
TrepEmaClient trepEmaClient = new TrepEmaClient(baseCurrency);
consumer.registerClient(EmaFactory.createReqMsg().serviceName(SERVICE_NAME).payload(batch), trepEmaClient);
// sleep for a while in order to let TrepEmaClient get all rate messages
Thread.sleep(EMA_CLIENT_WAITING_TIME.toMillis());
ExchangeRates rates = trepEmaClient.getRates();
String originalRefreshMsg = trepEmaClient.getOriginalRefreshMsg();
String ratesXml = XmlUtil.jaxbMarshallToString(rates);
if (ratesXml == null) {
return null;
}
return new TrepResult(ratesXml, originalRefreshMsg);
} catch (OmmException exception) {
LOGGER.error(exception.getMessage());
} finally {
consumer.uninitialize();
}
return null;
}
Best Answer
-
Hi @ning.kang
One way of confirming when you have received a response for all items in your Batch is to count the number of
- RefreshMsg and
- StatusMsg with a Closed stream state
that you receive.
For every valid instrument you should get a RefreshMsg callback and for invalid instruments (e.g. invalid RIC, Expired RIC, un-licensed RIC etc.) you would get a StatusMsg callback with a StreamState of Closed.
You could then create a loop that sleeps until the above total matches the number of items in your Batch request.
You may need to speak to whoever developed the trepEmaClient to help you - because that is not one of our Classes - it is a custom implementation.
I should also add that if you are only interested in snapping your instruments (as appears to be the case) then you should be using the snapshot option e.g.
consumer.registerClient(EmaFactory.createReqMsg().serviceName(SERVICE_NAME).payload(batch).interestAfterRefresh(false), trepEmaClient);
This way you only receive Refresh or Status events and not any Update events.
0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛