Server Time - 8.02 18 Jan
BTC Price - $881.443
LTC Price - $2.93999
cryptonit offers an SocketIO service you can connect to, to receive content in realtime. This is of special interest if you are building a webservice with information from our website or any other application which requires actual content.
Reasons for SocketIO
Every API we are offering has the disadvantage that you have to poll data. This is not a big issue of you only want to receive once a certain piece of information, perform your action and delete to the data you have requested from our servers. However, as your application becomes more complex and requires the information to be as actual as possible it would be necessary to poll very frequently data from our servers. This is not a satisfying solution, since you cannot be sure your data is still actual even after 1 second. Furthermore, it produced much needless traffic in times when content does not change. Here is where SocketIO comes in. It is a standardized protocol to listen for changes and get notified in realtime.
The usage depends partly on the programming language you are using. For nearly all languages there are implementations of SocketIO available making its use very simple. Often it is only required to define the URL and port of the SocketIO server and implement some code to be executed in case a notification/message arrives. There is only one pitfall we have discovered. Our SocketIO server uses TLS/SSL to encrypt data. Many SocketIO libraries are only able to process unencrypted data. Some others have the possibility to use encrypted communication but require some special care in setting up the certificates.
Connect to SocketIO server
The cryptonit SocketIO server is available under: URL: https://cryptonit.net Port: 8443 Be aware of the "https" which means to use encrypted communication. Depending on your library you may have to strip off the protocol and configure encryption differently. Please consult the documentation of your library.
Process incoming messages
Messages arrive as normal string but are formatted to be a well defined JSON object. Depending on your library your messages might be already in JSON format or are still a simple string which must first be converted to JSON. We assume you have a proper JSON object for following explanation.
Most important in this JSON object is the "channel" entry. Please always check the channel before you process the body part of the message. The main "data" of the message depends on the channel used to deliver it and unexpected behavior can occur when parsing a JSON objects you do not expect. The SocketIO server at cryptonit is used to deliver various content.
The data or "body" part of the message itself is again a JSON object. Its content depends on the on the channel. A list of channels and their transferred data is given below.
Given an example of a JSON object returned by the SocketIO server:
"<some JSON object>"
This channel transports all changes ongoing in the exchange. These are newly placed, canceled or filled orders. For all cases you receive a full object containing all data as you would receive it when performing a normal query against the database. One example taken from here would be:
"type": XXX, // placed, filled or canceled
"bid_currency": "BTC", // some currency (LTC, USD, etc.)
"ask_currency": "LTC", // some currency (LTC, USD, etc.)
"bid_amount": "4.87696051", // amount in current bid
"ask_amount": "487.696051", // amount in current ask
"bid_rate": "100.0", // bid rate
"ask_rate": "0.01", // ask rate
"created": "12312312" // timestamp when order was placed
"filled": "12312313" // timestamp when order was filled (only if type is filled)