buy contract with strike rate using deriv api

How to buy the contract with strike rate I have an external api that sends fxPair,direction,expiry and strikeRate, so i thought of using barrier but i get error every time saying invalid offerings or price moved, when i remove the barrier the contract is purchased at the current market price
here is what i'm doing i wait for the current_spot to reach the required strikerate and buy the contract

await contract.onUpdate().pipe(find(({ current_spot }) => 
  {
      if(param.contract_type=="CALL"){
          return current_spot.value <= srRate
      }else if(param.contract_type=="PUT"){
          return current_spot.value >= srRate
      }
  } )).toPromise();

Once the promise is resolved i purchase the contract

    const buy = await contract.buy();

Can anybody please provide me some working example for buying the contract when strikeRate is reached using Deriv api

Sign In or Register to comment.