ostium-python-sdk 0.1.22__tar.gz → 0.1.24__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 (22) hide show
  1. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/PKG-INFO +34 -7
  2. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/README.md +24 -5
  3. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/ostium.py +9 -0
  4. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/sdk.py +2 -3
  5. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/subgraph.py +50 -0
  6. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk.egg-info/PKG-INFO +34 -7
  7. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/setup.py +1 -1
  8. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/__init__.py +0 -0
  9. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/abi.py +0 -0
  10. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/balance.py +0 -0
  11. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/config.py +0 -0
  12. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/constants.py +0 -0
  13. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/formulae.py +0 -0
  14. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/formulae_wrapper.py +0 -0
  15. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/price.py +0 -0
  16. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk/utils.py +0 -0
  17. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk.egg-info/SOURCES.txt +0 -0
  18. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk.egg-info/dependency_links.txt +0 -0
  19. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk.egg-info/requires.txt +0 -0
  20. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/ostium_python_sdk.egg-info/top_level.txt +0 -0
  21. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/pyproject.toml +0 -0
  22. {ostium_python_sdk-0.1.22 → ostium_python_sdk-0.1.24}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: ostium-python-sdk
3
- Version: 0.1.22
3
+ Version: 0.1.24
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
@@ -12,6 +12,14 @@ Classifier: Programming Language :: Python :: 3.8
12
12
  Requires-Python: >=3.8
13
13
  Description-Content-Type: text/markdown
14
14
  Requires-Dist: web3>=6.0.0
15
+ Dynamic: author
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
15
23
 
16
24
  # Ostium Python SDK
17
25
 
@@ -174,6 +182,9 @@ trade_params = {
174
182
  }
175
183
 
176
184
  try:
185
+ sdk.ostium.set_slippage_percentage(1)
186
+ print(f"Slippage percentage set to: {sdk.ostium.get_slippage_percentage()}%")
187
+
177
188
  # Get latest price for BTC
178
189
  latest_price, _ = await sdk.price.get_price("BTC", "USD")
179
190
  print(f"Latest price: {latest_price}")
@@ -224,7 +235,7 @@ except Exception as e:
224
235
 
225
236
  ### Create a Short ETH Limit Order
226
237
 
227
- This example shows how to create a short ETH limit order, 10% below the current ETHUSD price.
238
+ This example shows how to create a short ETH limit order, 10% above the current ETHUSD price. So if price goes up 10% we order a Short ETH trade.
228
239
 
229
240
  ```python
230
241
  # Get private key from environment variable
@@ -253,19 +264,19 @@ try:
253
264
  # Get latest price for ETH
254
265
  latest_price, _ = await sdk.price.get_price("ETH", "USD")
255
266
  print(f"Latest price: {latest_price}")
256
- # Execute trade at current market price
267
+ # Execute LIMIT trade order at 10% above the current price
257
268
  receipt = sdk.ostium.perform_trade(order_params, at_price=latest_price * 1.1)
258
269
  print(
259
270
  f"Order successful! Transaction hash: {receipt['transactionHash'].hex()}")
260
271
 
261
- # Wait for the transaction to be confirmed
272
+ # Wait for the order to be confirmed
262
273
  await asyncio.sleep(10)
263
274
 
264
275
  # Get public address from private key
265
276
  account = Account.from_key(private_key)
266
277
  trader_public_address = account.address
267
278
 
268
- # Get the trade details
279
+ # Get the order details
269
280
  open_orders = await sdk.subgraph.get_orders(trader_public_address)
270
281
  for order_index, order_data in enumerate(open_orders):
271
282
  print(f"Order {order_index + 1}: {order_data}\n")
@@ -281,8 +292,24 @@ except Exception as e:
281
292
  print(f"Order failed: {str(e)}")
282
293
  ```
283
294
 
284
- <b>NOTE:</b> Similiarly you can create a Stop order, just use 'STOP' as the order_type and make sure at_price is set to the stop loss price.
295
+ <b>NOTE:</b> Similiarly you can create a Stop order, just use 'STOP' as the order_type and make sure at_price is set to an acceptable stop loss price.
296
+
297
+
298
+ ### Add Colateral
299
+ TBD
300
+
301
+ ### Add control of Slippage (also in the SDK) - Not only default
302
+ TBD
303
+
304
+ ### Tp / Sl - explain not specifying what means - 900 % for TP max and SL meaning
305
+ TBD
306
+
307
+ ### Maybe take or Make sure we have the error mapping from code to string errro msgs.
308
+ TBD
309
+
285
310
 
311
+ ### Funding rate calculation - SDK to get breakdown of FF, RF, PnL, etc.
312
+ TBD
286
313
 
287
314
 
288
315
  ## Example Usage Scripts
@@ -159,6 +159,9 @@ trade_params = {
159
159
  }
160
160
 
161
161
  try:
