ostium-python-sdk 0.1.3__tar.gz → 0.1.5__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.
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/PKG-INFO +40 -2
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/README.md +39 -1
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/ostium.py +47 -60
- ostium_python_sdk-0.1.5/ostium_python_sdk/sdk.py +39 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk.egg-info/PKG-INFO +40 -2
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/setup.py +1 -1
- ostium_python_sdk-0.1.3/ostium_python_sdk/sdk.py +0 -33
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/__init__.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/abi.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/balance.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/config.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/constants.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/formulae.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/formulae_wrapper.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/price.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/subgraph.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk/utils.py +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk.egg-info/SOURCES.txt +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk.egg-info/dependency_links.txt +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk.egg-info/requires.txt +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk.egg-info/top_level.txt +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/pyproject.toml +0 -0
- {ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ostium-python-sdk
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
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
|
|
@@ -13,7 +13,6 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
Requires-Dist: web3>=6.0.0
|
|
15
15
|
|
|
16
|
-
|
|
17
16
|
# Ostium Python SDK
|
|
18
17
|
|
|
19
18
|
A python based SDK developed for interacting with Ostium v1 Trading Platform (https://ostium.app/)
|
|
@@ -38,6 +37,45 @@ Developed using:
|
|
|
38
37
|
python=3.8
|
|
39
38
|
```
|
|
40
39
|
|
|
40
|
+
## Usage Example
|
|
41
|
+
|
|
42
|
+
### Opening a Trade
|
|
43
|
+
```python
|
|
44
|
+
from ostium_python_sdk import OstiumSDK
|
|
45
|
+
from dotenv import load_dotenv
|
|
46
|
+
|
|
47
|
+
# Load environment variables if using .env file
|
|
48
|
+
load_dotenv()
|
|
49
|
+
|
|
50
|
+
# Initialize SDK (using environment variables)
|
|
51
|
+
sdk = OstiumSDK(network="arbitrum")
|
|
52
|
+
|
|
53
|
+
# Or initialize with explicit private key
|
|
54
|
+
# sdk = OstiumSDK(
|
|
55
|
+
# network="arbitrum",
|
|
56
|
+
# private_key="your_private_key_here",
|
|
57
|
+
# rpc_url="https://arb1.arbitrum.io/rpc"
|
|
58
|
+
# )
|
|
59
|
+
|
|
60
|
+
# Define trade parameters
|
|
61
|
+
trade_params = {
|
|
62
|
+
'collateral': 100, # USDC amount
|
|
63
|
+
'leverage': 10, # Leverage multiplier
|
|
64
|
+
'asset_type': 0, # 0 for BTC
|
|
65
|
+
'direction': True, # True for Long, False for Short
|
|
66
|
+
'order_type': 'MARKET' # 'MARKET', 'LIMIT', or 'STOP'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
# Get latest price for BTC
|
|
71
|
+
latest_price = sdk.ostium.get_latest_price(trade_params['asset_type'])
|
|
72
|
+
|
|
73
|
+
# Execute trade at current market price
|
|
74
|
+
receipt = sdk.ostium.perform_trade(trade_params, at_price=latest_price)
|
|
75
|
+
print(f"Trade successful! Transaction hash: {receipt['transactionHash'].hex()}")
|
|
76
|
+
except Exception as e:
|
|
77
|
+
print(f"Trade failed: {str(e)}")
|
|
78
|
+
|
|
41
79
|
## Example Usage Script
|
|
42
80
|
|
|
43
81
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
# Ostium Python SDK
|
|
3
2
|
|
|
4
3
|
A python based SDK developed for interacting with Ostium v1 Trading Platform (https://ostium.app/)
|
|
@@ -23,6 +22,45 @@ Developed using:
|
|
|
23
22
|
python=3.8
|
|
24
23
|
```
|
|
25
24
|
|
|
25
|
+
## Usage Example
|
|
26
|
+
|
|
27
|
+
### Opening a Trade
|
|
28
|
+
```python
|
|
29
|
+
from ostium_python_sdk import OstiumSDK
|
|
30
|
+
from dotenv import load_dotenv
|
|
31
|
+
|
|
32
|
+
# Load environment variables if using .env file
|
|
33
|
+
load_dotenv()
|
|
34
|
+
|
|
35
|
+
# Initialize SDK (using environment variables)
|
|
36
|
+
sdk = OstiumSDK(network="arbitrum")
|
|
37
|
+
|
|
38
|
+
# Or initialize with explicit private key
|
|
39
|
+
# sdk = OstiumSDK(
|
|
40
|
+
# network="arbitrum",
|
|
41
|
+
# private_key="your_private_key_here",
|
|
42
|
+
# rpc_url="https://arb1.arbitrum.io/rpc"
|
|
43
|
+
# )
|
|
44
|
+
|
|
45
|
+
# Define trade parameters
|
|
46
|
+
trade_params = {
|
|
47
|
+
'collateral': 100, # USDC amount
|
|
48
|
+
'leverage': 10, # Leverage multiplier
|
|
49
|
+
'asset_type': 0, # 0 for BTC
|
|
50
|
+
'direction': True, # True for Long, False for Short
|
|
51
|
+
'order_type': 'MARKET' # 'MARKET', 'LIMIT', or 'STOP'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try:
|
|
55
|
+
# Get latest price for BTC
|
|
56
|
+
latest_price = sdk.ostium.get_latest_price(trade_params['asset_type'])
|
|
57
|
+
|
|
58
|
+
# Execute trade at current market price
|
|
59
|
+
receipt = sdk.ostium.perform_trade(trade_params, at_price=latest_price)
|
|
60
|
+
print(f"Trade successful! Transaction hash: {receipt['transactionHash'].hex()}")
|
|
61
|
+
except Exception as e:
|
|
62
|
+
print(f"Trade failed: {str(e)}")
|
|
63
|
+
|
|
26
64
|
## Example Usage Script
|
|
27
65
|
|
|
28
66
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import traceback
|
|
3
3
|
from enum import Enum
|
|
4
|
-
|
|
5
|
-
from .abi import usdc_abi, ostium_trading_abi, ostium_trading_storage_abi
|
|
6
4
|
from web3 import Web3
|
|
5
|
+
from .abi import usdc_abi, ostium_trading_abi, ostium_trading_storage_abi
|
|
7
6
|
from .utils import convert_to_scaled_integer, fromErrorCodeToMessage, get_tp_sl_prices, to_base_units
|
|
8
7
|
|
|
9
8
|
|
|
@@ -14,14 +13,18 @@ class OpenOrderType(Enum):
|
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
class Ostium:
|
|
17
|
-
def __init__(self, w3: Web3, usdc_address: str, ostium_trading_storage_address: str, ostium_trading_address: str) -> None:
|
|
18
|
-
|
|
16
|
+
def __init__(self, w3: Web3, usdc_address: str, ostium_trading_storage_address: str, ostium_trading_address: str, private_key: str) -> None:
|
|
17
|
+
if not private_key:
|
|
18
|
+
raise ValueError(
|
|
19
|
+
"Private key is required for Ostium initialization")
|
|
19
20
|
|
|
21
|
+
self.web3 = w3
|
|
22
|
+
self.private_key = private_key
|
|
20
23
|
self.usdc_address = usdc_address
|
|
21
24
|
self.ostium_trading_storage_address = ostium_trading_storage_address
|
|
22
25
|
self.ostium_trading_address = ostium_trading_address
|
|
23
26
|
|
|
24
|
-
# Create contract
|
|
27
|
+
# Create contract instances
|
|
25
28
|
self.usdc_contract = self.web3.eth.contract(
|
|
26
29
|
address=self.usdc_address, abi=usdc_abi)
|
|
27
30
|
self.ostium_trading_storage_contract = self.web3.eth.contract(
|
|
@@ -29,26 +32,27 @@ class Ostium:
|
|
|
29
32
|
self.ostium_trading_contract = self.web3.eth.contract(
|
|
30
33
|
address=self.ostium_trading_address, abi=ostium_trading_abi)
|
|
31
34
|
|
|
35
|
+
def _get_account(self) -> Web3.eth.account:
|
|
36
|
+
"""Get account from stored private key"""
|
|
37
|
+
return self.web3.eth.account.from_key(self.private_key)
|
|
38
|
+
|
|
32
39
|
def get_block_number(self):
|
|
33
40
|
return self.web3.eth.get_block('latest')['number']
|
|
34
41
|
|
|
35
42
|
def get_nonce(self, address):
|
|
36
43
|
return self.web3.eth.get_transaction_count(address)
|
|
37
44
|
|
|
38
|
-
def perform_trade(self, trade_params,
|
|
39
|
-
account = self.
|
|
40
|
-
|
|
45
|
+
def perform_trade(self, trade_params, at_price):
|
|
46
|
+
account = self._get_account()
|
|
41
47
|
amount = to_base_units(trade_params['collateral'], decimals=6)
|
|
42
48
|
self.__approve(account, amount)
|
|
49
|
+
|
|
43
50
|
try:
|
|
44
|
-
# Log input trade parameters for verification
|
|
45
51
|
print("Final trade parameters being sent:", trade_params)
|
|
46
|
-
|
|
47
52
|
tp_price, sl_price = get_tp_sl_prices(trade_params)
|
|
48
|
-
|
|
53
|
+
|
|
49
54
|
trade = {
|
|
50
55
|
'collateral': convert_to_scaled_integer(trade_params['collateral'], precision=5, scale=6),
|
|
51
|
-
# Example open price, adjust as needed
|
|
52
56
|
'openPrice': convert_to_scaled_integer(at_price),
|
|
53
57
|
'tp': convert_to_scaled_integer(tp_price),
|
|
54
58
|
'sl': convert_to_scaled_integer(sl_price),
|
|
@@ -59,7 +63,7 @@ class Ostium:
|
|
|
59
63
|
'buy': trade_params['direction']
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
order_type = OpenOrderType.MARKET.value
|
|
66
|
+
order_type = OpenOrderType.MARKET.value
|
|
63
67
|
|
|
64
68
|
if 'order_type' in trade_params:
|
|
65
69
|
if trade_params['order_type'] == 'LIMIT':
|
|
@@ -71,75 +75,65 @@ class Ostium:
|
|
|
71
75
|
else:
|
|
72
76
|
raise Exception('Invalid order type')
|
|
73
77
|
|
|
74
|
-
# Log the structured trade object to be sent
|
|
75
|
-
# print("Structured trade object:", trade)
|
|
76
|
-
|
|
77
78
|
trade_tx = self.ostium_trading_contract.functions.openTrade(
|
|
78
79
|
trade, order_type, 9000).build_transaction({'from': account.address})
|
|
79
80
|
trade_tx['nonce'] = self.get_nonce(account.address)
|
|
80
81
|
|
|
81
82
|
signed_tx = self.web3.eth.account.sign_transaction(
|
|
82
|
-
trade_tx, private_key=
|
|
83
|
+
trade_tx, private_key=self.private_key)
|
|
83
84
|
trade_tx_hash = self.web3.eth.send_raw_transaction(
|
|
84
85
|
signed_tx.raw_transaction)
|
|
85
|
-
# print('Trade TX Hash:', trade_tx_hash.hex())
|
|
86
|
-
|
|
87
|
-
# Wait for the trade transaction to be mined
|
|
88
86
|
trade_receipt = self.web3.eth.wait_for_transaction_receipt(
|
|
89
87
|
trade_tx_hash)
|
|
90
88
|
print('Trade Receipt:', trade_receipt)
|
|
91
89
|
return trade_receipt
|
|
90
|
+
|
|
92
91
|
except Exception as e:
|
|
93
92
|
reason_string, suggestion = fromErrorCodeToMessage(e)
|
|
94
93
|
print(
|
|
95
94
|
f"An error ({str(e)}) occurred during the trading process - parsed as {reason_string}")
|
|
96
|
-
# traceback.print_exc() # This prints the full traceback
|
|
97
95
|
raise Exception(
|
|
98
96
|
f'{reason_string}\n\n{suggestion}' if suggestion != None else reason_string)
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def cancel_limit_order(self, pairID, index, pvt_key):
|
|
103
|
-
account = self.web3.eth.account.from_key(pvt_key)
|
|
98
|
+
def cancel_limit_order(self, pairID, index):
|
|
99
|
+
account = self._get_account()
|
|
104
100
|
|
|
105
101
|
trade_tx = self.ostium_trading_contract.functions.cancelOpenLimitOrder(
|
|
106
102
|
int(pairID), int(index)).build_transaction({'from': account.address})
|
|
107
103
|
trade_tx['nonce'] = self.get_nonce(account.address)
|
|
108
104
|
|
|
109
105
|
signed_tx = self.web3.eth.account.sign_transaction(
|
|
110
|
-
trade_tx, private_key=
|
|
111
|
-
trade_tx_hash = self.
|
|
106
|
+
trade_tx, private_key=self.private_key)
|
|
107
|
+
trade_tx_hash = self.web3.eth.send_raw_transaction(
|
|
112
108
|
signed_tx.raw_transaction)
|
|
113
109
|
print('Cancel Limit Order TX Hash:', trade_tx_hash.hex())
|
|
114
110
|
|
|
115
|
-
# Wait for the trade transaction to be mined
|
|
116
111
|
trade_receipt = self.web3.eth.wait_for_transaction_receipt(
|
|
117
112
|
trade_tx_hash)
|
|
118
113
|
print('Cancel Limit Order Receipt:', trade_receipt)
|
|
119
114
|
return trade_receipt
|
|
120
115
|
|
|
121
|
-
def close_trade(self, pairID, index
|
|
122
|
-
account = self.
|
|
116
|
+
def close_trade(self, pairID, index):
|
|
117
|
+
account = self._get_account()
|
|
123
118
|
|
|
124
119
|
trade_tx = self.ostium_trading_contract.functions.closeTradeMarket(
|
|
125
120
|
int(pairID), int(index)).build_transaction({'from': account.address})
|
|
126
121
|
trade_tx['nonce'] = self.get_nonce(account.address)
|
|
127
122
|
|
|
128
123
|
signed_tx = self.web3.eth.account.sign_transaction(
|
|
129
|
-
trade_tx, private_key=
|
|
130
|
-
trade_tx_hash = self.
|
|
124
|
+
trade_tx, private_key=self.private_key)
|
|
125
|
+
trade_tx_hash = self.web3.eth.send_raw_transaction(
|
|
131
126
|
signed_tx.raw_transaction)
|
|
132
127
|
print('Trade TX Hash:', trade_tx_hash.hex())
|
|
133
128
|
|
|
134
|
-
# Wait for the trade transaction to be mined
|
|
135
129
|
trade_receipt = self.web3.eth.wait_for_transaction_receipt(
|
|
136
130
|
trade_tx_hash)
|
|
137
131
|
print('Trade Receipt:', trade_receipt)
|
|
138
132
|
return trade_receipt
|
|
139
133
|
|
|
140
|
-
def add_collateral(self, pairID, index, collateral
|
|
134
|
+
def add_collateral(self, pairID, index, collateral):
|
|
141
135
|
try:
|
|
142
|
-
account = self.
|
|
136
|
+
account = self._get_account()
|
|
143
137
|
amount = to_base_units(collateral, decimals=6)
|
|
144
138
|
self.__approve(account, amount)
|
|
145
139
|
|
|
@@ -148,11 +142,11 @@ class Ostium:
|
|
|
148
142
|
add_collateral_tx['nonce'] = self.get_nonce(account.address)
|
|
149
143
|
|
|
150
144
|
signed_tx = self.web3.eth.account.sign_transaction(
|
|
151
|
-
add_collateral_tx, private_key=
|
|
145
|
+
add_collateral_tx, private_key=self.private_key)
|
|
152
146
|
add_collateral_tx_hash = self.web3.eth.send_raw_transaction(
|
|
153
147
|
signed_tx.raw_transaction)
|
|
154
148
|
print('Add Collateral TX Hash:', add_collateral_tx_hash.hex())
|
|
155
|
-
|
|
149
|
+
|
|
156
150
|
add_collateral_receipt = self.web3.eth.wait_for_transaction_receipt(
|
|
157
151
|
add_collateral_tx_hash)
|
|
158
152
|
print('Add Collateral Receipt:', add_collateral_receipt)
|
|
@@ -160,13 +154,12 @@ class Ostium:
|
|
|
160
154
|
|
|
161
155
|
except Exception as e:
|
|
162
156
|
print("An error occurred during the add collateral process:")
|
|
163
|
-
traceback.print_exc()
|
|
164
|
-
raise e
|
|
157
|
+
traceback.print_exc()
|
|
158
|
+
raise e
|
|
165
159
|
|
|
166
|
-
def update_tp(self, pairID, index, tp
|
|
160
|
+
def update_tp(self, pairID, index, tp):
|
|
167
161
|
try:
|
|
168
|
-
account = self.
|
|
169
|
-
|
|
162
|
+
account = self._get_account()
|
|
170
163
|
tp_value = to_base_units(tp, decimals=18)
|
|
171
164
|
|
|
172
165
|
update_tp_tx = self.ostium_trading_contract.functions.updateTp(
|
|
@@ -174,18 +167,19 @@ class Ostium:
|
|
|
174
167
|
update_tp_tx['nonce'] = self.get_nonce(account.address)
|
|
175
168
|
|
|
176
169
|
signed_tx = self.web3.eth.account.sign_transaction(
|
|
177
|
-
update_tp_tx, private_key=
|
|
170
|
+
update_tp_tx, private_key=self.private_key)
|
|
178
171
|
update_tp_tx_hash = self.web3.eth.send_raw_transaction(
|
|
179
172
|
signed_tx.raw_transaction)
|
|
180
173
|
print('Update TP TX Hash:', update_tp_tx_hash.hex())
|
|
174
|
+
|
|
181
175
|
except Exception as e:
|
|
182
176
|
print("An error occurred during the update tp process:")
|
|
183
|
-
traceback.print_exc()
|
|
184
|
-
raise e
|
|
177
|
+
traceback.print_exc()
|
|
178
|
+
raise e
|
|
185
179
|
|
|
186
|
-
def update_sl(self, pairID, index, sl
|
|
180
|
+
def update_sl(self, pairID, index, sl):
|
|
187
181
|
try:
|
|
188
|
-
account = self.
|
|
182
|
+
account = self._get_account()
|
|
189
183
|
sl_value = to_base_units(sl, decimals=18)
|
|
190
184
|
|
|
191
185
|
update_sl_tx = self.ostium_trading_contract.functions.updateSl(
|
|
@@ -193,24 +187,19 @@ class Ostium:
|
|
|
193
187
|
update_sl_tx['nonce'] = self.get_nonce(account.address)
|
|
194
188
|
|
|
195
189
|
signed_tx = self.web3.eth.account.sign_transaction(
|
|
196
|
-
update_sl_tx, private_key=
|
|
190
|
+
update_sl_tx, private_key=self.private_key)
|
|
197
191
|
update_sl_tx_hash = self.web3.eth.send_raw_transaction(
|
|
198
192
|
signed_tx.raw_transaction)
|
|
199
193
|
print('Update SL TX Hash:', update_sl_tx_hash.hex())
|
|
194
|
+
|
|
200
195
|
except Exception as e:
|
|
201
|
-
print(f"An error occurred during the update sl process: {e}")
|
|
202
196
|
reason_string, suggestion = fromErrorCodeToMessage(str(e))
|
|
203
197
|
print(
|
|
204
198
|
f"An error occurred during the update sl process: {reason_string}")
|
|
205
|
-
# traceback.print_exc() # This prints the full traceback
|
|
206
|
-
# Optionally re-raise the exception if you want it to propagate
|
|
207
199
|
raise Exception(
|
|
208
200
|
f'{reason_string}\n\n{suggestion}' if suggestion != None else reason_string)
|
|
209
201
|
|
|
210
202
|
def __approve(self, account, collateral):
|
|
211
|
-
# Approve the transaction
|
|
212
|
-
# Approval tx should only be done if sufficient amount is not already approved.
|
|
213
|
-
|
|
214
203
|
allowance = self.usdc_contract.functions.allowance(
|
|
215
204
|
account.address, self.ostium_trading_storage_address).call()
|
|
216
205
|
|
|
@@ -223,25 +212,23 @@ class Ostium:
|
|
|
223
212
|
approve_tx['nonce'] = self.get_nonce(account.address)
|
|
224
213
|
|
|
225
214
|
signed_tx = self.web3.eth.account.sign_transaction(
|
|
226
|
-
approve_tx, private_key=
|
|
215
|
+
approve_tx, private_key=self.private_key)
|
|
227
216
|
approve_tx_hash = self.web3.eth.send_raw_transaction(
|
|
228
217
|
signed_tx.raw_transaction)
|
|
229
218
|
print('Approval TX Hash:', approve_tx_hash.hex())
|
|
230
219
|
|
|
231
|
-
# Ensure the approval transaction is mined
|
|
232
220
|
approve_receipt = self.web3.eth.wait_for_transaction_receipt(
|
|
233
221
|
approve_tx_hash)
|
|
234
222
|
print('Approval Receipt:', approve_receipt)
|
|
235
223
|
|
|
236
|
-
def withdraw(self, amount, receiving_address
|
|
224
|
+
def withdraw(self, amount, receiving_address):
|
|
237
225
|
try:
|
|
238
|
-
account = self.
|
|
226
|
+
account = self._get_account()
|
|
239
227
|
amount_in_base_units = to_base_units(amount, decimals=6)
|
|
240
228
|
|
|
241
229
|
if not self.web3.is_address(receiving_address):
|
|
242
230
|
raise ValueError("Invalid Arbitrum address format")
|
|
243
231
|
|
|
244
|
-
# Use USDCs' transfer function to send funds to the receiving address
|
|
245
232
|
transfer_tx = self.usdc_contract.functions.transfer(
|
|
246
233
|
receiving_address,
|
|
247
234
|
amount_in_base_units
|
|
@@ -250,7 +237,7 @@ class Ostium:
|
|
|
250
237
|
transfer_tx['nonce'] = self.get_nonce(account.address)
|
|
251
238
|
|
|
252
239
|
signed_tx = self.web3.eth.account.sign_transaction(
|
|
253
|
-
transfer_tx, private_key=
|
|
240
|
+
transfer_tx, private_key=self.private_key)
|
|
254
241
|
transfer_tx_hash = self.web3.eth.send_raw_transaction(
|
|
255
242
|
signed_tx.raw_transaction)
|
|
256
243
|
print('Transfer TX Hash:', transfer_tx_hash.hex())
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from dotenv import load_dotenv
|
|
2
|
+
import os
|
|
3
|
+
from web3 import Web3
|
|
4
|
+
from .ostium import Ostium
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class OstiumSDK:
|
|
8
|
+
def __init__(self, network="arbitrum", private_key: str = None, rpc_url: str = None):
|
|
9
|
+
load_dotenv()
|
|
10
|
+
self.private_key = private_key or os.getenv('OSTIUM_PRIVATE_KEY')
|
|
11
|
+
if not self.private_key:
|
|
12
|
+
raise ValueError(
|
|
13
|
+
"No private key provided. Please provide via constructor or OSTIUM_PRIVATE_KEY environment variable")
|
|
14
|
+
|
|
15
|
+
# Use provided RPC URL or get from env
|
|
16
|
+
self.rpc_url = rpc_url or os.getenv('OSTIUM_RPC_URL')
|
|
17
|
+
if not self.rpc_url:
|
|
18
|
+
raise ValueError(
|
|
19
|
+
"No RPC URL provided. Please provide via constructor or OSTIUM_RPC_URL environment variable")
|
|
20
|
+
|
|
21
|
+
# Initialize Web3
|
|
22
|
+
self.w3 = Web3(Web3.HTTPProvider(self.rpc_url))
|
|
23
|
+
|
|
24
|
+
# Set network-specific addresses
|
|
25
|
+
if network == "arbitrum":
|
|
26
|
+
self.usdc_address = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
|
|
27
|
+
self.ostium_trading_storage_address = "0x937F3002dE1C7b9E6f461f5F5C5Ac5cA8A1a6339"
|
|
28
|
+
self.ostium_trading_address = "0x4c78B6566864e374a5949C6EE1408Fd0Fe01A6ED"
|
|
29
|
+
else:
|
|
30
|
+
raise ValueError(f"Unsupported network: {network}")
|
|
31
|
+
|
|
32
|
+
# Initialize Ostium instance
|
|
33
|
+
self.ostium = Ostium(
|
|
34
|
+
self.w3,
|
|
35
|
+
self.usdc_address,
|
|
36
|
+
self.ostium_trading_storage_address,
|
|
37
|
+
self.ostium_trading_address,
|
|
38
|
+
private_key=self.private_key
|
|
39
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ostium-python-sdk
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
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
|
|
@@ -13,7 +13,6 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
Requires-Dist: web3>=6.0.0
|
|
15
15
|
|
|
16
|
-
|
|
17
16
|
# Ostium Python SDK
|
|
18
17
|
|
|
19
18
|
A python based SDK developed for interacting with Ostium v1 Trading Platform (https://ostium.app/)
|
|
@@ -38,6 +37,45 @@ Developed using:
|
|
|
38
37
|
python=3.8
|
|
39
38
|
```
|
|
40
39
|
|
|
40
|
+
## Usage Example
|
|
41
|
+
|
|
42
|
+
### Opening a Trade
|
|
43
|
+
```python
|
|
44
|
+
from ostium_python_sdk import OstiumSDK
|
|
45
|
+
from dotenv import load_dotenv
|
|
46
|
+
|
|
47
|
+
# Load environment variables if using .env file
|
|
48
|
+
load_dotenv()
|
|
49
|
+
|
|
50
|
+
# Initialize SDK (using environment variables)
|
|
51
|
+
sdk = OstiumSDK(network="arbitrum")
|
|
52
|
+
|
|
53
|
+
# Or initialize with explicit private key
|
|
54
|
+
# sdk = OstiumSDK(
|
|
55
|
+
# network="arbitrum",
|
|
56
|
+
# private_key="your_private_key_here",
|
|
57
|
+
# rpc_url="https://arb1.arbitrum.io/rpc"
|
|
58
|
+
# )
|
|
59
|
+
|
|
60
|
+
# Define trade parameters
|
|
61
|
+
trade_params = {
|
|
62
|
+
'collateral': 100, # USDC amount
|
|
63
|
+
'leverage': 10, # Leverage multiplier
|
|
64
|
+
'asset_type': 0, # 0 for BTC
|
|
65
|
+
'direction': True, # True for Long, False for Short
|
|
66
|
+
'order_type': 'MARKET' # 'MARKET', 'LIMIT', or 'STOP'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
# Get latest price for BTC
|
|
71
|
+
latest_price = sdk.ostium.get_latest_price(trade_params['asset_type'])
|
|
72
|
+
|
|
73
|
+
# Execute trade at current market price
|
|
74
|
+
receipt = sdk.ostium.perform_trade(trade_params, at_price=latest_price)
|
|
75
|
+
print(f"Trade successful! Transaction hash: {receipt['transactionHash'].hex()}")
|
|
76
|
+
except Exception as e:
|
|
77
|
+
print(f"Trade failed: {str(e)}")
|
|
78
|
+
|
|
41
79
|
## Example Usage Script
|
|
42
80
|
|
|
43
81
|
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
from web3 import Web3
|
|
3
|
-
from .config import NetworkConfig
|
|
4
|
-
from .ostium import Ostium
|
|
5
|
-
# from .formulae import Formulae
|
|
6
|
-
from .subgraph import SubgraphClient
|
|
7
|
-
from .price import Price
|
|
8
|
-
from .balance import Balance
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class OstiumSDK:
|
|
12
|
-
def __init__(
|
|
13
|
-
self,
|
|
14
|
-
network_config: NetworkConfig,
|
|
15
|
-
custom_rpc_url: Optional[str] = None,
|
|
16
|
-
custom_graph_url: Optional[str] = None
|
|
17
|
-
):
|
|
18
|
-
self.config = network_config
|
|
19
|
-
self.w3 = Web3(Web3.HTTPProvider(
|
|
20
|
-
custom_rpc_url or network_config.rpc_url
|
|
21
|
-
))
|
|
22
|
-
self.ostium = Ostium(
|
|
23
|
-
self.w3,
|
|
24
|
-
network_config.contracts["usdc"],
|
|
25
|
-
network_config.contracts["trading"],
|
|
26
|
-
network_config.contracts["tradingStorage"]
|
|
27
|
-
)
|
|
28
|
-
# self.formulae = Formulae()
|
|
29
|
-
self.subgraph = SubgraphClient(
|
|
30
|
-
custom_graph_url or network_config.graph_url
|
|
31
|
-
)
|
|
32
|
-
self.price = Price()
|
|
33
|
-
self.balance = Balance(self.w3, network_config.contracts["usdc"])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{ostium_python_sdk-0.1.3 → ostium_python_sdk-0.1.5}/ostium_python_sdk.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|