C2Pro or collective2 Code

Questions about MultiCharts .NET and user contributed studies.
rsquared
Posts: 3
Joined: 20 Apr 2012
Been thanked: 1 time

C2Pro or collective2 Code

Postby rsquared » 24 Aug 2014

I have been working on connecting to C2Pro. Here is my code so far. Please add any updates that you make to the code that might be helpful for others.

One thing that might be helpful is the pseudo XML parser for the responses from the website. I am not sure what all the responses are and the formats might be.

Thanks

Code: Select all

public string Strat_ID = "1234";
public string PassWord = "abc";
public enum Duration
{
DAY,
GTC
}
public enum Action
{
BTO,
SSHORT,
STO,
BTC,
STC
}
public enum Instrument
{
stock,
option,
future,
forex

};

public enum OrdStatus
{
Open,
Canceled,
PendCancel,
Sending
};
public struct Order
{
public string systemid;
public string pw;
public string SigID;
public Action action;
public string quant;
public string dollars;
public Instrument instrument;
public string symbol;
public string limit;
public string Stop_Loss;
public string Profit_Target;
public Duration duration;
public OrdStatus status;

};

public void CancelAllPendingOrders()
{
try
{
string sURL = "";
sURL = "http://www.collective2.com/cgi-perl/signal.mpl?cmd=cancelallpending&systemid=" + Strat_ID.ToString() + "&pw=" + PassWord.ToString() + "";
//Output.WriteLine(sURL);
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(sURL);

WebResponse response = request.GetResponse ();
// Display the status.
Output.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
//Output.WriteLine (responseFromServer);
// Clean up the streams.

reader.Close ();
dataStream.Close ();
response.Close ();

reader.Dispose();
dataStream.Dispose();
response.Dispose();
}
catch (Exception x)
{
Output.WriteLine(Bars.Info.Name.ToString() + " " + x.ToString());
}
}
public void CloseAllPositions()
{
try
{
string sURL = "";
sURL = "http://www.collective2.com/cgi-perl/signal.mpl?cmd=closeallpositions&systemid=" + Strat_ID.ToString() + "&pw=" + PassWord.ToString() + "";
//Output.WriteLine(sURL);
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(sURL);

WebResponse response = request.GetResponse ();
// Display the status.
Output.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
//Output.WriteLine (responseFromServer);
// Clean up the streams.

reader.Close ();
dataStream.Close ();
response.Close ();

reader.Dispose();
dataStream.Dispose();
response.Dispose();
}
catch (Exception x)
{
Output.WriteLine(Bars.Info.Name.ToString() + " " + x.ToString());
}
}
public void Send(Order info)
{
try
{
string sURL = "";
sURL = "http://www.collective2.com/cgi-perl/signal.mpl?cmd=signal&systemid=" + Strat_ID.ToString() + "&pw=" + PassWord.ToString() + "&instrument=" + info.instrument.ToString() + "&action=" + info.action.ToString() + "&quant=" + info.quant.ToString() + "&symbol=" + info.symbol.ToString() + "&limit=" + info.limit.ToString() + "&duration=" + info.duration.ToString() + "&stoploss=" + info.Stop_Loss.ToString() + "&profittarget=" + info.Profit_Target.ToString() + "&signalid=" + info.SigID.ToString() + "";
//Output.WriteLine(sURL);
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(sURL);

WebResponse response = request.GetResponse ();
// Display the status.
Output.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
//Output.WriteLine (responseFromServer);
// Clean up the streams.

reader.Close ();
dataStream.Close ();
response.Close ();

reader.Dispose();
dataStream.Dispose();
response.Dispose();
}
catch (Exception x)
{
Output.WriteLine(Bars.Info.Name.ToString() + " " + x.ToString());
}

}
public string Cancel(string id)
{
try
{
string sURL;
sURL = "http://www.collective2.com/cgi-perl/signal.mpl?cmd=cancel&signalid=" + id.ToString() + "&systemid=" + Strat_ID.ToString() + "pw=" + PassWord.ToString() + "";

// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(sURL);

WebResponse response = request.GetResponse ();
// Display the status.
Output.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
//Output.WriteLine (responseFromServer);
// Clean up the streams.

reader.Close ();
dataStream.Close ();
response.Close ();

reader.Dispose();
dataStream.Dispose();
response.Dispose();
}
catch (Exception x)
{
Output.WriteLine(Bars.Info.Name.ToString() + " " + x.ToString());
}


}

Return to “MultiCharts .NET”