162
+ sdk.ostium.set_slippage_percentage(1)
163
+ print(f"Slippage percentage set to: {sdk.ostium.get_slippage_percentage()}%")
164
+
162
165
  # Get latest price for BTC
163
166
  latest_price, _ = await sdk.price.get_price("BTC", "USD")
164
167
  print(f"Latest price: {latest_price}")
@@ -209,7 +212,7 @@ except Exception as e:
209
212
 
210
213
  ### Create a Short ETH Limit Order
211
214
 
212
- This example shows how to create a short ETH limit order, 10% below the current ETHUSD price.
215
+ This example shows how to create a short ETH limit order, 10% above the current ETHUSD price. So if price goes up 10% we order a Short ETH trade.
213
216
 
214
217
  ```python
215
218
  # Get private key from environment variable
@@ -238,19 +241,19 @@ try:
238
241
  # Get latest price for ETH
239
242
  latest_price, _ = await sdk.price.get_price("ETH", "USD")
240
243
  print(f"Latest price: {latest_price}")
241
- # Execute trade at current market price
244
+ # Execute LIMIT trade order at 10% above the current price
242
245
  receipt = sdk.ostium.perform_trade(order_params, at_price=latest_price * 1.1)
243
246
  print(
244
247
  f"Order successful! Transaction hash: {receipt['transactionHash'].hex()}")
245
248
 
246
- # Wait for the transaction to be confirmed
249
+ # Wait for the order to be confirmed
247
250
  await asyncio.sleep(10)
248
251
 
249
252
  # Get public address from private key
250
253
  account = Account.from_key(private_key)
251
254
  trader_public_address = account.address
252
255
 
253
- # Get the trade details
256
+ # Get the order details
254
257
  open_orders = await sdk.subgraph.get_orders(trader_public_address)
255
258
  for order_index, order_data in enumerate(open_orders):
256
259
  print(f"Order {order_index + 1}: {order_data}\n")
@@ -266,8 +269,24 @@ except Exception as e:
266
269
  print(f"Order failed: {str(e)}")
267
270
  ```
268
271
 
269
- <b>NOTE:</b> Similiarly you can create a Stop order, just use 'STOP' as the order_type and make sure at_price is set to the stop loss price.
272
+ <b>NOTE:</b> Similiarly you can create a Stop order, just use 'STOP' as the order_type and make sure at_price is set to an acceptable stop loss price.
273
+
274
+
275
+ ### Add Colateral
276
+ TBD
277
+
278
+ ### Add control of Slippage (also in the SDK) - Not only default
279
+ TBD
280
+
281
+ ### Tp / Sl - explain not specifying what means - 900 % for TP max and SL meaning
282
+ TBD
283
+
284
+ ### Maybe take or Make sure we have the error mapping from code to string errro msgs.
285
+ TBD
286
+
270
287
 
288
+ ### Funding rate calculation - SDK to get breakdown of FF, RF, PnL, etc.
289
+ TBD
271
290
 
272
291
 
273
292
  ## Example Usage Scripts
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import traceback
3
3
  from enum import Enum
4
+ from ostium_python_sdk.constants import PRECISION_2
4
5
  from web3 import Web3
5
6
  from .abi import usdc_abi, ostium_trading_abi, ostium_trading_storage_abi
6
7
  from .utils import convert_to_scaled_integer, fromErrorCodeToMessage, get_tp_sl_prices, to_base_units
@@ -33,6 +34,14 @@ class Ostium:
33
34
  self.ostium_trading_contract = self.web3.eth.contract(
34
35
  address=self.ostium_trading_address, abi=ostium_trading_abi)
35
36
 
37
+ self.slippage_percentage = 9 * PRECISION_2
38
+
39
+ def set_slippage_percentage(self, slippage_percentage):
40
+ self.slippage_percentage = slippage_percentage * PRECISION_2
41
+
42
+ def get_slippage_percentage(self):
43
+ return self.slippage_percentage / PRECISION_2
44
+
36
45
  def _get_account(self) -> Account:
37
46
  """Get account from stored private key"""
38
47
  return self.web3.eth.account.from_key(self.private_key)
@@ -54,6 +54,5 @@ class OstiumSDK:
54
54
  # Initialize subgraph client
55
55
  self.subgraph = SubgraphClient(url=self.network_config.graph_url)
56
56
 
57
- self.balance = Balance(self.w3, self.network_config.contracts["usdc"])
58
- self.price = Price()
59
-
57
+ self.balance = Balance(self.w3, self.network_config.contracts["usdc"])
58
+ self.price = Price()
@@ -185,3 +185,53 @@ class SubgraphClient:
185
185
  result = await self.client.execute_async(query, variable_values={"trader": trader})
186
186
 
187
187
  return result['limits']
