Skip to content

Commit

Permalink
sync orders and setholdings fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Broad committed Aug 15, 2014
1 parent 7f1c89a commit 882d252
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 6 deletions.
18 changes: 18 additions & 0 deletions QuantConnect.Algorithm.Interface/IAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,24 @@ List<string> LogMessages
//void OnData(Ticks ticks);
//void OnData(TradeBars tradebars);

/// <summary>
/// Send debug message
/// </summary>
/// <param name="message"></param>
void Debug(string message);

/// <summary>
/// Save entry to the Log
/// </summary>
/// <param name="message">String message</param>
void Log(string message);

/// <summary>
/// Send an error message for the algorithm
/// </summary>
/// <param name="message">String message</param>
void Error(string message);

/// <summary>
/// Call this method at the end of each day of data.
/// </summary>
Expand Down
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions QuantConnect.Algorithm/0_Algorithm_Tests_SetHolding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public void OnData(TradeBars data)
{
SetHoldings("SPY", -0.5); step++;
}

if (Time.Date == new DateTime(2013, 11, 1) && step == 5)
{
SetHoldings("IBM", -0.5, true); //Succeed.
SetHoldings("SPY", -0.5); step++;
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions QuantConnect.Algorithm/QCAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,10 @@ public int Order(string symbol, int quantity, OrderType type = OrderType.Market,
{
//Wait for the market order to fill.
//This is processed in a parallel thread.
while (!Transactions.Orders.ContainsKey(orderId) || Transactions.Orders[orderId].Status != OrderStatus.Filled || _processingOrder)
while (!Transactions.Orders.ContainsKey(orderId) ||
(Transactions.Orders[orderId].Status != OrderStatus.Filled &&
Transactions.Orders[orderId].Status != OrderStatus.Invalid &&
Transactions.Orders[orderId].Status != OrderStatus.Canceled) || _processingOrder)
{
Thread.Sleep(1);
}
Expand Down Expand Up @@ -927,7 +930,8 @@ public List<int> Liquidate(string symbolToLiquidate = "")
quantity = Math.Abs(Portfolio[symbol].Quantity);
}
//Liquidate at market price.
orderIdList.Add(Transactions.AddOrder(new Order(symbol, quantity, OrderType.Market, Time, Securities[symbol].Price)));
orderIdList.Add(Order(symbol, quantity, OrderType.Market));
//orderIdList.Add(Transactions.AddOrder(new Order(symbol, quantity, OrderType.Market, Time, Securities[symbol].Price)));
}
}
return orderIdList;
Expand Down Expand Up @@ -1004,7 +1008,7 @@ public void SetHoldings(string symbol, decimal percentage, bool liquidateExistin
if (Math.Abs(Securities[symbol].Price) > 0)
{
//3. Now rebalance the symbol requested:
deltaQuantity = Math.Floor(deltaValue / Securities[symbol].Price);
deltaQuantity = Math.Round(deltaValue / Securities[symbol].Price);
}

//Determine if we need to place an order:
Expand Down
6 changes: 3 additions & 3 deletions QuantConnect.Algorithm/QuantConnect.Algorithm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
<None Include="2_Algorithm_ExponentialMovingAverage.cs" />
<None Include="3_Algorithm_CustomDataSource.cs" />
<None Include="4_Algorithm_Custom_Charting.cs" />
<None Include="0_Algorithm_NitfyINR.cs" />
<None Include="0_Algorithm_CashTests.cs" />
<Compile Include="0_Algorithm_SetHoldingTests.cs" />
<None Include="0_Algorithm_Tests_Cash.cs" />
<None Include="0_Algorithm_Tests_NitfyINR.cs" />
<Compile Include="0_Algorithm_Tests_SetHolding.cs" />
<Compile Include="QCAlgorithm.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified QuantConnect.Algorithm/bin/Debug/QuantConnect.Algorithm.dll
Binary file not shown.
Binary file modified QuantConnect.Algorithm/bin/Debug/QuantConnect.Algorithm.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified QuantConnect.Algorithm/obj/Debug/QuantConnect.Algorithm.dll
Binary file not shown.
Binary file modified QuantConnect.Algorithm/obj/Debug/QuantConnect.Algorithm.pdb
Binary file not shown.

0 comments on commit 882d252

Please sign in to comment.