contracts for multiple accounts

Hello ,

Pls I will like to know how to buy contracts for multiple accounts .

here's how I coded it but I got an error :

const app_id = [appid1,appid2];
const api_token = ["token1", "token2"] ;

const connection = new WebSocket(wss://ws.derivws.com/websockets/v3?app_id=${app_id}&api_token=${api_token});

const api = new DerivAPIBasic({ connection });

async function authorize() {
try {
await api.authorize(api_token);
console.log('Account authorized');
buycontract();
} catch (error) {
console.error('Account authorization failed:', error);
}
}

// Function to send a message through the WebSocket connection
function sendMessage(message) {
connection.send(JSON.stringify(message));
}

// Function to buy a contract
function buyContract() {
const proposalData = {
buy: '1',
price: 1,
parameters: {
amount: 1,
basis: 'stake',
contract_type: 'CALLE',
currency: 'USD',
duration: 1,
duration_unit: 'm',
symbol: 'R_100',
},
req_id: 10,
};

sendMessage(proposalData);
}

here's the sample I followed from the API Explorer :

{
"buy_contract_for_multiple_accounts": "AE79667A-3561-11E6-880B-19CE0BCBE464",
"price": 2.57,
"tokens": [
"EWHdv7feGJRmMf1kqv79lgfPiGjLLGV9GHTZFQ345FzJSfNE",
"ONqj76yAnVKnPtc",
"oSpp7ohpGf50tP6",
"uz6OSIcFIcPKK5T"
]
}

pls how can I modify my code to enable it buy contract for multiple accounts ?

Thanks

Tagged:

Comments

Sign In or Register to comment.