public void CalculateRunnerProfitForTwoRunners() { var orc1 = new OrderRunnerChangeStub(1) .WithMatchedBack(3.5, 10.99); var orc2 = new OrderRunnerChangeStub(2) .WithMatchedBack(10, 1.5); var orc3 = new OrderRunnerChangeStub(3) .WithMatchedLay(11, 6.2); var orc4 = new OrderRunnerChangeStub(4) .WithMatchedBack(8, 2) .WithMatchedLay(8.8, 3); var oc = new OrderChangeStub() .WithOrderRunnerChange(orc1) .WithOrderRunnerChange(orc2) .WithOrderRunnerChange(orc3) .WithOrderRunnerChange(orc4); _market.OnChange(_change.WithOrderChange(oc).Build()); Assert.Equal(33.18, _market.Runners[1].Profit); Assert.Equal(9.71, _market.Runners[2].Profit); Assert.Equal(-73.49, _market.Runners[3].Profit); Assert.Equal(-15.69, _market.Runners[4].Profit); }
public void DoNotProcessOrderChangeForWrongMarket() { var orc = new OrderRunnerChangeStub(1).WithMatchedBack(2.5, 10.99); var oc = new OrderChangeStub("WrongMarketId").WithOrderRunnerChange(orc); var c = _change.WithOrderChange(oc).Build(); _market.OnChange(c); Assert.Empty(_market.Runners); }
public void ProcessOrderChange() { var orc = new OrderRunnerChangeStub() .WithMatchedBack(3.5, 10.99); var oc = new OrderChangeStub() .WithOrderRunnerChange(orc); _market.OnChange(_change.WithOrderChange(oc).Build()); Assert.Equal(-10.99, _market.Runners[12345].IfLose); }
public void HandleNullSelectionIdOnOrderChange() { var orc = new OrderRunnerChangeStub() .WithMatchedBack(3.5, 10.99); orc.SelectionId = null; var oc = new OrderChangeStub() .WithOrderRunnerChange(orc); _market.OnChange(_change.WithOrderChange(oc).Build()); Assert.Empty(_market.Runners); }
public async Task AdjustBankForMarketLiability(double bank, double liability) { var rc = new RunnerChangeStub().WithBestAvailableToBack(0, 2.5, 2.99); var mc = new MarketChangeStub().WithTotalMatched(10).WithRunnerChange(rc); _subscription.WithMarketChange(mc); var orc = new OrderRunnerChangeStub().WithUnmatchedBack(2.5, liability); var oc = new OrderChangeStub().WithOrderRunnerChange(orc); _subscription.WithOrderChange(oc); _subscription.WithMarketChange(mc); _trader.AddStrategy(new StrategySpy()); await _trader.TradeMarket("1.2345", bank, default); Assert.Equal(Math.Round((bank - Math.Round(liability, 2)) / 2, 2), _strategy.Stake); }
public void CalculateTotalLiability(double size) { var orc1 = new OrderRunnerChangeStub(1) .WithMatchedBack(3.5, 10.99); var orc2 = new OrderRunnerChangeStub(2) .WithMatchedBack(10, 1.5) .WithMatchedLay(9.5, 20.01) .WithUnmatchedBack(11, size); var oc = new OrderChangeStub() .WithOrderRunnerChange(orc1) .WithOrderRunnerChange(orc2); _market.OnChange(_change.WithOrderChange(oc).Build()); Assert.Equal(45.99, _market.Runners[1].Profit); Assert.Equal(-167.58, _market.Runners[2].Profit); var expected = -167.58 - Math.Round(size, 2); Assert.Equal(Math.Round(expected, 2), _market.Liability); }