Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MATP-1115 Photon Market Data List View does not retain symbols on res… #1118

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void start()
event.consume();
}
});
restoreSymbols();
}
/**
* Create a new MarketDataListView instance.
Expand All @@ -156,6 +157,21 @@ public MarketDataListView(Region inParent,
inEvent,
inProperties);
}
/**
* Restore the symbol layout.
*/
private void restoreSymbols()
{
Properties windowProperties = getViewProperties();
String symbolList = windowProperties.getProperty(symbolsKey);
if(symbolList != null) {
symbolList = symbolList.replaceAll("\\[|\\]","");
String[] symbols = symbolList.split(",");
for(String symbol : symbols) {
doMarketDataRequest(symbol);
}
}
}
/**
* Update the view properties for this view.
*/
Expand All @@ -166,6 +182,37 @@ private void updateViewProperties()
String.valueOf(symbolsByRequestId.values()));
}
}
/**
* Perform the market data request for the given symbol.
*
* @param inSymbol a <code>String</code> value
*/
private void doMarketDataRequest(String inSymbol)
{
if(inSymbol == null) {
return;
}
inSymbol = inSymbol.toUpperCase();
if(symbolsByRequestId.values().contains(inSymbol)) {
return;
}
Instrument instrument = tradeClient.resolveSymbol(inSymbol);
String marketDataRequestId = UUID.randomUUID().toString();
MarketDataItem newItem = new MarketDataItem(instrument,
marketDataRequestId);
marketDataTable.getItems().add(newItem);
MarketDataRequest request = MarketDataRequestBuilder.newRequest().withSymbols(inSymbol).withAssetClass(AssetClass.getFor(instrument.getSecurityType()))
.withContent(Content.LATEST_TICK,Content.TOP_OF_BOOK,Content.MARKET_STAT).withRequestId(marketDataRequestId).create();
MarketDataRowListener rowListener = new MarketDataRowListener(newItem);
symbolsByRequestId.put(marketDataRequestId,
inSymbol);
SLF4JLoggerProxy.debug(this,
"Submitting {}",
request);
marketdataClient.request(request,
rowListener);
updateViewProperties();
}
/**
* Initialize the Add Symbol controls.
*/
Expand All @@ -184,29 +231,7 @@ private void initializeAddSymbol()
addSymbolButton.setOnAction(event -> {
String symbol = StringUtils.trimToNull(addSymbolTextField.getText());
addSymbolTextField.setText(null);
if(symbol == null) {
return;
}
symbol = symbol.toUpperCase();
if(symbolsByRequestId.values().contains(symbol)) {
return;
}
Instrument instrument = tradeClient.resolveSymbol(symbol);
String marketDataRequestId = UUID.randomUUID().toString();
MarketDataItem newItem = new MarketDataItem(instrument,
marketDataRequestId);
marketDataTable.getItems().add(newItem);
MarketDataRequest request = MarketDataRequestBuilder.newRequest().withSymbols(symbol).withAssetClass(AssetClass.getFor(instrument.getSecurityType()))
.withContent(Content.LATEST_TICK,Content.TOP_OF_BOOK,Content.MARKET_STAT).withRequestId(marketDataRequestId).create();
MarketDataRowListener rowListener = new MarketDataRowListener(newItem);
symbolsByRequestId.put(marketDataRequestId,
symbol);
SLF4JLoggerProxy.debug(this,
"Submitting {}",
request);
marketdataClient.request(request,
rowListener);
updateViewProperties();
doMarketDataRequest(symbol);
});
addSymbolLayout.setAlignment(Pos.CENTER_RIGHT);
addSymbolLayout.getChildren().addAll(addSymbolTextField,
Expand Down