Skip to content

Commit f001b54

Browse files
committed
add spot_exchange_rpc examples
1 parent b88071a commit f001b54

11 files changed

+489
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import grpc
19+
20+
import injective.exchange_api.injective_spot_exchange_rpc_pb2 as spot_exchange_rpc_pb
21+
import injective.exchange_api.injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc
22+
23+
async def main() -> None:
24+
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
25+
spot_exchange_rpc = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(channel)
26+
27+
mkt_id = "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"
28+
subacc_id = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000"
29+
30+
ordresp = await spot_exchange_rpc.SubaccountOrdersList(spot_exchange_rpc_pb.SubaccountOrdersListRequest(subaccount_id=subacc_id, market_id=mkt_id))
31+
print("\n-- Subaccount Orders Update:\n", ordresp)
32+
33+
if __name__ == '__main__':
34+
logging.basicConfig(level=logging.INFO)
35+
asyncio.get_event_loop().run_until_complete(main())
36+
37+
38+
39+
40+
41+
42+
43+
44+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
import grpc
19+
20+
import injective.exchange_api.injective_spot_exchange_rpc_pb2 as spot_exchange_rpc_pb
21+
import injective.exchange_api.injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc
22+
23+
async def main() -> None:
24+
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
25+
spot_exchange_rpc = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(channel)
26+
27+
mkt_id = "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"
28+
subacc_id = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000"
29+
30+
traderesp = await spot_exchange_rpc.SubaccountTradesList(spot_exchange_rpc_pb.SubaccountTradesListRequest(subaccount_id=subacc_id, market_id=mkt_id))
31+
print("\n-- Subaccount Trades Update:\n", traderesp)
32+
33+
34+
if __name__ == '__main__':
35+
logging.basicConfig(level=logging.INFO)
36+
asyncio.get_event_loop().run_until_complete(main())
37+
38+
39+
40+
41+
42+
43+
44+
45+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import grpc
19+
20+
import injective.exchange_api.injective_spot_exchange_rpc_pb2 as spot_exchange_rpc_pb
21+
import injective.exchange_api.injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc
22+
23+
async def main() -> None:
24+
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
25+
spot_exchange_rpc = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(channel)
26+
27+
mkt_id = "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"
28+
29+
mresp = await spot_exchange_rpc.Market(spot_exchange_rpc_pb.MarketRequest(market_id=mkt_id))
30+
print("\n-- Market Update:\n", mresp)
31+
32+
33+
if __name__ == '__main__':
34+
logging.basicConfig(level=logging.INFO)
35+
asyncio.get_event_loop().run_until_complete(main())
36+
37+
38+
39+
40+
41+
42+
43+
44+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import grpc
19+
20+
import injective.exchange_api.injective_spot_exchange_rpc_pb2 as spot_exchange_rpc_pb
21+
import injective.exchange_api.injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc
22+
23+
async def main() -> None:
24+
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
25+
spot_exchange_rpc = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(channel)
26+
27+
status = "active"
28+
29+
mresp = await spot_exchange_rpc.Markets(spot_exchange_rpc_pb.MarketsRequest(market_status=status))
30+
print("\n-- Markets Update:\n", mresp)
31+
32+
33+
if __name__ == '__main__':
34+
logging.basicConfig(level=logging.INFO)
35+
asyncio.get_event_loop().run_until_complete(main())
36+
37+
38+
39+
40+
41+
42+
43+
44+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
import grpc
19+
20+
import injective.exchange_api.injective_spot_exchange_rpc_pb2 as spot_exchange_rpc_pb
21+
import injective.exchange_api.injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc
22+
23+
async def main() -> None:
24+
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
25+
spot_exchange_rpc = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(channel)
26+
27+
stream_req = spot_exchange_rpc_pb.StreamMarketsRequest()
28+
stream_resp = spot_exchange_rpc.StreamMarkets(stream_req)
29+
async for market in stream_resp:
30+
print("\n-- Market Update:\n", market)
31+
32+
if __name__ == '__main__':
33+
logging.basicConfig(level=logging.INFO)
34+
asyncio.get_event_loop().run_until_complete(main())
35+
36+
37+
38+
39+
40+
41+
42+
43+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import grpc
19+
20+
import injective.exchange_api.injective_spot_exchange_rpc_pb2 as spot_exchange_rpc_pb
21+
import injective.exchange_api.injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc
22+
23+
async def main() -> None:
24+
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
25+
spot_exchange_rpc = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(channel)
26+
27+
mkt_id = "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"
28+
29+
orderbookresp = await spot_exchange_rpc.Orderbook(spot_exchange_rpc_pb.OrderbookRequest(market_id=mkt_id))
30+
print("\n-- Orderbook Update:\n", orderbookresp)
31+
32+
33+
if __name__ == '__main__':
34+
logging.basicConfig(level=logging.INFO)
35+
asyncio.get_event_loop().run_until_complete(main())
36+
37+
38+
39+
40+
41+
42+
43+
44+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
import grpc
19+
20+
import injective.exchange_api.injective_spot_exchange_rpc_pb2 as spot_exchange_rpc_pb
21+
import injective.exchange_api.injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc
22+
23+
async def main() -> None:
24+
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
25+
spot_exchange_rpc = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(channel)
26+
27+
mkt_id = "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"
28+
29+
ordresp = await spot_exchange_rpc.Orders(spot_exchange_rpc_pb.OrdersRequest(market_id=mkt_id))
30+
print("\n-- Orders Update:\n", ordresp)
31+
32+
if __name__ == '__main__':
33+
logging.basicConfig(level=logging.INFO)
34+
asyncio.get_event_loop().run_until_complete(main())
35+
36+
37+
38+
39+
40+
41+
42+
43+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import grpc
19+
20+
import injective.exchange_api.injective_spot_exchange_rpc_pb2 as spot_exchange_rpc_pb
21+
import injective.exchange_api.injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc
22+
23+
async def main() -> None:
24+
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
25+
spot_exchange_rpc = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(channel)
26+
27+
mkt_id = "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"
28+
execution_s = "maker"
29+
30+
traderesp = await spot_exchange_rpc.Trades(spot_exchange_rpc_pb.TradesRequest(market_id=mkt_id, execution_side=execution_s))
31+
print("\n-- Trades Update:\n", traderesp)
32+
33+
if __name__ == '__main__':
34+
logging.basicConfig(level=logging.INFO)
35+
asyncio.get_event_loop().run_until_complete(main())
36+
37+
38+
39+
40+
41+
42+
43+
44+

0 commit comments

Comments
 (0)