static void Main(string[] args) { O2GSession session = null; string sOrderType = Constants.Orders.LimitEntry; try { LoginParams loginParams = new LoginParams(ConfigurationManager.AppSettings); SampleParams sampleParams = new SampleParams(ConfigurationManager.AppSettings); PrintSampleParams("FindRowByColumnValue", loginParams, sampleParams); session = O2GTransport.createSession(); session.useTableManager(O2GTableManagerMode.Yes, null); SessionStatusListener statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin); session.subscribeSessionStatus(statusListener); statusListener.Reset(); session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection); if (statusListener.WaitEvents() && statusListener.Connected) { ResponseListener responseListener = new ResponseListener(); TableListener tableListener = new TableListener(responseListener); session.subscribeResponse(responseListener); O2GTableManager tableManager = session.getTableManager(); O2GTableManagerStatus managerStatus = tableManager.getStatus(); while (managerStatus == O2GTableManagerStatus.TablesLoading) { Thread.Sleep(50); managerStatus = tableManager.getStatus(); } if (managerStatus == O2GTableManagerStatus.TablesLoadFailed) { throw new Exception("Cannot refresh all tables of table manager"); } O2GAccountRow account = GetAccount(tableManager, sampleParams.AccountID); if (account == null) { if (string.IsNullOrEmpty(sampleParams.AccountID)) { throw new Exception("No valid accounts"); } else { throw new Exception(string.Format("The account '{0}' is not valid", sampleParams.AccountID)); } } else { if(!sampleParams.AccountID.Equals(account.AccountID)) { sampleParams.AccountID = account.AccountID; Console.WriteLine("AccountID='{0}'", sampleParams.AccountID); } } O2GOfferRow offer = GetOffer(tableManager, sampleParams.Instrument); if (offer == null) { throw new Exception(string.Format("The instrument '{0}' is not valid", sampleParams.Instrument)); } O2GLoginRules loginRules = session.getLoginRules(); if (loginRules == null) { throw new Exception("Cannot get login rules"); } O2GTradingSettingsProvider tradingSettingsProvider = loginRules.getTradingSettingsProvider(); int iBaseUnitSize = tradingSettingsProvider.getBaseUnitSize(sampleParams.Instrument, account); int iAmount = iBaseUnitSize * sampleParams.Lots; double dRate; double dRateStop; double dRateLimit; double dBid = offer.Bid; double dAsk = offer.Ask; double dPointSize = offer.PointSize; // For the purpose of this example we will place entry order 8 pips from the current market price // and attach stop and limit orders 10 pips from an entry order price if (sOrderType.Equals(Constants.Orders.LimitEntry)) { if (sampleParams.BuySell.Equals(Constants.Buy)) { dRate = dAsk - 8 * dPointSize; dRateLimit = dRate + 10 * dPointSize; dRateStop = dRate - 10 * dPointSize; } else { dRate = dBid + 8 * dPointSize; dRateLimit = dRate - 10 * dPointSize; dRateStop = dRate + 10 * dPointSize; } } else { if (sampleParams.BuySell.Equals(Constants.Buy)) { dRate = dAsk + 8 * dPointSize; dRateLimit = dRate + 10 * dPointSize; dRateStop = dRate - 10 * dPointSize; } else { dRate = dBid - 8 * dPointSize; dRateLimit = dRate - 10 * dPointSize; dRateStop = dRate + 10 * dPointSize; } } tableListener.SubscribeEvents(tableManager); O2GRequest request = CreateELSRequest(session, offer.OfferID, sampleParams.AccountID, iAmount, dRate, dRateLimit, dRateStop, sampleParams.BuySell, sOrderType); if (request == null) { throw new Exception("Cannot create request"); } string sRequestID = request.RequestID; responseListener.SetRequestID(sRequestID); tableListener.SetRequestID(sRequestID); session.sendRequest(request); if (!responseListener.WaitEvents()) { throw new Exception("Response waiting timeout expired"); } Console.WriteLine("Search by RequestID:{0}", sRequestID); FindOrders(tableManager, sRequestID); Console.WriteLine("Search by Type:{0} and BuySell:{1}", sOrderType, sampleParams.BuySell); FindOrdersByTypeAndDirection(tableManager, sOrderType, sampleParams.BuySell); Console.WriteLine("Search conditional orders"); FindConditionalOrders(tableManager); Console.WriteLine("Done!"); tableListener.UnsubscribeEvents(tableManager); statusListener.Reset(); session.logout(); statusListener.WaitEvents(); session.unsubscribeResponse(responseListener); } session.unsubscribeSessionStatus(statusListener); } catch (Exception e) { Console.WriteLine("Exception: {0}", e.ToString()); } finally { if (session != null) { session.Dispose(); } } }
public TableListener Notifications(NotificationSharedBy sharedBy = NotificationSharedBy.Schema) => _onNotification ?? (_onNotification = DMLTriggerManager.GetTiggerListener(this, sharedBy));
static void Main(string[] args) { O2GSession session = null; try { LoginParams loginParams = new LoginParams(ConfigurationManager.AppSettings); SampleParams sampleParams = new SampleParams(ConfigurationManager.AppSettings); PrintSampleParams("CreateEntryOrder", loginParams, sampleParams); session = O2GTransport.createSession(); session.useTableManager(O2GTableManagerMode.Yes, null); SessionStatusListener statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin); session.subscribeSessionStatus(statusListener); statusListener.Reset(); session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection); if (statusListener.WaitEvents() && statusListener.Connected) { ResponseListener responseListener = new ResponseListener(); TableListener tableListener = new TableListener(responseListener); session.subscribeResponse(responseListener); O2GTableManager tableManager = session.getTableManager(); O2GTableManagerStatus managerStatus = tableManager.getStatus(); while (managerStatus == O2GTableManagerStatus.TablesLoading) { Thread.Sleep(50); managerStatus = tableManager.getStatus(); } if (managerStatus == O2GTableManagerStatus.TablesLoadFailed) { throw new Exception("Cannot refresh all tables of table manager"); } O2GAccountRow account = GetAccount(tableManager, sampleParams.AccountID); if (account == null) { if (string.IsNullOrEmpty(sampleParams.AccountID)) { throw new Exception("No valid accounts"); } else { throw new Exception(string.Format("The account '{0}' is not valid", sampleParams.AccountID)); } } sampleParams.AccountID = account.AccountID; O2GOfferRow offer = GetOffer(tableManager, sampleParams.Instrument); if (offer == null) { throw new Exception(string.Format("The instrument '{0}' is not valid", sampleParams.Instrument)); } O2GLoginRules loginRules = session.getLoginRules(); if (loginRules == null) { throw new Exception("Cannot get login rules"); } O2GTradingSettingsProvider tradingSettingsProvider = loginRules.getTradingSettingsProvider(); int iBaseUnitSize = tradingSettingsProvider.getBaseUnitSize(sampleParams.Instrument, account); int iAmount = iBaseUnitSize * sampleParams.Lots; int iCondDistEntryLimit = tradingSettingsProvider.getCondDistEntryLimit(sampleParams.Instrument); int iCondDistEntryStop = tradingSettingsProvider.getCondDistEntryStop(sampleParams.Instrument); string sOrderType = GetEntryOrderType(offer.Bid, offer.Ask, sampleParams.Rate, sampleParams.BuySell, offer.PointSize, iCondDistEntryLimit, iCondDistEntryStop); tableListener.SubscribeEvents(tableManager); O2GRequest request = CreateEntryOrderRequest(session, offer.OfferID, sampleParams.AccountID, iAmount, sampleParams.Rate, sampleParams.BuySell, sOrderType, sampleParams.ExpireDate); if (request == null) { throw new Exception("Cannot create request"); } responseListener.SetRequestID(request.RequestID); tableListener.SetRequestID(request.RequestID); session.sendRequest(request); if (responseListener.WaitEvents()) { Console.WriteLine("Done!"); } else { throw new Exception("Response waiting timeout expired"); } tableListener.UnsubscribeEvents(tableManager); statusListener.Reset(); session.logout(); statusListener.WaitEvents(); session.unsubscribeResponse(responseListener); } session.unsubscribeSessionStatus(statusListener); } catch (Exception e) { Console.WriteLine("Exception: {0}", e.ToString()); } finally { if (session != null) { session.Dispose(); } } }