188
+
189
+ async def get_recent_history(self, trader, last_n_orders=10):
190
+ query = gql(
191
+ """
192
+ query ListOrdersHistory($trader: Bytes, $last_n_orders: Int) {
193
+ orders(
194
+ where: { trader: $trader, isPending: false}
195
+ first: $last_n_orders
196
+ orderBy: executedAt
197
+ orderDirection: desc
198
+ ) {
199
+ id
200
+ isBuy
201
+ trader
202
+ notional
203
+ tradeNotional
204
+ collateral
205
+ leverage
206
+ orderType
207
+ orderAction
208
+ price
209
+ initiatedAt
210
+ executedAt
211
+ executedTx
212
+ isCancelled
213
+ cancelReason
214
+ profitPercent
215
+ totalProfitPercent
216
+ isPending
217
+ amountSentToTrader
218
+ rolloverFee
219
+ fundingFee
220
+ pair {
221
+ id
222
+ from
223
+ to
224
+ feed
225
+ longOI
226
+ shortOI
227
+ group {
228
+ name
229
+ }
230
+ }
231
+ }
232
+ }
233
+ """
234
+ )
235
+ result = await self.client.execute_async(query, variable_values={"trader": trader, "last_n_orders": last_n_orders})
236
+
237
+ return list(reversed(result['orders'])) # Reverse the final list
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: ostium-python-sdk
3
- Version: 0.1.22
3
+ Version: 0.1.24
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
@@ -12,6 +12,14 @@ Classifier: Programming Language :: Python :: 3.8
12
12
  Requires-Python: >=3.8
13
13
  Description-Content-Type: text/markdown
14
14
  Requires-Dist: web3>=6.0.0
15
+ Dynamic: author
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
15
23
 
16
24
  # Ostium Python SDK
17
25
 
@@ -174,6 +182,9 @@ trade_params = {
174
182
  }
175
183
 
176
184
  try:
185
+ sdk.ostium.set_slippage_percentage(1)
186
+ print(f"Slippage percentage set to: {sdk.ostium.get_slippage_percentage()}%")
187
+
177
188
  # Get latest price for BTC
178
189
  latest_price, _ = await sdk.price.get_price("BTC", "USD")
179
190
  print(f"Latest price: {latest_price}")
@@ -224,7 +235,7 @@ except Exception as e:
224
235
 
225
236
  ### Create a Short ETH Limit Order
226
237
 
227
- This example shows how to create a short ETH limit order, 10% below the current ETHUSD price.
238
+ This example shows how to create a short ETH limit order, 10% above the current ETHUSD price. So if price goes up 10% we order a Short ETH trade.
228
239
 
229
240
  ```python
230
241
  # Get private key from environment variable
@@ -253,19 +264,19 @@ try:
253
264
  # Get latest price for ETH
254
265
  latest_price, _ = await sdk.price.get_price("ETH", "USD")
255
266
  print(f"Latest price: {latest_price}")
256
- # Execute trade at current market price
267
+ # Execute LIMIT trade order at 10% above the current price
257
268
  receipt = sdk.ostium.perform_trade(order_params, at_price=latest_price * 1.1)
258
269
  print(
259
270
  f"Order successful! Transaction hash: {receipt['transactionHash'].hex()}")
260
271
 
261
- # Wait for the transaction to be confirmed
272
+ # Wait for the order to be confirmed
262
273
  await asyncio.sleep(10)
263
274
 
264
275
  # Get public address from private key
265
276
  account = Account.from_key(private_key)
266
277
  trader_public_address = account.address
267
278
 
268
- # Get the trade details
279
+ # Get the order details
269
280
  open_orders = await sdk.subgraph.get_orders(trader_public_address)
270
281
  for order_index, order_data in enumerate(open_orders):
271
282
  print(f"Order {order_index + 1}: {order_data}\n")
@@ -281,8 +292,24 @@ except Exception as e:
281
292
  print(f"Order failed: {str(e)}")
282
293
  ```
283
294
 
284
- <b>NOTE:</b> Similiarly you can create a Stop order, just use 'STOP' as the order_type and make sure at_price is set to the stop loss price.
295
+ <b>NOTE:</b> Similiarly you can create a Stop order, just use 'STOP' as the order_type and make sure at_price is set to an acceptable stop loss price.
296
+
297
+
298
+ ### Add Colateral
299
+ TBD
300
+
301
+ ### Add control of Slippage (also in the SDK) - Not only default
302
+ TBD
303
+
304
+ ### Tp / Sl - explain not specifying what means - 900 % for TP max and SL meaning
305
+ TBD
306
+
307
+ ### Maybe take or Make sure we have the error mapping from code to string errro msgs.
308
+ TBD
309
+
285
310
 
311
+ ### Funding rate calculation - SDK to get breakdown of FF, RF, PnL, etc.
312
+ TBD
286
313
 
287
314
 
288
315
  ## Example Usage Scripts
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="ostium-python-sdk",
5
- version="0.1.22",
5
+ version="0.1.24",
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  "web3>=6.0.0",