Topics
Forum Topics not found
Replies
taskman9
27 Mar 2017, 15:32
RE:
hans177 said:
Ok, I managed to do it, without really understanding what I'm doing of course ;)
1. Subscribe to quote updates
2.
private AsyncCallback quoteReceived; ... quoteReceived = new AsyncCallback(OnTick); ... _priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);3.
private void OnTick(IAsyncResult ar) { int bytesRead = _priceStream.EndRead(ar); if (bytesRead > 0) { Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytesRead)); _priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null); } }
Ohw. great....Fullcode example pls?
@taskman9
taskman9
27 Mar 2017, 14:16
RE:
hans177 said:
Hi, looks to me like you are getting quote replies.
How do you get these MarketDataSnapshotFullRefresh-messages? What's the best way to do it? Some endless _priceStream.Read-loop?
Hello Hans, i'm totally clueless about the chain of processes. But you can see i'm running the endless Read loop (in another thread where i posted my code).
You can try that code. If you try it,please let me know if you get any clue.
@taskman9
taskman9
27 Mar 2017, 11:24
RE:
#EOL said:
Hey taskman9
According to Spotware FIX specification you can't subscribe to only bid or only ask spot events, so the part |267=2|269=0|269=1| is compulsory for spot subscription request, while your requests are not correct from protocol point of view: field NoMDEntryTypes (tag 267) [that means "number of market data entry types"] is set to 2, but it is followed by only one MDEntryType (tag 269) field
Hello EOL, please help me man.I sent |267=2|269=0|269=1| but still no replies. After 30seconds,i'm simply seeing a hearbeat & TESTID
Here's my test-code :
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; namespace FixNoSSL { public class FixSocketClient { // cserver ip fix public static string host = "94.75.214.147"; // fix server id public static string FixID = "pepperstone.3190557"; // ctrader account public static string Account = "3190557"; // ctrader password public static string Password = "2276"; public static int total; public static string m = ""; public static int msgSeqenceNum = 1; public static void StartClient(string host) { string time = DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss.fff"); string body = "35=A|34="+ msgSeqenceNum+"|49=" + FixID + "|50=" + Account + "|52=" + time + "|56=CSERVER|57=QUOTE|98=0|108=30|553=" + Account + "|554=" + Password + "|"; // body length int bodylen = body.Length; string fix = "8=FIX.4.4|9=" + bodylen + "|"; // message string message = fix + body; message = message.Replace('|', '\u0001'); byte[] messageBytes = Encoding.ASCII.GetBytes(message); for (int i = 0; i < message.Length; i++) total += messageBytes[i]; int checksum = total % 256; string checksumStr = checksum.ToString().PadLeft(3, '0'); string sum = "10=" + checksumStr + "|"; string m = fix + body + sum; m = m.Replace('|', '\u0001'); Console.WriteLine(">>>>\nSend to server (hit any key) {0}", m); Console.ReadKey(); // Data buffer for incoming data. byte[] bytes = new byte[1024]; // Connect to a remote device. try { // Establish the remote endpoint for the socket. // This example uses port 11000 on the local computer. IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(host), 5201); // Create a TCP/IP socket. Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect the socket to the remote endpoint. Catch any errors. try { sender.Connect(remoteEP); Console.WriteLine("SOCKET CONECTED {0}", sender.RemoteEndPoint.ToString()); // Encode the data string into a byte array. byte[] msg = Encoding.ASCII.GetBytes(m); // Send the data through the socket. int bytesSent = sender.Send(msg); // Receive the response from the remote device. int bytesRec = sender.Receive(bytes); Console.WriteLine("INCOMING SERVER Reply >>\n"+ Encoding.ASCII.GetString(bytes, 0, bytesRec)); Console.WriteLine("Want to send data request? Type 'y' for yes"); string str = Console.ReadLine(); if (str == "y") { try { while (true) { msgSeqenceNum++; time = DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss.fff"); body = "35=V|49=" + FixID + "|56=CSERVER|34="+msgSeqenceNum+"|52=" + time + "|50=QUOTE|57=ANY|262=131129531|263=1|264=1|265=1|146=1|55=1|267=2|269=0|269=1|"; // body length bodylen = body.Length; fix = "8=FIX.4.4|9=" + bodylen + "|"; // message message = fix + body; message = message.Replace('|', '\u0001'); messageBytes = Encoding.ASCII.GetBytes(message);//converted to 0's &1s for (int i = 0; i < message.Length; i++) total += messageBytes[i]; checksum = total % 256; checksumStr = checksum.ToString().PadLeft(3, '0'); sum = "10=" + checksumStr + "|"; m = fix + body + sum; m = m.Replace('|', '\u0001'); msg = Encoding.ASCII.GetBytes(m);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Send the data through the socket. Console.WriteLine("Sent This meggase to get quote:\n"+ Encoding.ASCII.GetString(msg)); bytesSent = sender.Send(msg); // Receive the response from the remote device. bytesRec = sender.Receive(bytes); if (bytes.Length!=0) { Console.WriteLine("SERVER Reply >>\n {0}", Encoding.ASCII.GetString(bytes, 0, bytesRec)); } } } catch (Exception ex2) { Console.WriteLine(ex2.Message); } } // Release the socket. sender.Shutdown(SocketShutdown.Both); sender.Close(); } catch (ArgumentNullException ane) { Console.WriteLine("ArgumentNullException : {0}", ane.ToString()); } catch (SocketException se) { Console.WriteLine("SocketException : {0}", se.ToString()); } catch (Exception e) { Console.WriteLine("Unexpected exception : {0}", e.ToString()); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } public static int Main(String[] args) { while (true) { StartClient(host); Thread.Sleep(5000); } } } }
@taskman9
taskman9
27 Mar 2017, 02:54
RE:
#EOL said:
Hi there.
Take a look on this log that works for me: https://goo.gl/oOrnpT
I think the problem with yours one is tag misordering.
I bet MDEntryType (tag 269) records shold be strictly after NoMDEntryTypes (tag 267)
Hi EOL, I follwed your example but I'm not getting any quote reply. And CSERVER sending me HEARTBEAT & TESTID.
Can you you take a look at my messages to see if they matches with yours?
shared FIX logs with you at:
http://fixparser.targetcompid.com?sharedlink=-KgBuGVR7E7YHHHj_KEd
key to unlock:
G#YtmrE3XlnCvSCR3DtpEMNoBTDJUM9cfCrmk6c3(8p:xvyKCI8
@taskman9
taskman9
27 Mar 2017, 02:40
RE:
hans177 said:
I guess I have to set a timer and check for new data, because there is no system event when there is new data available on the TCP stream?
Hi Hnas, can you you take a look at my messages to see if they matches with yours?
shared FIX logs with you at:
http://fixparser.targetcompid.com?sharedlink=-KgBuGVR7E7YHHHj_KEd key to unlock:
G#YtmrE3XlnCvSCR3DtpEMNoBTDJUM9cfCrmk6c3(8p:xvyKCI8
I'm not getting any quote reply. And CSERVER sending me HEARTBEAT & TESTID.
@taskman9
taskman9
26 Mar 2017, 19:30
RE: RE: RE: where is error n this example
mindbreaker said:
Thanks
Hi, can any one help?
I tried codes from post #17 & got this exception:
System.Net.Sockets.SocketException (0x80004005): No such host is known at System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean include IPv6) at System.Net.Dns.GetHostEntry(String hostNameOrAddress) at FixNoSSL.FixSocketClient.StartClient(String host) in c:\users\workstation\ documents\visual studio 2015\Projects\test01\test01\Program.cs:line 65
the code:
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; namespace FixNoSSL { public class FixSocketClient { // cserver ip fix public static string host = "78.129.190.32"; // fix server id public static string FixID = "pepperstone.3190557"; // ctrader account public static string Account = "3190557"; // ctrader password public static string Password = "2276"; public static int total; public static string m = ""; public static void StartClient(string host) { string time = DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss.fff"); string body = "35=A|34=1|49=" + FixID + "|50=QUOTE|52=" + time + "|56=CSERVER|98=0|108=30|553=" + Account + "|554=" + Password + "|"; // body length int bodylen = body.Length; string fix = "8=FIX.4.4|9=" + bodylen + "|"; // message string message = fix + body; message = message.Replace('|', '\u0001'); byte[] messageBytes = Encoding.ASCII.GetBytes(message);//converted to 0's &1s for (int i = 0; i < message.Length; i++) total += messageBytes[i]; int checksum = total % 256; string checksumStr = checksum.ToString().PadLeft(3, '0'); string sum = "10=" + checksumStr + "|"; string m = fix + body + sum; m = m.Replace('|', '\u0001'); Console.WriteLine("Send to server (hit any key) {0}", m); Console.ReadKey(); // Data buffer for incoming data. byte[] bytes = new byte[1024]; // Connect to a remote device. try { // Establish the remote endpoint for the socket. // This example uses port 11000 on the local computer. IPHostEntry ipHostInfo = Dns.GetHostEntry(host); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint remoteEP = new IPEndPoint(ipAddress, 5201); // Create a TCP/IP socket. Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect the socket to the remote endpoint. Catch any errors. try { sender.Connect(remoteEP); Console.WriteLine("SOCKET CONECTED {0}", sender.RemoteEndPoint.ToString()); // Encode the data string into a byte array. byte[] msg = Encoding.ASCII.GetBytes(m); // Send the data through the socket. int bytesSent = sender.Send(msg); // Receive the response from the remote device. int bytesRec = sender.Receive(bytes); Console.WriteLine("SERVER SEND >> {0}", Encoding.ASCII.GetString(bytes, 0, bytesRec)); // Release the socket. sender.Shutdown(SocketShutdown.Both); sender.Close(); } catch (ArgumentNullException ane) { Console.WriteLine("ArgumentNullException : {0}", ane.ToString()); } catch (SocketException se) { Console.WriteLine("SocketException : {0}", se.ToString()); } catch (Exception e) { Console.WriteLine("Unexpected exception : {0}", e.ToString()); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } public static int Main(String[] args) { while (true) { StartClient(host); Thread.Sleep(5000); } } } }
@taskman9
taskman9
27 Mar 2017, 15:52
RE:
hans177 said:
Ok let me try this
@taskman9