Replies: 1 comment 1 reply
-
If I understand your question correctly, you want to stream Level 1 trades (aka "ticks") for 1000 tickers, correct? If so, here is that example. Note that you'll have to load in your ticker list however you'd like into the final IQFeed4j iqFeed4j = new IQFeed4j(); // Load configuration from "iqfeed4j.properties"
try {
// Start "IQConnect.exe"
iqFeed4j.startIQConnect();
System.out.println(iqFeed4j.iqConnectExecutable().waitForConnection(5000) + " attempts to connect.");
// Start Level 1 feed and wait at most 5 seconds to validate the connection
iqFeed4j.startLevel1Feed();
iqFeed4j.level1().waitForProtocolVersionValidation(5, TimeUnit.SECONDS);
// Let's listen to the "most recent" trades.
// This includes both qualified (round lots) and non-qualified trades (odd lots).
iqFeed4j.level1().selectUpdateFieldNames(
SummaryUpdateField.MOST_RECENT_TRADE,
SummaryUpdateField.MOST_RECENT_TRADE_SIZE,
SummaryUpdateField.MOST_RECENT_TRADE_MARKET_CENTER,
SummaryUpdateField.MOST_RECENT_TRADE_DATE,
SummaryUpdateField.MOST_RECENT_TRADE_TIME);
// Load your ticker list (for you it'd be 1000 tickers loaded from a file or something)
final String[] tickers = new String[]{"AAPL", "TSLA", "QQQ"}; // IQFeed supports max 1800 Level 1 tickers
// Create a "fundamental data" listener for getting data such as: stock splits, fiscal year end, etc.
FeedMessageListener<FundamentalData> fundamentalDataListener = (fundamentalData) -> {
System.out.printf("%s %.2f split was on %s.\n",
fundamentalData.getSymbol(),
fundamentalData.getSplitFactor1(),
fundamentalData.getSplitFactor1Date());
};
// Create a "summary update" listener for listening to trade data and such.
FeedMessageListener<SummaryUpdate> summaryUpdateListener = (summaryUpdate) -> {
System.out.printf("%s trade occurred with %d shares at $%.4f with " +
"the market center code %d at %s %s with a latency of %s milliseconds.\n",
summaryUpdate.getSymbol(),
summaryUpdate.getMostRecentTradeSize(),
summaryUpdate.getMostRecentTrade(),
summaryUpdate.getMostRecentTradeMarketCenter(),
summaryUpdate.getMostRecentTradeDate(),
summaryUpdate.getMostRecentTradeTime(),
ChronoUnit.MILLIS.between(
summaryUpdate.getMostRecentTradeTime(),
LocalTime.now(ZoneId.of("America/New_York"))));
};
// Create a "trade correction" listener to listening to trade corrects (which are rare)
FeedMessageListener<TradeCorrection> tradeCorrectionListener = (tradeCorrection) -> {
System.out.printf("%s %s trade correction occured at %s\n",
tradeCorrection.getSymbol(),
tradeCorrection.getCorrectionType().toString().toLowerCase(),
tradeCorrection.getTradeTime());
};
// Loop through all the tickers in the ticker list and request a Level 1 subscription for each ticker
for (String ticker : tickers) {
iqFeed4j.level1().requestWatchTrades(ticker, fundamentalDataListener, summaryUpdateListener,
tradeCorrectionListener);
}
} catch (Exception exception) {
exception.printStackTrace();
} If you want to watch a ticker for interval bars that consist of 1000 ticks, you'll need to use the DerivativeFeed for that. Refer the to Javadoc here for requesting interval bars. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
is there any way you can write an example of how to stream 1000 tick interval bars ,please .
Beta Was this translation helpful? Give feedback.
All reactions