Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-python
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
abel committed Aug 23, 2023
2 parents 485a27b + aa191ae commit d67b6b8
Show file tree
Hide file tree
Showing 37 changed files with 511 additions and 169 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,34 @@ make tests
```

### Changelogs
**0.7.1**(change before release)
**0.8**(change before release)
* Refactor Composer to be created with all the markets and tokens. The Composer now uses the real markets and tokens to convert human-readable values to chain format
* The Composer can still be instantiated without markets and tokens. When markets and tokens are not provided the Composer loads the required information from the Denoms used in previous versions
* Change in AsyncClient to be able to create Composer instances for the client network, markets and tokens
* Examples have been adapted to create Composer instances using the AsyncClient

**0.7.1.1**
* Fixed Testnet network URLs

**0.7.1**
* Include implementation of the MessageBroadcaster, to simplify the transaction creation and broadcasting process.

**0.7.0.6**
* ADD SEI/USDT in metadata

**0.7.0.5**
* Added the required logic in the MsgSubaccountTransfer message to translate amounts and token into the correct amount and token name representation for the chain

**0.7.0.4**
* Synchronized decimals for ATOM and WETH in Testnet with the configuration provided by the indexer

**0.7.0.3**
* Add FRCOIN testnet

**0.7.0.2**
* Removed from AsyncClient all references to the deprecated OrderBook RPC endpoints (replaced them with OrderBookV2)
* Updated all orderbook examples

**0.7**
* Removed references to pysha3 library (and also eip712-struct that required it) and replaced it with other implementation to allow the project to work with Python 3.11
* Updated sentry nodes LCD URL, for each sentry node to use its own service
Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/0_LocalOrderHash.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def main() -> None:

# prepare trade info
spot_market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
deriv_market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
deriv_market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"

spot_orders = [
Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/13_MsgIncreasePositionMargin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def main() -> None:
subaccount_id = address.get_subaccount_id(index=0)

# prepare trade info
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"

# prepare tx msg
msg = composer.MsgIncreasePositionMargin(
Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/16_MsgSubaccountTransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def main() -> None:
source_subaccount_id=subaccount_id,
destination_subaccount_id=dest_subaccount_id,
amount=100,
denom="inj"
denom="INJ"
)

# build sim tx
Expand Down
4 changes: 2 additions & 2 deletions examples/chain_client/17_MsgBatchUpdateOrders.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ async def main() -> None:
# prepare trade info
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"

derivative_market_id_create = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
derivative_market_id_create = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"

derivative_market_id_cancel = "0xd5e4b12b19ecf176e4e14b42944731c27677819d2ed93be4104ad7025529c7ff"
derivative_market_id_cancel_2 = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
derivative_market_id_cancel_2 = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
spot_market_id_cancel = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
spot_market_id_cancel_2 = "0x7a57e705bb4e09c88aecfc295569481dbf2fe1d5efe364651fbe72385938e9b0"

Expand Down
64 changes: 64 additions & 0 deletions examples/chain_client/44_MessageBroadcaster.py
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 examples/chain_client/45_MessageBroadcasterWithGranteeAccount.py
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())
2 changes: 1 addition & 1 deletion examples/chain_client/6_MsgCreateDerivativeLimitOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def main() -> None:
subaccount_id = address.get_subaccount_id(index=0)

# prepare trade info
market_id = "0x141e3c92ed55107067ceb60ee412b86256cedef67b1227d6367b4cdf30c55a74"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"

# prepare tx 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 @@ -23,7 +23,7 @@ async def main() -> None:
subaccount_id = address.get_subaccount_id(index=0)

# prepare trade info
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"

# prepare tx msg
Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/8_MsgCancelDerivativeOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def main() -> None:
subaccount_id = address.get_subaccount_id(index=0)

# prepare trade info
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
order_hash = "0x667ee6f37f6d06bf473f4e1434e92ac98ff43c785405e2a511a0843daeca2de9"

# prepare tx msg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main() -> None:
client = AsyncClient(network, insecure=False)
subaccount = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000"
order_direction = "buy"
market_id = "0xe112199d9ee44ceb2697ea0edd1cd422223c105f3ed2bdf85223d3ca59f5909a"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
subacc_order_summary = await client.get_subaccount_order_summary(
subaccount_id=subaccount,
# order_direction=order_direction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
order_side = "sell"
subaccount_id = "0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000"
orders = await client.stream_historical_derivative_orders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
subaccount_id = "0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000"
trades = await client.get_derivative_trades(
market_id=market_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main() -> None:
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_ids = [
"0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3",
"0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
"0xd5e4b12b19ecf176e4e14b42944731c27677819d2ed93be4104ad7025529c7ff"
]
subaccount_id = "0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main() -> None:
network = Network.testnet()
client = AsyncClient(network, insecure=False)
subaccount_id = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000"
market_id = "0xe112199d9ee44ceb2697ea0edd1cd422223c105f3ed2bdf85223d3ca59f5909a"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
skip = 1
limit = 2
orders = await client.get_derivative_subaccount_orders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main() -> None:
network = Network.testnet()
client = AsyncClient(network, insecure=False)
subaccount_id = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000"
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
execution_type = "market"
direction = "sell"
skip = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
subaccount_id = "0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000"
skip=0
limit=3
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
skip=0
limit=3
end_time=1675717201465
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async def main() -> None:
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_ids = [
"0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3",
"0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
"0xd5e4b12b19ecf176e4e14b42944731c27677819d2ed93be4104ad7025529c7ff"
]
markets = await client.get_derivative_orderbooks(market_ids=market_ids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
market = await client.get_derivative_market(market_id=market_id)
print(market)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
subaccount_id = "0x295639d56c987f0e24d21bb167872b3542a6e05a000000000000000000000000"
is_conditional = "false"
skip = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main() -> None:
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_ids = [
"0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3",
"0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
"0xd5e4b12b19ecf176e4e14b42944731c27677819d2ed93be4104ad7025529c7ff"
]
orderbooks = await client.get_derivative_orderbooksV2(market_ids=market_ids)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
market = await client.get_derivative_orderbook(market_id=market_id)
print(market)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
markets = await client.stream_derivative_orderbook(market_id=market_id)
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
markets = await client.stream_derivative_orderbook_snapshot(market_ids=[market_id])
async for market in markets:
print(market)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def main() -> None:
network = Network.testnet()
async_client = AsyncClient(network, insecure=False)

market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
orderbook = Orderbook(market_id=market_id)

# start getting price levels updates
Expand Down
Loading

0 comments on commit d67b6b8

Please sign in to comment.