Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ eip712_structs = "*"
coincurve = "*"
aiocron = "*"
websockets = "*"
urllib3 = "<2"

[dev-packages]

[requires]
python_version = "3"
python_version = "3.8"
288 changes: 147 additions & 141 deletions Pipfile.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Note that the [sync client](https://github.com/InjectiveLabs/sdk-python/blob/mas


### Changelogs
**0.6.3.1**
* Update the code to the new structure of transaction simulation responses

**0.6.2.7**
* Fix margin calculation in utils

Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/17_MsgBatchUpdateOrders.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
4 changes: 2 additions & 2 deletions examples/chain_client/20_MsgExec.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
data=(str(sim_res_msg[0]).replace("results:", ''))
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
data=sim_res_msg[0]
unpacked_msg_res = ProtoMsgComposer.UnpackMsgExecResponse(
msg_type=msg0.__class__.__name__,
data=data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/33_MsgCancelBinaryOptionsOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/36_MsgRelayProviderPrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/3_MsgCreateSpotLimitOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/4_MsgCreateSpotMarketOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/6_MsgCreateDerivativeLimitOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/7_MsgCreateDerivativeMarketOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
print("---Simulation Response---")
print(sim_res_msg)

Expand Down
67 changes: 34 additions & 33 deletions pyinjective/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,44 +900,44 @@ def MsgVote(
# you need to figure out this magic prefix number to trim request-msg-header off the data
# this method handles only exchange responses
@staticmethod
def MsgResponses(data, simulation=False):
def MsgResponses(response, simulation=False):
data = response.result
if not simulation:
data = bytes.fromhex(data)
header_map = {
"/injective.exchange.v1beta1.MsgCreateSpotLimitOrder": injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
"/injective.exchange.v1beta1.MsgCreateSpotMarketOrder": injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
"/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder": injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
"/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder": injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
"/injective.exchange.v1beta1.MsgCancelSpotOrder": injective_exchange_tx_pb.MsgCancelSpotOrderResponse,
"/injective.exchange.v1beta1.MsgCancelDerivativeOrder": injective_exchange_tx_pb.MsgCancelDerivativeOrderResponse,
"/injective.exchange.v1beta1.MsgBatchCancelSpotOrders": injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchCancelDerivativeOrders": injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchCreateSpotLimitOrders": injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchCreateDerivativeLimitOrders": injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchUpdateOrders": injective_exchange_tx_pb.MsgBatchUpdateOrdersResponse,
"/injective.exchange.v1beta1.MsgDeposit": injective_exchange_tx_pb.MsgDepositResponse,
"/injective.exchange.v1beta1.MsgWithdraw": injective_exchange_tx_pb.MsgWithdrawResponse,
"/injective.exchange.v1beta1.MsgSubaccountTransfer": injective_exchange_tx_pb.MsgSubaccountTransferResponse,
"/injective.exchange.v1beta1.MsgLiquidatePosition": injective_exchange_tx_pb.MsgLiquidatePositionResponse,
"/injective.exchange.v1beta1.MsgIncreasePositionMargin": injective_exchange_tx_pb.MsgIncreasePositionMarginResponse,
"/injective.auction.v1beta1.MsgBid": injective_auction_tx_pb.MsgBidResponse,
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsLimitOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsLimitOrderResponse,
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsMarketOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsMarketOrderResponse,
"/injective.exchange.v1beta1.MsgCancelBinaryOptionsOrder": injective_exchange_tx_pb.MsgCancelBinaryOptionsOrderResponse,
"/injective.exchange.v1beta1.MsgAdminUpdateBinaryOptionsMarket": injective_exchange_tx_pb.MsgAdminUpdateBinaryOptionsMarketResponse,
"/injective.exchange.v1beta1.MsgInstantBinaryOptionsMarketLaunch": injective_exchange_tx_pb.MsgInstantBinaryOptionsMarketLaunchResponse,
"/cosmos.bank.v1beta1.MsgSend": cosmos_bank_tx_pb.MsgSendResponse,
"/cosmos.authz.v1beta1.MsgGrant": cosmos_authz_tx_pb.MsgGrantResponse,
"/cosmos.authz.v1beta1.MsgExec": cosmos_authz_tx_pb.MsgExecResponse,
"/cosmos.authz.v1beta1.MsgRevoke": cosmos_authz_tx_pb.MsgRevokeResponse,
"/injective.oracle.v1beta1.MsgRelayPriceFeedPrice": injective_oracle_tx_pb.MsgRelayPriceFeedPriceResponse,
"/injective.oracle.v1beta1.MsgRelayProviderPrices": injective_oracle_tx_pb.MsgRelayProviderPrices,
"/injective.exchange.v1beta1.MsgCreateSpotLimitOrderResponse": injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
"/injective.exchange.v1beta1.MsgCreateSpotMarketOrderResponse": injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
"/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrderResponse": injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
"/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrderResponse": injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
"/injective.exchange.v1beta1.MsgCancelSpotOrderResponse": injective_exchange_tx_pb.MsgCancelSpotOrderResponse,
"/injective.exchange.v1beta1.MsgCancelDerivativeOrderResponse": injective_exchange_tx_pb.MsgCancelDerivativeOrderResponse,
"/injective.exchange.v1beta1.MsgBatchCancelSpotOrdersResponse": injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchCancelDerivativeOrdersResponse": injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchCreateSpotLimitOrdersResponse": injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchCreateDerivativeLimitOrdersResponse": injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchUpdateOrdersResponse": injective_exchange_tx_pb.MsgBatchUpdateOrdersResponse,
"/injective.exchange.v1beta1.MsgDepositResponse": injective_exchange_tx_pb.MsgDepositResponse,
"/injective.exchange.v1beta1.MsgWithdrawResponse": injective_exchange_tx_pb.MsgWithdrawResponse,
"/injective.exchange.v1beta1.MsgSubaccountTransferResponse": injective_exchange_tx_pb.MsgSubaccountTransferResponse,
"/injective.exchange.v1beta1.MsgLiquidatePositionResponse": injective_exchange_tx_pb.MsgLiquidatePositionResponse,
"/injective.exchange.v1beta1.MsgIncreasePositionMarginResponse": injective_exchange_tx_pb.MsgIncreasePositionMarginResponse,
"/injective.auction.v1beta1.MsgBidResponse": injective_auction_tx_pb.MsgBidResponse,
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsLimitOrderResponse": injective_exchange_tx_pb.MsgCreateBinaryOptionsLimitOrderResponse,
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsMarketOrderResponse": injective_exchange_tx_pb.MsgCreateBinaryOptionsMarketOrderResponse,
"/injective.exchange.v1beta1.MsgCancelBinaryOptionsOrderResponse": injective_exchange_tx_pb.MsgCancelBinaryOptionsOrderResponse,
"/injective.exchange.v1beta1.MsgAdminUpdateBinaryOptionsMarketResponse": injective_exchange_tx_pb.MsgAdminUpdateBinaryOptionsMarketResponse,
"/injective.exchange.v1beta1.MsgInstantBinaryOptionsMarketLaunchResponse": injective_exchange_tx_pb.MsgInstantBinaryOptionsMarketLaunchResponse,
"/cosmos.bank.v1beta1.MsgSendResponse": cosmos_bank_tx_pb.MsgSendResponse,
"/cosmos.authz.v1beta1.MsgGrantResponse": cosmos_authz_tx_pb.MsgGrantResponse,
"/cosmos.authz.v1beta1.MsgExecResponse": cosmos_authz_tx_pb.MsgExecResponse,
"/cosmos.authz.v1beta1.MsgRevokeResponse": cosmos_authz_tx_pb.MsgRevokeResponse,
"/injective.oracle.v1beta1.MsgRelayPriceFeedPriceResponse": injective_oracle_tx_pb.MsgRelayPriceFeedPriceResponse,
"/injective.oracle.v1beta1.MsgRelayProviderPricesResponse": injective_oracle_tx_pb.MsgRelayProviderPrices,
}

response = tx_response_pb.TxResponseData.FromString(data)
msgs = []
for msg in response.messages:
msgs.append(header_map[msg.header].FromString(msg.data))
for msg in data.msg_responses:
msgs.append(header_map[msg.type_url].FromString(msg.value))

return msgs

Expand Down Expand Up @@ -967,4 +967,5 @@ def UnpackMsgExecResponse(msg_type, data):
"MsgInstantBinaryOptionsMarketLaunch": injective_exchange_tx_pb.MsgInstantBinaryOptionsMarketLaunchResponse,
}

return header_map[msg_type].FromString(bytes(data, "utf-8"))
responses = [header_map[msg_type].FromString(result) for result in data.results]
return responses
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
EMAIL = "achilleas@injectivelabs.com"
AUTHOR = "Injective Labs"
REQUIRES_PYTHON = ">=3.7.0"
VERSION = "0.6.3.0"
VERSION = "0.6.3.1"

REQUIRED = [
"protobuf",
Expand Down