Skip to content

Instantly share code, notes, and snippets.

@joeybeninghove
Created January 31, 2025 05:51
Show Gist options
  • Save joeybeninghove/a91f47370f7859810797cf6f298b2f33 to your computer and use it in GitHub Desktop.
Save joeybeninghove/a91f47370f7859810797cf6f298b2f33 to your computer and use it in GitHub Desktop.
[Subject(typeof(TradeManager))]
class when_price_is_updated
{
static ITradeManager subject;
static Mock<ILevelRepository> level_repository;
static Mock<IBroker> broker;
static Mock<ILevel> level;
static Mock<IStopLoss> stop_loss;
static Mock<IConfiguration> configuration;
static Mock<ITakeProfit> take_profit;
static int contracts = 1;
static int target_in_ticks = 40;
static IEnumerable<IOrder> pending_orders = new List<IOrder>();
static IEnumerable<ITrade> trades = new List<ITrade>();
Establish context = () =>
{
level = new Mock<ILevel>();
stop_loss = new Mock<IStopLoss>();
take_profit = new Mock<ITakeProfit>();
level_repository = new Mock<ILevelRepository>();
configuration = new Mock<IConfiguration>();
broker = new Mock<IBroker>();
configuration.Setup(c => c.Contracts).Returns(contracts);
configuration.Setup(c => c.TargetInTicks).Returns(target_in_ticks);
broker.Setup(b => b.CreateStopLoss(Moq.It.IsAny<double>())).Returns(stop_loss.Object);
broker.Setup(b => b.CreateTakeProfit(target_in_ticks)).Returns(take_profit.Object);
subject = new TradeManager(level_repository.Object, broker.Object, configuration.Object);
};
class and_level_above_price_does_not_have_a_pending_order
{
static readonly double new_price = 100;
static readonly double level_price = 105;
Establish context = () =>
{
level.Setup(l => l.PendingOrders).Returns(pending_orders);
level.Setup(l => l.Price).Returns(level_price);
level_repository.Setup(lr => lr.GetNextLevelAbove(new_price)).Returns(level.Object);
};
class and_level_above_price_has_not_had_any_trades
{
Establish context = () =>
{
level.Setup(l => l.Trades).Returns(trades);
};
Because of = () =>
subject.PriceUpdated(new_price);
It creates_a_sell_limit_order = () =>
{
broker.Verify(b => b.CreateLimitOrder(
Side.Sell,
level_price,
contracts,
stop_loss.Object,
take_profit.Object
));
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment