Git Product home page Git Product logo

python-deriv-api's Introduction

python-deriv-api

A python implementation of deriv api library.

PyPI Python 3.9.6 Test status

Go through api.deriv.com to know simple easy steps on how to register and get access. Use this all-in-one python library to set up and make your app running or you can extend it.

Requirement

Python (3.9.6 or higher is recommended) and pip3

Note: There is bug in 'websockets' package with python 3.9.7, hope that will be fixed in 3.9.8 as mentioned in python-websockets/websockets#1051. Please exclude python 3.9.7.

Installation

python3 -m pip install python_deriv_api

Usage

This is basic deriv-api python library which helps to make websockets connection and deal the API calls (including subscription).

Import the module

from deriv_api import DerivAPI

Access

api = DerivAPI(endpoint='ws://...', app_id=1234);
response = await api.ping({'ping': 1})
print(response) 

Creating a websockets connection and API instantiation

You can either create an instance of websockets and pass it as connection or pass the endpoint and app_id to the constructor to create the connection for you.

If you pass the connection it's up to you to reconnect in case the connection drops (cause API doesn't know how to create the same connection).

  • Pass the arguments needed to create a connection:
   api = DerivAPI(endpoint='ws://...', app_id=1234);
  • create and use a previously opened connection:
   connection = await websockets.connect('ws://...')
   api = DerivAPI(connection=connection)

Documentation

API reference

The complete API reference is hosted here

Examples here

Development

git clone https://github.com/binary-com/python-deriv-api
cd python-deriv-api

Setup environment

make setup

Setup environment and run test

make all

Run test

python setup.py pytest

or

pytest

or

make test

Generate documentations

Generate html version of the docs and publish it to gh-pages

make gh-pages

Build the package

make build

Run examples

set token and run example

export DERIV_TOKEN=xxxTokenxxx
PYTHONPATH=. python3 examples/simple_bot1.py

python-deriv-api's People

Contributors

chylli-deriv avatar lim-deriv avatar mukesh-deriv avatar sasikala-binary avatar sasikalachinnasamy avatar shantanu-deriv avatar tom-binary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

python-deriv-api's Issues

Support for trade types such as rise/fall and matches/differs

Can anyone suggest an approach to incorporate various trade types like "rise/fall" and "matches/differs" using the python deriv API library? If you have any ideas, kindly share a code snippet or provide guidance on how to implement these trade types effectively. Your guidance on effectively integrating these trade types would be much appreciated.

WebSocket reconection

I have a similar issue that was mention earlier about stuck at some point, it will be great if you can help me to build some kind of reconnection method.

InvalidStatusCode: server rejected WebSocket connection: HTTP 403

File "/Users/aka/opt/anaconda3/lib/python3.9/site-packages/websockets/legacy/client.py", line 658, in await_impl
await protocol.handshake(
File "/Users/aka/opt/anaconda3/lib/python3.9/site-packages/websockets/legacy/client.py", line 328, in handshake
raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 403
Screenshot 2023-04-09 at 6 54 23 PM

It doesn't do nothing

I makethe first lines:

api = DerivAPI(app_id=app_id)
print (api)

Get the object:
<deriv_api.deriv_api.DerivAPI object at 0x0000022AF7504280>

And nothing more happens!

I am using simple_bot4.py from samples folder

Connection Closes/ Stuck at some point

Websocket stuck after working for nearly 30mins to 1 hr. I tried pinging every 30 seconds, eventhough losing connection with server. Sometimes it might go beyond 2 hours and stuck from there.

ResponseError("Please enter a stake amount that's at least 0.35.")

proposal = await api.proposal({"proposal": 1,
"amount": 0.99,
"barrier": "6",
"basis": "stake",
"contract_type": "DIGITDIFF",
"currency": "USD",
"duration": 1,
"duration_unit": "t",
"symbol": TR_SYM
})
The issue here it seems, the proposal does not see the digits after the decimal point for the amount. When I put 1.2 it only registers 1.

Install problem

Hi

I am trying install with command:

C:\Users\Jhon>pip install python_deriv_api

And get:

ERROR: Could not find a version that satisfies the requirement python_deriv_api (from versions: none) ERROR: No matching distribution found for python_deriv_api

Can you help me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.