Skip to content

Commit 211e3cc

Browse files
Merge pull request #44 from InjectiveLabs/update-sdk
Update sdk
2 parents 272ad72 + 3dd9e6f commit 211e3cc

File tree

11 files changed

+252
-18
lines changed

11 files changed

+252
-18
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ python pyinjective/fetch_metadata.py
8686

8787

8888
### Changelogs
89+
0.5.4
90+
* Added PortfolioRequest, GetTxByHashRequest, AuctionRequest, AuctionsRequest, StreamBidsRequest and provided examples
91+
* Updated the composer with MsgIncreasePosition and MsgLiquidatePosition
92+
* Added reduce-only orders to the composer and updated examples
93+
8994
0.5.3
9095
* add skip, and limit to trade request
9196

examples/chain_client_examples/12_ExchangeMsgBatchCreateDerivativeLimitOrders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ async def main() -> None:
4848
fee_recipient=fee_recipient,
4949
price=41027,
5050
quantity=0.01,
51+
is_buy=True,
5152
leverage=0.7,
52-
is_buy=True
5353
),
5454
composer.DerivativeOrder(
5555
market_id=market_id,
5656
subaccount_id=subaccount_id,
5757
fee_recipient=fee_recipient,
5858
price=62140,
5959
quantity=0.01,
60-
leverage=1.4,
61-
is_buy=False
60+
is_buy=False,
61+
is_reduce_only=True
6262
),
6363
]
6464

examples/chain_client_examples/6_ExchangeMsgCreateDerivativeLimitOrder.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ async def main() -> None:
4848
market_id=market_id,
4949
subaccount_id=subaccount_id,
5050
fee_recipient=fee_recipient,
51-
price=44054.48,
52-
quantity=0.01,
53-
leverage=0.7,
54-
is_buy=True
51+
price=50000,
52+
quantity=0.1,
53+
is_buy=False,
54+
leverage=1,
55+
is_reduce_only=False
5556
)
5657

