本文整理汇总了C#中IBrokerage.GetOpenOrders方法的典型用法代码示例。如果您正苦于以下问题:C# IBrokerage.GetOpenOrders方法的具体用法?C# IBrokerage.GetOpenOrders怎么用?C# IBrokerage.GetOpenOrders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBrokerage
的用法示例。
在下文中一共展示了IBrokerage.GetOpenOrders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
//.........这里部分代码省略.........
{
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();
var minResolution = new Lazy<Resolution>(() => algorithm.Securities.Min(x => x.Value.Resolution));
foreach (var holding in holdings)
{
Log.Trace("BrokerageSetupHandler.Setup(): Has existing holding: " + holding);
if (!algorithm.Portfolio.ContainsKey(holding.Symbol))
{
Log.Trace("BrokerageSetupHandler.Setup(): Adding unrequested security: " + holding.Symbol);
// for items not directly requested set leverage to 1 and at the min resolution
algorithm.AddSecurity(holding.Type, holding.Symbol, minResolution.Value, null, true, 1.0m, false);
}
algorithm.Portfolio[holding.Symbol].SetHoldings(holding.AveragePrice, (int) holding.Quantity);
algorithm.Securities[holding.Symbol].SetMarketPrice(new TradeBar
{
示例2: Setup
//.........这里部分代码省略.........
"This may be caused by incorrect login credentials or an unsupported account type.", 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;
}
Log.Trace("BrokerageSetupHandler.Setup(): Fetching cash balance from brokerage...");
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.Amount);
algorithm.Portfolio.SetCash(cash.Symbol, cash.Amount, cash.ConversionRate);
}
}
catch (Exception err)
{
Log.Error(err);
AddInitializationError("Error getting cash balance from brokerage: " + err.Message);
return false;
}
Log.Trace("BrokerageSetupHandler.Setup(): Fetching open orders from brokerage...");
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.ToString() + " - " + 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;
}
Log.Trace("BrokerageSetupHandler.Setup(): Fetching holdings from brokerage...");
try
{
// populate the algorithm with the account's current holdings
var holdings = brokerage.GetAccountHoldings();
var supportedSecurityTypes = new HashSet<SecurityType> { SecurityType.Equity, SecurityType.Forex, SecurityType.Cfd };
var minResolution = new Lazy<Resolution>(() => algorithm.Securities.Select(x => x.Value.Resolution).DefaultIfEmpty(Resolution.Second).Min());
foreach (var holding in holdings)
{
Log.Trace("BrokerageSetupHandler.Setup(): Has existing holding: " + holding);
// verify existing holding security type
if (!supportedSecurityTypes.Contains(holding.Type))
{
Log.Error("BrokerageSetupHandler.Setup(): Unsupported security type: " + holding.Type + "-" + holding.Symbol.Value);
AddInitializationError("Found unsupported security type in existing brokerage holdings: " + holding.Type + ". " +
"QuantConnect currently supports the following security types: " + string.Join(",", supportedSecurityTypes));