ostium-python-sdk 0.1.28__tar.gz → 0.1.31__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/PKG-INFO +14 -2
  2. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/README.md +8 -1
  3. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/constants.py +5 -1
  4. ostium_python_sdk-0.1.31/ostium_python_sdk/sdk.py +165 -0
  5. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk.egg-info/PKG-INFO +14 -2
  6. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/setup.py +1 -1
  7. ostium_python_sdk-0.1.28/ostium_python_sdk/sdk.py +0 -65
  8. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/__init__.py +0 -0
  9. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/abi/__init__.py +0 -0
  10. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/abi/abi.py +0 -0
  11. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/abi/faucet_abi.py +0 -0
  12. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/balance.py +0 -0
  13. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/config.py +0 -0
  14. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/exceptions.py +0 -0
  15. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/faucet.py +0 -0
  16. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/formulae.py +0 -0
  17. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/formulae_wrapper.py +0 -0
  18. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/ostium.py +0 -0
  19. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/price.py +0 -0
  20. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/subgraph.py +0 -0
  21. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk/utils.py +0 -0
  22. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk.egg-info/SOURCES.txt +0 -0
  23. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk.egg-info/dependency_links.txt +0 -0
  24. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk.egg-info/requires.txt +0 -0
  25. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/ostium_python_sdk.egg-info/top_level.txt +0 -0
  26. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/pyproject.toml +0 -0
  27. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/setup.cfg +0 -0
  28. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/tests/__init__.py +0 -0
  29. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/tests/test_slippage.py +0 -0
  30. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/tests/test_trade_get_tp_price.py +0 -0
  31. {ostium_python_sdk-0.1.28 → ostium_python_sdk-0.1.31}/tests/test_trade_liquidation_price.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ostium-python-sdk
3
- Version: 0.1.28
3
+ Version: 0.1.31
4
4
  Summary: A python based SDK developed for interacting with Ostium, a leveraged trading application for trading currencies, commodities, indices, crypto and more.
5
5
  Home-page: https://github.com/0xOstium/ostium-python-sdk
6
6
  Author: ami@ostium.io
@@ -26,7 +26,10 @@ Dynamic: requires-dist
26
26
  Dynamic: requires-python
27
27
  Dynamic: summary
28
28
 
