Module deriv_api.deriv_api

Classes

class DerivAPI (**options)

The minimum functionality provided by DerivAPI, provides direct calls to the API. api.cache is available if you want to use the cached data

Examples

  • 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)

Parameters

options : dict with following keys
    connection : websockets.WebSocketClientProtocol
        A ready to use connection
    endpoint : String
        API server to connect to
    app_id : String
        Application ID of the API user
    lang : String
        Language of the API communication
    brand : String
        Brand name
    middleware : MiddleWares
        middlewares to call on certain API actions. Now two middlewares are supported: sendWillBeCalled and
        sendIsCalled

Properties

cache: Cache Temporary cache default to InMemory storage : Cache If specified, uses a more persistent cache (local storage, etc.) events: Observable An Observable object that will send data when events like 'connect', 'send', 'message' happen

Ancestors

Methods

async def subscribe(self, request)

Subscribe to a given request

Parameters

request : dict
    Subscribe request

Example

>>> proposal_subscription = api.subscribe({"proposal_open_contract": 1, "contract_id": 11111111, "subscribe": 1})

Returns

Observable
async def forget(self, subs_id)

Forget / unsubscribe the specific subscription.

Parameters

subs_id : str
    subscription id

Returns

Returns dict
async def forget_all(self, *types)

Forget / unsubscribe the subscriptions of given types.

Possible values are: 'ticks', 'candles', 'proposal', 'proposal_open_contract', 'balance', 'transaction'

Parameter

*types : Any number of non-keyword arguments

Example

api.forget_all("ticks", "candles")

Returns

Returns the dict
def expect_response(self, *msg_types)

Expect specific message types

Parameters

*msg_types : variable number of non-key string argument
    Expect these types to be received by the API

Returns

 Resolves to a single response or an array
async def clear(self)

Disconnect and cancel all the tasks

Inherited members