/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using QuantConnect.Packets;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using System.Collections.Generic;
using QuantConnect.Brokerages.Paper;
namespace QuantConnect.Tests.Brokerages.Models;
///
/// A customized PaperBrokerage implementation that allows manual control over the cash balance.
///
internal class PaperBrokerageWithManualCashBalance : PaperBrokerage
{
private decimal _cashBalance;
///
/// Gets the current cash balance.
///
public decimal CashBalance => _cashBalance;
///
/// Increases the cash balance by the specified amount.
///
/// The amount to add to the cash balance.
public void IncreaseCashBalance(decimal amount)
{
_cashBalance += amount;
}
///
/// Initializes a new instance of the class
/// with the specified algorithm, job packet, and initial cash balance.
///
/// The algorithm instance.
/// The live node job packet.
/// The initial cash balance.
public PaperBrokerageWithManualCashBalance(IAlgorithm algorithm, LiveNodePacket job, decimal initialCashBalance) : base(algorithm, job)
{
_cashBalance = initialCashBalance;
}
///
/// Reduces the cash balance by the specified amount.
///
/// The amount to subtract from the cash balance.
public void DecreaseCashBalance(decimal amount)
{
_cashBalance -= amount;
}
///
/// Gets the current cash balances held in the account.
///
/// A list containing the current cash balance in USD.
public override List GetCashBalance()
{
return [new CashAmount(_cashBalance, Currencies.USD)];
}
}