ostium-python-sdk 0.2.101__tar.gz → 0.2.103__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.2.101 → ostium_python_sdk-0.2.103}/PKG-INFO +1 -1
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/formulae.py +83 -144
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/sdk.py +14 -14
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/subgraph.py +0 -3
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk.egg-info/PKG-INFO +1 -1
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/setup.py +1 -1
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/MANIFEST.in +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/README.md +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/__init__.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/abi/__init__.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/abi/abi.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/abi/faucet_abi.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/balance.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/config.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/constants.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/exceptions.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/faucet.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/formulae_wrapper.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/ostium.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/price.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/utils.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk.egg-info/SOURCES.txt +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk.egg-info/dependency_links.txt +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk.egg-info/requires.txt +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk.egg-info/top_level.txt +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/pyproject.toml +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/requirements-dev.txt +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/requirements.txt +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/setup.cfg +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/tests/__init__.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/tests/test_get_price_impact.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/tests/test_slippage.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/tests/test_trade_get_tp_price.py +0 -0
- {ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/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.2.
|
|
3
|
+
Version: 0.2.103
|
|
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
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
from decimal import Decimal
|
|
1
|
+
from decimal import Decimal, getcontext, ROUND_DOWN
|
|
2
2
|
from .constants import MAX_PROFIT_P, MAX_STOP_LOSS_P, PRECISION_16, PRECISION_2, PRECISION_6, PRECISION_12, PRECISION_18, LIQ_THRESHOLD_P
|
|
3
3
|
from typing import Dict
|
|
4
|
+
from .scscript.funding import getPendingAccFundingFees, getTargetFundingRate
|
|
4
5
|
|
|
6
|
+
quantization_6 = Decimal('0.000001')
|
|
7
|
+
quantization_18 = Decimal('0.000000000000000001')
|
|
5
8
|
#
|
|
6
9
|
# This is a copy-cat of formulae repo originally written in TypeScript
|
|
7
10
|
#
|
|
@@ -343,70 +346,9 @@ def CurrentTotalProfitP(total_profit: str, collateral: str) -> str:
|
|
|
343
346
|
raise Exception(
|
|
344
347
|
f"Unable to compute Current Total Profit Percentage: {error}")
|
|
345
348
|
|
|
346
|
-
# given desired TP percentage, like 35, 50, 75, 100, 500 and 900 which is max: gives you the TP price
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
def get_target_funding_rate(
|
|
350
|
-
normalized_oi_delta: Decimal,
|
|
351
|
-
hill_inflection_point: Decimal,
|
|
352
|
-
max_fr: Decimal,
|
|
353
|
-
hill_pos_scale: Decimal,
|
|
354
|
-
hill_neg_scale: Decimal,
|
|
355
|
-
) -> Decimal:
|
|
356
|
-
a = Decimal('184')
|
|
357
|
-
k = Decimal('16')
|
|
358
|
-
|
|
359
|
-
x = a * normalized_oi_delta / PRECISION_2
|
|
360
|
-
x2 = x * x * PRECISION_6 # convert to PRECISION_18
|
|
361
|
-
hill = x2 * PRECISION_18 / (k * PRECISION_16 + x2)
|
|
362
|
-
|
|
363
|
-
if normalized_oi_delta >= 0:
|
|
364
|
-
target_fr = hill_pos_scale * hill / PRECISION_2 + hill_inflection_point
|
|
365
|
-
else:
|
|
366
|
-
target_fr = hill_neg_scale * \
|
|
367
|
-
Decimal('-1') * hill / PRECISION_2 + hill_inflection_point
|
|
368
|
-
|
|
369
|
-
if target_fr > PRECISION_18:
|
|
370
|
-
target_fr = PRECISION_18
|
|
371
|
-
elif target_fr < PRECISION_18 * Decimal('-1'):
|
|
372
|
-
target_fr = PRECISION_18 * Decimal('-1')
|
|
373
|
-
|
|
374
|
-
return target_fr * max_fr / PRECISION_18
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
def exponential_approximation(x: Decimal) -> Decimal:
|
|
378
|
-
approx_threshold = Decimal('793231258909201900')
|
|
379
|
-
|
|
380
|
-
if abs(x) < approx_threshold:
|
|
381
|
-
three_with_precision = PRECISION_18 * 3
|
|
382
|
-
numerator = x + three_with_precision
|
|
383
|
-
numerator = numerator * numerator / PRECISION_18 + three_with_precision
|
|
384
|
-
denominator = x - three_with_precision
|
|
385
|
-
denominator = denominator * denominator / PRECISION_18 + three_with_precision
|
|
386
|
-
|
|
387
|
-
return numerator * PRECISION_18 / denominator
|
|
388
|
-
else:
|
|
389
|
-
k = [1648721, 1284025, 1133148, 1064494, 1031743,
|
|
390
|
-
1015748, 1007843, 1003915, 1001955, 1000977]
|
|
391
|
-
integer_part = abs(x) // PRECISION_18
|
|
392
|
-
decimal_part = abs(x) - (integer_part * PRECISION_18)
|
|
393
|
-
|
|
394
|
-
approx = PRECISION_6
|
|
395
|
-
|
|
396
|
-
for ki in k:
|
|
397
|
-
decimal_part = decimal_part * 2
|
|
398
|
-
if decimal_part >= PRECISION_18:
|
|
399
|
-
approx = approx * Decimal(str(ki)) / PRECISION_6
|
|
400
|
-
decimal_part = decimal_part - PRECISION_18
|
|
401
|
-
if decimal_part == 0:
|
|
402
|
-
break
|
|
403
|
-
|
|
404
|
-
return (PRECISION_18 * PRECISION_18 /
|
|
405
|
-
(Decimal('2') ** integer_part *
|
|
406
|
-
(approx / Decimal('1000') * Decimal('1e15'))) /
|
|
407
|
-
Decimal('1e15') * Decimal('1e15'))
|
|
408
|
-
|
|
409
349
|
|
|
350
|
+
# returns (acc_funding_long, acc_funding_short, latest_funding_rate, target_fr)
|
|
351
|
+
# latest_funding_rate and target_fr are in % per year - how much long pay per year
|
|
410
352
|
def get_funding_rate(
|
|
411
353
|
acc_per_oi_long: str,
|
|
412
354
|
acc_per_oi_short: str,
|
|
@@ -424,89 +366,86 @@ def get_funding_rate(
|
|
|
424
366
|
s_factor_up_scale_p: str,
|
|
425
367
|
s_factor_down_scale_p: str,
|
|
426
368
|
verbose: bool = False
|
|
427
|
-
) ->
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
369
|
+
) -> tuple[int, int, int, int]:
|
|
370
|
+
"""
|
|
371
|
+
Calculate funding rates and return as integers multiplied by PRECISION_18
|
|
372
|
+
Returns: (acc_funding_long, acc_funding_short, latest_funding_rate, target_fr)
|
|
373
|
+
"""
|
|
374
|
+
def log(message):
|
|
375
|
+
if verbose:
|
|
376
|
+
print(message)
|
|
377
|
+
|
|
378
|
+
# Set decimal precision
|
|
379
|
+
getcontext().prec = 128
|
|
380
|
+
getcontext().rounding = ROUND_DOWN
|
|
381
|
+
|
|
382
|
+
# Convert all inputs to Decimal
|
|
435
383
|
oi_long_dec = Decimal(oi_long)
|
|
436
384
|
oi_short_dec = Decimal(oi_short)
|
|
437
385
|
oi_cap_dec = Decimal(oi_cap)
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
386
|
+
|
|
387
|
+
log(f"Input values:")
|
|
388
|
+
log(f"OI Long: {oi_long_dec}")
|
|
389
|
+
log(f"OI Short: {oi_short_dec}")
|
|
390
|
+
log(f"OI Cap: {oi_cap_dec}")
|
|
391
|
+
log(f"Last Funding Rate: {last_funding_rate}")
|
|
392
|
+
log(f"Last Update Block: {last_update_block}")
|
|
393
|
+
log(f"Latest Block: {latest_block}")
|
|
394
|
+
|
|
395
|
+
# Calculate normalized OI delta
|
|
446
396
|
open_interest_max = max(oi_long_dec, oi_short_dec)
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
397
|
+
normalized_oi_delta = ((oi_long_dec - oi_short_dec)
|
|
398
|
+
* PRECISION_6) / max(oi_cap_dec, open_interest_max)
|
|
399
|
+
|
|
400
|
+
log(f"\nCalculated values:")
|
|
401
|
+
log(f"Open Interest Max: {open_interest_max}")
|
|
402
|
+
log(f"Normalized OI Delta: {normalized_oi_delta}")
|
|
403
|
+
|
|
404
|
+
# Get funding values
|
|
405
|
+
acc_funding_long, acc_funding_short, latest_funding_rate, target_fr = getPendingAccFundingFees(
|
|
406
|
+
blockNumber=Decimal(latest_block),
|
|
407
|
+
lastUpdateBlock=Decimal(last_update_block),
|
|
408
|
+
valueLong=Decimal(acc_per_oi_long),
|
|
409
|
+
valueShort=Decimal(acc_per_oi_short),
|
|
410
|
+
openInterestUsdcLong=oi_long_dec,
|
|
411
|
+
openInterestUsdcShort=oi_short_dec,
|
|
412
|
+
OiCap=oi_cap_dec,
|
|
413
|
+
maxFundingFeePerBlock=Decimal(max_funding_fee_per_block),
|
|
414
|
+
lastFundingRate=Decimal(last_funding_rate),
|
|
415
|
+
hillInflectionPoint=Decimal(hill_inflection_point),
|
|
416
|
+
hillPosScale=Decimal(hill_pos_scale),
|
|
417
|
+
hillNegScale=Decimal(hill_neg_scale),
|
|
418
|
+
springFactor=Decimal(spring_factor),
|
|
419
|
+
sFactorUpScale=Decimal(s_factor_up_scale_p),
|
|
420
|
+
sFactorDownScaleP=Decimal(s_factor_down_scale_p),
|
|
468
421
|
)
|
|
469
422
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
acc_per_oi_short_dec -= (acc_funding_rate * oi_long_dec / oi_short_dec
|
|
500
|
-
if oi_short_dec > 0 else Decimal('0'))
|
|
501
|
-
else:
|
|
502
|
-
if oi_short_dec > 0:
|
|
503
|
-
acc_per_oi_short_dec -= acc_funding_rate
|
|
504
|
-
acc_per_oi_long_dec += (acc_funding_rate * oi_short_dec / oi_long_dec
|
|
505
|
-
if oi_long_dec > 0 else Decimal('0'))
|
|
506
|
-
|
|
507
|
-
return {
|
|
508
|
-
'accFundingLong': str(acc_per_oi_long_dec),
|
|
509
|
-
'accFundingShort': str(acc_per_oi_short_dec),
|
|
510
|
-
'latestFundingRate': str(fr),
|
|
511
|
-
'targetFr': str(target_fr)
|
|
512
|
-
}
|
|
423
|
+
log(f"\nIntermediate results:")
|
|
424
|
+
log(f"Acc Funding Long (pre-conversion): {acc_funding_long}")
|
|
425
|
+
log(f"Acc Funding Short (pre-conversion): {acc_funding_short}")
|
|
426
|
+
log(f"Latest Funding Rate (pre-conversion): {latest_funding_rate}")
|
|
427
|
+
log(f"Target Funding Rate (pre-conversion): {target_fr}")
|
|
428
|
+
|
|
429
|
+
acc_funding_long_int = (
|
|
430
|
+
acc_funding_long / PRECISION_18).quantize(quantization_18, rounding=ROUND_DOWN)
|
|
431
|
+
acc_funding_short_int = (
|
|
432
|
+
acc_funding_short / PRECISION_18).quantize(quantization_18, rounding=ROUND_DOWN)
|
|
433
|
+
latest_funding_rate = (
|
|
434
|
+
latest_funding_rate / PRECISION_18).quantize(quantization_18, rounding=ROUND_DOWN)
|
|
435
|
+
target_fr = (target_fr / PRECISION_18).quantize(quantization_18,
|
|
436
|
+
rounding=ROUND_DOWN)
|
|
437
|
+
|
|
438
|
+
log(f"\nFinal results (multiplied by 10^18):")
|
|
439
|
+
log(f"Acc Funding Long: {acc_funding_long_int}")
|
|
440
|
+
log(f"Acc Funding Short: {acc_funding_short_int}")
|
|
441
|
+
log(f"Latest Funding Rate: {latest_funding_rate}")
|
|
442
|
+
log(f"Target Funding Rate: {target_fr}")
|
|
443
|
+
|
|
444
|
+
return (
|
|
445
|
+
acc_funding_long_int,
|
|
446
|
+
acc_funding_short_int,
|
|
447
|
+
((latest_funding_rate * 10 / 3 * 60) * 60 * 24 * 365 *
|
|
448
|
+
100).quantize(quantization_6, rounding=ROUND_DOWN),
|
|
449
|
+
((target_fr * 10 / 3 * 60) * 60 * 24 * 365 *
|
|
450
|
+
100).quantize(quantization_6, rounding=ROUND_DOWN),
|
|
451
|
+
)
|
|
@@ -144,30 +144,30 @@ class OstiumSDK:
|
|
|
144
144
|
self.log(f"Block number: {block_number}")
|
|
145
145
|
|
|
146
146
|
# Get current price
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
pair_details['to']
|
|
150
|
-
)
|
|
151
|
-
self.log(f"Price: {price}")
|
|
147
|
+
last_trade_price = pair_details['lastTradePrice']
|
|
148
|
+
self.log(f"lastTradePrice: {last_trade_price}")
|
|
152
149
|
|
|
153
|
-
|
|
154
|
-
(Decimal(pair_details['longOI'])
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
long_oi = int(
|
|
151
|
+
(Decimal(pair_details['longOI']) *
|
|
152
|
+
Decimal(last_trade_price) / PRECISION_18 / PRECISION_12)
|
|
153
|
+
)
|
|
154
|
+
short_oi = int(
|
|
155
|
+
(Decimal(pair_details['shortOI']) *
|
|
156
|
+
Decimal(last_trade_price) / PRECISION_18 / PRECISION_12)
|
|
157
|
+
)
|
|
157
158
|
|
|
158
|
-
self.log(f"notional_long_oi: {
|
|
159
|
-
self.log(f"notional_short_oi: {
|
|
159
|
+
self.log(f"notional_long_oi: {long_oi}")
|
|
160
|
+
self.log(f"notional_short_oi: {short_oi}")
|
|
160
161
|
|
|
161
162
|
ret = get_funding_rate(
|
|
162
163
|
pair_details['curFundingLong'],
|
|
163
164
|
pair_details['curFundingShort'],
|
|
164
165
|
pair_details['lastFundingRate'],
|
|
165
|
-
# pair_details['lastFundingVelocity'],
|
|
166
166
|
pair_details['maxFundingFeePerBlock'],
|
|
167
167
|
pair_details['lastFundingBlock'],
|
|
168
168
|
block_number,
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
long_oi, # Needs to be in USD
|
|
170
|
+
short_oi, # Needs to be in USD
|
|
171
171
|
pair_details['maxOI'],
|
|
172
172
|
pair_details['hillInflectionPoint'],
|
|
173
173
|
pair_details['hillPosScale'],
|
|
@@ -50,8 +50,6 @@ class SubgraphClient:
|
|
|
50
50
|
maxOI
|
|
51
51
|
makerFeeP
|
|
52
52
|
takerFeeP
|
|
53
|
-
usageFeeP
|
|
54
|
-
utilizationThresholdP
|
|
55
53
|
makerMaxLeverage
|
|
56
54
|
curFundingLong
|
|
57
55
|
curFundingShort
|
|
@@ -70,7 +68,6 @@ class SubgraphClient:
|
|
|
70
68
|
hillInflectionPoint
|
|
71
69
|
hillPosScale
|
|
72
70
|
hillNegScale
|
|
73
|
-
lastOiDelta
|
|
74
71
|
springFactor
|
|
75
72
|
sFactorUpScaleP
|
|
76
73
|
sFactorDownScaleP
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: ostium-python-sdk
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.103
|
|
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
|
|
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.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk/formulae_wrapper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk.egg-info/requires.txt
RENAMED
|
File without changes
|
{ostium_python_sdk-0.2.101 → ostium_python_sdk-0.2.103}/ostium_python_sdk.egg-info/top_level.txt
RENAMED
|
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.2.101 → ostium_python_sdk-0.2.103}/tests/test_trade_liquidation_price.py
RENAMED
|
File without changes
|