private static void SendRefreshCancelAssert(Broker broker) { var configStore = new JsonConfigStore(ConfigPath, new List <IConfigValidator>()); var brokerConfig = configStore.Config.Brokers.First(x => x.Broker == broker); var router = new BrokerAdapterRouter(new List <IBrokerAdapter> { new Bitflyer.BrokerAdapter(new RestClient(), configStore), new Coincheck.BrokerAdapter(new RestClient(), configStore), new Quoine.BrokerAdapter(new RestClient(), configStore) }); var quotes = router.FetchQuotes(broker); var bestAsk = quotes.Min(x => x.Price); var targetAsk = bestAsk - 50000; var order = new Order { Broker = broker, Size = 0.01m, Price = targetAsk, Side = OrderSide.Buy, CashMarginType = brokerConfig.CashMarginType, LeverageLevel = brokerConfig.LeverageLevel }; Debug.WriteLine(order); Assert.AreEqual(OrderStatus.PendingNew, order.Status); Assert.AreEqual(null, order.BrokerOrderId); router.Send(order); Debug.WriteLine("Sent the order."); Debug.WriteLine(order); Assert.AreEqual(OrderStatus.New, order.Status); Assert.IsTrue(order.BrokerOrderId != null); Assert.IsTrue(!order.BrokerOrderId.IsNullOrEmpty()); var lastUpdated = order.LastUpdated; while (true) { Debug.WriteLine("Checking if order is refreshed."); Thread.Sleep(500); router.Refresh(order); Debug.WriteLine("Refreshed."); Debug.WriteLine(order); if (lastUpdated != order.LastUpdated) { break; } Debug.WriteLine("Not refreshed yet."); } Assert.AreEqual(OrderStatus.New, order.Status); router.Cancel(order); Debug.WriteLine("Canceled."); Debug.WriteLine(order); Assert.AreEqual(OrderStatus.Canceled, order.Status); }
public void Init() { _baZb = new Mock <IBrokerAdapter>(); _baZb.Setup(x => x.Broker).Returns(Broker.Zb); _baZb.Setup(x => x.Send(It.IsAny <Order>())); _baHpx = new Mock <IBrokerAdapter>(); _baHpx.Setup(x => x.Broker).Returns(Broker.Hpx); _baHpx.Setup(x => x.Send(It.IsAny <Order>())); _brokerAdapters = new List <IBrokerAdapter>() { _baZb.Object, _baHpx.Object }; _target = new BrokerAdapterRouter(_brokerAdapters); }
public void Init() { _baBitflyer = new Mock <IBrokerAdapter>(); _baBitflyer.Setup(x => x.Broker).Returns(Broker.Bitflyer); _baBitflyer.Setup(x => x.Send(It.IsAny <Order>())); _baCoincheck = new Mock <IBrokerAdapter>(); _baCoincheck.Setup(x => x.Broker).Returns(Broker.Coincheck); _baCoincheck.Setup(x => x.Send(It.IsAny <Order>())); _baQuoine = new Mock <IBrokerAdapter>(); _baQuoine.Setup(x => x.Broker).Returns(Broker.Quoine); _baQuoine.Setup(x => x.Send(It.IsAny <Order>())); _brokerAdapters = new List <IBrokerAdapter>() { _baBitflyer.Object, _baCoincheck.Object, _baQuoine.Object }; _target = new BrokerAdapterRouter(_brokerAdapters); }