Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var ioc = MockEnvironmentCreator.Create();

            var trader = ioc.RegisterTrader("*****@*****.**");

            var srvOrderRegistrator = ioc.GetObject <SrvOrdersRegistrator>();

            ioc.DepositAcount(trader.Id, "EUR", 10000);

            var limitOrder = LimitOrder.Create(trader.Id, "EURUSD", "USD", OrderAction.Sell, 1000, 1.55555);

            srvOrderRegistrator.RegisterTradeOrderAsync(limitOrder).Wait();

            var marketOrder = MarketOrder.Create(trader.Id, "EURUSD", "USD", OrderAction.Buy, 1000);

            srvOrderRegistrator.RegisterTradeOrderAsync(marketOrder).Wait();

            var eurBalance = ioc.GetBalance(trader.Id, "EUR");
            var usdBalance = ioc.GetBalance(trader.Id, "USD");

            Console.WriteLine("EUR Balance " + eurBalance);
            Console.WriteLine("USD Balance " + usdBalance);

            Console.ReadLine();
        }
Exemplo n.º 2
0
        public void Text_Exchange_USDJPY()
        {
            var ioc = MockEnvironmentCreator.Create();

            var trader1 = ioc.RegisterTrader("*****@*****.**");
            var trader2 = ioc.RegisterTrader("*****@*****.**");

            var srvOrderRegistrator = ioc.GetObject <SrvOrdersRegistrator>();

            ioc.DepositAcount(trader1.Id, "USD", 10000);
            ioc.DepositAcount(trader2.Id, "EUR", 10000);

            var limitOrder = LimitOrder.Create(trader1.Id, "EURUSD", "USD", OrderAction.Sell, 1000, 2);

            srvOrderRegistrator.RegisterTradeOrderAsync(limitOrder).Wait();

            var marketOrder = MarketOrder.Create(trader2.Id, "EURUSD", "USD", OrderAction.Buy, 1000);

            srvOrderRegistrator.RegisterTradeOrderAsync(marketOrder).Wait();

            var eurBalanceTrader1 = ioc.GetBalance(trader1.Id, "EUR");
            var usdBalanceTrader1 = ioc.GetBalance(trader1.Id, "USD");

            var eurBalanceTrader2 = ioc.GetBalance(trader2.Id, "EUR");
            var usdBalanceTrader2 = ioc.GetBalance(trader2.Id, "USD");

            Assert.AreEqual(9000, Math.Round(usdBalanceTrader1, 2));
            Assert.AreEqual(500, Math.Round(eurBalanceTrader1, 2));


            Assert.AreEqual(1000, Math.Round(usdBalanceTrader2, 2));
            Assert.AreEqual(9500, Math.Round(eurBalanceTrader2, 2));
        }
Exemplo n.º 3
0
        public async Task DoLimitOrder2(LkeHubLimitOrder2Model model)
        {
            double volume;

            try
            {
                volume = model.Volume.ParseAnyDouble();
            }
            catch (Exception)
            {
                SendMessage("#volume" + model.CurTo, Phrases.InvalidAmountFormat);
                return;
            }


            double bid;

            try
            {
                bid = model.Bid.ParseAnyDouble();
            }
            catch (Exception)
            {
                SendMessage("#lobid" + model.CurTo, Phrases.InvalidRateFormat);
                return;
            }

            double ask;

            try
            {
                ask = model.Ask.ParseAnyDouble();
            }
            catch (Exception)
            {
                SendMessage("#loask" + model.CurTo, Phrases.InvalidRateFormat);
                return;
            }

            var traderId    = GetTraderId();
            var asset       = Dependencies.AssetPairsDictionary.FindByBasedOrQuotingAsset(model.CurFrom, model.CurTo);
            var limitOrder1 = LimitOrder.Create(traderId, asset.Id, model.CurFrom, OrderAction.Sell, volume, ask);
            var limitOrder2 = LimitOrder.Create(traderId, asset.Id, model.CurFrom, OrderAction.Buy, volume, bid);

            try
            {
                await Dependencies.SrvOrdersRegistrator.RegisterLinkedLimitOrders(limitOrder1, limitOrder2);

                SendMessage("#lobid" + model.CurTo, Phrases.OrderHasBeenRegistered);
            }
            catch (Exception ex)
            {
                SendMessage("#lobid" + model.CurTo, ex.Message);
            }
        }
Exemplo n.º 4
0
        public async Task DoLimitOrder(LkeHubLimitOrderModel model)
        {
            var orderAction = model.Action == "sell" ? OrderAction.Sell : OrderAction.Buy;

            double volume;

            try
            {
                volume = model.Volume.ParseAnyDouble();
            }
            catch (Exception)
            {
                SendMessage("#volume" + model.CurTo, Phrases.InvalidAmountFormat);
                return;
            }

            double price;
            var    id = orderAction == OrderAction.Sell ? "#slr" : "#blr";

            try
            {
                price = model.Price.ParseAnyDouble();
            }
            catch (Exception)
            {
                SendMessage(id + model.CurTo, Phrases.InvalidRateFormat);
                return;
            }


            var traderId   = GetTraderId();
            var asset      = Dependencies.AssetPairsDictionary.FindByBasedOrQuotingAsset(model.CurFrom, model.CurTo);
            var limitOrder = LimitOrder.Create(traderId, asset.Id, model.CurFrom, orderAction, volume, price);

            try
            {
                await Dependencies.SrvOrdersRegistrator.RegisterTradeOrderAsync(limitOrder);

                SendMessage(id + model.CurTo, Phrases.OrderHasBeenRegistered);
            }
            catch (Exception ex)
            {
                SendMessage(id + model.CurTo, ex.Message);
            }
        }
Exemplo n.º 5
0
        public void TestBuyLimitOrder()
        {
            var ioc = MockEnvironmentCreator.Create();

            var trader = ioc.RegisterTrader("*****@*****.**");

            var srvOrderRegistrator = ioc.GetObject <SrvOrdersRegistrator>();

            ioc.DepositAcount(trader.Id, "USD", 10000);

            var limitOrder = LimitOrder.Create(trader.Id, "EURUSD", "USD", OrderAction.Buy, 1000, 1.55555);

            srvOrderRegistrator.RegisterTradeOrderAsync(limitOrder).Wait();

            var orderBook = ioc.GetObject <SrvLimitOrderBookGenerator>().GetOrderBooksAsync().Result;


            var eurUsdOrderBook = orderBook.First(itm => itm.Asset == "EURUSD");

            Assert.AreEqual(1000, eurUsdOrderBook.Items[0].Volume);
            Assert.AreEqual(1.55555, eurUsdOrderBook.Items[0].Rate);
            Assert.AreEqual(BookOrderType.Bid, eurUsdOrderBook.Items[0].Type);
        }