How to make Authorization
I have made a small program with Javascript. I still can not make Buy Contract, balance and others.
This is from my computer to server :
{"authorize":"p30KLzwBIYpGa0"}
Server answered like this :
{"authorize":{"balance":"9870.77","country":"id","currency":"USD","email":"tonyismanto@yahoo.com","fullname":" ","is_virtual":1,"landing_company_fullname":"Binary Ltd","landing_company_name":"virtual","loginid":"VRTC1414067","scopes":["read","trade","payments","admin"]},"echo_req":{"authorize":"p30KLzwBIYpGa0"},"msg_type":"authorize"}
I tried to know my balance :
{"balance":1}
But the server said like this:
{"echo_req":{"balance":1},"error":{"code":"AuthorizationRequired","message":"Please log in."},"msg_type":"balance"}
I have tried it with API Playground. There is no problem.
Answers
@tony_bot when you connect to websocket you first send
{"authorize":"p30KLzwBIYpGa0"}
call to authorize the connection and on same connection i.e when you get authorize response you can sendbalance
call. Can you paste your code here so as to help you better?@Raunak , I have sent the file
Thank You.
@tony_bot you are opening a new connection for every call which is not a good practice, and when you send
buy
call over new connection, then that connection is not authorized hence you get authorization errorBetter to use callback as per your need
if you want to attach events then keep
ws
object in your scope and onClick of buy do thisws.send(JSON.stringify({buy: <proposal_id>, price: 5})
what do you mean with price:5 in
ws.send(JSON.stringify({buy: <proposal_id>, price: 5}) raunak
help?