Automate download of realtime trade and marketdepth stocks demonstration

Source: Internet
Author: User
Using system;
Using system. Windows. forms;

Using smartquant. Fix;
Using smartquant. Data;
Using smartquant. instruments;
Using smartquant. providers;

Public class script
{
Static void main ()
{
// Connect provider
Imarketdataprovider provider = Providermanager . Marketdataproviders [providerid. IB];

Provider. Connect (10*1000 );

If (! Provider. isconnected)
{
MessageBox. Show ("cannot connect to provider! ");

Return;
}

// Setup bar factory if needed
Provider. barfactory. Reset ();

Provider. barfactory. Items. Clear ();

Provider. barfactory. Items. Add (bartype. Time, 60, true); // 1 min bars
Provider. barfactory. Items. Add (bartype. Time, 300, true); // 5 min bars

Provider. barfactory. Enabled = true;

// Subscribe to events
Provider. newtrade + = new tradeeventhandler (onnewtrade );
Provider. newquote + = new quoteeventhandler (onnewquote );
Provider. newbar + = new bareventhandler (onnewbar );

// Get instruments
Instrumentlist instruments = new instrumentlist ();

Foreach (Instrument instrument in instrumentmanager. Instruments)
{
If (instrument. securitytype = securitytype. commonstock)
Instruments. Add (instrument );
}

// Request market data
Foreach (Instrument instrument in instruments)
{
Instrument. requestmarketdata (
Provider,
Marketdatatype. Trade | marketdatatype. Quote );
}

// Wait
MessageBox. Show ("Press OK button to stop .");

// Unsubscribe from events
Provider. newtrade-= new tradeeventhandler (onnewtrade );
Provider. newquote-= new quoteeventhandler (onnewquote );
Provider. newbar-= new bareventhandler (onnewbar );

// Cancel market data
Foreach (Instrument instrument in instruments)
{
Instrument. cancelmarketdata (
Provider,
Marketdatatype. Trade | marketdatatype. Quote );
}

// Reset bar factory
Provider. barfactory. Enabled = false;
Provider. barfactory. Reset ();

// Disconnect provider
Provider. Disconnect ();

// Flush memory data
Datamanager. server. Flush ();
}

Static void onnewtrade (Object sender, tradeeventargs ARGs)
{
Instrument instrument = args. Instrument as instrument;

Instrument. Add (ARGs. Trade );
}

Static void onnewquote (Object sender, quoteeventargs ARGs)
{
Instrument instrument = args. Instrument as instrument;

Instrument. Add (ARGs. Quote );
}

Static void onnewbar (Object sender, bareventargs ARGs)
{
Instrument instrument = args. Instrument as instrument;

Instrument. Add (ARGs. bar );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.