# 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](https://github.com/Flex-Community/fp-sdk-python/tree/main/examples) directory as well as the [tests](https://github.com/Flex-Community/fp-sdk-python/tree/main/tests).
### Public functions
```python
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
```python
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](hhttps://github.com/Flex-Community/fp-sdk-python/blob/main/LICENSE).
Raw data
{
"_id": null,
"home_page": "https://github.com/Flex-Community/fp-sdk-python",
"name": "fp-v2-python",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "flextrade exchange perp dex defi ethereum eth arbitrum blast",
"author": "Flex-Community",
"author_email": "marketing@flexdex.finance",
"download_url": "https://files.pythonhosted.org/packages/3d/4b/0c4c9de5b0e11bc66ae02064fa87d874aa76cb07d363300c4112e2b081a2/fp-v2-python-1.3.2.tar.gz",
"platform": null,
"description": "# Python SDK for Flex Perpetual\n\nThis library is tested against Python versions 3.6, 3.9, and 3.11.\n\n## Installation\n\nThis package is available on PyPI. To install run the command below:\n\n```\n$ pip install fp-v2-python\n```\n\n## Getting Started\n\nThe `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](https://github.com/Flex-Community/fp-sdk-python/tree/main/examples) directory as well as the [tests](https://github.com/Flex-Community/fp-sdk-python/tree/main/tests).\n\n### Public functions\n\n```python\nfrom flextrade.flextrade_client import Client\nfrom flextrade.constants.markets import BASE_MARKET_ETH_USD\nfrom flextrade.enum import Action\n\n#\n# Using publicly access functions\n#\nflextrade_client = Client(\n rpc_url=RPC_URL\n)\n# Get oracle price, adaptive price, and price impact of a new position\nflextrade_client.public.get_price(BASE_MARKET_ETH_USD, Action.SELL, 1000)\n# Get market information\nflextrade_client.public.get_market_info(BASE_MARKET_ETH_USD)\n# Get sub account in address format\nflextrade_client.public.get_sub_account(1)\n# Get position ID\nflextrade_client.public.get_position_id(some_account, some_sub_account_id, BASE_MARKET_ETH_USD)\n# Get position info\nflextrade_client.public.get_position_info(some_account, some_sub_account_id, BASE_MARKET_ETH_USD)\n```\n\n### Private function\n\n```python\nfrom flextrade.flextrade_client import Client\nfrom flextrade.constants.markets import BASE_MARKET_ETH_USD\nfrom flextrade.constants.tokens import BASE_SEPOLIA_COLLATERAL_USDC\nfrom flextrade.enum import Action\n\n#\n# Initailized client with private key\n#\nflextrade_client = Client(\n eth_private_key=PRIVATE_KEY,\n rpc_url=RPC_URL\n)\n# Get public address of the ethereum key\nflextrade_client.private.get_public_address()\n# Deposit ETH as collateral\nflextrade_client.private.deposit_eth_collateral(sub_account_id=0, amount=10.123)\n# Deposit ERC20 as collateral. This function will automatically\n# approve CrossMarginHandler if needed.\nflextrade_client.private.deposit_erc20_collateral(sub_account_id=0, token_address=BASE_SEPOLIA_COLLATERAL_USDC, amount=100.10)\n# Create a market order\ncreate_market_order = flextrade_client.private.create_market_order(\n sub_account_id=0, market_index=BASE_MARKET_ETH_USD, buy=Action.BUY, size=100, reduce_only=False\n)\nprint(create_market_order)\n# Create a trigger order\n# trigger_above_threshold = The current price must go above (if True) or below (if False)\n# the trigger price in order for the order to be executed\ncreate_order = flextrade_client.private.create_trigger_order(\n sub_account_id=0,\n market_index=BASE_MARKET_ETH_USD,\n buy=Action.BUY,\n size=100,\n trigger_price=1800,\n trigger_above_threshold=True,\n reduce_only=False)\nprint(create_order)\n# Update the order\nupdate_order = flextrade_client.private.update_trigger_order(\n 0, create_order[\"order\"][\"orderIndex\"], Action.SELL, 50, 1700, True, False)\nprint(update_order)\n# Cancel the order\ncancel_order = flextrade_client.private.cancel_trigger_order(\n 0, update_order[\"order\"][\"orderIndex\"])\n```\n\n## Running Tests\n\nTo run tests, you will need have to clone the repo, update .env, and run:\n\n```\n$ make test\n```\n\nPlease note that to run tests, Tenderly account is required.\n\n## License\n\nThe primary license for Flex-Community/fp-sdk-python is the MIT License, see [here](hhttps://github.com/Flex-Community/fp-sdk-python/blob/main/LICENSE).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python SDK Flex Perpetual",
"version": "1.3.2",
"project_urls": {
"Homepage": "https://github.com/Flex-Community/fp-sdk-python"
},
"split_keywords": [
"flextrade",
"exchange",
"perp",
"dex",
"defi",
"ethereum",
"eth",
"arbitrum",
"blast"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3d4b0c4c9de5b0e11bc66ae02064fa87d874aa76cb07d363300c4112e2b081a2",
"md5": "b521777ecb25471098da2f8034633e1e",
"sha256": "e0b616c2eb35ca8221b75cb962f8e2b2cd013140925a01dbe49433fd9d7c4957"
},
"downloads": -1,
"filename": "fp-v2-python-1.3.2.tar.gz",
"has_sig": false,
"md5_digest": "b521777ecb25471098da2f8034633e1e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 53651,
"upload_time": "2024-10-18T16:54:43",
"upload_time_iso_8601": "2024-10-18T16:54:43.536719Z",
"url": "https://files.pythonhosted.org/packages/3d/4b/0c4c9de5b0e11bc66ae02064fa87d874aa76cb07d363300c4112e2b081a2/fp-v2-python-1.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-18 16:54:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Flex-Community",
"github_project": "fp-sdk-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"tox": true,
"lcname": "fp-v2-python"
}