binary-com / binary-live-api

JS library to consume Binary.com WebSocket API
https://developers.binary.com
MIT License
45 stars 74 forks source link

How can I get contract_type from transaction stream? #163

Closed arnavzek closed 3 years ago

wilburforce83 commented 3 years ago

Hi There,

So, once you have a contract open, you can subscribe to it with:

api.getContractInfo(contract_id).then(function (response) {
    console.log(response);
})

where contract_id is collected from:

 api.buyContractParams(parameters, 2500).then(  // I am guessing you already know how to place a contract

                (response, reject) => {
                let contract_id = response.buy.contract_id;
});

this will return the following as a response:

image

You'll see you have subscribed to a bucket load of information which you can use. In your request you want the contract type, so you can do this:

api.getContractInfo(contract_id).then(function (response) {
    console.log(response); // full response as shown above
    console.log(response.proposal_open_contract.contract_type); // to show the contract type
})