Module deriv_api.subscription_manager

Classes

class SubscriptionManager (api)

Subscription Manager - manage subscription channels

Makes sure there is always only one subscription channel for all requests of subscriptions, keeps a history of received values for the subscription of ticks and forgets channels that do not have subscribers. It also ensures that subscriptions are revived after connection drop/account changed.

Parameters

api : deriv_api.DerivAPI

Example

  • create a new subscription for R_100
>>> source_tick_50: Observable  = await api.subscribe({'ticks': 'R_50'})
>>> subscription_id = 0
>>> def tick_50_callback(data):
>>>     global subscription_id
>>>     subscription_id = data['subscription']['id']
>>>     print(data)
>>> source_tick_50.subscribe(tick_50_callback)
  • forget all ticks
>>> await api.forget_all('ticks')
  • forget based on subscription id
>>> await api.forget(subscription_id)

Methods

async def subscribe(self, request)

Subscribe to a given request, returns a stream of new responses, Errors should be handled by the user of the stream

Example

>>> ticks = api.subscribe({ 'ticks': 'R_100' })
>>> ticks.subscribe(call_back_function)

Parameters

request : dict
A request object acceptable by the API

Returns

Observable
    An RxPY SObservable