Skip to content

Commit 53496cf

Browse files
author
abel
committed
(fix) Configured different extra gas cost for spot and derivative post only orders
1 parent 6eefa4c commit 53496cf

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

pyinjective/core/gas_limit_estimator.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
DERIVATIVE_ORDER_CREATION_GAS_LIMIT = 70_000
1717
SPOT_ORDER_CANCELATION_GAS_LIMIT = 50_000
1818
DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT = 60_000
19-
# POST ONLY orders take around 50% more gas to create than normal orders, due to the validations
20-
POST_ONLY_ORDER_MULTIPLIER = 0.5
19+
# POST ONLY orders take around 60% (for spot) and 50% (for derivative) more gas to create than normal orders
20+
# due to the required validations
21+
SPOT_POST_ONLY_ORDER_MULTIPLIER = 0.6
22+
DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER = 0.5
2123

2224

2325
class GasLimitEstimator(ABC):
@@ -109,7 +111,7 @@ def gas_limit(self) -> int:
109111
total = 0
110112
total += self.GENERAL_MESSAGE_GAS_LIMIT
111113
total += len(self._message.orders) * SPOT_ORDER_CREATION_GAS_LIMIT
112-
total += math.ceil(len(post_only_orders) * SPOT_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER)
114+
total += math.ceil(len(post_only_orders) * SPOT_ORDER_CREATION_GAS_LIMIT * SPOT_POST_ONLY_ORDER_MULTIPLIER)
113115

114116
return total
115117

@@ -150,7 +152,9 @@ def gas_limit(self) -> int:
150152
total = 0
151153
total += self.GENERAL_MESSAGE_GAS_LIMIT
152154
total += len(self._message.orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT
153-
total += math.ceil(len(post_only_orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER)
155+
total += math.ceil(
156+
len(post_only_orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT * DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER
157+
)
154158

155159
return total
156160

@@ -204,12 +208,16 @@ def gas_limit(self) -> int:
204208
total += len(self._message.derivative_orders_to_create) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT
205209
total += len(self._message.binary_options_orders_to_create) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT
206210

207-
total += math.ceil(len(post_only_spot_orders) * SPOT_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER)
211+
total += math.ceil(len(post_only_spot_orders) * SPOT_ORDER_CREATION_GAS_LIMIT * SPOT_POST_ONLY_ORDER_MULTIPLIER)
208212
total += math.ceil(
209-
len(post_only_derivative_orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER
213+
len(post_only_derivative_orders)
214+
* DERIVATIVE_ORDER_CREATION_GAS_LIMIT
215+
* DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER
210216
)
211217
total += math.ceil(
212-
len(post_only_binary_options_orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER
218+
len(post_only_binary_options_orders)
219+
* DERIVATIVE_ORDER_CREATION_GAS_LIMIT
220+
* DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER
213221
)
214222

215223
total += len(self._message.spot_orders_to_cancel) * SPOT_ORDER_CANCELATION_GAS_LIMIT

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "injective-py"
3-
version = "1.2.0-rc2"
3+
version = "1.2.0-rc3"
44
description = "Injective Python SDK, with Exchange API Client"
55
authors = ["Injective Labs <[email protected]>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)