Skip to main content

Python SDK for Flex Perpetual

This library is tested against Python versions 3.6, 3.9, and 3.11.

Installation

This package is available on PyPI. To install run the command below:

$ pip install fp-v2-python

Getting Started

The Client object contains two major attributes: Public and Private. As the names suggest, Public is for public functions that don't require an Ethereum private key, and Private is for functions specifically for the given key. For more comprehensive examples, please refer to the examples directory as well as the tests.

Public functions

from flextrade.flextrade_client import Client
from flextrade.constants.markets import BASE_MARKET_ETH_USD
from flextrade.enum import Action

#
# Using publicly access functions
#
flextrade_client = Client(
    rpc_url=RPC_URL
)
# Get oracle price, adaptive price, and price impact of a new position
flextrade_client.public.get_price(BASE_MARKET_ETH_USD, Action.SELL, 1000)
# Get market information
flextrade_client.public.get_market_info(BASE_MARKET_ETH_USD)
# Get sub account in address format
flextrade_client.public.get_sub_account(1)
# Get position ID
flextrade_client.public.get_position_id(some_account, some_sub_account_id, BASE_MARKET_ETH_USD)
# Get position info
flextrade_client.public.get_position_info(some_account, some_sub_account_id, BASE_MARKET_ETH_USD)

Private function

from flextrade.flextrade_client import Client
from flextrade.constants.markets import BASE_MARKET_ETH_USD
from flextrade.constants.tokens import BASE_SEPOLIA_COLLATERAL_USDC
from flextrade.enum import Action

#
# Initailized client with private key
#
flextrade_client = Client(
    eth_private_key=PRIVATE_KEY,
    rpc_url=RPC_URL
)
# Get public address of the ethereum key
flextrade_client.private.get_public_address()
# Deposit ETH as collateral
flextrade_client.private.deposit_eth_collateral(sub_account_id=0, amount=10.123)
# Deposit ERC20 as collateral. This function will automatically
# approve CrossMarginHandler if needed.
flextrade_client.private.deposit_erc20_collateral(sub_account_id=0, token_address=BASE_SEPOLIA_COLLATERAL_USDC, amount=100.10)
# Create a market order
create_market_order = flextrade_client.private.create_market_order(
  sub_account_id=0, market_index=BASE_MARKET_ETH_USD, buy=Action.BUY, size=100, reduce_only=False
)
print(create_market_order)
# Create a trigger order
# trigger_above_threshold = The current price must go above (if True) or below (if False)
# the trigger price in order for the order to be executed
create_order = flextrade_client.private.create_trigger_order(
  sub_account_id=0,
  market_index=BASE_MARKET_ETH_USD,
  buy=Action.BUY,
  size=100,
  trigger_price=1800,
  trigger_above_threshold=True,
  reduce_only=False)
print(create_order)
# Update the order
update_order = flextrade_client.private.update_trigger_order(
  0, create_order["order"]["orderIndex"], Action.SELL, 50, 1700, True, False)
print(update_order)
# Cancel the order
cancel_order = flextrade_client.private.cancel_trigger_order(
  0, update_order["order"]["orderIndex"])

Running Tests

To run tests, you will need have to clone the repo, update .env, and run:

$ make test

Please note that to run tests, Tenderly account is required.

License

The primary license for Flex-Community/fp-sdk-python is the MIT License, see here.

Metadata

Release files for fp-v2-python 1.3.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 fp-v2-python 1.3.2
File Size Uploaded Provenance Actions
fp-v2-python-1.3.2.tar.gz 53.7 kB Without provenance Details for fp-v2-python-1.3.2.tar.gz

Release files / fp-v2-python-1.3.2.tar.gz

Download URL fp-v2-python-1.3.2.tar.gz
Size 53.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e0b616c2eb35ca8221b75cb962f8e2b2cd013140925a01dbe49433fd9d7c4957
BLAKE2b-256 checksum
How to use checksums
3d4b0c4c9de5b0e11bc66ae02064fa87d874aa76cb07d363300c4112e2b081a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Security for fp-v2-python 1.3.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.

Release history Release notifications | RSS feed

This release

1.3.2 This release

1 release file No provenance

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