Skip to content

Commit

Permalink
Add support for IBGateway v985 (QuantConnect#5812)
Browse files Browse the repository at this point in the history
* Add support for IBGateway v985

- Effective in TWS version 985 and later, for US stocks the bid, ask, and last size quotes are shown in shares (not in lots).

* Add missing error log in IB symbol mapper

* Trigger build
  • Loading branch information
StefanoRaggi authored Jul 30, 2021
1 parent 41636c9 commit 1793add
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions Brokerages/InteractiveBrokers/InteractiveBrokersBrokerage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public sealed class InteractiveBrokersBrokerage : Brokerage, IDataQueueHandler,
private readonly ISecurityProvider _securityProvider;
private readonly IDataAggregator _aggregator;
private readonly IB.InteractiveBrokersClient _client;
private readonly int _ibVersion;
private readonly string _agentDescription;
private readonly EventBasedDataQueueHandlerSubscriptionManager _subscriptionManager;

Expand Down Expand Up @@ -259,6 +260,7 @@ public InteractiveBrokersBrokerage(
_account = account;
_host = host;
_port = port;
_ibVersion = Convert.ToInt32(ibVersion, CultureInfo.InvariantCulture);
_agentDescription = agentDescription;

_symbolMapper = new InteractiveBrokersSymbolMapper(mapFileProvider);
Expand Down Expand Up @@ -2736,12 +2738,13 @@ private void HandleTickPrice(object sender, IB.TickPriceEventArgs e)
/// <summary>
/// Modifies the quantity received from IB based on the security type
/// </summary>
public static int AdjustQuantity(SecurityType type, int size)
public int AdjustQuantity(SecurityType type, int size)
{
switch (type)
{
case SecurityType.Equity:
return size * 100;
// Effective in TWS version 985 and later, for US stocks the bid, ask, and last size quotes are shown in shares (not in lots).
return _ibVersion < 985 ? size * 100 : size;
default:
return size;
}
Expand Down Expand Up @@ -3429,5 +3432,6 @@ private static class AccountValueKeys
{
1100, 1101, 1102, 2103, 2104, 2105, 2106, 2107, 2108, 2119, 2157, 2158, 10197
};

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
Expand Down Expand Up @@ -198,8 +198,9 @@ public string GetBrokerageSymbol(Symbol symbol)

return Symbol.Create(brokerageSymbol, securityType, market);
}
catch (Exception)
catch (Exception exception)
{
Log.Error(exception, "Error in GetLeanSymbol");
throw new ArgumentException($"Invalid symbol: {brokerageSymbol}, security type: {securityType}, market: {market}.");
}
}
Expand Down
2 changes: 1 addition & 1 deletion Brokerages/QuantConnect.Brokerages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NodaTime" Version="3.0.5" />
<PackageReference Include="QuantConnect.IBAutomater" Version="2.0.43" />
<PackageReference Include="QuantConnect.IBAutomater" Version="2.0.44" />
<PackageReference Include="RestSharp" Version="106.6.10" />
<PackageReference Include="System.ComponentModel.Composition" Version="5.0.0" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.0" />
Expand Down

0 comments on commit 1793add

Please sign in to comment.