Python SDK to interact with Kwenta's smart contracts, subgraphs, and Synthetix perps.
Install the SDK using pip:
pip install kwenta
For more information on usage, see the Usage section and the sample scripts.
Create a python virtual environment, activate it and install libraries:
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
pip install -e ./module
This method will install the local version of the module in editable mode. You can make changes to the SDK and test them without reinstalling the module.
To configure an instance of the Kwenta SDK, you need to specify some parameters. At minimum you need to specify the network_id
and provider_rpc
to read data from the contracts. If you specify a wallet_address
and private_key
you can also submit transactions or create transaction data using the SDK.:
from kwenta import Kwenta
kwenta = Kwenta(
network_id=10,
provider_rpc=YOUR_RPC,
wallet_address=YOUR_ADDRESS,
private_key=YOUR_PRIVATE_KEY
)
SDK Versions below 1.6.0 will only support Kwenta V1 isolated margin. Please use the current version to utilize Smart Margin functionality.
Queries will default to Kwenta's public Hosted Service endpoints for The Graph.
- To fetch perps data specify endpoint
gql_endpoint_perps
: defaults to Optimism-perps subgraph - To fetch rates specify endpoint
gql_endpoint_perps
: defaults to Optimism-perps subgraph
- Specify the endpoint of a Pyth price service as
price_service_endpoint
defaults to the public Pyth price service. This should be updated for any production applications to use a private Pyth price service.
- Search telegram for bot named "@botfather"
- Message the bot with and type "/newbot"
- Input bot name (This will become channel name)
- Specify API token as
telegram_token
- Specify channel name as
telegram_channel_name
kwenta
:
- Fetch market info
- Fetch position info
- Open positions
- Close positions
- Modify open positions
- Transfer margin
- Execute and cancel orders
- Limit and stop limit orders
kwenta.queries
:
- Fetch historical trades
- Fetch historical positions
- Fetch historical funding rates
kwenta.pyth
:
- Fetch price update data from Pyth price feed
Parameter | Type | Description |
---|---|---|
provider_rpc |
string |
Required. Endpoint for the provider's RPC. |
wallet_address |
string |
Required. Wallet address for transactions. |
sm_address |
string |
Optional. Address of the smart contract, defaults to None. |
private_key |
string |
Optional. Private key for the wallet, defaults to None. |
network_id |
int |
Optional. Network ID to connect to, defaults to None. |
use_estimate_gas |
bool |
Optional. Whether or not to use gas estimation for transactions, defaults to True. |
gql_endpoint_perps |
string |
Optional. GraphQL endpoint for perps, defaults to None. |
gql_endpoint_rates |
string |
Optional. GraphQL endpoint for rates, defaults to None. |
price_service_endpoint |
string |
Optional. Endpoint for the price service, defaults to None. |
telegram_token |
string |
Optional. Token for the Telegram bot, defaults to None. |
telegram_channel_name |
string |
Optional. Name of the Telegram channel for notifications, defaults to None. |