ostium-python-sdk 0.2.106__tar.gz → 0.2.107__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 (36) hide show
  1. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/PKG-INFO +1 -1
  2. ostium_python_sdk-0.2.107/ostium_python_sdk/scscript/funding.py +163 -0
  3. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk.egg-info/PKG-INFO +1 -1
  4. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk.egg-info/SOURCES.txt +2 -0
  5. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/setup.py +1 -1
  6. ostium_python_sdk-0.2.107/tests/__init__.py +0 -0
  7. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/MANIFEST.in +0 -0
  8. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/README.md +0 -0
  9. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/__init__.py +0 -0
  10. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/abi/__init__.py +0 -0
  11. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/abi/abi.py +0 -0
  12. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/abi/faucet_abi.py +0 -0
  13. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/balance.py +0 -0
  14. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/config.py +0 -0
  15. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/constants.py +0 -0
  16. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/exceptions.py +0 -0
  17. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/faucet.py +0 -0
  18. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/formulae.py +0 -0
  19. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/formulae_wrapper.py +0 -0
  20. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/ostium.py +0 -0
  21. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/price.py +0 -0
  22. {ostium_python_sdk-0.2.106/tests → ostium_python_sdk-0.2.107/ostium_python_sdk/scscript}/__init__.py +0 -0
  23. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/sdk.py +0 -0
  24. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/subgraph.py +0 -0
  25. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk/utils.py +0 -0
  26. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk.egg-info/dependency_links.txt +0 -0
  27. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk.egg-info/requires.txt +0 -0
  28. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/ostium_python_sdk.egg-info/top_level.txt +0 -0
  29. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/pyproject.toml +0 -0
  30. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/requirements-dev.txt +0 -0
  31. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/requirements.txt +0 -0
  32. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/setup.cfg +0 -0
  33. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/tests/test_get_price_impact.py +0 -0
  34. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/tests/test_slippage.py +0 -0
  35. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/tests/test_trade_get_tp_price.py +0 -0
  36. {ostium_python_sdk-0.2.106 → ostium_python_sdk-0.2.107}/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.106
