Commit Graph

172 Commits

Author SHA1 Message Date
Colton Sellers 041a111b92 Implement safe exiting for Lean (#4972) 2020-11-27 18:14:18 -03:00
Michael Handschuh 1d1c8f5f82 Don't raise IBrokerage.OptionPositionAssigned on exercise (#4801) 2020-10-07 14:40:34 -03:00
Colton Sellers f135fb8060 Bug Backtesting Brokerage Clones (#4644)
* fix order updates

* Fix option exercise issue

* Regression changes

* Update regressions to reflect fixes

* Refactor handling of order to fully fix #2846

* Regression Algorithm for unit test

* Pre review

* Fix breaking tests

* OrderImmutability Regression Algo

* OrderImmutability Regression Algo Compile

* Address review

* Update regressions with new orderhash
2020-09-09 19:44:56 -03:00
Martin Molinero 7989d41aa7 Fix SecurityCache OHLC data type
- Fix for Equity SecurityCache OHLC default data type to be used. Will
  ignore QuoteBars
2020-04-08 19:31:37 -03:00
Martin Molinero aac426fd63 Refactor BrokerageTransactionHandler
- Rename 'fill' to 'orderEvent'.
- Remove duplicate order event log
- Move 'NewOrderEvent' invoke so it applies for all order event types
2020-04-02 17:07:37 -03:00
Martin Molinero 8e14aa7a89 Replace IsUpdate for OrderStatus.UpdateSubmitted 2020-03-30 20:03:58 -03:00
Martin Molinero 78ae2d7e1b Add Price and Quantity to OrderEvent
- Adding order current Quantity, StopPrice and LimitPrice to the
OrderEvent instance
- Adding OrderTicketDemoAlgorithm as a regression test
2020-03-30 11:07:18 -03:00
Martin Molinero 6e40ce5300 Add OrderEvent id
- Adding incremental OrderEvent Id per Order instance. Adding unit test
2020-03-30 11:07:18 -03:00
Martin Molinero de4acffe00 Refactor
- Add new OrderEvent collection into ITransactionHandler which will be
consumed by the ResultHandler
2020-02-27 18:47:44 -03:00
Martin Molinero 107e117881 Address reviews 2020-02-26 10:47:54 -03:00
Michael Handschuh e4d1005c4a Update Lean.Engine to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:45 -04:00
AlexCatarino 1ab8d84ee7 Prevents Warning of Price Rounding When Increment is Non-Positive
Moves the logic of sending warning message of price rounding inside the if-condition of valid increment value.
2019-08-05 22:33:23 +01:00
Stefano Raggi bf3aeb96de Add GetMinimumPriceVariationParameters 2019-08-01 21:52:08 +02:00
Stefano Raggi bce36fd9de Revert public RoundOrderPrices 2019-08-01 10:19:41 +02:00
Stefano Raggi 422af0610a Fix order price rounding in EquityPriceVariationModel 2019-07-31 15:48:14 +02:00
Stefano Raggi 34152bbbcc Update IB cash sync to not be performed during server reset times
A new IBrokerageCashSynchronizer interface has been added to allow brokerage implementations to handle the cash sync process. Most of the cash sync logic has been moved from the BrokerageTransactionHandler to the base Brokerage class.
The IB brokerage will not attempt to perform cash sync during server reset times, respecting the different regional schedules (see also #3413).
2019-07-29 18:01:54 +02:00
Martin Molinero 7f12cbb901 Addressing reviews 2019-05-15 18:56:08 -03:00
Martin Molinero f976ffa099 Removing BacktestingTransactionHandler thread
- For backtesting the algorithm thread will sequentially process pending
order requests
   - Adding new non blocking `BusyCollection`
- Updating `UpdateOrderRegressionAlgorithm` that suffered of a race
condition: it supposed `OnOrderEvent` would be called after the call to
`Transactions.AddOrder()` was finished
2019-05-10 16:15:24 -03:00
Martin Molinero cfa08a11fb Address reviews
- Removing `using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm`
- Removing `QCAlgorithmFrameworkBridge`
- Removing `IsFrameworkAlgorithm`
- Making `EmitInsightBasedOnFill` private. Adding new
`IOrderEventProvider` exposing an `event` to which `QCAlgorithm` will
subscribe.
- `AccountType.Cash` algorithms will be allowed to manually trade and
emight insights manually or with alpha model.
2019-04-03 21:55:44 -03:00
Martin Molinero 5b04cfe202 Emiting Insights based on Fills
- Classic Algorithms will emight insights based on order fills.
   - To be able to update generated insights closed time, we will not
   clone emitted insights.
   - `InsightAnalysisContext` will update `AnalysisEndTimeUtc` when the
   Insight period is closed and the period is `EndOfTimeTimeSpan`
- Adding new regression algorithm asserting on the new emitted insights
- Adding unit tests
- `LiveTradingResultHandler` will store `AlphaRunTimeStatistics`
- Making `DefaultAlphaHandler.ProcessAsynchronousEvents` virtual to
facilitate cloud changes
2019-03-26 16:09:22 -03:00
Stefano Raggi 576e91f593 Append fill order event message to order tag 2019-03-12 20:34:30 +01:00
Stefano Raggi e14d520517 Update OandaBrokerage.GetCashBalance to include currencies for open positions 2019-02-21 11:19:48 +01:00
Stefano Raggi 99d96d681a Update BrokerageTransactionHandler.AddOrder to wait for order to be processed 2019-02-18 23:28:28 +01:00
Martin Molinero 8e41371e19 Non-Usd brokerage support
- `GetCashBalance()` will return a `List<CashAmount>`, will not need to
set conversion rates, which requires knowing what the account currency is.
- Removing `Global.Holding` conversion rate field. It wasn't being used
and required knowing what the account currency is.
- Adding equality operators for `CashAmount`. Adding unit tests.
2018-12-27 12:13:43 -03:00
Martin Molinero 0933da9303 Refactor previous commits
- Removing `AccountCurrency` from `Cash` and `Brokerage` classes.
`ICurrencyConverter` will now provide the `AccountCurrency`
- Adding new static `OrderFee.Zero` which will return a 0 order fee in
`NullCurrency`
- Adding static `Currencies.USD` value, replacing all "USD".
- Addin new static `Currencies.NullCurrency`
- Updating Bitfinex `FeeModel` so it return fees in quote currency.
Adding unit tests
2018-12-13 11:30:40 -03:00
Martin Molinero b7bcdbef04 Adding OrderFee to OrderEvent
- Replacing `decimal` for `OrderFee` at the `OrderEvent`.
- Adding `FeeModelNotUsingAccountCurrency` regression test
- Adding unit tests for `CashBuyingPowerModel` and `SecurityMarginModel`
with non account currency fees
2018-12-10 13:18:41 -03:00
Stefano Raggi bd4c799d2b Rename parameter classes from Context to Parameters 2018-11-29 22:05:49 +01:00
Stefano Raggi 78f3b4b099 Refactor additional IBuyingPowerModel methods to use context objects 2018-11-27 22:50:15 +01:00
Stefano Raggi bd6485e1e1 Fix potential endless loop in BrokerageSetupHandler daily cash sync
- added tracking of failed cash sync attempts and throw if maximum reached
- added extra log traces in IB GetCashBalance and in BrokerageTransactionHandler
- added endless loop unit tests for both BrokerageTransactionHandler and InteractiveBrokersBrokerage
2018-11-02 14:45:38 +01:00
Martin Molinero f5d7ee5476 Fix so we perform cash sync only once 2018-09-17 16:09:41 -03:00
Stefano Raggi bcd4223405 Add additional logging of margin info for submit order requests 2018-09-12 20:48:21 +02:00
Stefano Raggi 74bc5d7689 Add logging of margin information in Live mode 2018-09-12 18:42:17 +02:00
Martin Molinero 8cd4d4d6e1 Adding lock for HandleOrderEvent 2018-07-23 09:28:40 -03:00
Martin Molinero 2c7a0b0510 Fix cancelled order status setting location 2018-07-12 14:08:21 -03:00
Martin Molinero f38431446d Fixing null pointer exception at brokeragetransactionhelper 2018-06-27 18:10:04 -03:00
Martin Molinero 82c2532a31 Improve performance for backtests with a large amount of trades 2018-06-21 16:59:29 -03:00
Michael Handschuh c25afbad29 Add fill/update/cancel times to order object
LastFillTime is updated on each partial/fill order event
LastUpdateTime is updated on each submitted order event w/ update count > 0
CancelTime is updated on canceled order events

Also fixes bug in regression algorithm where it used Time instead of UtcTime
for creating the SubmitOrderRequest object.
2018-05-02 14:16:33 -04:00
Stefano Raggi 0310b2945a Fix GDAX fees for limit orders in backtesting
Fixes #1852
2018-04-13 20:57:21 +02:00
Stefano Raggi 11d4c0ea58 Prevent order status overwriting in BrokerageTransactionHandler.HandleSubmitOrderRequest
Fixes #1799
The order status should be set to Submitted only in PlaceOrder (for all brokerage implementations).
2018-03-28 18:45:10 +02:00
Stefano Raggi 4318c17974 Update buying power model interface for better messaging
The HasSufficientBuyingPowerForOrder method has been updated to return a result object including the reason the order cannot be executed.

The SetHoldings method has also been updated to display a message if CalculateOrderQuantity returns zero.
2018-02-27 11:24:15 +01:00
Stefano Raggi acb5db6cf5 Rename Security.MarginModel to BuyingPowerModel 2018-01-31 11:47:34 +01:00
Stefano Raggi c9542abc42 Rename ISecurityMarginModel.CanExecuteOrder to HasSufficientBuyingPowerForOrder 2018-01-31 11:47:33 +01:00
Stefano Raggi 66b265d890 Move GetSufficientCapitalForOrder to SecurityMarginModel.CanExecuteOrder 2018-01-31 11:47:33 +01:00
Stefano Raggi f37d0cc962 Optimize loops for performance on cashbook and securities 2017-12-20 21:58:59 +01:00
Stefano Raggi c6aba7bfec Reduce full locking on ConcurrentDictionary objects
This PR is an attempt to reduce contention in concurrent dictionaries, replacing method calls using full locks with lock-free equivalents:

- dictionary.Count -> dictionary.Skip(0).Count()
- dictionary.Keys -> dictionary.Select(x => x.Key)
- dictionary.Values -> dictionary.Select(x => x.Value)

The most frequent usages of these methods are: CashBook, SecurityManager, UniverseManager and indirectly, SecurityPortfolioManager.

The reasons for this update are explained very clearly in this article:
https://arbel.net/2013/02/03/best-practices-for-using-concurrentdictionary/
2017-12-20 17:18:54 +01:00
Stefano Raggi 1295c91551 Update order event messages for option expiration
The message for short option order events at expiration was "Automatic option assignment on expiration" for both ITM and OTM. It has now been corrected to "Option expiration" for OTM short options.

The same message is now also being reported in QCAlgorithm.OnAssignmentOrderEvent instead of the generic "Option Assignment" message.
2017-12-05 00:49:41 +01:00
Andrew 7325b52e51 OrderTickets are initialized in BrokerageSetupHandler
- Created public property on ITransactionHandler that wraps the private OrderTicket dictionary. Allows BrokerageSetupHandler to add the order tickets

Refactored ToOrderTicket extension method to handle several types of order
2017-08-28 14:19:04 -04:00
Stefano Raggi 9139ca7c40 Merge master into issue-330/decimal-quantity 2017-06-19 23:50:26 +02:00
Stefano Raggi 4b59634a14 Fix time zone bug in cash sync
PR #861 didn't fix the issue properly, this one should do it
2017-04-24 16:08:58 +02:00
Stefano Raggi c78b9579bb Fix time zone bug in cash sync
With the update in the PR, cash synchronization in BrokerageTransactionHandler will now always be performed at 7:45 AM NewYork time, even if Lean is running in a different time zone.
2017-04-22 16:57:16 +02:00