5758
# build sim tx
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2021 Injective Labs
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Injective Exchange API client for Python. Example only."""
15+
16+
import asyncio
17+
import logging
18+
19+
from pyinjective.client import Client
20+
from pyinjective.constant import Network
21+
22+
23+
async def main() -> None:
24+
network = Network.testnet()
25+
client = Client(network, insecure=True)
26+
account_address = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
27+
portfolio = client.get_portfolio(account_address=account_address)
28+
print(portfolio)
29+
30+
if __name__ == '__main__':
31+
logging.basicConfig(level=logging.INFO)
32+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 Injective Labs
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Injective Exchange API client for Python. Example only."""
15+
16+
import asyncio
17+
import logging
18+
19+
from pyinjective.client import Client
20+
from pyinjective.constant import Network
21+
22+
async def main() -> None:
23+
network = Network.testnet()
24+
client = Client(network, insecure=True)
25+
bid_round = 135
26+
auction = client.get_auction(bid_round=bid_round)
27+
print(auction)
28+
29+
if __name__ == '__main__':
30+
logging.basicConfig(level=logging.INFO)
31+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2021 Injective Labs
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Injective Exchange API client for Python. Example only."""
15+
16+
import asyncio
17+
import logging
18+
19+
from pyinjective.client import Client
20+
from pyinjective.constant import Network
21+
22+
async def main() -> None:
23+
network = Network.testnet()
24+
client = Client(network, insecure=True)
25+
auctions = client.get_auctions()
26+
print(auctions)
27+
28+
if __name__ == '__main__':
29+
logging.basicConfig(level=logging.INFO)
30+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 Injective Labs
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Injective Exchange API client for Python. Example only."""
15+
16+
import asyncio
17+
import logging
18+
19+
from pyinjective.client import Client
20+
from pyinjective.constant import Network
21+
22+
async def main() -> None:
23+
network = Network.testnet()
24+
client = Client(network, insecure=True)
25+
bids = client.stream_bids()
26+
for bid in bids:
27+
print(bid)
28+
29+
if __name__ == '__main__':
30+
logging.basicConfig(level=logging.INFO)
31+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 Injective Labs
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Injective Exchange API client for Python. Example only."""
15+
16+
import asyncio
17+
import logging
18+
19+
from pyinjective.client import Client
20+
from pyinjective.constant import Network
21+
22+
async def main() -> None:
23+
network = Network.testnet()
24+
client = Client(network, insecure=True)
25+
tx_hash = "0x298c3a789bb53b5978f8140fcfe9ec8a4447211b95618d8b108fcf521625fb1a"
26+
account = client.get_tx_by_hash(tx_hash=tx_hash)
27+
print(account)
28+
29+
if __name__ == '__main__':
30+
logging.basicConfig(level=logging.INFO)
31+
asyncio.get_event_loop().run_until_complete(main())

pyinjective/async_client.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
service_pb2_grpc as tx_service_grpc,
2222
service_pb2 as tx_service,
2323
)
24+
2425
from .proto.exchange import (
2526
injective_accounts_rpc_pb2 as exchange_accounts_rpc_pb,
2627
injective_accounts_rpc_pb2_grpc as exchange_accounts_rpc_grpc,
@@ -33,7 +34,11 @@
3334
injective_derivative_exchange_rpc_pb2 as derivative_exchange_rpc_pb,
3435
injective_derivative_exchange_rpc_pb2_grpc as derivative_exchange_rpc_grpc,
3536
injective_meta_rpc_pb2 as exchange_meta_rpc_pb,
36-
injective_meta_rpc_pb2_grpc as exchange_meta_rpc_grpc
37+
injective_meta_rpc_pb2_grpc as exchange_meta_rpc_grpc,
38+
injective_explorer_rpc_pb2 as explorer_rpc_pb,
39+
injective_explorer_rpc_pb2_grpc as explorer_rpc_grpc,
40+
injective_auction_rpc_pb2 as auction_rpc_pb,
41+
injective_auction_rpc_pb2_grpc as auction_rpc_grpc
3742
)
3843

3944
from .constant import Network
@@ -73,6 +78,8 @@ def __init__(
7378
self.stubInsurance = insurance_rpc_grpc.InjectiveInsuranceRPCStub(self.exchange_channel)
7479
self.stubSpotExchange = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(self.exchange_channel)
7580
self.stubDerivativeExchange = derivative_exchange_rpc_grpc.InjectiveDerivativeExchangeRPCStub(self.exchange_channel)
81+
self.stubExplorer = explorer_rpc_grpc.InjectiveExplorerRPCStub(self.exchange_channel)
82+
self.stubAuction = auction_rpc_grpc.InjectiveAuctionRPCStub(self.exchange_channel)
7683

7784
# default client methods
7885
async def get_latest_block(self) -> tendermint_query.GetLatestBlockResponse:
@@ -135,6 +142,21 @@ async def get_chain_id(self) -> str:
135142

136143
# Injective Exchange client methods
137144

145+
# Auction RPC
146+
147+
async def get_auction(self, bid_round: int):
148+
req = auction_rpc_pb.AuctionRequest(round=bid_round)
149+
return await self.stubAuction.AuctionEndpoint(req)
150+
151+
async def get_auctions(self):
152+
req = auction_rpc_pb.AuctionsRequest()
153+
return await self.stubAuction.Auctions(req)
154+
155+
async def stream_bids(self):
156+
req = auction_rpc_pb.StreamBidsRequest()
157+
return await self.stubAuction.StreamBids(req)
158+
159+
138160
# Meta RPC
139161

140162
async def ping(self):
@@ -155,6 +177,12 @@ async def stream_keepalive(self):
155177
req = exchange_meta_rpc_pb.StreamKeepaliveRequest()
156178
return self.stubMeta.StreamKeepalive(req)
157179

180+
# Explorer RPC
181+
182+
async def get_tx_by_hash(self, tx_hash: str):
183+
req = explorer_rpc_pb.GetTxByTxHashRequest(hash=tx_hash)
184+
return await self.stubExplorer.GetTxByTxHash(req)
185+
158186
#AccountsRPC
159187

160188
async def stream_subaccount_balance(self, subaccount_id: str):
@@ -192,6 +220,10 @@ async def get_order_states(
192220
)
193221
return await self.stubExchangeAccount.OrderStates(req)
194222

223+
async def get_portfolio(self, account_address: str):
224+
req = exchange_accounts_rpc_pb.PortfolioRequest(account_address=account_address)
225+
return await self.stubExchangeAccount.Portfolio(req)
226+
195227

196228
# OracleRPC
197229

@@ -218,6 +250,7 @@ async def get_redemptions(self, redeemer: str = '', redemption_denom: str = '',
218250
req = insurance_rpc_pb.RedemptionsRequest(redeemer=redeemer, redemption_denom=redemption_denom, status=status)
219251
return await self.stubInsurance.Redemptions(req)
220252

253+
221254
# SpotRPC
222255

223256
async def get_spot_market(self, market_id: str):
@@ -333,4 +366,4 @@ async def get_derivative_subaccount_trades(self, subaccount_id: str, market_id:
333366

334367
async def get_funding_payments(self, subaccount_id: str, market_id: str = ''):
335368
req = derivative_exchange_rpc_pb.FundingPaymentsRequest(subaccount_id=subaccount_id, market_id=market_id)
336-
return await self.stubDerivativeExchange.FundingPayments(req)
369+
return await self.stubDerivativeExchange.FundingPayments(req)

pyinjective/client.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
injective_derivative_exchange_rpc_pb2_grpc as derivative_exchange_rpc_grpc,
3333
injective_meta_rpc_pb2 as exchange_meta_rpc_pb,
3434
injective_meta_rpc_pb2_grpc as exchange_meta_rpc_grpc,
35+
injective_explorer_rpc_pb2 as explorer_rpc_pb,
36+
injective_explorer_rpc_pb2_grpc as explorer_rpc_grpc,
37+
injective_auction_rpc_pb2 as auction_rpc_pb,
38+
injective_auction_rpc_pb2_grpc as auction_rpc_grpc
3539
)
3640

3741
from .constant import Network
@@ -82,6 +86,8 @@ def __init__(
8286
exchange_channel
8387
)
8488
)
89+
self.stubExplorer = explorer_rpc_grpc.InjectiveExplorerRPCStub(exchange_channel)
90+
self.stubAuction = auction_rpc_grpc.InjectiveAuctionRPCStub(exchange_channel)
8591

8692
# default client methods
8793
def get_latest_block(self) -> tendermint_query.GetLatestBlockResponse:
@@ -158,6 +164,20 @@ def get_chain_id(self) -> str:
158164

159165
# Injective Exchange client methods
160166

167+
# Auction RPC
168+
169+
def get_auction(self, bid_round: int):
170+
req = auction_rpc_pb.AuctionRequest(round=bid_round)
171+
return self.stubAuction.AuctionEndpoint(req)
172+
173+
def get_auctions(self):
174+
req = auction_rpc_pb.AuctionsRequest()
175+
return self.stubAuction.Auctions(req)
176+
177+
def stream_bids(self):
178+
req = auction_rpc_pb.StreamBidsRequest()
179+
return self.stubAuction.StreamBids(req)
180+
161181
# Meta RPC
162182

163183
def ping(self):
@@ -178,6 +198,12 @@ def stream_keepalive(self):
178198
req = exchange_meta_rpc_pb.StreamKeepaliveRequest()
179199
return self.stubMeta.StreamKeepalive(req)
180200

201+
# Explorer RPC
202+
203+
def get_tx_by_hash(self, tx_hash: str):
204+
req = explorer_rpc_pb.GetTxByTxHashRequest(hash=tx_hash)
205+
return self.stubExplorer.GetTxByTxHash(req)
206+
181207
# AccountsRPC
182208

183209
def stream_subaccount_balance(self, subaccount_id: str):
@@ -233,6 +259,10 @@ def get_order_states(
233259
)
234260
return self.stubExchangeAccount.OrderStates(req)
235261

262+
def get_portfolio(self, account_address: str):
263+
req = exchange_accounts_rpc_pb.PortfolioRequest(account_address=account_address)
264+
return self.stubExchangeAccount.Portfolio(req)
265+
236266
# OracleRPC
237267

238268
def stream_oracle_prices(
@@ -276,7 +306,7 @@ def get_redemptions(
276306
)
277307
return self.stubInsurance.Redemptions(req)
278308

279-
# SpotRPC
309+
# SpotRPC
280310

281311
def get_spot_market(self, market_id: str):
282312
req = spot_exchange_rpc_pb.MarketRequest(market_id=market_id)
@@ -478,4 +508,4 @@ def get_funding_payments(self, subaccount_id: str, market_id: str = ""):
478508
req = derivative_exchange_rpc_pb.FundingPaymentsRequest(
479509
subaccount_id=subaccount_id, market_id=market_id
480510
)
481-
return self.stubDerivativeExchange.FundingPayments(req)
511+
return self.stubDerivativeExchange.FundingPayments(req)

0 commit comments

Comments
 (0)