29
- [Changelog](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md)
29
+ # Changelog
30
+ [![Changelog](https://img.shields.io/badge/changelog-View%20Latest%20Changes-blue.svg)](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md)
31
+
32
+ Track all notable changes, updates, and improvements to the Ostium Python SDK in our [Changelog](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md).
30
33
 
31
34
  # Ostium Python SDK
32
35
 
@@ -454,7 +457,11 @@ python examples/example-get-balance.py
454
457
  See [example-get-balance.py](https://github.com/0xOstium/ostium_python_sdk/blob/main/examples/example-get-balance.py) for an example of how to use the SDK.
455
458
 
456
459
 
460
+ ## Run an example from local install
457
461
 
462
+ ```bash
463
+ pip uninstall ostium-python-sdk && pip install -e . && python examples/example-pairs-details.py
464
+ ```
458
465
 
459
466
 
460
467
 
@@ -465,6 +472,11 @@ All notable changes to the Ostium Python SDK will be documented in this file.
465
472
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
466
473
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
467
474
 
475
+ ## [0.1.31] - 2025-01-13
476
+
477
+ ### Added
478
+ - Add `get_formatted_pairs_details` on sdk class
479
+
468
480
  ## [0.1.25] - 2025-01-13
469
481
 
470
482
  ### Added
@@ -1,4 +1,7 @@
1
- [Changelog](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md)
1
+ # Changelog
2
+ [![Changelog](https://img.shields.io/badge/changelog-View%20Latest%20Changes-blue.svg)](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md)
3
+
4
+ Track all notable changes, updates, and improvements to the Ostium Python SDK in our [Changelog](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md).
2
5
 
3
6
  # Ostium Python SDK
4
7
 
@@ -426,5 +429,9 @@ python examples/example-get-balance.py
426
429
  See [example-get-balance.py](https://github.com/0xOstium/ostium_python_sdk/blob/main/examples/example-get-balance.py) for an example of how to use the SDK.
427
430
 
428
431
 
432
+ ## Run an example from local install
429
433
 
434
+ ```bash
435
+ pip uninstall ostium-python-sdk && pip install -e . && python examples/example-pairs-details.py
436
+ ```
430
437
 
@@ -2,10 +2,14 @@
2
2
  # Constants
3
3
  from decimal import Decimal
4
4
 
5
- PRECISION_2 = Decimal('100')
5
+
6
6
  MAX_PROFIT_P = Decimal('900') # 900% * PRECISION_6
7
7
  MAX_STOP_LOSS_P = Decimal('85')
8
+
9
+ PRECISION_2 = Decimal('100')
8
10
  PRECISION_6 = Decimal('1000000')
11
+ PRECISION_9 = Decimal('1000000000')
9
12
  PRECISION_12 = Decimal('1000000000000')
10
13
  PRECISION_18 = Decimal('1000000000000000000')
14
+
11
15
  LIQ_THRESHOLD_P = Decimal('90') # -90% (of collateral)
@@ -0,0 +1,165 @@
1
+ from dotenv import load_dotenv
2
+ import os
3
+ from decimal import Decimal
4
+ from .constants import PRECISION_2, PRECISION_6, PRECISION_12, PRECISION_18, PRECISION_9
5
+
6
+ from ostium_python_sdk.faucet import Faucet
7
+ from .balance import Balance
8
+ from .price import Price
9
+ from web3 import Web3
10
+ from .ostium import Ostium
11
+ from .config import NetworkConfig
12
+ from typing import Union
13
+ from .subgraph import SubgraphClient
14
+
15
+
16
+ class OstiumSDK:
17
+ def __init__(self, network: Union[str, NetworkConfig], private_key: str = None, rpc_url: str = None):
18
+ load_dotenv()
19
+ self.private_key = private_key or os.getenv('PRIVATE_KEY')
20
+ if not self.private_key:
21
+ raise ValueError(
22
+ "No private key provided. Please provide via constructor or PRIVATE_KEY environment variable")
23
+
24
+ self.rpc_url = rpc_url or os.getenv('RPC_URL')
25
+ if not self.rpc_url:
26
+ network_name = "mainnet" if isinstance(
27
+ network, str) and network == "mainnet" else "testnet"
28
+ raise ValueError(
29
+ f"No RPC URL provided for {network_name}. Please provide via constructor or RPC_URL environment variable")
30
+
31
+ # Initialize Web3
32
+ self.w3 = Web3(Web3.HTTPProvider(self.rpc_url))
33
+
34
+ # Get network configuration
35
+ if isinstance(network, NetworkConfig):
36
+ self.network_config = network
37
+ elif isinstance(network, str):
38
+ if network == "mainnet":
39
+ self.network_config = NetworkConfig.mainnet()
40
+ elif network == "testnet":
41
+ self.network_config = NetworkConfig.testnet()
42
+ else:
43
+ raise ValueError(
44
+ f"Unsupported network: {network}. Use 'mainnet' or 'testnet'")
45
+ else:
46
+ raise ValueError(
47
+ "Network must be either a NetworkConfig instance or a string ('mainnet' or 'testnet')")
48
+
49
+ # Initialize Ostium instance
50
+ self.ostium = Ostium(
51
+ self.w3,
52
+ self.network_config.contracts["usdc"],
53
+ self.network_config.contracts["tradingStorage"],
54
+ self.network_config.contracts["trading"],
55
+ private_key=self.private_key
56
+ )
57
+
58
+ # Initialize subgraph client
59
+ self.subgraph = SubgraphClient(url=self.network_config.graph_url)
60
+
61
+ self.balance = Balance(self.w3, self.network_config.contracts["usdc"])
62
+ self.price = Price()
63
+
64
+ if self.network_config.is_testnet:
65
+ self.faucet = Faucet(self.w3, self.private_key)
66
+ else:
67
+ self.faucet = None
68
+
69
+ async def get_formatted_pairs_details(self) -> list:
70
+ """
71
+ Get formatted details for all trading pairs, with proper decimal conversion.
72
+
73
+ Crypto pairs example:
74
+ BTC-USD:
75
+ - price: 65432.50
76
+ - longOI: 0.41008148 (410.08148 BTC)
77
+ - shortOI: 2.59812309 (2,598.12309 BTC)
78
+ - maxOI: 1000.00000000
79
+ - utilizationP: 80.00%
80
+ - makerFeeP: 0.01%
81
+ - takerFeeP: 0.10%
82
+ - maxLeverage: 50x
83
+ - group: crypto
84
+
85
+ ETH-USD:
86
+ - price: 3050.50
87
+ - longOI: 5.90560023 (5,905.60023 ETH)
88
+ - shortOI: 0.00000000
89
+ - maxOI: 1000.00000000
90
+ - utilizationP: 80.00%
91
+ - makerFeeP: 0.01%
92
+ - takerFeeP: 0.10%
93
+ - maxLeverage: 50x
94
+ - group: crypto
95
+
96
+ Returns:
97
+ list: List of dictionaries containing formatted pair details including:
98
+ - id: Pair ID
99
+ - from: Base asset (e.g., 'BTC')
100
+ - to: Quote asset (e.g., 'USD')
101
+ - price: Current market price
102
+ - isMarketOpen: Market open status
103
+ - longOI: Total long open interest in notional value
104
+ - shortOI: Total short open interest in notional value
105
+ - maxOI: Maximum allowed open interest
106
+ - utilizationP: Utilization threshold percentage
107
+ - makerFeeP: Maker fee percentage
108
+ - takerFeeP: Taker fee percentage
109
+ - usageFeeP: Usage fee percentage
110
+ - maxLeverage: Maximum allowed leverage
111
+ - minLeverage: Minimum allowed leverage
112
+ - makerMaxLeverage: Maximum leverage for makers
113
+ - group: Trading group name
114
+ - groupMaxCollateralP: Maximum collateral percentage for the group
115
+ - minLevPos: Minimum leverage position size
116
+ - lastFundingRate: Latest funding rate
117
+ - curFundingLong: Current funding for longs
118
+ - curFundingShort: Current funding for shorts
119
+ - lastFundingBlock: Block number of last funding update
120
+ - lastFundingVelocity: Velocity of last funding rate change
121
+ """
122
+ pairs = await self.subgraph.get_pairs()
123
+ formatted_pairs = []
124
+
125
+ for pair in pairs:
126
+ pair_details = await self.subgraph.get_pair_details(pair['id'])
127
+
128
+ # Get current price and market status
129
+ try:
130
+ price, is_market_open = await self.price.get_price(
131
+ pair_details['from'],
132
+ pair_details['to']
133
+ )
134
+ except ValueError:
135
+ price = 0
136
+ is_market_open = False
137
+
138
+ formatted_pair = {
139
+ 'id': int(pair_details['id']),
140
+ 'from': pair_details['from'],
141
+ 'to': pair_details['to'],
142
+ 'price': price,
143
+ 'isMarketOpen': is_market_open,
144
+ 'longOI': Decimal(pair_details['longOI']) / PRECISION_18,
145
+ 'shortOI': Decimal(pair_details['shortOI']) / PRECISION_18,
146
+ 'maxOI': Decimal(pair_details['maxOI']) / PRECISION_18,
147
+ 'utilizationP': Decimal(pair_details['utilizationThresholdP']) / PRECISION_2,
148
+ 'makerFeeP': Decimal(pair_details['makerFeeP']) / PRECISION_6,
149
+ 'takerFeeP': Decimal(pair_details['takerFeeP']) / PRECISION_6,
150
+ 'usageFeeP': Decimal(pair_details['usageFeeP']) / PRECISION_6,
151
+ 'maxLeverage': Decimal(pair_details['group']['maxLeverage']) / PRECISION_2,
152
+ 'minLeverage': Decimal(pair_details['group']['minLeverage']) / PRECISION_2,
153
+ 'makerMaxLeverage': Decimal(pair_details['makerMaxLeverage']) / PRECISION_2,
154
+ 'group': pair_details['group']['name'],
155
+ 'groupMaxCollateralP': Decimal(pair_details['group']['maxCollateralP']) / PRECISION_2,
156
+ 'minLevPos': Decimal(pair_details['fee']['minLevPos']) / PRECISION_9,
157
+ 'lastFundingRate': Decimal(pair_details['lastFundingRate']) / PRECISION_9,
158
+ 'curFundingLong': Decimal(pair_details['curFundingLong']) / PRECISION_9,
159
+ 'curFundingShort': Decimal(pair_details['curFundingShort']) / PRECISION_9,
160
+ 'lastFundingBlock': int(pair_details['lastFundingBlock']),
161
+ 'lastFundingVelocity': int(pair_details['lastFundingVelocity'])
162
+ }
163
+ formatted_pairs.append(formatted_pair)
164
+
165
+ return formatted_pairs
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ostium-python-sdk
3
- Version: 0.1.28
3
+ Version: 0.1.31
4
4
  Summary: A python based SDK developed for interacting with Ostium, a leveraged trading application for trading currencies, commodities, indices, crypto and more.
5
5
  Home-page: https://github.com/0xOstium/ostium-python-sdk
6
6
  Author: ami@ostium.io
@@ -26,7 +26,10 @@ Dynamic: requires-dist
26
26
  Dynamic: requires-python
27
27
  Dynamic: summary
28
28
 
29
- [Changelog](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md)
29
+ # Changelog
30
+ [![Changelog](https://img.shields.io/badge/changelog-View%20Latest%20Changes-blue.svg)](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md)
31
+
32
+ Track all notable changes, updates, and improvements to the Ostium Python SDK in our [Changelog](https://github.com/0xOstium/ostium-python-sdk/blob/main/CHANGELOG.md).
30
33
 
31
34
  # Ostium Python SDK
32
35
 
@@ -454,7 +457,11 @@ python examples/example-get-balance.py
454
457
  See [example-get-balance.py](https://github.com/0xOstium/ostium_python_sdk/blob/main/examples/example-get-balance.py) for an example of how to use the SDK.
455
458
 
456
459
 
460
+ ## Run an example from local install
457
461
 
462
+ ```bash
463
+ pip uninstall ostium-python-sdk && pip install -e . && python examples/example-pairs-details.py
464
+ ```
458
465
 
459
466
 
460
467
 
@@ -465,6 +472,11 @@ All notable changes to the Ostium Python SDK will be documented in this file.
465
472
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
466
473
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
467
474
 
475
+ ## [0.1.31] - 2025-01-13
476
+
477
+ ### Added
478
+ - Add `get_formatted_pairs_details` on sdk class
479
+
468
480
  ## [0.1.25] - 2025-01-13
469
481
 
470
482
  ### Added
@@ -12,7 +12,7 @@ if changelog_path.exists():
12
12
 
13
13
  setup(
14
14
  name="ostium-python-sdk",
15
- version="0.1.28",
15
+ version="0.1.31",
16
16
  packages=find_packages(),
17
17
  install_requires=[
18
18
  "web3>=6.0.0",
@@ -1,65 +0,0 @@
1
- from dotenv import load_dotenv
2
- import os
3
-
4
- from ostium_python_sdk.faucet import Faucet
5
- from .balance import Balance
6
- from .price import Price
7
- from web3 import Web3
8
- from .ostium import Ostium
9
- from .config import NetworkConfig
10
- from typing import Union
11
- from .subgraph import SubgraphClient
12
-
13
-
14
- class OstiumSDK:
15
- def __init__(self, network: Union[str, NetworkConfig], private_key: str = None, rpc_url: str = None):
16
- load_dotenv()
17
- self.private_key = private_key or os.getenv('PRIVATE_KEY')
18
- if not self.private_key:
19
- raise ValueError(
20
- "No private key provided. Please provide via constructor or PRIVATE_KEY environment variable")
21
-
22
- self.rpc_url = rpc_url or os.getenv('RPC_URL')
23
- if not self.rpc_url:
24
- network_name = "mainnet" if isinstance(
25
- network, str) and network == "mainnet" else "testnet"
26
- raise ValueError(
27
- f"No RPC URL provided for {network_name}. Please provide via constructor or RPC_URL environment variable")
28
-
29
- # Initialize Web3
30
- self.w3 = Web3(Web3.HTTPProvider(self.rpc_url))
31
-
32
- # Get network configuration
33
- if isinstance(network, NetworkConfig):
34
- self.network_config = network
35
- elif isinstance(network, str):
36
- if network == "mainnet":
37
- self.network_config = NetworkConfig.mainnet()
38
- elif network == "testnet":
39
- self.network_config = NetworkConfig.testnet()
40
- else:
41
- raise ValueError(
42
- f"Unsupported network: {network}. Use 'mainnet' or 'testnet'")
43
- else:
44
- raise ValueError(
45
- "Network must be either a NetworkConfig instance or a string ('mainnet' or 'testnet')")
46
-
47
- # Initialize Ostium instance
48
- self.ostium = Ostium(
49
- self.w3,
50
- self.network_config.contracts["usdc"],
51
- self.network_config.contracts["tradingStorage"],
52
- self.network_config.contracts["trading"],
53
- private_key=self.private_key
54
- )
55
-
56
- # Initialize subgraph client
57
- self.subgraph = SubgraphClient(url=self.network_config.graph_url)
58
-
59
- self.balance = Balance(self.w3, self.network_config.contracts["usdc"])
60
- self.price = Price()
61
-
62
- if self.network_config.is_testnet:
63
- self.faucet = Faucet(self.w3, self.private_key)
64
- else:
65
- self.faucet = None