public MainWindowTest() { InitializeComponent(); helper = new Helper(); tradeSetting = helper.ReadSetting(); //SetGmailSetting(); apiProcessor = new BaseProcessor(tradeSetting, helper); apiProcessor.LogAdded += LogAdded; apiProcessor.LoadMasterContract(); mtmConnect = new MTMConnect(apiProcessor); mtmConnect.OnMTMChanged += UpdateMTM; mtmConnect.OnMTMTargetHit += MTMTargetHit; mtmConnect.OnError += MTMConnectError; tickerConnect = new TickerHelper(apiProcessor); tickerConnect.OnTickerChanged += TickerConnect_OnTickerChanged; tickerConnect.OnError += MTMConnectError; Instrument bankNiftyInst = new Instrument { code = "26009", symbol = "Nifty Bank", exchange = "1" }; tickerConnect.SubscribeToken(bankNiftyInst); CheckToken(); InitializeSetting(); }
protected void CheckOrderStatus(string message) { Logger.Debug("CheckOrderStatus time: " + TradeSetting.GetStringTime(DateTime.Now)); OrderResponce orderResponce = JsonConvert.DeserializeObject <OrderResponce>(message.Substring(3)); if (orderResponce.Order.Id != TestContent.SentOrderId) { return; } if (orderResponce.Order.Status == Status.COMPLETELY_FILLED) { TestContent.OrderStatus = OrderStatus.FILLED; return; } else if (orderResponce.Order.Status == Status.CANCELED) { TestContent.OrderStatus = OrderStatus.CANCELED; return; } else if (orderResponce.Order.Status == Status.NEW) { TestContent.OrderStatus = OrderStatus.PENDING; return; } TestContent.OrderStatus = OrderStatus.INDEFINITE; }
public BaseProcessor(TradeSetting tradeSetting, Helper helper) { aliceBlue = new AliceBlue(); this.tradeSetting = tradeSetting; this.helper = helper; masterContact = new List <Instrument>(); ExecutedOrders = new List <OrderResponse>(); }
public BaseEngine() { helper = new Helper(); tradeSetting = helper.ReadSetting(); apiProcessor = new BaseProcessor(tradeSetting, helper); apiProcessor.LoadMasterContract(); tickerHelper = new TickerHelper(apiProcessor); }
protected void SaveTransactions(string message) { List <TransactionDto> transactions = JsonConvert.DeserializeObject <TransactionDto[]>(message.Substring(3)).ToList(); Logger.Debug("SaveTransactions time: " + TradeSetting.GetStringTime(DateTime.Now)); Logger.Debug("Transactions count: {0}", transactions.Count); TestContent.BaseTransactions = transactions.FindAll(t => t.CurrencyId == BaseSymbol); TestContent.TermTransactions = transactions.FindAll(t => t.CurrencyId == TermSymbol); }
protected void OrderResponce(string message) { Logger.Debug("OrderResponce time: " + TradeSetting.GetStringTime(DateTime.Now)); TestContent.IsOrderSent = IsSuccessStatus(message.Substring(0, 3), "Order is not sent, Status:"); if (TestContent.IsOrderSent) { SaveSentOrderId(message.Substring(3)); } else if (!TestContent.IsOrderSent) { TestContent.IsSuccess = false; TestContent.OrderStatus = OrderStatus.INDEFINITE; } }
private void GeneralCheck(string testName, bool isPassive) { long sentOrderTime = StompWebSocketService.ConvertToUnixTimestamp(DateTime.Now.AddSeconds(-1)); Logger.Debug("Send order time: {0}", TradeSetting.GetStringTime(DateTime.Now)); if (Order.Type == OrderType.LIMIT && isPassive) { WaitSendingLimitOrder(); } else { TraderSubscriber.SendOrder(Order, OrderResponce); TestContent.OrderStatus = OrderStatus.PENDING; } WaitOrderStatus(); if (TestContent.IsSuccess) { ManagerSubscriber.GetTransactions(SaveTransactions, sentOrderTime); Thread.Sleep(1000); try { CheckCommissions(isPassive); } catch (Exception ex) { TestContent.IsSuccess = false; Console.WriteLine("While calculating commissions an error occured: {0}", ex.Message); Console.WriteLine("Stack trace: {0}", ex.StackTrace); } try { TraderSubscriber.CheckBalance(CheckNewBalance); } catch (Exception ex) { TestContent.IsSuccess = false; Console.WriteLine("While checking balance an error occured: {0}", ex.Message); Console.WriteLine("Stack trace: {0}", ex.StackTrace); } Thread.Sleep(2000); } AddTestResult(TestContent.IsSuccess && TestContent.IsOrderSent, testName); }
public TradeSetting ReadSetting() { TradeSetting tradeSetting = new TradeSetting { UserId = ConfigurationManager.AppSettings["UserId"], Password = ConfigurationManager.AppSettings["Password"], ClientId = ConfigurationManager.AppSettings["ClientId"], ClientSecret = ConfigurationManager.AppSettings["ClientSecret"], Token = ConfigurationManager.AppSettings["Token"], TokenCreatedOn = ConfigurationManager.AppSettings["TokenCreatedOn"], Quantity = ConfigurationManager.AppSettings["Quantity"], StopLossPercentage = ConfigurationManager.AppSettings["StopLossPercentage"], ExpiryWeek = ConfigurationManager.AppSettings["ExpiryWeek"], Answer1 = ConfigurationManager.AppSettings["Answer1"], Answer2 = ConfigurationManager.AppSettings["Answer2"], MTMProfit = ConfigurationManager.AppSettings["MTMProfit"], MTMLoss = ConfigurationManager.AppSettings["MTMLoss"] }; return(tradeSetting); }
public Security SaveSecurity(string id, Security security) { security.ModificationTime = TradeSetting.GetStringTime(DateTime.UtcNow); return(_restService.Put <Security, Security>("/api/securities/" + id, security)); }
public TradeSetting SaveTradeSetting(string id, TradeSetting setting) { setting.ModificationTime = TradeSetting.GetStringTime(DateTime.UtcNow); return(_restService.Put <TradeSetting, TradeSetting>("/api/users/" + id + "/securitytradingsettings/" + setting.SecurityId, setting)); }