-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-python …
…into dev
- Loading branch information
Showing
37 changed files
with
511 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import asyncio | ||
|
||
from pyinjective.composer import Composer as ProtoMsgComposer | ||
from pyinjective.core.broadcaster import MsgBroadcasterWithPk | ||
from pyinjective.constant import Network | ||
from pyinjective.wallet import PrivateKey | ||
|
||
|
||
async def main() -> None: | ||
# select network: local, testnet, mainnet | ||
network = Network.testnet() | ||
composer = ProtoMsgComposer(network=network.string()) | ||
private_key_in_hexa = "f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3" | ||
|
||
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation( | ||
network=network, | ||
private_key=private_key_in_hexa, | ||
use_secure_connection=True | ||
) | ||
|
||
priv_key = PrivateKey.from_hex(private_key_in_hexa) | ||
pub_key = priv_key.to_public_key() | ||
address = pub_key.to_address() | ||
subaccount_id = address.get_subaccount_id(index=0) | ||
|
||
# prepare trade info | ||
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" | ||
|
||
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" | ||
|
||
spot_orders_to_create = [ | ||
composer.SpotOrder( | ||
market_id=spot_market_id_create, | ||
subaccount_id=subaccount_id, | ||
fee_recipient=fee_recipient, | ||
price=3, | ||
quantity=55, | ||
is_buy=True, | ||
is_po=False | ||
), | ||
composer.SpotOrder( | ||
market_id=spot_market_id_create, | ||
subaccount_id=subaccount_id, | ||
fee_recipient=fee_recipient, | ||
price=300, | ||
quantity=55, | ||
is_buy=False, | ||
is_po=False | ||
), | ||
] | ||
|
||
# prepare tx msg | ||
msg = composer.MsgBatchUpdateOrders( | ||
sender=address.to_acc_bech32(), | ||
spot_orders_to_create=spot_orders_to_create, | ||
) | ||
|
||
# broadcast the transaction | ||
result = await message_broadcaster.broadcast([msg]) | ||
print("---Transaction Response---") | ||
print(result) | ||
|
||
if __name__ == "__main__": | ||
asyncio.get_event_loop().run_until_complete(main()) |
54 changes: 54 additions & 0 deletions
54
examples/chain_client/45_MessageBroadcasterWithGranteeAccount.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import asyncio | ||
|
||
from pyinjective.composer import Composer as ProtoMsgComposer | ||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.broadcaster import MsgBroadcasterWithPk | ||
from pyinjective.constant import Network | ||
from pyinjective.wallet import PrivateKey, Address | ||
|
||
|
||
async def main() -> None: | ||
# select network: local, testnet, mainnet | ||
network = Network.testnet() | ||
composer = ProtoMsgComposer(network=network.string()) | ||
|
||
# initialize grpc client | ||
client = AsyncClient(network, insecure=False) | ||
await client.sync_timeout_height() | ||
|
||
# load account | ||
private_key_in_hexa = "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e" | ||
priv_key = PrivateKey.from_hex(private_key_in_hexa) | ||
pub_key = priv_key.to_public_key() | ||
address = pub_key.to_address() | ||
|
||
message_broadcaster = MsgBroadcasterWithPk.new_for_grantee_account_using_simulation( | ||
network=network, | ||
grantee_private_key=private_key_in_hexa, | ||
use_secure_connection=True | ||
) | ||
|
||
# prepare tx msg | ||
market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" | ||
granter_inj_address = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" | ||
granter_address = Address.from_acc_bech32(granter_inj_address) | ||
granter_subaccount_id = granter_address.get_subaccount_id(index=0) | ||
|
||
msg = composer.MsgCreateSpotLimitOrder( | ||
sender=granter_inj_address, | ||
market_id=market_id, | ||
subaccount_id=granter_subaccount_id, | ||
fee_recipient=address.to_acc_bech32(), | ||
price=7.523, | ||
quantity=0.01, | ||
is_buy=True, | ||
is_po=False | ||
) | ||
|
||
# broadcast the transaction | ||
result = await message_broadcaster.broadcast([msg]) | ||
print("---Transaction Response---") | ||
print(result) | ||
|
||
if __name__ == "__main__": | ||
asyncio.get_event_loop().run_until_complete(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
examples/exchange_client/derivative_exchange_rpc/16_StreamOrderbooks.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
examples/exchange_client/derivative_exchange_rpc/23_StreamOrderbooksV2.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.