This project demonstrates how to use the Deriv API to implement an options trading system for rise and fall contracts.
- Connect to the Deriv API.
- Subscribe to market tick updates.
- Fetch active trading symbols.
- Retrieve contract details for specific symbols.
- Request price proposals for contracts.
- Execute buy orders for options contracts.
- Disconnect from the API when operations are complete.
- Node.js (version 14 or later).
- A Deriv App ID. You can create one by registering at Deriv.
-
Clone this repository:
git clone https://github.com/mayuran-deriv/trade-rise-fall.git cd trade-rise-fall
-
Install dependencies:
npm install
- Replace
'YOUR_APP_ID'
with your Deriv App ID in the example code. - Run the example script:
node index.js
- Monitor the console output to see API responses and logs.
const derivAPI = new DerivAPIService({
app_id: 'YOUR_APP_ID'
});
Replace 'YOUR_APP_ID'
with your Deriv application ID.
await derivAPI.subscribeTicks('R_100');
Subscribes to live tick updates for the symbol R_100
.
const symbols = await derivAPI.getActiveSymbols();
Retrieves all active trading symbols available.
const contracts = await derivAPI.getContractsForSymbol('R_100');
Fetches available contract types and details for symbol R_100
.
const proposal = await derivAPI.getPriceProposal({
proposal: 1,
amount: 100,
basis: 'stake',
contract_type: 'CALL',
currency: 'USD',
duration: 5,
duration_unit: 'min',
symbol: 'R_100'
});
Requests a price proposal for a CALL contract with:
- Amount: $100
- Duration: 5 minutes
- Currency: USD
const buyResponse = await derivAPI.buyContract({
buy: proposal.proposal!.id,
price: 100
});
Purchases the proposed contract using the specified price.
derivAPI.disconnect();
Closes the connection to the Deriv API.
- Always ensure proper error handling and logging when working with real-time data and transactions.
- The example uses a demo account; do not use real funds without thorough testing.
This project is licensed under the MIT License.
For questions or support, please email: [email protected]