public void PrintOffer(O2GOfferTableRow offerRow, string sInstrument) { Offer offer; if (mOffers.FindOffer(offerRow.OfferID, out offer)) { if (offerRow.isTimeValid && offerRow.isBidValid && offerRow.isAskValid) { offer.Date = offerRow.Time; offer.Bid = offerRow.Bid; offer.Ask = offerRow.Ask; } } else { offer = new Offer(offerRow.OfferID, offerRow.Instrument, offerRow.Digits, offerRow.PointSize, offerRow.Time, offerRow.Bid, offerRow.Ask); mOffers.AddOffer(offer); } if (string.IsNullOrEmpty(sInstrument) || offerRow.Instrument.Equals(sInstrument)) { Console.WriteLine("{0}, {1}, Bid={2}, Ask={3}", offer.OfferID, offer.Instrument, offer.Bid, offer.Ask); } }
public void onChanged(string rowID, O2GRow rowData) { O2GTableType type = rowData.TableType; switch (type) { case O2GTableType.Offers: O2GOfferTableRow offers = (O2GOfferTableRow)(rowData); break; case O2GTableType.Accounts: O2GAccountTableRow account = (O2GAccountTableRow)(rowData); break; case O2GTableType.Summary: O2GSummaryTableRow row = (O2GSummaryTableRow)(rowData); break; case O2GTableType.ClosedTrades: Console.WriteLine("CLOSED TRADES TRIGGERED FROM CHANGED TABLELISTENER!"); O2GClosedTradeTableRow closed = (O2GClosedTradeTableRow)(rowData); break; } }
private void RaiseOnOfferIfValid(O2GOfferTableRow row) { if (!instruments.Contains(row.Instrument)) { return; } if (row.isTimeValid && row.isBidValid && row.isAskValid) { var tickOn = new DateTime(row.Time.Ticks, DateTimeKind.Utc).ToEstFromUtc(); if (!testingMode && tickOn.IsTickOn()) { return; } var symbol = row.Instrument.ToSymbol(); var offer = new Offer() { Symbol = symbol, TickOn = tickOn, BidRate = row.Bid.ToRoundedRate(symbol), AskRate = row.Ask.ToRoundedRate(symbol), }; OnOffer?.Invoke(this, new GenericArgs <Offer>(offer)); } }
public Offers(O2GTableManager mTblMgr) { while (mTblMgr.getStatus() != O2GTableManagerStatus.TablesLoaded && mTblMgr.getStatus() != O2GTableManagerStatus.TablesLoadFailed) { Thread.Sleep(50); } O2GOffersTable table = (O2GOffersTable)mTblMgr.getTable(O2GTableType.Offers); OffersListener listener = new OffersListener(); O2GOfferTableRow row = null; table.subscribeUpdate(O2GTableUpdateType.Insert, listener); table.subscribeUpdate(O2GTableUpdateType.Update, listener); try { mTblMgr.lockUpdates(); for (int ii = 0; ii < table.Count; ii++) { row = table.getRow(ii); foreach (O2GTableColumn CurrentColumn in table.Columns) { if (CurrentColumn.ID == "Instrument") { CurrencyList.Add(row.getCell(1).ToString()); } } } } finally { mTblMgr.unlockUpdates(); } table.unsubscribeUpdate(O2GTableUpdateType.Insert, listener); table.unsubscribeUpdate(O2GTableUpdateType.Update, listener); }
/// <summary> /// Extracts offer detials and creates TradeSharp Tick messages /// </summary> /// <param name="offerRow"></param> public void ExtractOfferDetails(O2GOfferTableRow offerRow) { try { if (_subscriptionList.Contains(offerRow.Instrument)) { // Create new Tick object Tick tick = new Tick(new Security() { Symbol = offerRow.Instrument }, Common.Core.Constants.MarketDataProvider.Fxcm, offerRow.Time); // Extract BID information tick.BidPrice = (decimal)offerRow.Bid; tick.BidSize = 1; // Extract ASK information tick.AskPrice = (decimal)offerRow.Ask; tick.AskSize = 1; // Raise event to notify listeners if (_dataEvent != null) { _dataEvent(tick); } } } catch (Exception exception) { _logger.Error(exception, _type.FullName, "ExtractOfferDetails"); } }
/// <summary> /// Find valid offer by instrument name /// </summary> /// <param name="tableManager"></param> /// <param name="sInstrument"></param> /// <returns>offer</returns> private static O2GOfferTableRow GetOffer(O2GTableManager tableManager, string sInstrument) { bool bHasOffer = false; O2GOfferTableRow offer = null; O2GOffersTable offersTable = (O2GOffersTable)tableManager.getTable(O2GTableType.Offers); for (int i = 0; i < offersTable.Count; i++) { offer = offersTable.getRow(i); if (offer.Instrument.Equals(sInstrument)) { if (offer.SubscriptionStatus.Equals("T")) { bHasOffer = true; break; } } } if (!bHasOffer) { return(null); } else { return(offer); } }
static void offers_RowChanged(object sender, RowEventArgs e) { O2GOfferTableRow row = (O2GOfferTableRow)e.RowData; string sCurrentInstrument = row.Instrument; if ((sInstrument.Equals("")) || (sInstrument.Equals(sCurrentInstrument))) { PrintOffer(row); } }
public void PrintOffers(O2GOffersTable offers, string sInstrument) { O2GOfferTableRow offerRow = null; O2GTableIterator iterator = new O2GTableIterator(); while (offers.getNextRow(iterator, out offerRow)) { PrintOffer(offerRow, sInstrument); } }
public static void printOffers(O2GOffersTable offers) { O2GOfferTableRow row = null; O2GTableIterator iterator = new O2GTableIterator(); while (offers.getNextRow(iterator, out row)) { string sCurrentInstrument = row.Instrument; if ((sInstrument.Equals("")) || (sInstrument.Equals(sCurrentInstrument))) { PrintOffer(row); } } }
//This function will fill the rates table and put it in a list to be accessed later internal void fillRatesGrid() { //This is to make sure the current thread is calling this function, if not call it agian if (INSTANCE.InvokeRequired) { try { SetNullCallback callback = new SetNullCallback(fillRatesGrid); Invoke(callback, new object[] { }); } catch (Exception ex) { logger.Error(ex.Message); throw ex; } } else { //Get list of symbols from the offers table O2GTableIterator iterator = new O2GTableIterator(); O2GOfferTableRow offerRow = null; if (tss != null) { Thread.Sleep(3000); O2GOffersTable offersTbl = tss.OffersTable; if (offersTbl == null) { //Log.logMessageToFile("Login", "OfferTable null"); logger.Debug("OfferTable is empty"); return; } temp = new ConcurrentDictionary <int, string>(); templist = new ConcurrentBag <int>(); while (offersTbl.getNextRow(iterator, out offerRow)) { if (offerRow.SubscriptionStatus.Equals("T")) { templist.Add(Convert.ToInt32(offerRow.OfferID)); logger.Debug("Offer {0}; Symbol {1}", offerRow.OfferID, offerRow.Instrument); temp.TryAdd(Convert.ToInt32(offerRow.OfferID), offerRow.Instrument); } } } } }
public void onAdded(string rowID, O2GRow rowData) { O2GTableType type = rowData.TableType; switch (type) { case O2GTableType.Offers: O2GOfferTableRow offers = (O2GOfferTableRow)(rowData); break; case O2GTableType.Accounts: O2GAccountTableRow account = (O2GAccountTableRow)(rowData); break; case O2GTableType.Trades: break; } }
private void offersTableUpdated(object sender, RowEventArgs e) { O2GOfferTableRow otr = (O2GOfferTableRow)e.RowData; if (otr != null && realTimeInstrumentsList.Count > 0) { var instrument = otr.Instrument.Contains('/') ? this.deNormalizeSymbol(otr.Instrument) : otr.Instrument; if (realTimeInstrumentsList.Contains(instrument)) { RealTimeDataUpdated?.Invoke(this, new RealTimeDataUpdatedEventArgs(new Instrument { Name = instrument, Type = InstrumentType.Forex }, otr.Bid, otr.Volume, otr.Time)); } //instrument, otr.Bid, otr.Ask, otr.Volume, otr.Time); //RealTimeDataUpdated?.Invoke(this, new RealTimeDataUpdatedEventArgs { Data = new Tuple<string, double, double, int, DateTime>(instrument, otr.Bid, otr.Ask, otr.Volume, otr.Time) }); } }
/// <summary> /// Print estimates trading commissions /// </summary> private static void printEstimatedTradingCommissions(O2GSession session, O2GOfferTableRow offer, O2GAccountTableRow account, int iAmount, string sBuySell) { //wait until commissions related information will be loaded O2GCommissionsProvider commissionProvider = session.getCommissionsProvider(); while (commissionProvider.getStatus() == O2GCommissionStatus.CommissionStatusLoading) { System.Threading.Thread.Sleep(1000); } if (commissionProvider.getStatus() != O2GCommissionStatus.CommissionStatusReady) { throw new Exception("Could not calculate the estimated commissions."); } //calculate commissions Console.WriteLine("Commission for open the position is {0}.", commissionProvider.calcOpenCommission(offer, account, iAmount, sBuySell, 0)); Console.WriteLine("Commission for close the position is {0}.", commissionProvider.calcCloseCommission(offer, account, iAmount, sBuySell, 0)); Console.WriteLine("Total commission for open and close the position is {0}.", commissionProvider.calcTotalCommission(offer, account, iAmount, sBuySell, 0, 0)); }
public void HandleOffers(O2GOffersTable offers) { var offerIds = new Dictionary <string, string>(); var rows = new List <O2GOfferTableRow>(); O2GOfferTableRow row = null; var iterator = new O2GTableIterator(); while (offers.getNextRow(iterator, out row)) { rows.Add(row); offerIds.Add(row.Instrument, row.OfferID); } OnOfferIds?.Invoke(this, new GenericArgs <Dictionary <string, string> >(offerIds)); rows.ForEach(r => RaiseOnOfferIfValid(r)); }
public Offers(MainForm CurrentForm, O2GTableManager mTblMgr) { CreateTable(); CurrentForm.PopulateTable(OffersTable); while (mTblMgr.getStatus() != O2GTableManagerStatus.TablesLoaded && mTblMgr.getStatus() != O2GTableManagerStatus.TablesLoadFailed) { Thread.Sleep(50); } O2GOffersTable table = (O2GOffersTable)mTblMgr.getTable(O2GTableType.Offers); OffersListener listener = new OffersListener(); O2GOfferTableRow row = null; for (int i = 0; i < table.Count; i++) { DataRow CurrentRow = OffersTable.NewRow(); OffersTable.Rows.Add(CurrentRow); } CurrentForm.GetTableData(table, listener, row, mTblMgr); }
public void onChanged(string rowID, O2GRow rowData) { O2GTableType type = rowData.TableType; switch (type) { case O2GTableType.Offers: O2GOfferTableRow offers = (O2GOfferTableRow)(rowData); break; case O2GTableType.Accounts: O2GAccountTableRow account = (O2GAccountTableRow)(rowData); break; case O2GTableType.Trades: O2GTradeTableRow trade = (O2GTradeTableRow)(rowData); break; case O2GTableType.Summary: O2GSummaryTableRow row = (O2GSummaryTableRow)(rowData); break; } }
public void onChanged(string rowID, O2GRow rowData) { O2GOfferTableRow trade = (O2GOfferTableRow)rowData; }
public void HandleOffer(O2GOfferTableRow row) => RaiseOnOfferIfValid(row);
public static void PrintOffer(O2GOfferTableRow row) { //Console.WriteLine("OfferID: {0}, Instrument: {1}, Bid: {2}, Ask: {3}, PipCost: {4}", row.OfferID, row.Instrument, row.Bid, row.Ask, row.PipCost); // Console.WriteLine(row.Instrument); fm.onUpdate(row.Bid, row.Ask); }
static void Main(string[] args) { O2GSession session = null; try { LoginParams loginParams = new LoginParams(ConfigurationManager.AppSettings); SampleParams sampleParams = new SampleParams(ConfigurationManager.AppSettings); PrintSampleParams("CalculateTradingCommissions", loginParams, sampleParams); session = O2GTransport.createSession(); session.useTableManager(O2GTableManagerMode.Yes, null); statusListener = new SessionStatusListener(session); session.subscribeSessionStatus(statusListener); statusListener.Reset(); session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection); if (statusListener.WaitEvents() && statusListener.Connected) { 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"); } O2GAccountTableRow account = GetAccount(tableManager, sampleParams.AccountID); if (account == null) { throw new Exception(string.IsNullOrEmpty(sampleParams.AccountID) ? "No valid accounts" : string.Format("The account '{0}' is not valid", sampleParams.AccountID)); } O2GOfferTableRow 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; printEstimatedTradingCommissions(session, offer, account, iAmount, sampleParams.BuySell); Console.WriteLine("Done!"); } } catch (Exception e) { Console.WriteLine("Exception: {0}", e.ToString()); } finally { if (session != null) { if (statusListener.Connected) { statusListener.Reset(); session.logout(); statusListener.WaitEvents(); } session.unsubscribeSessionStatus(statusListener); session.Dispose(); } } }