Skip to main content

ftxusderivatives-python

An unofficial Python wrapper for the REST and WebSocket APIs of FTX US Derivatives, formerly known as LedgerX. I have no affiliation with FTX US Derivatives. Use this at your own risk.

Features

  • Implementation of all REST endpoints, detailed here
  • WebSocket implementation: live orderbook tops, account balances, open positions info, order fills, server heartbeat, reconnect logic
  • Simple handling of authentication
  • HTTP request error handling and retry logic
  • Logging support

Quick Start

Register an account with FTX US Derivatives. [optional]

Generate an API key and configure permissions. [optional]

Install ftxusderviatives-python: pip install ftxusderivatives-python

Here's some example code to get started with. Note that API calls that require authentication will not work if you do not enter your API key.

###############################
# REST API Example
###############################
from rest_lx.rest import LxClient

api_key = ""  # TODO: Put API key here

# Init REST client
client = LxClient(api_key=api_key)

# list active day-ahead-swap contracts
swaps = client.list_contracts({
    'active': True,
    'derivative_type': 'day_ahead_swap',
})

# grab BTC day-ahead-swap contract ID
data = swaps['data']
cbtc_swap = filter(lambda data: data['underlying_asset'] == 'CBTC', data)
contract_id = next(cbtc_swap)['id']
print(f"BTC swap contract_id: {contract_id}")

# retrieve your position for BTC day-ahead-swap contract (requires authentication)
position = client.retrieve_contract_position(contract_id)
print(f"BTC swap position: {position}")

# place bid for BTC next-day swap
lx_buy = {
    'order_type': 'limit',
    'contract_id': contract_id,
    'is_ask': False,
    'swap_purpose': 'undisclosed',
    'size': 1,
    'price': 100,  # $1 (100 cents)
    'volatile': True
}
order = client.create_order(**lx_buy)

# cancel placed order
message_id = order['data']['mid']  # order ID
client.cancel_single_order(message_id=message_id, contract_id=contract_id)

###############################
# WebSocket Example
###############################
from websocket_lx.client import LxWebsocketClient
import time

# Init WebSocket client
ws = LxWebsocketClient(api_key=api_key)

# Subscribe to orderbook-top feed for BTC day-ahead-swap contract
ws.subscribe(contract_id=contract_id)
ws.connect()

# Grab orderbook-top for BTC day-ahead-swap once a second
while True:
    top = ws.get_book_top(contract_id=contract_id)
    print(top)
    time.sleep(1)

Todo

Contributing

Contributions, fixes, recommendations, and all other feedback is welcome. If you are fixing a bug, please open an issue first with all relevant details, and mention the issue number in the pull request.

Contact

I can be reached on discord at Nenye#5335, or through email at nenye@ndili.net. Otherwise, feel free to open a PR or Issue here.

Metadata

Release files for ftxusderivatives-python 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ftxusderivatives-python 0.1.2
File Size Uploaded Provenance Actions
ftxusderivatives-python-0.1.2.tar.gz 11.0 kB Without provenance Details for ftxusderivatives-python-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ftxusderivatives-python 0.1.2
File Interpreter ABI Platform Actions
ftxusderivatives_python-0.1.2-py3-none-any.whl Python 3 none any Details for ftxusderivatives_python-0.1.2-py3-none-any.whl

Total release size: 21.7 kB

Release files / ftxusderivatives-python-0.1.2.tar.gz

Download URL ftxusderivatives-python-0.1.2.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f6469c2c4752fe9dc6026da4ea1957db4439d5f3ee5332383dd514ba35da6a26
BLAKE2b-256 checksum
How to use checksums
9345fd8fce261e5aafe170ff72add3b035a36bce91bf62a5131ac53075bd5be4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.1 Windows/10

Release files / ftxusderivatives_python-0.1.2-py3-none-any.whl

Download URL ftxusderivatives_python-0.1.2-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
293b5c9fd7b1443145d65435686baf1c4423d94a960ac76cf355eabfa7f44cbb
BLAKE2b-256 checksum
How to use checksums
a756dabd66c5455973ad7c720e0839e7c716cd681d8360753ce111816253f7b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.1 Windows/10

Security for ftxusderivatives-python 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page