3
+ Version: 0.2.107
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
@@ -0,0 +1,163 @@
1
+ import sys
2
+ from eth_abi import encode
3
+ from decimal import *
4
+ import math
5
+
6
+ PRECISION_2 = Decimal(1e2)
7
+ PRECISION_6 = Decimal(1e6)
8
+ PRECISION_18 = Decimal(1e18)
9
+ quantization_2 = Decimal('0.01')
10
+ quantization_3 = Decimal('0.001')
11
+ quantization_6 = Decimal('0.000001')
12
+ quantization_12 = Decimal('0.000000000001')
13
+ quantization_18 = Decimal('0.000000000000000001')
14
+
15
+ def getTargetFundingRate(normalizedOiDelta, hillInflectionPoint, maxFundingFeePerBlock, hillPosScale, hillNegScale):
16
+ a = Decimal('1.84')
17
+ n = 2
18
+ K = Decimal('0.16')
19
+ x = (a*normalizedOiDelta).quantize(quantization_6, rounding=ROUND_DOWN)
20
+ x2 = (x**n).quantize(quantization_18, rounding=ROUND_DOWN)
21
+ hill = (x2/(K + x2)).quantize(quantization_18, rounding=ROUND_DOWN)
22
+
23
+ targetFr = (hillPosScale * hill).quantize(quantization_18, rounding=ROUND_DOWN) + hillInflectionPoint if normalizedOiDelta >= 0 \
24
+ else (-hillNegScale * hill).quantize(quantization_18, rounding=ROUND_DOWN) + hillInflectionPoint
25
+
26
+ if targetFr > Decimal('1'):
27
+ targetFr = Decimal('1')
28
+ elif targetFr < Decimal('-1'):
29
+ targetFr = Decimal('-1')
30
+
31
+ return (maxFundingFeePerBlock * targetFr).quantize(quantization_18, rounding=ROUND_DOWN)
32
+
33
+
34
+ def getPendingAccFundingFees(
35
+ blockNumber: Decimal,
36
+ lastUpdateBlock: Decimal,
37
+ valueLong: Decimal,
38
+ valueShort: Decimal,
39
+ openInterestUsdcLong: Decimal,
40
+ openInterestUsdcShort: Decimal,
41
+ OiCap: Decimal,
42
+ maxFundingFeePerBlock: Decimal,
43
+ lastFundingRate: Decimal,
44
+ hillInflectionPoint: Decimal,
45
+ hillPosScale: Decimal,
46
+ hillNegScale: Decimal,
47
+ springFactor: Decimal,
48
+ sFactorUpScale: Decimal,
49
+ sFactorDownScaleP: Decimal,
50
+ ):
51
+
52
+ numBlocks = blockNumber - lastUpdateBlock
53
+ openInterestMax = max(openInterestUsdcLong, openInterestUsdcShort)
54
+ normalizedOiDelta = ((openInterestUsdcLong - openInterestUsdcShort).quantize(quantization_6, rounding=ROUND_DOWN) / max(OiCap, openInterestMax).quantize(quantization_6, rounding=ROUND_DOWN)).quantize(quantization_6, rounding=ROUND_DOWN)
55
+
56
+ targetFr = getTargetFundingRate(normalizedOiDelta, hillInflectionPoint, maxFundingFeePerBlock, hillPosScale, hillNegScale)
57
+
58
+ # New regime selection based on funding rates:
59
+ if lastFundingRate * targetFr >= 0: # Same sign
60
+ if abs(targetFr) > abs(lastFundingRate):
61
+ sFactor = springFactor
62
+ else:
63
+ sFactor = sFactorDownScaleP * springFactor / 100
64
+ else:
65
+ sFactor = sFactorUpScale * springFactor / 100
66
+
67
+ expComp = exponentialApproximation(-sFactor * numBlocks)
68
+ accFundingRate = (targetFr * numBlocks).quantize(quantization_18, rounding=ROUND_DOWN) + ((Decimal(1) - expComp) * (lastFundingRate - targetFr) / sFactor).quantize(quantization_18, rounding=ROUND_DOWN)
69
+
70
+ fr = targetFr + ((lastFundingRate - targetFr) * expComp).quantize(quantization_18, rounding=ROUND_DOWN)
71
+
72
+ if accFundingRate > 0:
73
+ if openInterestUsdcLong > 0:
74
+ valueLong += accFundingRate
75
+ valueShort -= (accFundingRate * openInterestUsdcLong / openInterestUsdcShort).quantize(quantization_18, rounding=ROUND_DOWN) if openInterestUsdcShort > 0 else 0
76
+ else:
77
+ if openInterestUsdcShort > 0:
78
+ valueShort -= accFundingRate
79
+ valueLong += (accFundingRate * openInterestUsdcShort / openInterestUsdcLong).quantize(quantization_18, rounding=ROUND_DOWN) if openInterestUsdcLong > 0 else 0
80
+
81
+ return (valueLong.quantize(quantization_18, rounding=ROUND_DOWN), valueShort.quantize(quantization_18, rounding=ROUND_DOWN), fr.quantize(quantization_18, rounding=ROUND_DOWN), targetFr.quantize(quantization_18, rounding=ROUND_DOWN))
82
+
83
+
84
+ def exponentialApproximation(value):
85
+ if abs(value) < Decimal('0.7932312589092019'):
86
+ numeratorTmp = value + Decimal('3');
87
+ numerator = (numeratorTmp * numeratorTmp).quantize(quantization_18, rounding=ROUND_DOWN) + Decimal('3');
88
+ denominatorTmp = value - Decimal('3');
89
+ denominator = (denominatorTmp * denominatorTmp).quantize(quantization_18, rounding=ROUND_DOWN) + Decimal('3');
90
+
91
+ return (numerator / denominator).quantize(quantization_18, rounding=ROUND_DOWN);
92
+ elif abs(value) <= Decimal('6.906'):
93
+ k = [Decimal('1.648721'), Decimal('1.284025'), Decimal('1.133148'), Decimal('1.064494'), Decimal('1.031743'), Decimal('1.015748'), Decimal('1.007843'), Decimal('1.003915'), Decimal('1.001955'), Decimal('1.000977')]
94
+ product = Decimal('1.0')
95
+
96
+ integer_part = math.floor(abs(value))
97
+ decimal_part = abs(value) - integer_part
98
+
99
+ for i in range(len(k)):
100
+ decimal_part *= 2
101
+ if decimal_part >= 1:
102
+ product *= k[i]
103
+ decimal_part -= 1
104
+ product = product.quantize(quantization_6, rounding=ROUND_DOWN)
105
+ if decimal_part == 0:
106
+ break
107
+ product = product.quantize(quantization_3, rounding=ROUND_DOWN) * Decimal(2)**(integer_part)
108
+
109
+ return (Decimal(1) / product.quantize(quantization_18, rounding=ROUND_DOWN)).quantize(quantization_3, rounding=ROUND_DOWN)
110
+ else:
111
+ return Decimal(0)
112
+
113
+ if __name__ == "__main__":
114
+ getcontext().prec = 128
115
+ getcontext().rounding = ROUND_DOWN
116
+ getcontext().clear_flags()
117
+
118
+ if sys.argv[1] == "targetFundingRate":
119
+ normalizedOiDelta = Decimal(sys.argv[2]) / PRECISION_6
120
+ hillInflectionPoint = Decimal(sys.argv[3]) / PRECISION_18
121
+ maxFundingFeePerBlock = Decimal(sys.argv[4]) / PRECISION_18
122
+ hillPosScale = Decimal(sys.argv[5]) / PRECISION_2
123
+ hillNegScale = Decimal(sys.argv[6]) / PRECISION_2
124
+
125
+ result = getTargetFundingRate(
126
+ normalizedOiDelta,
127
+ hillInflectionPoint,
128
+ maxFundingFeePerBlock,
129
+ hillPosScale,
130
+ hillNegScale
131
+ )
132
+ encodedResult = "0x" + \
133
+ encode(["int"], [int(result*PRECISION_18)]).hex()
134
+ # returns targetFr
135
+ print(encodedResult)
136
+ elif sys.argv[1] == "accFundingRate":
137
+ blockNumber = Decimal(sys.argv[2])
138
+ lastUpdateBlock = Decimal(sys.argv[3])
139
+ valueLong = Decimal(sys.argv[4]) / PRECISION_18
140
+ valueShort = Decimal(sys.argv[5]) / PRECISION_18
141
+ openInterestUsdcLong = Decimal(sys.argv[6]) / PRECISION_6
142
+ openInterestUsdcShort = Decimal(sys.argv[7]) / PRECISION_6
143
+ oiCap = Decimal(sys.argv[8]) / PRECISION_6
144
+ maxFundingFeePerBlock = Decimal(sys.argv[9]) / PRECISION_18
145
+ lastFundingRate = Decimal(sys.argv[10]) / PRECISION_18
146
+ hillInflectionPoint = Decimal(sys.argv[11]) / PRECISION_18
147
+ hillPosScale = Decimal(sys.argv[12]) / PRECISION_2
148
+ hillNegScale = Decimal(sys.argv[13]) / PRECISION_2
149
+ springFactor = Decimal(sys.argv[14]) / PRECISION_18
150
+ sFactorUpScale = Decimal(sys.argv[15]) / PRECISION_2
151
+ sFactorDownScaleP = Decimal(sys.argv[16]) / PRECISION_2
152
+
153
+ result = getPendingAccFundingFees(blockNumber, lastUpdateBlock, valueLong, valueShort, openInterestUsdcLong,
154
+ openInterestUsdcShort, oiCap, maxFundingFeePerBlock, lastFundingRate,
155
+ hillInflectionPoint, hillPosScale, hillNegScale, springFactor, sFactorUpScale, sFactorDownScaleP)
156
+ encodedResult = "0x" + \
157
+ encode(["int", "int", "int64"], [int(result[0]*PRECISION_18),
158
+ int(result[1]*PRECISION_18), int(result[2]*PRECISION_18)]).hex()
159
+ # returns valueLong, valueShort, fr
160
+ print(encodedResult)
161
+ else:
162
+ print("Invalid Operation")
163
+ sys.exit(1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ostium-python-sdk
3
- Version: 0.2.106
3
+ Version: 0.2.107
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
@@ -25,6 +25,8 @@ ostium_python_sdk.egg-info/top_level.txt
25
25
  ostium_python_sdk/abi/__init__.py
26
26
  ostium_python_sdk/abi/abi.py
27
27
  ostium_python_sdk/abi/faucet_abi.py
28
+ ostium_python_sdk/scscript/__init__.py
29
+ ostium_python_sdk/scscript/funding.py
28
30
  tests/__init__.py
29
31
  tests/test_get_price_impact.py
30
32
  tests/test_slippage.py
@@ -19,7 +19,7 @@ if changelog_path.exists():
19
19
 
20
20
  setup(
21
21
  name="ostium-python-sdk",
22
- version="0.2.106",
22
+ version="0.2.107",
23
23
  packages=find_packages(),
24
24
  install_requires=read_requirements('requirements.txt'),
25
25
  extras_require={
File without changes