Commit Graph

40 Commits

Author SHA1 Message Date
Martin Molinero 35ca60aa31 Fix duplicate OnOrderEvent invoke
- `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
2019-05-22 15:33:09 -03: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
Stefano Raggi ffb67e4241 Add new unit tests 2019-03-12 21:54:29 +01:00
Martin Molinero efaf1a5863 Review: Replace Sleep for ManualResetEvent 2019-02-27 20:18:38 -03:00
Martin Molinero ed5f7ab58c Moving price scale factoring to new enumerator
- 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.
2019-02-27 15:11:34 -03: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
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
Stefano Raggi 44412f2273 Move HistoryProviderBase to QuantConnect.Common project 2018-10-14 23:07:09 +02:00
Stefano Raggi dbaf109c78 Post-review updates
- Renamed events in SubscriptionDataReader and IHistoryProvider
- Added HistoryProvider base class with events and event invocators
2018-10-14 22:29:06 +02:00
Stefano Raggi 9fad26bc8f Add events to IHistoryProvider and SubscriptionDataReader
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.
2018-10-14 22:29:04 +02:00
Stefano Raggi 77b37f4dfd Update IHistoryProvider.Initialize to use HistoryProviderInitializeParameters
This is only a mechanical refactor for the updated IHistoryProvider.Initialize method in all IHistoryProvider implementations, call sites and unit tests.
2018-10-14 22:29:02 +02:00
Michael Handschuh bc3bc893f4 Merge pull request #2520 from Martin-Molinero/refactor-2516-datamanager-wraps-idatafeed
DataManager wraps IDataFeed
2018-09-20 11:44:10 -04:00
Martin Molinero 1997197f47 Fix failing unit tests 2018-09-18 12:10:42 -03:00
Martin Molinero f5d7ee5476 Fix so we perform cash sync only once 2018-09-17 16:09:41 -03:00
Martin Molinero 41873b2315 Fixing unit tests 2018-08-31 16:06:41 -03:00
Martin Molinero 2c7a0b0510 Fix cancelled order status setting location 2018-07-12 14:08:21 -03:00
Andrew 3786b351c9 Updated GDAX currency pair lot sizes to 1/100m in symbol-properties-db
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
2017-10-23 13:56:35 -04:00
jameschch@outlook.com d6f5fb2a33 merge from master 2017-09-15 12:55:06 +01:00
jameschch@outlook.com 564e0c3d95 Removes obsolete references to bitfinex 2017-09-01 15:16:46 +01:00
jameschch@outlook.com 3754b33026 Adds crypto unit tests 2017-08-30 15:40:35 +01:00
Stefano Raggi 4a12c28823 More decimal quantity fixes
- Reverted some changes to algorithms
- Changed UpdateOrderCommand.Quantity from int to decimal
- Fixed DefaultMarginCallModel for decimals and LotSize
2017-06-22 20:45:57 +02:00
Stefano Raggi 9139ca7c40 Merge master into issue-330/decimal-quantity 2017-06-19 23:50:26 +02:00
Andrew 672e134939 Removed ApiDataProvider
Refactored IHistoryProvider interface order of parameters
2017-02-16 15:47:06 -05:00
Andrew b6171cc9d5 Renamed IDataFileProvider to IDataProvider using resharper
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
2017-02-15 12:16:50 -05:00
Andrew ed2107132e IHistoryProvider.Initialize() requires a DataCacheProvider
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
2017-02-15 12:16:49 -05:00
Andrew 952e1d19e3 Added interface IDataCacheProvider that defines a mechanism for caching data
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.
2017-02-15 12:16:49 -05:00
Stefano Raggi 23d7812804 Add new CancelPending order status
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.
2017-01-02 21:00:35 +01:00
AlexCatarino ed70d85c5b Adds a function to round order prices
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.
2016-09-20 15:36:45 -03:00
jameschch@outlook.com befbfc20ca merge latest upstream 2016-07-26 20:03:03 +01:00
Petr Drastil 003e490ec2 HandleOrderEvent() should be called when quantity is zero 2016-07-13 02:44:34 +02:00
Petr Drastil 72116c659b Moved response processing into HandleOrderRequest() 2016-07-10 20:36:07 +02:00
Petr Drastil 3c534fa8d1 Removed internal modifiers. 2016-07-10 19:35:23 +02:00
Petr Drastil 9f8b28f60f Order is not placed if order is lower than minimum lot size 2016-07-08 16:25:09 +02:00
jameschch@outlook.com 0e8755dc48 Changes related to #330 order quantity decimalized 2016-06-24 11:53:29 +01:00
jameschch@outlook.com 7763efdc83 Changes related to #330 order quantity decimalized 2016-06-24 11:28:21 +01:00
devalkeralia c0cd418a92 Removed unnecessary imports 2016-06-15 19:05:24 -04:00
devalkeralia f258236db6 Created tests for Brokerage Transaction Handler 2016-06-15 18:34:41 -04:00