How to work with transaction stream

edited January 2016 in General

This post is to explain on how to make transaction stream work for you.

Please read this Contract expiry time vs sell time before, as these terms will be used quite often in here

To get notification about transactions whenever they are executed you need to subscribe to Transaction stream

{
  "transaction": 1,
  "subscribe": 1
}

this will give an initial response with an subscription id when subscribed successfully

{
  "echo_req": {
    "subscribe": 1,
    "transaction": 1
  },
  "transaction": {
    "id": "B81005F2-C24A-11E5-992B-51FEB5EDDAFC"
  },
  "msg_type": "transaction"
}

So now, when you buy a contract then you get response to buy plus you will get transaction notification response as shown below

{
  "echo_req": {
    "subscribe": 1,
    "transaction": 1
  },
  "transaction": {
    "amount": "-1.0300",
    "balance": "1335.0100",
    "transaction_id": "14337505328",
    "contract_id": "7243837448",
    "action": "buy",
    "id": "B81005F2-C24A-11E5-992B-51FEB5EDDAFC"
  },
  "msg_type": "transaction"
}

So when contract gets expired (contract expiry is different from contract sell, sell may happen at or after contract expiry as contract is sold by our system after evaluation) it may take some time for contract to be sold by system. But, if you want to force system to sell expired contracts you can invoke Sell expired call. Please note that manually invoking it is same as system auto selling as system also use this call to sell contracts.

{
  "sell_expired": 1
}

in response to this call you will response stating how may contracts were sold

{
  "echo_req": {
    "sell_expired": 1
  },
  "sell_expired": {
    "count": 1
  },
  "msg_type": "sell_expired"
}

and as you are subscribed to transaction stream you will get this response also

{
  "echo_req": {
    "subscribe": 1,
    "transaction": 1
  },
  "transaction": {
    "amount": "2.0000",
    "balance": "1337.0100",
    "transaction_id": "14337532688",
    "contract_id": "7243837448",
    "action": "sell",
    "id": "B81005F2-C24A-11E5-992B-51FEB5EDDAFC"
  },
  "msg_type": "transaction"
}

Later you can use forget or forget all to cancel this subscription

{
  "forget": "B81005F2-C24A-11E5-992B-51FEB5EDDAFC"
}
{
  "forget_all": "transaction"
}
Sign In or Register to comment.