Example #1
0
 public OrderService(
     IOrderHistoryRepository orderHistoryRepository,
     IOrderQueue orderQueue)
 {
     this.orderHistoryRepository = orderHistoryRepository;
     this.orderQueue             = orderQueue;
 }
Example #2
0
 public AccountTab(IAccountHandlerInterface AccountHandler, ITradeHandlerInterface TradeHandler, IOrderQueue OrderQueueHandler)
 {
     InitializeComponent();
     m_AccountHandler     = AccountHandler;
     m_oTradeHandler      = TradeHandler;
     m_oOrderQueueHandler = OrderQueueHandler;
     //this.KeyDown += AccountTab_KeyDown;
     typeof(TableLayoutPanel).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(tlp_Account, true, null);
 }
        public async Task <IActionResult> Post([FromServices] IOrderQueue orderQueue, [FromBody] Order order)
        {
            await Task.Delay(500).ContinueWith(task =>
            {
                _logger.LogInformation($"Order (Id: {order.ItemId}) is placed successfully for customer: {order.CustomerId}");
                orderQueue.EnQueue(order);
            });

            return(Ok());
        }
Example #4
0
 public OrderQueueService(IOrderQueue orderQueue, IOrderCoordinator orderCoordinator, IContactRepository contactRepository)
 {
     if (orderQueue == null)
     {
         throw new ArgumentNullException("orderQueue");
     }
     _orderQueue = orderQueue;
     if (orderCoordinator == null)
     {
         throw new ArgumentNullException("orderCoordinator");
     }
     _orderCoordinator = orderCoordinator;
     if (contactRepository == null)
     {
         throw new ArgumentNullException("contactRepository");
     }
     _contactRepository = contactRepository;
 }
        public void MatchOrders(ref IOrderQueue orders)
        {
            Console.WriteLine("MatchOrders started.");
            List<IOrder> buyOrders = orders.Where(x => x.Direction == OrderDirection.Buy && x.Status != OrderStatus.Filled).ToList();
            List<IOrder> sortedBuyOrders = buyOrders.Any(x => x.Direction == OrderDirection.Buy) ? buyOrders.OrderBy(x => x.Price.Amount).ThenBy(x => x.CreatedTime).ToList() : new List<IOrder>();

            List<IOrder> sellOrders = orders.Where(x => x.Direction == OrderDirection.Sell && x.Status != OrderStatus.Filled).ToList();
            List<IOrder> sortedSellOrders = sellOrders.Any(x => x.Direction == OrderDirection.Sell) ? sellOrders.OrderBy(x => x.Price.Amount).ThenBy(x => x.CreatedTime).ToList() : new List<IOrder>();

            foreach (Order buyOrder in sortedBuyOrders)
            {
                List<IOrder> sellOrderCandidates = sortedSellOrders.Where(x => Equals(x.Item, buyOrder.Item)).ToList();

                int buyNotFilled = buyOrder.Size - buyOrder.FilledSize;
                Debug.Assert(buyNotFilled > 0);

                foreach (Order sellCandidate in sellOrderCandidates)
                {
                    if (sellCandidate.Price.Amount <= buyOrder.Price.Amount)
                    {
                        int buyAmountFilled = Math.Min(buyNotFilled, sellCandidate.Size);

                        buyOrder.AddTrade(new Trade(_tradeCounter++, DateTime.Now, sellCandidate.CreatedBy, buyOrder.Item, buyAmountFilled, sellCandidate.Price.Amount, TradeState.Executed));
                        sellCandidate.AddTrade(new Trade(_tradeCounter++, DateTime.Now, buyOrder.CreatedBy, buyOrder.Item, buyAmountFilled, sellCandidate.Price.Amount, TradeState.Executed));

                        buyNotFilled -= buyAmountFilled;

                        if (buyNotFilled == 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Example #6
0
        public Exchange(IOrderMatchingStrategy matchingStrategy, IOrderQueue orderQueue, IOrderQueue tempOrderQueue, int id, string code, string name, bool asyncMatching, bool strictQueueingOrder)
        {
            _matchingStrategy = matchingStrategy;
            _orderQueue = orderQueue;
            _tempOrderQueue = tempOrderQueue;

            Id = id;
            Code = code;
            Name = name;

            _strictQueueingOrder = strictQueueingOrder;
            _asyncMatching = asyncMatching;

            if (asyncMatching)
            {
                _matchingThreadStarted = new ManualResetEvent(false);

                _matchingThread = new Thread(MatchingThread);
                _matchingThread.IsBackground = true;
                _matchingThread.Start();
                _matchingThreadStarted.WaitOne();
            }
        }
Example #7
0
 public OrderHandler(IOrderQueue orderQueue, IOrderRepository orderRepository, IOrderRecordFactory orderRecordFactory)
 {
     this.orderQueue         = orderQueue;
     this.orderRepository    = orderRepository;
     this.orderRecordFactory = orderRecordFactory;
 }
Example #8
0
        public Account_Trade(IAccountHandlerInterface AccountHandler, ITradeHandlerInterface TradeHandler, IOrderQueue OrderHandler)
        {
            InitializeComponent();
            this.Dock            = DockStyle.Fill;
            m_oAh                = AccountHandler;
            m_oTradeHandler      = TradeHandler;
            m_oOrderQueueHandler = OrderHandler;
            //comboBox_Symbols
            AutoCompleteStringCollection list = new AutoCompleteStringCollection();

            list.AddRange(ImperaturGlobal.Instruments.Select(i => i.Symbol).ToArray());
            comboBox_Symbols.AutoCompleteMode         = AutoCompleteMode.Suggest;
            comboBox_Symbols.AutoCompleteSource       = AutoCompleteSource.CustomSource;
            comboBox_Symbols.AutoCompleteCustomSource = list;
            comboBox_Symbols.DataSource            = ImperaturGlobal.Instruments.Select(i => i.Symbol).ToList();
            comboBox_Symbols.Text                  = "";
            comboBox_Symbols.SelectedIndexChanged += ComboBox_Symbols_SelectedIndexChanged;
            this.textBox_Quantity.KeyDown         += TextBox_Quantity_KeyDown;
            tableLayoutPanel_Graph.Visible         = false;
            m_oGraphSettingDays = 7;

            m_oDateRanges    = new List <Tuple <int, string, bool> >();
            m_oIndicator     = new List <Tuple <TA_Indicator, string, bool> >();
            m_oGraphSettings = new List <Tuple <TA_Settings, string, bool> >();

            //DateRanges
            m_oDateRanges.Add(new Tuple <int, string, bool>(1, "1 day", false));
            m_oDateRanges.Add(new Tuple <int, string, bool>(3, "3 days", false));
            m_oDateRanges.Add(new Tuple <int, string, bool>(7, "7 days", false));
            m_oDateRanges.Add(new Tuple <int, string, bool>(90, "3 months", false));
            m_oDateRanges.Add(new Tuple <int, string, bool>(365, "1 year", false));

            //Indicators
            foreach (TA_Indicator indicator in Enum.GetValues(typeof(TA_Indicator)))
            {
                m_oIndicator.Add(new Tuple <TA_Indicator, string, bool>(indicator, indicator.ToString(), false));
            }

            foreach (TA_Settings setting in Enum.GetValues(typeof(TA_Settings)))
            {
                m_oGraphSettings.Add(new Tuple <TA_Settings, string, bool>(setting, setting.ToString(), false));
            }
            foreach (var dr in m_oDateRanges)
            {
                comboBox_daterange.Items.Add(dr.Item2);
            }
            comboBox_daterange.SelectedIndexChanged += ComboBox_daterange_SelectedIndexChanged;

            foreach (var dr in m_oIndicator)
            {
                checkBoxComboBox_TA.Items.Add(dr.Item2);
            }

            checkBoxComboBox_TA.CheckBoxCheckedChanged += CheckBoxComboBox_TA_CheckBoxCheckedChanged;
            //checkBoxComboBox_TA.DropDownClosed += CheckBoxComboBox_TA_DropDownClosed;
            foreach (var dr in m_oGraphSettings)
            {
                checkBoxComboBox_Settings.Items.Add(dr.Item2);
            }
            checkBoxComboBox_Settings.CheckBoxCheckedChanged += CheckBoxComboBox_Settings_CheckBoxCheckedChanged;
            SetDateRangeToNumber(7);
        }
Example #9
0
 public Account_MainInfo(IOrderQueue OrderQueueHandler)
 {
     InitializeComponent();
     m_oOrderQueueHandler = OrderQueueHandler;
 }
Example #10
0
        private void CreateImperaturMarket(ImperaturData SystemData)
        {
            m_oImperaturData = SystemData;

            CreateSystemNotification("Starting the initializing sequence");
            ImperaturGlobal.GetLogWithDirectory(m_oImperaturData.SystemDirectory).Info("Starting the initialize sequence");
            CreateSystemNotification("Creating cache objects");
            ImperaturGlobal.Initialize(m_oImperaturData, InitiateNinjectKernel(), null);


            List <account.AccountCacheType> BusinessAccounts = new List <account.AccountCacheType>();
            List <IAccountInterface>        oLAB             = new List <IAccountInterface>();

            CreateSystemNotification("Loading accounts");
            if (GetAccountHandler().Accounts().Where(a => a.GetAccountType().Equals(account.AccountType.Bank)).Count() == 0)
            {
                //create internalbankaccount for balance transactions
                //start by create the bankaccount
                oLAB.Add(
                    ImperaturGlobal.Kernel.Get <IAccountInterface>(
                        new Ninject.Parameters.ConstructorArgument("Customer", (object)null),
                        new Ninject.Parameters.ConstructorArgument("AccountType", AccountType.Bank),
                        new Ninject.Parameters.ConstructorArgument("AccountName", "INTERNALBANK")
                        )
                    );
            }
            if (GetAccountHandler().Accounts().Where(a => a.GetAccountType().Equals(account.AccountType.House)).Count() == 0)
            {
                //create internalbankaccount for balance transactions
                //start by create the bankaccount
                oLAB.Add(
                    ImperaturGlobal.Kernel.Get <IAccountInterface>(
                        new Ninject.Parameters.ConstructorArgument("Customer", (object)null),
                        new Ninject.Parameters.ConstructorArgument("AccountType", AccountType.House),
                        new Ninject.Parameters.ConstructorArgument("AccountName", "INTERNALHOUSE")
                        )
                    );
            }
            if (oLAB.Count() > 0)
            {
                GetAccountHandler().CreateAccount(oLAB);
            }

            //add all business accounts to cache
            BusinessAccounts = GetAccountHandler().Accounts().Where(a => !a.GetAccountType().Equals(account.AccountType.Customer)).
                               Select(b =>
                                      new account.AccountCacheType
            {
                AccountType = b.GetAccountType(),
                Identifier  = b.Identifier
            }).ToList();

            CreateSystemNotification("Initializing business accounts");
            ImperaturGlobal.InitializeBusinessAccount(BusinessAccounts);

            CreateSystemNotification("Loading instruments and qoutes");
            ImperaturGlobal.Quotes = GetTradeHandler().GetQuotes();

            CreateSystemNotification("Setting events");
            m_oQuoteTimer          = new System.Timers.Timer();
            m_oQuoteTimer.Elapsed += M_oQuoteTimer_Elapsed;
            m_oQuoteTimer.Interval = 1000 * 60 * Convert.ToInt32(m_oImperaturData.QuoteRefreshTime);
            m_oQuoteTimer.Enabled  = true;

            m_oDisplayCurrency = ImperaturGlobal.Kernel.Get <ICurrency>(new Ninject.Parameters.ConstructorArgument("CurrencyCode", m_oImperaturData.SystemCurrency));
            m_oTradeHandler.QuoteUpdateEvent += M_oTradeHandler_QuoteUpdateEvent;

            m_oOrderQueue      = null;
            m_oTradeAutomation = ImperaturGlobal.Kernel.Get <ITradeAutomation>(new Ninject.Parameters.ConstructorArgument("AccountHandler", GetAccountHandler()));

            m_oTradeAutomation.SystemNotificationEvent += M_oTradeAutomation_SystemNotificationEvent;
            OrderQueue.QueueMaintence(m_oAccountHandler);
            ImperaturGlobal.GetLog().Info("End of the initialize sequence");
            m_oAccountHandler.GetProfitPerForecast();
        }
Example #11
0
 public Exchange(IOrderMatchingStrategy matchingStrategy, IOrderQueue orderQueue, IOrderQueue tempOrderQueue, int id, string code, string name, bool asyncMatching)
     : this(matchingStrategy, orderQueue, tempOrderQueue, id, code, name, asyncMatching, true)
 {
 }
 public static void SetQueueType(OrderQueueType type)
 {
     _orderQueue = OrderQueueFactory.Create(type);
 }
Example #13
0
 public void MatchOrders(ref IOrderQueue orders)
 {
     Thread.Sleep(200);
 }
 public EmailNotificationHostedService(ILogger <EmailNotificationHostedService> logger,
                                       IOrderQueue queue)
 {
     _logger = logger;
     _queue  = queue;
 }