Skip to content

Commit ac54f6e

Browse files
maximshen007peiyun@inj21
authored andcommitted
Update README.md
moved examples out of src add examples url to readme, bump vesrion to 0.2.7 add url to examples
1 parent b143ec5 commit ac54f6e

24 files changed

+34
-28
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## Injective Python SDK
22

3-
WIP
4-
53
Note: Apple `M1` processor is not supported
64

75
### Dependences
@@ -26,17 +24,18 @@ import injective.exchange_api
2624
### Usage
2725
Requires Python 3.9+
2826

27+
[link to examples](https://github.com/InjectiveLabs/sdk-python/tree/master/examples)
2928
```bash
3029
$ pipenv shell
3130
$ pipenv install
3231

3332
# connecting to Injective Exchange API
3433
# and listening for new orders
35-
$ python src/exchange_api/examples/example.py
34+
$ python examples/exchange_api_example/examples/example.py
3635

3736
# sending a msg with bank transfer
3837
# signs and posts a Tx to the Injective Chain
39-
$ python src/chainclient/examples/example.py
38+
$ python examples/chain_client_example/examples/example.py
4039
```
4140
Upgrade `pip` to the latest version, if you see these warnings:
4241
```

src/injective/chain_client/examples/example.py renamed to examples/chain_client_examples/example.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
# Copyright 2021 Injective Labs
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,20 +18,24 @@
2018
import logging
2119
import json
2220

23-
from .._transaction import Transaction as Transaction
24-
from .._wallet import generate_wallet as generate_wallet
25-
from .._wallet import privkey_to_address as privkey_to_address
26-
from .._wallet import privkey_to_pubkey as privkey_to_pubkey
27-
from .._wallet import pubkey_to_address as pubkey_to_address
28-
from .._wallet import seed_to_privkey as seed_to_privkey
21+
from injective.chain_client._transaction import Transaction
22+
from injective.chain_client._wallet import (
23+
generate_wallet,
24+
privkey_to_address,
25+
privkey_to_pubkey,
26+
pubkey_to_address,
27+
seed_to_privkey,
28+
)
2929

3030

3131
MIN_GAS_PRICE = 500000000
3232

3333

3434
async def main() -> None:
3535
# user1 @ e2e-multinode
36-
sender_pk = seed_to_privkey("physical page glare junk return scale subject river token door mirror title")
36+
sender_pk = seed_to_privkey(
37+
"physical page glare junk return scale subject river token door mirror title"
38+
)
3739
sender_acc_addr = privkey_to_address(sender_pk)
3840
print("Sender Account:", sender_acc_addr)
3941

@@ -49,7 +51,7 @@ async def main() -> None:
4951
sequence=acc_seq,
5052
gas=200000,
5153
fee=200000 * MIN_GAS_PRICE,
52-
sync_mode="block"
54+
sync_mode="block",
5355
)
5456
tx.add_cosmos_bank_msg_send(
5557
recipient="inj1qy69k458ppmj45c3vqwcd6wvlcuvk23x0hsz58", # maxim @ e2e-multinode
@@ -64,42 +66,47 @@ async def main() -> None:
6466

6567
tx_json = tx.get_signed()
6668

67-
print('Signed Tx:', tx_json)
68-
print('Sent Tx:', await post_tx(tx_json))
69+
print("Signed Tx:", tx_json)
70+
print("Sent Tx:", await post_tx(tx_json))
6971

7072

7173
async def get_account_num_seq(address: str) -> (int, int):
7274
async with aiohttp.ClientSession() as session:
7375
async with session.request(
74-
'GET', 'http://localhost:10337/cosmos/auth/v1beta1/accounts/' + address,
75-
headers={'Accept-Encoding': 'application/json'},
76+
"GET",
77+
"http://localhost:10337/cosmos/auth/v1beta1/accounts/" + address,
78+
headers={"Accept-Encoding": "application/json"},
7679
) as response:
7780
if response.status != 200:
7881
print(await response.text())
7982
raise ValueError("HTTP response status", response.status)
8083

8184
resp = json.loads(await response.text())
82-
acc = resp['account']['base_account']
83-
return acc['account_number'], acc['sequence']
85+
acc = resp["account"]["base_account"]
86+
return acc["account_number"], acc["sequence"]
8487

8588

8689
async def post_tx(tx_json: str):
8790
async with aiohttp.ClientSession() as session:
8891
async with session.request(
89-
'POST', 'http://localhost:10337/txs', data=tx_json,
90-
headers={'Content-Type': 'application/json'},
92+
"POST",
93+
"http://localhost:10337/txs",
94+
data=tx_json,
95+
headers={"Content-Type": "application/json"},
9196
) as response:
9297
if response.status != 200:
9398
print(await response.text())
9499
raise ValueError("HTTP response status", response.status)
95100

96101
resp = json.loads(await response.text())
97-
if 'code' in resp:
102+
if "code" in resp:
98103
print("Response:", resp)
99-
raise ValueError('sdk error %d: %s' % (resp['code'], resp['raw_log']))
104+
raise ValueError("sdk error %d: %s" % (resp["code"], resp["raw_log"]))
100105

101-
return resp['txhash']
106+
return resp["txhash"]
102107

103-
if __name__ == '__main__':
108+
109+
if __name__ == "__main__":
104110
logging.basicConfig(level=logging.INFO)
105-
asyncio.get_event_loop().run_until_complete(main())
111+
asyncio.get_event_loop().run_until_complete(main())
112+

src/injective/exchange_api/examples/accounts_rpc/1_StreamSubaccountBalanceRequest.py renamed to examples/exchange_api_examples/accounts_rpc/1_StreamSubaccountBalanceRequest.py

File renamed without changes.

src/injective/exchange_api/examples/accounts_rpc/2_SubaccountBalanceRequest.py renamed to examples/exchange_api_examples/accounts_rpc/2_SubaccountBalanceRequest.py

File renamed without changes.

src/injective/exchange_api/examples/accounts_rpc/3_SubaccountsListRequest.py renamed to examples/exchange_api_examples/accounts_rpc/3_SubaccountsListRequest.py

File renamed without changes.

src/injective/exchange_api/examples/accounts_rpc/4_SubaccountBalancesListRequest.py renamed to examples/exchange_api_examples/accounts_rpc/4_SubaccountBalancesListRequest.py

File renamed without changes.

src/injective/exchange_api/examples/accounts_rpc/5_SubaccountHistoryRequest.py renamed to examples/exchange_api_examples/accounts_rpc/5_SubaccountHistoryRequest.py

File renamed without changes.

src/injective/exchange_api/examples/accounts_rpc/6_SubaccountOrderSummaryRequest.py renamed to examples/exchange_api_examples/accounts_rpc/6_SubaccountOrderSummaryRequest.py

File renamed without changes.
File renamed without changes.

src/injective/exchange_api/examples/spot_exchange_rpc/10_SubaccountOrdersListRequest.py renamed to examples/exchange_api_examples/spot_exchange_rpc/10_SubaccountOrdersListRequest.py

File renamed without changes.

0 commit comments

Comments
 (0)