FTX python wrapper with rest API, websocket API.
Project description
Python FTX API Sample Code
FTX is a cryptocurrency derivatives exchange.
This is a wrapper around the FTX API as described on FTX, including all features the API provides using clear and readable objects, both for the REST as the websocket API. I am in no way affiliated with FTX, use at your own risk.
If you think something is broken, something is missing or have any questions, please open an Issue
Get Started and Documentation
If you're new to FTX, use the following link to save 5% on all of your trade fees.
Install
pip install python-ftx-api
Usage
Change your API KEY and your SECRET KEY.
Restful Api Sample Code
from pyftx import Client
API = "your-api-key"
SECRET = "your-secret-key"
subaccount_name = "your-subaccount_name"
client = Client(API, SECRET, subaccount=subaccount_name)
info = client.get_markets()
print(info)
Websocket Sample Code
from pyftx import ThreadedWebsocketManager
def on_read(event):
print(event)
API = "your-api-key"
SECRET = "your-secret-key"
subaccount_name = "your-subaccount_name"
wsm = ThreadedWebsocketManager(API, SECRET, subaccount=subaccount_name)
wsm.start()
# Un-auth subscribe - Public Channels
name = 'market_connection'
wsm.start_socket(on_read, socket_name=name)
wsm.subscribe(name, channel="ticker", op="subscribe", market="ETH-PERP")
# Auth subscribe - [filled](https://docs.ftx.com/#fills-2)
name = 'private_connection'
wsm.start_socket(on_read, socket_name=name)
wsm.login(socket_name=name)
wsm.subscribe(
name,
channel="fills",
op="subscribe",
)
# Auth subscribe -[orders](https://docs.ftx.com/#orders-2)
ws_type = 'private_connection'
wsm.start_socket(on_read, socket_name=ws_type)
wsm.login(socket_name=ws_type)
wsm.subscribe(
ws_type,
channel="orders",
op="subscribe",
)
Websocket with arguments
from pyftx import ThreadedWebsocketManager
from functools import partial
API = "your-api-key"
SECRET = "your-secret-key"
subaccount_name = "your-subaccount_name"
def on_message(event, argument):
msg = "{}.event: {}".format(argument, event)
print("on message: ", msg)
wsm = ThreadedWebsocketManager(API, SECRET, subaccount=subaccount_name)
wsm.start()
# Un-auth subscribe - Public Channels
subaccount_name = "Cuongitl"
callback_with_arguments = partial(on_message, argument=subaccount_name)
name = 'market_connection'
wsm.start_socket(callback_with_arguments, socket_name=name)
wsm.subscribe(name, channel="ticker", op="subscribe", market="ETH-PERP")
Donate / Sponsor
I develop and maintain this package on my own for free in my spare time. Donations are greatly appreciated. If you prefer to donate any other currency please contact me.
-
BTC:
3LrqgdMbToh1mAD3sjhbv3oaEppXY7hkae
-
BTC:
0x329a9F2b01aDA25F15eAE4C633d3bed8442c7BC6
(BSC) -
USDT:
0x329a9F2b01aDA25F15eAE4C633d3bed8442c7BC6
(BSC) -
FTT:
0x329a9F2b01aDA25F15eAE4C633d3bed8442c7BC6
(ERC-20)
Release Notes
The release notes can be found here.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-ftx-api-0.0.4.tar.gz
.
File metadata
- Download URL: python-ftx-api-0.0.4.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1479c17c38dd1de010d534c1ea038ca4e258a734cf5b49bb999e5029deee540 |
|
MD5 | 2c9c0f857e27ceef0a4cb5e9625d9dac |
|
BLAKE2b-256 | af70a6979fbd1f66d85833684072ec5cd5d71bf45bbb9f27d7d98ff6e5436010 |
File details
Details for the file python_ftx_api-0.0.4-py2.py3-none-any.whl
.
File metadata
- Download URL: python_ftx_api-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1efceb38f57dac16ea2acc079a694217dc91394293e25b5b05cdb9554ed2f28 |
|
MD5 | 7fa502e6f226711dbc872fe697d74f54 |
|
BLAKE2b-256 | 56aa051a540f52e98baadeea70ed05bcaf3d9ca7b20f323daf504c56db398d8c |