using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Muell
{
///
/// Zusammenfassung für Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown daysBack;
private int lExpectedHandle = 0;
///
/// Erforderliche Designervariable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Erforderlich für die Windows Form-Designerunterstützung
//
InitializeComponent();
//
// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
//
}
///
/// Die verwendeten Ressourcen bereinigen.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Vom Windows Form-Designer generierter Code
///
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.daysBack = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.daysBack)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Enabled = true;
this.button1.Location = new System.Drawing.Point(56, 64);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "Go";
this.button1.Click += new System.EventHandler(this.RequestButton_Click);
//
// daysBack
//
this.daysBack.Location = new System.Drawing.Point(96, 16);
this.daysBack.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.daysBack.Name = "daysBack";
this.daysBack.Size = new System.Drawing.Size(56, 20);
this.daysBack.TabIndex = 1;
this.daysBack.Value = new System.Decimal(new int[] {
10,
0,
0,
0});
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 2;
this.label1.Text = "Days back:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(184, 101);
this.Controls.Add(this.label1);
this.Controls.Add(this.daysBack);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.daysBack)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// Der Haupteinstiegspunkt für die Anwendung.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private IESignal.HooksClass eSignal = new IESignal.HooksClass();
private void eSignal_OnBarsChanged(int lHandle)
{
if (lHandle == lExpectedHandle && eSignal.get_IsHistoryReady(lHandle) == 1)
{
int numBars = eSignal.get_GetNumBars(lHandle);
if (numBars == 0)
MessageBox.Show("OnBarsChanged: should not happen, numbars = 0");
//eSignal.ReleaseHistory(lHandle);
}
}
private void eSignal_OnBarsReceived(int lHandle)
{
if (lHandle == lExpectedHandle && eSignal.get_IsHistoryReady(lHandle) == 1)
{
int numBars = eSignal.get_GetNumBars(lHandle);
if (numBars == 0 || numBars < (int) daysBack.Value)
MessageBox.Show("OnBarsReceived: should not happen, numbars = " + numBars + " instead of " + (int) daysBack.Value);
else
MessageBox.Show("OnBarsReceived: got data, everything is ok");
//eSignal.ReleaseHistory(lHandle);
}
else
MessageBox.Show("OnBarsReceived: history is not yet ready");
//eSignal.ReleaseHistory(lHandle);
}
private void eSignal_OnEntitledValid()
{
if (eSignal.IsEntitled == 1)
{
button1.Enabled = true;
}
else
{
MessageBox.Show("Not entitled");
return;
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
eSignal.SetApplication("STHORNINGTON");
// clear any eSignal internal cache
eSignal.ClearSymbolCache();
eSignal.ReleaseAllHistory();
eSignal.ReleaseAllTimeSales();
eSignal.OnBarsChanged += new IESignal._IHooksEvents_OnBarsChangedEventHandler(eSignal_OnBarsChanged);
eSignal.OnBarsReceived += new IESignal._IHooksEvents_OnBarsReceivedEventHandler(eSignal_OnBarsReceived);
eSignal.OnEntitledValid += new IESignal._IHooksEvents_OnEntitledValidEventHandler(eSignal_OnEntitledValid);
//MessageBox.Show("Connected");
}
private void RequestButton_Click(object sender, System.EventArgs e)
{
RequestHistory();
}
private void RequestHistory()
{
//Clear all history
//eSignal.ReleaseAllHistory();
//eSignal.ClearSymbolCache();
eSignal.ReleaseHistory(lExpectedHandle);
lExpectedHandle = eSignal.get_RequestHistory("MSFT", "D", IESignal.barType.btBARS, (int) daysBack.Value, -1, -1);
if (eSignal.get_IsHistoryReady(lExpectedHandle) == 1)
{
eSignal_OnBarsReceived(lExpectedHandle);
}
// //Added sleep procedure
// System.Threading.Thread.Sleep(100);
//
// if (eSignal.get_IsHistoryReady(handle) == 1)
// {
// int numBars = eSignal.get_GetNumBars(handle);
// if (numBars == 0)
// {
// // !!! here is the problem: !!!
// // although eSignal says, that history is ready, there are no bars
// MessageBox.Show("this is the problem");
// return;
//
// }
// //eSignal.ReleaseHistory(handle);
// //RequestHistory();
// }
}
}
}