This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from nicelgueta/v0.7
0.7.0 changes
- Loading branch information
Showing
43 changed files
with
6,849 additions
and
2,392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ venv.bak/ | |
|
||
# other | ||
.vscode/ | ||
|
||
.master.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.account.Account |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.block_trading.Blocktrading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.convert.Convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.copy_trading.CopyTrading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.earn.Earn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.funding.Funding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.grid_trading.GridTrading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# pyokx | ||
[![Downloads](https://pepy.tech/badge/pyokx)](https://pepy.tech/project/pyokx) | ||
![Tests](https://github.com/nicelgueta/pyokx/actions/workflows/pyokx.yml/badge.svg) | ||
## Installation | ||
|
||
```shell | ||
pip install pyokx | ||
``` | ||
|
||
## Introduction | ||
|
||
pyokx is a completely unofficial python API wrapper developed to interact with the OKX V5 API. | ||
It's unique insofar as that it has been developed by scraping the API documentation to dynamically generate python code to provide an intuitive | ||
pythonic interface for exact same API. This idea essentially is to avoid the need to create separate documentation for this wrapper and instead you can simply refer to the official OKX docs for API usage. | ||
|
||
It's used by creating a base client instance to make and receive requests and passing that client to each API class (`APIComponent`), which has been dynamically generated from the API docs. | ||
|
||
|
||
**Let's start with an example.** | ||
|
||
Let's say we want to check all current positions. | ||
|
||
Check out the docs for get balance here: https://www.okx.com/docs-v5/en/#rest-api-account-get-positions | ||
|
||
We can see the endpoint belongs to the Account API and needs to be called with 3 parameters: | ||
|
||
![OKX-docs](assets/images/get-pos.png) | ||
|
||
In pyokx, you can see the method signature for the Account class is exactly the same: | ||
```python | ||
def get_positions( | ||
self, | ||
instType: str = None, | ||
instId: str = None, | ||
posId: str = None, | ||
use_proxy: bool = False, | ||
) -> APIReturn: | ||
``` | ||
|
||
So this can be easily implemented like so: | ||
|
||
1. Create `.env` file that contains your API information: | ||
``` | ||
KEY = replace_your_key_here | ||
SECRET = replace_your_secret_here | ||
PASSPHRASE = replace_your_passphrase_here | ||
``` | ||
|
||
2. Read API information from `.env` and create the base client: | ||
```python | ||
import os | ||
|
||
# python-dotenv should have been installed from the dependencies | ||
from dotenv import load_dotenv | ||
from pyokx import OKXClient, Account | ||
|
||
# read information from .env file | ||
load_dotenv() | ||
|
||
# create the base client: | ||
client = OKXClient( | ||
key = os.getenv('KEY'), | ||
secret = os.getenv('SECRET'), | ||
passphrase = os.getenv('PASSPHRASE'), | ||
) | ||
... | ||
``` | ||
|
||
3. Now you can create Account object and call endpoints | ||
```python | ||
... | ||
# create a component for the Account API by passing the client dependency | ||
account = Account(client) | ||
|
||
# get positions | ||
api_response = account.get_positions() | ||
|
||
# you can convert to a pandas dataframe to make it more readable | ||
df_response = api_response.to_df() | ||
print(df_response) | ||
|
||
# or you can get the raw response | ||
raw_response = api_response.response | ||
print(raw_response) | ||
``` | ||
|
||
That simple. | ||
|
||
______ | ||
|
||
|
||
## Key features | ||
|
||
### APIReturn | ||
|
||
This is essentially a wrapper around the response that is returned from every endpoint. This is to provide some useful helper methods such as dataframe conversion. | ||
|
||
### Proxies | ||
|
||
As is common with a lot of exchange APIs, for calls that require authentication (usually account/trade-related), it is strongly encouraged to limit your API key to a select list IP addresses to protect your account. On some systems this may require routing traffic through a forward proxy. pyokx supports this pattern by allowing you to pass the necessary proxies to the base client and you can trigger this behaviour by setting the `use_proxy` parameter to `True`. | ||
For example: | ||
```python | ||
proxies = { | ||
"http": "http://your-proxy-server.com", | ||
"https": "https://your-proxy-server.com", | ||
} | ||
client = OKXClient( | ||
key="key", | ||
secret="secret", | ||
passphrase="passphrase", | ||
proxies=proxies | ||
) | ||
|
||
# trigger the use of the proxy server with use_proxy | ||
account = Account(client) | ||
api_response = account.get_positions(use_proxy=True) | ||
|
||
``` | ||
|
||
## Development progress | ||
|
||
**It's still a very early version - so issues, feature requests and bugs are very welcome!** | ||
|
||
- [x] REST API implementation. | ||
- [x] Fix pythonic naming conventions when API names contain special characters | ||
- [x] Enhance documentation | ||
- [ ] Websocket API implementation. | ||
|
||
## Disclaimer | ||
> NB. pyokx is totally unofficial and is in no way affiliated with OKEX Crypto exchange and simply exists as a helpful wrapper to interact with the V5 API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.market_data.MarketData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.public_data.PublicData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.recurring_buy.RecurringBuy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.savings.Savings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.status.Status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.subaccount.Subaccount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.trade.Trade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: pyokx.trading_data.TradingData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
edit_uri: edit/main/docs/ | ||
markdown_extensions: | ||
- admonition | ||
- attr_list | ||
- codehilite | ||
- md_in_html | ||
- meta | ||
- pymdownx.highlight: | ||
use_pygments: true | ||
- pymdownx.superfences | ||
- pymdownx.tabbed | ||
nav: | ||
- Home: index.md | ||
- API Reference: | ||
- public_data.md | ||
- grid_trading.md | ||
- block_trading.md | ||
- trading_data.md | ||
- status.md | ||
- savings.md | ||
- earn.md | ||
- funding.md | ||
- recurring_buy.md | ||
- subaccount.md | ||
- trade.md | ||
- market_data.md | ||
- convert.md | ||
- account.md | ||
- copy_trading.md | ||
plugins: | ||
- search | ||
- mkdocstrings: | ||
handlers: | ||
python: | ||
rendering: | ||
heading_level: 2 | ||
show_bases: true | ||
show_category_heading: true | ||
show_object_full_path: false | ||
show_root_heading: true | ||
show_source: false | ||
repo_url: https://github.com/nicelgueta/pyokx | ||
site_name: pyokx | ||
theme: | ||
favicon: img/favicon.ico | ||
font: | ||
code: Source Code Pro | ||
text: Inter | ||
icon: | ||
repo: fontawesome/brands/github | ||
name: material | ||
palette: | ||
- media: (prefers-color-scheme) | ||
toggle: | ||
icon: material/brightness-auto | ||
name: Switch to light mode | ||
- accent: black | ||
media: '(prefers-color-scheme: light)' | ||
primary: black | ||
scheme: default | ||
toggle: | ||
icon: material/weather-sunny | ||
name: Switch to dark mode | ||
- accent: black | ||
media: '(prefers-color-scheme: dark)' | ||
primary: black | ||
scheme: slate | ||
toggle: | ||
icon: material/weather-night | ||
name: Switch to light mode | ||
watch: | ||
- pyokx/ | ||
- README.md |
Oops, something went wrong.