This event is fired as a response to a tradable commodities request either when the collection is resolved or when an error has occurred during the request processing.
Visual Basic |
---|
Public Event TradableCommoditiesResolved( _ ByVal gw_account_id As Long, _ ByVal cqg_commodities As CQGCommodities, _ ByVal cqg_error As CQGError _ ) |
- gw_account_id
Gateway account ID, for which tradable commodity names were requested, represented as Long
- The gw_account_id that was passed to the corresponding RequestTradableCommodities call.
- 0 if nothing was passed.
- cqg_commodities
Collection of the tradable commodities.
If an error has occurred, the collection will be empty.
- cqg_error
- CQGError object representing the error occurred while processing the tradable commodities request.
If no error has occurred, the parameter value is either Nothing or invalid error object depending on the UsedFromATLClient setting of the configuration.
The parameter can be checked for validity via the CQGCEL.IsValid method.
The examples below show how to request tradable commodities via CQG API.
Option Explicit Private WithEvents CEL As CQGCEL Private Sub Form_Load() ' Initialize CQGCEL instance. On Error Goto errHndl Set CEL = New CQGCEL CEL.APIConfiguration.CollectionsThrowException = False ' Disable application readiness checking CEL.APIConfiguration.ReadyStatusCheck = rscOff CEL.Startup Exit Sub errHndl: MsgBox "Error occurred during CEL initialization. " & Err.Description End Sub Private Sub Form_Unload(Cancel As Integer) On Error Goto errHndl CEL.Shutdown Exit Sub errHndl: MsgBox "Error occurred during CEL initialization. " & Err.Description End Sub ' Event is fired when the CQGCEL object is successfully started up Private Sub CEL_CELStarted() Debug.Print "CEL Version : " & CEL.Environment.CELVersion End Sub ' Event is fired when error occures in CQGCEL execution Private Sub cel_DataError(ByVal obj As Object, ByVal errorDescription As String) ' Print the error description Debug.Print "Data Error : " & errorDescription End Sub ' Event is fired when some changes occurred in the connection with the CQG data server Private Sub CEL_DataConnectionStatusChanged(ByVal newStatus As CQG.eConnectionStatus) Dim status As String Select Case newStatus Case csConnectionDelayed status = "Delayed" Case csConnectionDown status = "Down" Case csConnectionUp status = "Up" End Select Debug.Print "Data Connection Status changed to " & status End Sub ' Event is fired when the status of the connection with the CQG Gateway is changed Private Sub CEL_GWConnectionStatusChanged(ByVal newStatus As CQG.eConnectionStatus) Dim status As String Select Case newStatus Case csConnectionDelayed status = "Delayed" Case csConnectionDown status = "Down" Case csConnectionUp status = "Up" ' Changing subscription level sends request for accounts CEL.AccountSubscriptionLevel = aslAccountsOnly End Select Debug.Print "GW Connection Status changed to " & status End Sub ' Event is fired when the account or position information is changed Private Sub CEL_AccountChanged(ByVal change As CQG.eAccountChangeType, _ ByVal Account As CQG.ICQGAccount, _ ByVal position As CQG.ICQGPosition) If change = eAccountChangeType.actAccountsReloaded Then RequestAllTradeableCommodities End If End Sub ' This function requests all tradeable commodities for each account Private Sub RequestAllTradeableCommodities() Dim acc As CQGAccount For Each acc In CEL.Accounts Debug.Print "Request tradeable commodities for account : " & _ acc.GWAccountName CEL.RequestTradableCommodities acc.GWAccountID Next End Sub ' Event is fired when the list of tradable commodity names is resolved ' or when some error has occurred while request processing Private Sub CEL_TradableCommoditiesResolved(ByVal GWAccountID As Long, _ ByVal commodityNames As CQG.ICQGCommodities, _ ByVal cqgErr As CQG.ICQGError) Dim i As Long If Not cqgErr Is Nothing Then Debug.Print "Error occured during tradeable commodities request : " & cqgErr.Description Exit Sub End If Debug.Print "Tradeable commodities resolved for account : " & _ CEL.Accounts(GWAccountID).GWAccountName For i = 0 To commodityNames.Count - 1 Debug.Print vbTab & commodityNames(i) Next End Sub
using System; using System.Runtime.InteropServices; using CQG; namespace Samples { class TradableCommoditiesResolved : IDisposable { // CQGCEL instance declaration private CQGCEL cel = new CQGCELClass(); // Used to determine is the object manualy disposed private bool disposed = false; public TradableCommoditiesResolved() { // Initialize CQGCEL instance try { // Configure CEL cel.APIConfiguration.ReadyStatusCheck = eReadyStatusCheck.rscOff; cel.APIConfiguration.CollectionsThrowException = false; // Register to CEL's events cel.CELStarted += new _ICQGCELEvents_CELStartedEventHandler(cel_CELStarted); cel.DataError += new _ICQGCELEvents_DataErrorEventHandler(cel_DataError); cel.DataConnectionStatusChanged += new _ICQGCELEvents_DataConnectionStatusChangedEventHandler(cel_DataConnectionStatusChanged); cel.GWConnectionStatusChanged += new _ICQGCELEvents_GWConnectionStatusChangedEventHandler(cel_GWConnectionStatusChanged); cel.AccountChanged += new _ICQGCELEvents_AccountChangedEventHandler(cel_AccountChanged); cel.TradableCommoditiesResolved += new _ICQGCELEvents_TradableCommoditiesResolvedEventHandler(cel_TradableCommoditiesResolved); cel.Startup(); } catch (COMException ex) { Console.WriteLine("Error occurred during CEL initialization. {0}", ex.Message); } } ~TradableCommoditiesResolved() { Dispose(false); } #region CEL Event Handlers // Event is fired when the CQGCEL object is successfully started up void cel_CELStarted() { Console.WriteLine("CEL Version : {0}", cel.Environment.CELVersion); } // Event is fired when error occures in CQGCEL execution void cel_DataError(object obj, string errorDescription) { // Some error occurred Console.WriteLine("Data Error : " + errorDescription); } // Event is fired when some changes occurred in the connection // with the CQG data server void cel_DataConnectionStatusChanged(eConnectionStatus newStatus) { string status; switch (newStatus) { case eConnectionStatus.csConnectionDelayed: status = "Delayed"; break; case eConnectionStatus.csConnectionDown: status = "Down"; break; case eConnectionStatus.csConnectionUp: status = "Up"; break; default: status = "Unknown"; break; } Console.WriteLine("Data Connection Status changed to " + status); } // Event is fired when the status of the connection with the // CQG Gateway is changed void cel_GWConnectionStatusChanged(eConnectionStatus newStatus) { string status; switch (newStatus) { case eConnectionStatus.csConnectionDelayed: status = "Delayed"; break; case eConnectionStatus.csConnectionDown: status = "Down"; break; case eConnectionStatus.csConnectionUp: status = "Up"; // Changing subscription level sends request for accounts cel.AccountSubscriptionLevel = eAccountSubscriptionLevel.aslAccountsOnly; break; default: status = "Unknown"; break; } Console.WriteLine("GW Connection Status changed to " + status); } // Event is fired when the account or position information is changed void cel_AccountChanged(eAccountChangeType change, CQGAccount Account, CQGPosition position) { if (change == eAccountChangeType.actAccountsReloaded) { RequestAllTradeableCommodities(); } } // This function requests all tradeable commodities for each account void RequestAllTradeableCommodities() { foreach (CQGAccount acc in cel.Accounts) { Console.WriteLine("Request tradeable commodities for account : {0}", acc.GWAccountName); cel.RequestTradableCommodities(acc.GWAccountID); } } // Event is fired when the list of tradable commodity names is resolved // or when some error has occurred while request processing void cel_TradableCommoditiesResolved(int GWAccountID, CQGCommodities commodityNames, CQGError err) { if (err != null) { Console.WriteLine("Error occured during tradeable commodities request : {0}", err.Description); return; } Console.WriteLine("Tradeable commodities resolved for account : {0}", cel.Accounts[GWAccountID].GWAccountName); for (int i = 0; i < commodityNames.Count; i++) { Console.WriteLine("\t {0}", commodityNames[i]); } } #endregion #region IDisposable Members public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion #region Private Methods private void Dispose(bool disposing) { // Check to see if Dispose has already been called if (!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources if (disposing) { // Dispose managed resources } // If disposing is false, // only the following code is executed try { cel.Shutdown(); } catch { } } disposed = true; } #endregion } }