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(); }
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)); }
public async Task DoMarketOrder(LkeHubDealModel model) { if (model.Action != "sell" && model.Action != "buy") { SendMessage("#volume" + model.CurTo, Phrases.InvalidCommand); return; } double volume; try { volume = model.Volume.ParseAnyDouble(); } catch (Exception) { SendMessage("#volume" + model.CurTo, Phrases.InvalidAmountFormat); return; } var orderAction = model.Action == "sell" ? OrderAction.Sell : OrderAction.Buy; var traderId = GetTraderId(); var asset = Dependencies.AssetPairsDictionary.FindByBasedOrQuotingAsset(model.CurFrom, model.CurTo); var marketOrder = MarketOrder.Create(traderId, asset.Id, model.CurFrom, orderAction, volume); try { await Dependencies.SrvOrdersRegistrator.RegisterTradeOrderAsync(marketOrder); SendMessage("#volume" + model.CurTo, Phrases.OrderHasBeenRegistered); } catch (Exception ex) { SendMessage("#volume" + model.CurTo, ex.Message); } }