Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pytest = "*"
pytest-runner = "*"
pytest-mock = "*"
pytest-asyncio = "*"
pdoc3 = "*"

[requires]
python_version = "3.9.6"
8 changes: 8 additions & 0 deletions deriv_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
#
__pdoc__ = {
'deriv_api.cache' : False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the meaning of these false ? does that mean no doc for them ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, False means no document for them. For initial checking I made it false. I will include this also in API documentation

'deriv_api.in_memory' : False,
'deriv_api.errors' : False,
'deriv_api.utils' : False,
'deriv_api.subscription_manager' : False,
'deriv_api.custom_future': False
}
57 changes: 44 additions & 13 deletions deriv_api/deriv_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,55 @@
level=logging.ERROR
)

__pdoc__ = {
'deriv_api.deriv_api.DerivAPI.send': False,
'deriv_api.deriv_api.DerivAPI.api_connect': False,
'deriv_api.deriv_api.DerivAPI.get_url': False,
'deriv_api.deriv_api.DerivAPI.parse_response': False,
'deriv_api.deriv_api.DerivAPI.send_receive': False,
'deriv_api.deriv_api.DerivAPI.wsconnection' : False,
'deriv_api.deriv_api.DerivAPI.storage' : False
}

class DerivAPI(DerivAPICalls):
"""
The minimum functionality provided by DerivAPI, provides direct calls to the API.
`api.cache` is available if you want to use the cached data

example
apiFromEndpoint = deriv_api.DerivAPI({ endpoint: 'ws.binaryws.com', app_id: 1234 });

param {Object} options
param {WebSocket} options.connection - A ready to use connection
param {String} options.endpoint - API server to connect to
param {Number} options.app_id - Application ID of the API user
param {String} options.lang - Language of the API communication
param {String} options.brand - Brand name
param {Object} options.middleware - A middleware to call on certain API actions

property {Cache} cache - Temporary cache default to {InMemory}
property {Cache} storage - If specified, uses a more persistent cache (local storage, etc.)
Examples
--------
- Pass the arguments needed to create a connection:
>>> api = deriv_api.DerivAPI({ endpoint: 'ws://...', app_id: 1234 });

- create and use a previously opened connection:
>>> connection = await websockets.connect('ws://...')
>>> api = deriv_api.DerivAPI(connection=connection)

Args:
options (dict):

Parameters
----------
options.connection : websockets.WebSocketClientProtocol
A ready to use connection
options.endpoint : String
API server to connect to
options.app_id : String
Application ID of the API user
options.lang : String
Language of the API communication
options.brand : String
Brand name
options.middleware : String
A middleware to call on certain API actions

Properties
cache : Cache
Temporary cache default to {InMemory}
storage : Cache
If specified, uses a more persistent cache (local storage, etc.)
"""

wsconnection: Union[websockets.WebSocketClientProtocol, None] = None
storage: Union[InMemory, Cache, str] = ''

Expand Down Expand Up @@ -122,5 +151,7 @@ def parse_response(self, message: str) -> dict:
return data

async def disconnect(self) -> None:
""" To disconnect the websocket connection
"""
self.shouldReconnect = False
await self.wsconnection.close()
25 changes: 20 additions & 5 deletions deriv_api/deriv_api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ class DerivAPICalls:

async def account_closure(self, args=None):
"""
param args {Dict}
param args.account_closure {Number}: Must be `1`
param args.passthrough {Any}: [Optional] Used to pass data through the websocket, which may be retrieved via the `echo_req` output field.
param args.reason {String}: Reason for closing off accounts.
param args.req_id {Number}: [Optional] Used to map request to response.
Args:
args (dict):
Parameters
----------
args.account_closure : Number
Must be 1

args.passthrough : Any [Optional]
Used to pass data through the websocket, which may be retrieved via the echo_req output field.

args.reason : String
Reason for closing off accounts.

args.req_id : Number [Optional]
Used to map request to response.

"""

if args is None:
Expand Down Expand Up @@ -6029,6 +6040,10 @@ async def process_request(self, all_args):
raise ValueError(error)
return await self.send(parsed_args)

__pdoc__ = {
'parse_args' : False,
'validate_args' : False
}

def parse_args(all_args):
"""
Expand Down