public void CancelPartiallyFilled() { MatchingEngine engine = new MatchingEngine(); engine.InitOrderBook(); Order order1 = new Order(OrderSide.SELL, 1000, 10, OrderType.GFD, "order1"); Order order2 = new Order(OrderSide.BUY, 1100, 20, OrderType.GFD, "order2"); Order order3 = new Order(OrderSide.BUY, 1100, 20, OrderType.GFD, "order3"); Order order4 = new Order(OrderSide.SELL, 900, 60, OrderType.GFD, "order4"); engine.SendOrder(order1); engine.SendOrder(order2); engine.CancelOrder("order2"); engine.SendOrder(order3); engine.MaxBid.Should().Be(1100); engine.SendOrder(order4); order1.Status.Should().Be(OrderStatus.FILLED); order2.Status.Should().Be(OrderStatus.CANCELED); engine.OrderEntries[1100].TotalQuantity.Should().Be(0); engine.OrderEntries[1100].Orders.Count.Should().Be(0); engine.MaxBid.Should().Be(engine.MinPrice); engine.MinAsk.Should().Be(900); engine.OrderEntries[900].TotalQuantity.Should().Be(40); order2.Status.Should().Be(OrderStatus.CANCELED); order2.FilledQuantity.Should().Be(10); order3.Status.Should().Be(OrderStatus.FILLED); order4.Status.Should().Be(OrderStatus.ON_MARKET); order4.FilledQuantity.Should().Be(20); }
public MobiledgeXIntegration() { pIntegration = new PlatformIntegration(); me = new MatchingEngine(); // Set the platform specific way to get SIM carrier information. me.carrierInfo = pIntegration; }
public void Dispose() { if (matchingEngine != null) { matchingEngine.Dispose(); matchingEngine = null; } }
public MobiledgeXIntegration() { // Set the platform specific way to get SIM carrier information. pIntegration = new PlatformIntegration(); // Platform integration needs to initialize first: me = new MatchingEngine(pIntegration.CarrierInfo, pIntegration.NetInterface, pIntegration.UniqueID); // Optional NetTesting. netTest = new NetTest(me); }
public OrderBookActor(string tickerSymbol, MatchingEngine matchingEngine, ITradeEventPublisher publisher, ITradeEventSubscriptionManager subscriptionManager, IActorRef confirmationActor) { TickerSymbol = tickerSymbol; _matchingEngine = matchingEngine ?? CreateDefaultMatchingEngine(tickerSymbol, _log); _publisher = publisher; _confirmationActor = confirmationActor; _subscriptionManager = subscriptionManager; Recovers(); Commands(); }
public Meeting GetPair(string userMail) { var user = UserTable.Get(userMail); var all = UserTable.GetAll() .Where(u => !u.Email.Equals(user.Email, StringComparison.CurrentCultureIgnoreCase)).ToArray(); var result = MatchingEngine.GetPair(user, all); return(new Meeting { Date = DateTime.Today, FirstUserId = userMail, SecondUserId = result.Item2 }); }
async Task <bool> DoFindCloudlet() { bool ok = false; MatchingEngine dme = mexSample.dme; VerifyLocationReply reply = null; try { var deviceSourcedLocation = await LocationService.RetrieveLocation(); if (deviceSourcedLocation == null) { Debug.Log("VerifyLocation must have a device sourced location to send to DME."); return(false); } Debug.Log("Device sourced location: Lat: " + deviceSourcedLocation.latitude + " Long: " + deviceSourcedLocation.longitude); var verifyLocationRequest = dme.CreateVerifyLocationRequest( mexSample.carrierName, // TODO: carrierName is the current carrier string, and must be provided by the app. deviceSourcedLocation); reply = await dme.VerifyLocation(mexSample.host, mexSample.port, verifyLocationRequest); statusContainer.Post("VerifyLocation Reply mobile tower status: " + reply.tower_status.ToString()); if (reply.tower_status.Equals(FindCloudletReply.FindStatus.FIND_FOUND.ToString())) { ok = true; } } catch (System.Net.WebException we) { Console.WriteLine(we.StackTrace); statusContainer.Post(we.Source + ", WebException: " + we.Message); statusContainer.Post(we.StackTrace); } finally { if (reply != null) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(VerifyLocationReply)); MemoryStream ms = new MemoryStream(); serializer.WriteObject(ms, reply); string jsonStr = Util.StreamToString(ms); statusContainer.Post("VeryfyLocation Reply: " + jsonStr); } } return(ok); }
public void Test3() { MatchingEngine engine = new MatchingEngine(); UInt32 price = 1000; engine.InitOrderBook(); Order order1 = new Order(OrderSide.BUY, price, 10, OrderType.IOC, "order1"); engine.SendOrder(order1); engine.OrderDict.Keys.Should().Contain("order1"); engine.OrderEntries[price].TotalQuantity.Should().Be(0); engine.OrderEntries[price].Orders.Count.Should().Be(0); order1.Status.Should().Be(OrderStatus.CANCELED); engine.MaxBid.Should().Be(1); }
/// <summary> /// Constructor for MobiledgeXIntegration. This class has functions that wrap DistributedMatchEngine functions for ease of use /// </summary> public MobiledgeXIntegration(string orgName, string appName, string appVers, string developerAuthToken = "") { this.orgName = orgName; this.appVers = appVers; this.appName = appName; this.developerAuthToken = developerAuthToken; // Set the platform specific way to get SIM carrier information. pIntegration = new PlatformIntegration(); matchingEngine = new MatchingEngine(pIntegration.CarrierInfo, pIntegration.NetInterface, pIntegration.UniqueID, pIntegration.DeviceInfo); melMessaging = new MelMessaging(appName); matchingEngine.SetMelMessaging(melMessaging); }
public void CancelFilledOrderShouldFail() { MatchingEngine engine = new MatchingEngine(); engine.InitOrderBook(); Order order1 = new Order(OrderSide.BUY, 1000, 10, OrderType.GFD, "order1"); Order order2 = new Order(OrderSide.SELL, 1000, 10, OrderType.GFD, "order2"); engine.SendOrder(order1); engine.SendOrder(order2); engine.CancelOrder("order2"); order1.Status.Should().Be(OrderStatus.FILLED); order2.Status.Should().Be(OrderStatus.FILLED); engine.OrderEntries[1000].TotalQuantity.Should().Be(0); }
async Task <bool> DoRegisterClient() { bool ok = false; MatchingEngine dme = mexSample.dme; RegisterClientReply reply = null; try { var registerClientRequest = dme.CreateRegisterClientRequest( mexSample.carrierName, mexSample.orgName, mexSample.appName, mexSample.appVers, mexSample.authToken); reply = await dme.RegisterClient(mexSample.host, mexSample.port, registerClientRequest); // the dme object stores the session tokens, so the only thing to do here is // inspect parts of the JSON registration status and retry: if (reply.status != ReplyStatus.RS_SUCCESS) { statusContainer.Post("RegisterClient did not succeed!"); } else { ok = true; } } catch (System.Net.WebException we) { Console.WriteLine(we.StackTrace); statusContainer.Post(we.Source + ", WebException: " + we.Message); statusContainer.Post(we.StackTrace); } finally { if (reply != null) { statusContainer.Post( "RegisterClient Button results:" + " Status: " + reply.status + " SessionCookie: " + reply.session_cookie + " TokenServerURI: " + reply.token_server_uri ); } } return(ok); }
public MobiledgeXIntegration() { // Set the platform specific way to get SIM carrier information. pIntegration = new PlatformIntegration(); // The following is to allow Get{TCP, TLS, UDP}Connection APIs to return the configured // edge network path to your MobiledgeX AppInsts. Other connections will use the system // default network route. NetInterface netInterface = new SimpleNetInterface(pIntegration.NetworkInterfaceName); // Platform integration needs to initialize first: me = new MatchingEngine(pIntegration, netInterface); // Optional NetTesting. netTest = new NetTest(me); }
/// <summary> /// Constructor for MobiledgeXIntegration. This class has functions that wrap DistributedMatchEngine functions for ease of use /// </summary> public MobiledgeXIntegration(CarrierInfo carrierInfo = null, NetInterface netInterface = null, UniqueID uniqueId = null, DeviceInfo deviceInfo = null) { ConfigureMobiledgeXSettings(); // Set the platform specific way to get SIM carrier information. pIntegration = new PlatformIntegration(); // Optionally override each interface: matchingEngine = new MatchingEngine( carrierInfo == null ? pIntegration.CarrierInfo : carrierInfo, netInterface == null ? pIntegration.NetInterface : netInterface, uniqueId == null ? pIntegration.UniqueID : uniqueId, deviceInfo == null ? pIntegration.DeviceInfo : deviceInfo); melMessaging = new MelMessaging(appName); matchingEngine.SetMelMessaging(melMessaging); }
public void Test2() { MatchingEngine engine = new MatchingEngine(); UInt32 price = 1000; engine.InitOrderBook(); engine.SendOrder(new Order(OrderSide.BUY,price,10,OrderType.GFD,"order1")); engine.SendOrder(new Order(OrderSide.BUY,price,20,OrderType.GFD,"order2")); engine.OrderDict.Keys.Should().Contain("order1"); engine.OrderDict.Keys.Should().Contain("order2"); engine.OrderEntries[price].TotalQuantity.Should().Be(30); engine.OrderEntries[price].Orders.Count.Should().Be(2); engine.MaxBid.Should().Be(1000); }
private void Recovers() { Recover <SnapshotOffer>(offer => { if (offer.Snapshot is OrderbookSnapshot orderBook) { _matchingEngine = MatchingEngine.FromSnapshot(orderBook, _log); } }); Recover <Bid>(b => { _matchingEngine.WithBid(b); }); Recover <Ask>(a => { _matchingEngine.WithAsk(a); }); // Fill and Match can't modify the state of the MatchingEngine. Recover <Match>(m => { }); Recover <Fill>(f => { }); }
static void Main(String[] args) { /* Enter your code here. Read input using Console.ReadLine. Print output using Console.WriteLine. Your class should be named Solution */ var engine = new MatchingEngine(); /*var argsList = new List<string>(); * * while (true) * { * var arg = Console.ReadLine(); * * if (arg == null) * break; * * argsList.Add(arg); * }*/ foreach (var str in args) { var order = ProcessInputLine(str); if (order == null) { engine.PrintStatus(); } else if (order.TradeStatus == TradeStatus.Active) { engine.AddOrder(order); engine.Trade(); } else if (order.TradeStatus == TradeStatus.Modify) { engine.ModifyOrder(order); engine.Trade(); } else if (order.TradeStatus == TradeStatus.Cancelled) { engine.CancelOrder(order); } else if (order.OperationType == OperationType.None) { continue; } } }
public void SellOrderShouldNotMatchCanceledBuyOrder() { MatchingEngine engine = new MatchingEngine(); engine.InitOrderBook(); Order order1 = new Order(OrderSide.BUY, 1000, 10, OrderType.GFD, "order1"); engine.SendOrder(order1); engine.CancelOrder("order1"); engine.OrderDict.Keys.Should().Contain("order1"); engine.OrderEntries[1000].TotalQuantity.Should().Be(0); engine.OrderEntries[1000].Orders.Count.Should().Be(1); engine.MaxBid.Should().Be(1); order1.Status.Should().Be(OrderStatus.CANCELED); }
public void Start(QueueConfig consumerQueuConfig, QueueConfig producerQueueConfig, string filePath, ITimeProvider timeProvider, int quoteCurrencyDecimalPlances, int stepSize) { _outboundChannel = Channel.CreateBounded <byte[]>(new BoundedChannelOptions(100000) { FullMode = BoundedChannelFullMode.Wait, SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = false }); _outboundChannelReader = _outboundChannel.Reader; _outboundChannelWritter = _outboundChannel.Writer; var tradeListner = new TradeListener(_outboundChannelWritter, timeProvider); _matchingEngine = new MatchingEngine(quoteCurrencyDecimalPlances, stepSize, tradeListner, new TimeProvider()); _inboundChannel = Channel.CreateBounded <Message>(new BoundedChannelOptions(100000) { FullMode = BoundedChannelFullMode.Wait, SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = false }); _inboundChannelReader = _inboundChannel.Reader; _inboundChannelWritter = _inboundChannel.Writer; _outboundQueueChannel = Channel.CreateBounded <byte[]>(new BoundedChannelOptions(100000) { FullMode = BoundedChannelFullMode.Wait, SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = false }); _outboundQueueChannelReader = _outboundQueueChannel.Reader; _outboundQueueChannelWritter = _outboundQueueChannel.Writer; _outboundFileChannel = Channel.CreateBounded <byte[]>(new BoundedChannelOptions(100000) { FullMode = BoundedChannelFullMode.Wait, SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = false }); _outboundFileChannelReader = _outboundFileChannel.Reader; _outboundFileChannelWritter = _outboundFileChannel.Writer; _tradeLogger = new TradeLogger(filePath); _queueProducer = new QueueProducer(producerQueueConfig.ExchangeName, producerQueueConfig.ExchangeType, producerQueueConfig.QueueName, producerQueueConfig.RoutingKey, producerQueueConfig.HostName, producerQueueConfig.Vhost, producerQueueConfig.User, producerQueueConfig.Password); _queueConsumer = new QueueConsumer(consumerQueuConfig.ExchangeName, consumerQueuConfig.ExchangeType, consumerQueuConfig.QueueName, consumerQueuConfig.RoutingKey, consumerQueuConfig.HostName, consumerQueuConfig.Vhost, consumerQueuConfig.User, consumerQueuConfig.Password); _inboundQueueProcessor = Task.Factory.StartNew(QueueConsumer); _inboundChannelProcessor = Task.Factory.StartNew(async() => await InboundMessageProcessor()); _outboundChannelProcessor = Task.Factory.StartNew(async() => await OutboundMessageProcessor()); _outboundQueueChannelProcessor = Task.Factory.StartNew(async() => await OutboundQueueMessageProcessor()); _outboundFileChannelProcessor = Task.Factory.StartNew(async() => await OutboundFileMessageProcessor()); }
public void Test4() { MatchingEngine engine = new MatchingEngine(); engine.InitOrderBook(); Order order1 = new Order(OrderSide.BUY, 1000, 10, OrderType.GFD, "order1"); Order order2 = new Order(OrderSide.BUY, 1001, 20, OrderType.GFD, "order2"); engine.SendOrder(order1); engine.SendOrder(order2); engine.OrderDict.Keys.Should().Contain("order1"); engine.OrderEntries[1000].TotalQuantity.Should().Be(10); engine.OrderEntries[1000].Orders.Count.Should().Be(1); engine.OrderEntries[1001].TotalQuantity.Should().Be(20); engine.OrderEntries[1001].Orders.Count.Should().Be(1); order1.Status.Should().Be(OrderStatus.ON_MARKET); order2.Status.Should().Be(OrderStatus.ON_MARKET); engine.MaxBid.Should().Be(1001); }
public void ShouldRecreateFromNullOrderbookSnapshot() { var snapshot = new OrderbookSnapshot(TickerSymbol, DateTimeOffset.Now, 0.0d, 0.0d, null, null); var engine = MatchingEngine.FromSnapshot(snapshot); var ask = new Ask(TickerSymbol, "foo", 12.0m, 5.0, DateTimeOffset.Now); // bid is lower than ask - no trades var bid = new Bid(TickerSymbol, "bar", 11.0m, 4.0, DateTimeOffset.Now); // verify that engine still works normally var bidEvents = engine.WithBid(bid); var askEvents = engine.WithAsk(ask); askEvents.Should().BeEmpty(); bidEvents.Should().BeEmpty(); engine.AskTrades.Count.Should().Be(1); engine.BidTrades.Count.Should().Be(1); }
public static List <List <Message> > MatchOperationFullData(string path) { var message = new Message(); var resultPair = new List <List <Message> >(); var clentData = ReadFile(path); var SGdataPath = Environment.CurrentDirectory + "\\Data\\SgProposedDataforSampleData\\"; for (int i = 1; i < 18; i++) { var sgMessage = ReadFile(SGdataPath + (i).ToString() + "_message.txt"); var result = MatchingEngine.Match(clentData, sgMessage); if (result == "Matched" || result == "Mismatch") { resultPair.Add( new List <Message> { sgMessage, clentData }); } } return(resultPair); }
async Task <bool> DoFindCloudlet() { bool ok = false; MatchingEngine dme = mexSample.dme; FindCloudletReply reply = null; try { var deviceSourcedLocation = await LocationService.RetrieveLocation(); if (deviceSourcedLocation == null) { Debug.Log("FindCloudlet must have a device sourced location to send."); return(false); } Debug.Log("Device sourced location: Lat: " + deviceSourcedLocation.latitude + " Long: " + deviceSourcedLocation.longitude); var findCloudletRequest = dme.CreateFindCloudletRequest( mexSample.carrierName, mexSample.devName, mexSample.appName, mexSample.appVers, deviceSourcedLocation); if (findCloudletRequest == null) { Debug.Log("Failed to create request."); ok = false; return(ok); } reply = await dme.FindCloudlet(mexSample.host, mexSample.port, findCloudletRequest); statusContainer.Post("FindCloudlet Reply status: " + reply.status); } catch (System.Net.WebException we) { Console.WriteLine(we.StackTrace); statusContainer.Post(we.Source + ", WebException: " + we.Message); statusContainer.Post(we.StackTrace); } finally { if (reply != null) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(FindCloudletReply)); MemoryStream ms = new MemoryStream(); serializer.WriteObject(ms, reply); string jsonStr = Util.StreamToString(ms); statusContainer.Post("GPS Cloudlet location: " + jsonStr + ", fqdn: " + reply.fqdn); // The list of registered edge cloudlets that the app can use: if (reply.ports.Length == 0) { statusContainer.Post("There are no app ports for this app's edge cloudlets."); } else { statusContainer.Post("Cloudlet app ports:"); foreach (var appPort in reply.ports) { statusContainer.Post( "Protocol: " + appPort.proto + ", internal_port: " + appPort.internal_port + ", public_port: " + appPort.public_port + ", path_prefix: " + appPort.path_prefix + ", fqdn_prefix: " + appPort.fqdn_prefix ); } } } } return(ok); }