- `BacktestingBrokerage.Scan()` is now reentrant and was causing
duplicate processing and events. To solve this updateing the order
status keeped by the brokerage. Adding unit tests
- 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
- Adding new `PriceScaleFactorEnumerator` that will scale raw prices
based on a provided `SubscriptionDataConfig` and update the
`SubscriptionDataConfig.PriceScaleFactor`. Adding unit tests.
- `BaseData` factories (`TradeBar.cs`, `QuoteBar.cs`, `Tick.cs`) will
no longer scale factor prices, they will generate data points in raw
mode.
- `SubscriptionDataReader` will no longer update the
`SuscriptionDataConfig.PriceScaleFactor`
- Fix `BrokerageTransactionHandlerTests` unit test that was having a
race condition.
- `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.
- 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
- 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
The SubscriptionDataReaderHistoryProvider was using StubResultHandler, so no error messages were being shown or logged. By adding events to IHistoryProvider and SubscriptionDataReader, the dependency on IResultHandler could be removed completely and error messages are now pushed up the stack.
This is only a mechanical refactor for the updated IHistoryProvider.Initialize method in all IHistoryProvider implementations, call sites and unit tests.
Decreasing the fractional quantity of the gdax lot sizes required test corrections for BrokerageTransactionHandlerTests specifically RoundOff_LessThanLotSize_Fractional_Orders, RoundOff_Short_Fractional_Orders, RoundOff_Long_Fractional_Orders order. The quantity of the test orders needed to be reduced in order to comply with the updated lot order sizes
Also needed to change the FractionalQuantityRegressionAlgorithm - which is supposed to have one order fail because the quantity is too small. This order needed a smaller quantity in order to fail with the new lot sizes
Updated FactionionalQuantityRegressionAlgorithm tests
- Reverted some changes to algorithms
- Changed UpdateOrderCommand.Quantity from int to decimal
- Fixed DefaultMarginCallModel for decimals and LotSize
Refactored IDataProvider interface to return stream. The IDataProvider
Fetch method now only takes a key. The IDataProvider
has been reshuffled to be at the bottom of the LeanDataStack. It provides
data to the rest of the Lean stack. The default implementation of IDataProvider reads
data from disc.
All IDataCacheProviders now have constructors which take IDataProviders
and use them to find data on disc.
Renamed DataCacheProvider to ZipDataCacheProvider
Added comments to IDataProvider and it's implementations
Added comments to IDataCacheProvider and it's implementations
Fixed bug where DataCacheProvider was returning a stream without closing
the stream. Also, ZipFiles returned from ZipFileCacheProvider are
effectively disposed.
Removed date field from IDataCacheProvider interface
This interface was built around the existing implementation of the
DataCacheProvider. It's purpose is to define a method for caching data
files. Currently, most data files are either read from disc or retrieved
remotely. The IDataChceProvider returns returns a Stream and can handle
many types of data. The IDataFileCacheProvider is needed because keeping data in memory will improve performance and overcome certain File read/write limitations (such as sharing violations) currently experienced by Lean.
There are two implementations of this interface. The first is the
SingleZipEntryDataCache. This is the default implementation. It does not
cache and returns the first entry found within a ZipFile. The second is
the ZipEntryCacheProvider. This is a rework of the existing
DataCachePrivider. It caches ZipFiles for up to 10 seconds. It can
return specific entries for option and future ZipFiles. Otherwise, it
returns the first entry in a ZipFile.
Added IDataFileCacheProvider as parameter to IHistoryProvider.Initialize()
The IDataFileCacheProvider is very useful for the IHistoryProvider in that it can eliminate the need for history request to touch disc. This can greatly improve peerformance and eliminate disc bugs associated with disc read/writes. To minimize changes throughtout Lean, the default value for the IDataFileCacheProvider is null in the IHistoryProvider.Initialize method.
IDataCacheProviders are passed down the Lean stack. Each instance of a Subscription Enumerator factory decides what cache it
will use. In other words, the IDataCacheProvider is not configurable from
config.json. The IDataCacheProvider is passwed down the stack form the
Enumerator factory to the IStreamReader where it is used to retrieve data.
Added useful helper method to Unizp files into a Stream.
This new status is being added to solve the following problem with order cancellations:
Working orders (limit or stop) are usually cancelled by calling the OrderTicket.Cancel() method. This method is asynchronous in both backtesting and live, so reading the OrderStatus immediately after the Cancel call, can result in different values seen over different runs.
The solution introduces a new CancelPending value to the OrderStatus enum and guarantees that the order will have this status when the Cancel method returns (unless there was an error earlier, such as invalid order id). This status is meant to be temporary and will be overwritten/replaced by the Canceled value after the brokerage has completed the cancel operation.
Adds a function to round order prices to the minimum price variation. This procedure is needed to meet brokerage precision requirements.
In backtest mode when price is adjusted, there is no rounding.