Skip to content

Commit 60df3cd

Browse files
authored
Merge pull request #27 from guilyx/async
AsyncClient
2 parents de38352 + b68b3e7 commit 60df3cd

File tree

7 files changed

+569
-39
lines changed

7 files changed

+569
-39
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Checkout the [Changelog](https://github.com/guilyx/python-nexo/blob/master/docs/
5959
- Register a Nexo Account. [here](https://nexo.io/ref/vaqo55u5py?src=web-link)
6060
- Generate an API Key in Nexo Pro with the permissions you want.
6161

62+
## Advice
63+
64+
Priviledge Async Client. The advantage of async processing is that we don’t need to block on I/O which is every action that we make when we interact with the Nexo Pro servers.
65+
66+
By not blocking execution we can continue processing data while we wait for responses or new data from websockets.
67+
6268
## Set it up 💾
6369

6470
### PIP
@@ -67,11 +73,37 @@ Checkout the [Changelog](https://github.com/guilyx/python-nexo/blob/master/docs/
6773
2. Explore the API:
6874

6975
```python3
76+
#### Sync
77+
7078
import nexo
7179
import os
72-
c = nexo.Client("your_api_key", "your_api_secret")
80+
from dotenv import load_dotenv
81+
82+
# Loads your API keys from the .env file you created
83+
load_dotenv()
84+
key = os.getenv("NEXO_PUBLIC_KEY")
85+
secret = os.getenv("NEXO_SECRET_KEY")
86+
87+
# Instantiate Client and grab account balances
88+
c = nexo.Client(key, secret)
7389
balances = c.get_account_balances()
7490
print(balances)
91+
92+
#### Async
93+
94+
import nexo
95+
import os
96+
import asyncio
97+
from dotenv import load_dotenv
98+
99+
100+
load_dotenv()
101+
102+
key = os.getenv("NEXO_PUBLIC_KEY")
103+
secret = os.getenv("NEXO_SECRET_KEY")
104+
105+
client = nexo.AsyncClient.create(key, secret)
106+
print(await client.get_account_balances())
75107
```
76108

77109
### Docker (source)

codecov.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ parsers:
1717
ignore:
1818
- "setup.py"
1919
- "examples/*"
20+
- "nexo/async_client.py"
21+
- "nexo/client.py"
2022

2123
comment:
2224
layout: "reach,diff,flags,files,footer"
2325
behavior: default
24-
require_changes: no
26+
require_changes: no

examples/async_get_balances.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
from os import path
3+
4+
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
5+
6+
import nexo
7+
import os
8+
import asyncio
9+
from dotenv import load_dotenv
10+
11+
load_dotenv()
12+
13+
key = os.getenv("NEXO_PUBLIC_KEY")
14+
secret = os.getenv("NEXO_SECRET_KEY")
15+
16+
async def main():
17+
client = await nexo.AsyncClient.create(key, secret)
18+
print(await client.get_account_balances())
19+
20+
await client.close_connection()
21+
22+
if __name__ == "__main__":
23+
loop = asyncio.get_event_loop()
24+
loop.run_until_complete(main())

nexo/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
__version__ = "1.0.1"
66

7+
from nexo.async_client import AsyncClient
78
from nexo.client import Client
89
from nexo.response_serializers import (
910
AdvancedOrderResponse,

0 commit comments

Comments
 (0)