本文整理汇总了C#中IAlgorithm.SetCash方法的典型用法代码示例。如果您正苦于以下问题:C# IAlgorithm.SetCash方法的具体用法?C# IAlgorithm.SetCash怎么用?C# IAlgorithm.SetCash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAlgorithm
的用法示例。
在下文中一共展示了IAlgorithm.SetCash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBrokerage
/// <summary>
/// Creates a new IBrokerage instance
/// </summary>
/// <param name="job">The job packet to create the brokerage for</param>
/// <param name="algorithm">The algorithm instance</param>
/// <returns>A new brokerage instance</returns>
public IBrokerage CreateBrokerage(LiveNodePacket job, IAlgorithm algorithm)
{
//Try and use the live job packet cash if exists, otherwise resort to the user algo cash:
if (job.BrokerageData.ContainsKey("project-paper-equity"))
{
var consistentCash = Convert.ToDecimal(job.BrokerageData["project-paper-equity"]);
algorithm.SetCash(consistentCash);
}
return new PaperBrokerage(algorithm);
}
示例2: Setup
//.........这里部分代码省略.........
brokerage.Message += brokerageOnMessage;
// set the transaction models base on the brokerage properties
SetupHandler.UpdateTransactionModels(algorithm, algorithm.BrokerageModel);
algorithm.Transactions.SetOrderProcessor(transactionHandler);
algorithm.PostInitialize();
try
{
// this can fail for various reasons, such as already being logged in somewhere else
brokerage.Connect();
}
catch (Exception err)
{
Log.Error(err);
AddInitializationError("Error connecting to brokerage: " + err.Message);
return false;
}
if (!brokerage.IsConnected)
{
// if we're reporting that we're not connected, bail
AddInitializationError("Unable to connect to brokerage.");
return false;
}
try
{
// set the algorithm's cash balance for each currency
var cashBalance = brokerage.GetCashBalance();
foreach (var cash in cashBalance)
{
Log.Trace("BrokerageSetupHandler.Setup(): Setting " + cash.Symbol + " cash to " + cash.Quantity);
algorithm.SetCash(cash.Symbol, cash.Quantity, cash.ConversionRate);
}
}
catch (Exception err)
{
Log.Error(err);
AddInitializationError("Error getting cash balance from brokerage: " + err.Message);
return false;
}
try
{
// populate the algorithm with the account's outstanding orders
var openOrders = brokerage.GetOpenOrders();
foreach (var order in openOrders)
{
// be sure to assign order IDs such that we increment from the SecurityTransactionManager to avoid ID collisions
Log.Trace("BrokerageSetupHandler.Setup(): Has open order: " + order.Symbol + " - " + order.Quantity);
order.Id = algorithm.Transactions.GetIncrementOrderId();
transactionHandler.Orders.AddOrUpdate(order.Id, order, (i, o) => order);
}
}
catch (Exception err)
{
Log.Error(err);
AddInitializationError("Error getting open orders from brokerage: " + err.Message);
return false;
}
try
{
// populate the algorithm with the account's current holdings
var holdings = brokerage.GetAccountHoldings();