A python based SDK developed for interacting with Ostium, a leveraged trading application for trading currencies, commodities, indices, crypto and more.
Project description
Ostium Python SDK
A python based SDK developed for interacting with Ostium v1 Trading Platform (https://ostium.app/)
Ostium is a decentralized perpetuals exchange on Arbitrum (Ethereum L2) with a focus on providing a seamless experience for traders for trading currencies, commodities, indices, crypto and more.
This SDK is designed to be used by developers who want to build applications on top of Ostium and automate their trading strategies.
Pip Install
The SDK can be installed via pip:
pip install ostium-python-sdk
Requirements
Developed using:
python=3.8
Usage Example
Opening a Trade
from ostium_python_sdk import OstiumSDK
from dotenv import load_dotenv
# Load environment variables if using .env file
load_dotenv()
# Get private key from environment variable
private_key = os.getenv('PRIVATE_KEY')
if not private_key:
raise ValueError("PRIVATE_KEY not found in .env file")
rpc_url = os.getenv('RPC_URL')
if not rpc_url:
raise ValueError("RPC_URL not found in .env file")
# Initialize SDK
config = NetworkConfig.testnet()
sdk = OstiumSDK(config, private_key)
# Or initialize with explicit private key & rpc url
# sdk = OstiumSDK(
# network="arbitrum",
# private_key="your_private_key_here",
# rpc_url="https://arb1.arbitrum.io/rpc"
# )
# Get all available pairs
pairs = await sdk.subgraph.get_pairs()
print("\nPair Information:")
print("----------------------------------------")
for pair in pairs:
# Get detailed information for each pair from the Graph API
pair_details = await sdk.subgraph.get_pair_details(pair['id'])
print("\nPair Details:")
print("----------------------------------------")
# Print all available fields in pair_details
for key, value in pair_details.items():
print(f"{key}: {value}")
print("----------------------------------------")
# Define trade parameters
trade_params = {
'collateral': 100, # USDC amount
'leverage': 10, # Leverage multiplier
'asset_type': 0, # 0 for BTC
'direction': True, # True for Long, False for Short
'order_type': 'MARKET' # 'MARKET', 'LIMIT', or 'STOP'
}
try:
# Get latest price for BTC
latest_price = sdk.ostium.get_latest_price(trade_params['asset_type'])
# Execute trade at current market price
receipt = sdk.ostium.perform_trade(trade_params, at_price=latest_price)
print(f"Trade successful! Transaction hash: {receipt['transactionHash'].hex()}")
except Exception as e:
print(f"Trade failed: {str(e)}")
## Example Usage Script
### Read Block Number
To run the example:
```bash
python examples/example-read-block-number.py
See example-read-block-number.py for an example of how to use the SDK.
Read Positions
To run the example:
python examples/example-read-positions.py
See example-read-positions.py for an example of how to use the SDK.
Get Feed Prices
To open a trade you need the latest feed price.
See this example script on how to get the latest feed prices.
python examples/example-get-prices.py
See example-get-prices.py for an example of how to use the SDK.
Get Balance of an Address
See this example script on how to get the latest feed prices.
python examples/example-get-balance.py
See example-get-balance.py for an example of how to use the SDK.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ostium_python_sdk-0.1.12.tar.gz.
File metadata
- Download URL: ostium_python_sdk-0.1.12.tar.gz
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e46ad2ebdc9e3012e1078d894d9ac693c741e195e1632c56d88c6eb86b860ff4
|
|
| MD5 |
216adb5fadaf1476a89a863a6e2d9357
|
|
| BLAKE2b-256 |
4c8d726f29358116138b28f23f44e2b8528065546f545400329c1ca50db78933
|
File details
Details for the file ostium_python_sdk-0.1.12-py3-none-any.whl.
File metadata
- Download URL: ostium_python_sdk-0.1.12-py3-none-any.whl
- Upload date:
- Size: 26.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc5822fd6328b1ba0685b6a39aeb7ac9085fe98e36063cca44e1d44c7f819cdc
|
|
| MD5 |
97e888e530f6fad01f871619857b95d1
|
|
| BLAKE2b-256 |
af98fff6944168caa22e2fbd7b33e30598ed61ce14b827281869981b94bedf49
|