Skip to content

Commit

Permalink
Fix issue with multiple accounts. Small refactor for handling time zo…
Browse files Browse the repository at this point in the history
…ne offset
  • Loading branch information
Daniel Lindberg committed Jul 12, 2017
1 parent 856b1f2 commit a5d666b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Please use [pastebin](http://pastebin.com/) for uploading the logs.

- This is a early release of the plugin so **don't expect it to be bug free!**
- You WILL need to update the AssetsFix with Symbol names. For instance the EUR/USD name is CS.D.EURUSD.CFD.IP
- Prefer running your strategies with [Weekend = 7](http://www.zorro-trader.com/manual/en/weekend.htm) as the broker API tends to crash when IGs server goes offline for the weekend
- The default allowance for IG historic prices is 10 000 quotes per week. If your allowance goes to zero, you won't even be able to download quotes for the lookback period. This means it is not a good idea to use IG as a source for downloading long periods of historic data.
- Keep your historic data as up to date as possible and prefer using the [PRELOAD-flag](http://www.zorro-trader.com/manual/en/mode.htm) in you scripts. Even just filling the lookback will get rate limited if you have many assets and are too far behind on historic data.
- The default quotas for IG Streaming API connections is 40 concurrent connections. The plugin currently uses 2 streams per asset, which means so can at a maximum trade 20 assets at the same time. Contact IG if you need to raise your limit.
Expand Down
2 changes: 2 additions & 0 deletions c++/src/DllCallHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ DllCallHandler::BrokerAccount(const char *Account,
double *pTradeVal,
double *pMarginVal)
{
/* Account parameter not used for now, just ignore it rather than return an error
if (Account)
{
BrokerError("Multiple accounts are not yet supported!");
return 0;
}
*/
jdoubleArray jAccountParamsArray = env->NewDoubleArray(3);

jint res = (jlong)env->CallObjectMethod(JData::JIgZorroBridgeObject,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/danlind/igz/ZorroBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private void initComponents() {
accountHandler.startAccountSubscription();
tradeHandler = context.getBean(TradeHandler.class);
tradeHandler.checkTradesValid();
historyHandler.startTimeZoneOffsetSubscription();

if (!isFirstLogin) {
logger.debug("Zorro requested new login, resubscribing to all assets");
Expand Down Expand Up @@ -71,6 +72,7 @@ public int doLogin(final String User,

public int doLogout() {
logger.debug("Broker Logout called");
historyHandler.cancelSubscription();
return loginHandler.disconnect();
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/danlind/igz/brokerapi/BrokerAsset.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public BrokerAsset(MarketDataProvider marketDataProvider, VolumeProvider volumeP
*/
public void reconnectAll() {
marketDataProvider.getAllSubscribedEpics().stream().forEach(epic -> {
LOG.debug("Subscribing for epic {}", epic.getName());
LOG.debug("Re-subscribing for epic {}", epic.getName());
subscribeToLighstreamerTickUpdates(epic);
});
}
Expand All @@ -67,7 +67,6 @@ public int subscribeToLighstreamerTickUpdates(Epic epic) {
//TODO: How to handle close of stream on weekends? (Weekend = 7 is the obvious option for now)
LOG.info("Received complete signal from TickObservable for epic {}", epic.getName());
marketDataProvider.cancelSubscription(epic);
historyHandler.cancelSubscription();
}
);

Expand All @@ -82,8 +81,6 @@ public int subscribeToLighstreamerTickUpdates(Epic epic) {
() -> LOG.info("Received complete signal from VolumeObservable for epic {}", epic.getName())
);

historyHandler.getTimeZoneOffsetObservable();

//Init volume from historic data
List<PricesItem> pricesItems = historyHandler.getPriceHistory(epic, VOLUME_WINDOW_LENGTH);
pricesItems.stream().forEach(pricesItem -> volumeProvider.updateRollingVolume(epic, new Volume(pricesItem.getLastTradedVolume().intValue())));
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/danlind/igz/brokerapi/BrokerHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public int getPriceHistory(final Epic epic,
}
}

public void getTimeZoneOffsetObservable() {
public void startTimeZoneOffsetSubscription() {
if (Objects.nonNull(timeZoneOffsetSubscription)) {
logger.debug("Disposing of existing time offset subscription");
timeZoneOffsetSubscription.dispose();
Expand All @@ -67,7 +67,8 @@ public void getTimeZoneOffsetObservable() {
);
}

public void cancelTimeOffsetSubscription() {
public void cancelTimeZoneOffsetSubscription() {
logger.debug("Canceling time offset subscription");
timeZoneOffsetSubscription.dispose();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/danlind/igz/handler/HistoryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public List<PricesItem> getPriceHistory(final Epic epic,
return brokerHistory.getPriceHistory(epic, ticks);
}

public void getTimeZoneOffsetObservable() {
brokerHistory.getTimeZoneOffsetObservable();
public void startTimeZoneOffsetSubscription() {
brokerHistory.startTimeZoneOffsetSubscription();
}

public void cancelSubscription() {
brokerHistory.cancelTimeOffsetSubscription();
brokerHistory.cancelTimeZoneOffsetSubscription();
}
}

0 comments on commit a5d666b

Please sign in to comment.