Skip to content

Commit

Permalink
Merge pull request #145 from InjectiveLabs/f/add_event_order_fail
Browse files Browse the repository at this point in the history
feat: add stream event order fail
  • Loading branch information
achilleas-kal authored Sep 9, 2022
2 parents 717cead + 175d23f commit 675d71e
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@
# limitations under the License.
"""Injective Exchange API client for Python. Example only."""

import sys
sys.path.insert(0, '/Users/nam/desktop/injective/sdk-python/')

import asyncio
import logging
import json
import websockets
import base64

from pyinjective.async_client import AsyncClient
from pyinjective.constant import Network

async def main() -> None:
network = Network.mainnet()
client = AsyncClient(network, insecure=False)

event_filter = "tm.event='Tx' AND message.sender='inj1rwv4zn3jptsqs7l8lpa3uvzhs57y8duemete9e' AND message.action='/injective.exchange.v1beta1.MsgBatchUpdateOrders'"
event_filter = "tm.event='Tx' AND message.sender='inj1rwv4zn3jptsqs7l8lpa3uvzhs57y8duemete9e' AND message.action='/injective.exchange.v1beta1.MsgBatchUpdateOrders' AND injective.exchange.v1beta1.EventOrderFail.flags EXISTS"
query = json.dumps({
"jsonrpc": "2.0",
"method": "subscribe",
Expand All @@ -41,9 +36,21 @@ async def main() -> None:
async with websockets.connect(network.tm_websocket_endpoint) as ws:
await ws.send(query)
while True:
events = await ws.recv()
print(events)
await asyncio.sleep(1)
res = await ws.recv()
res = json.loads(res)
result = res["result"]
if result == {}:
continue

failed_order_hashes = result["events"]["injective.exchange.v1beta1.EventOrderFail.hashes"]
failed_order_codes = json.loads(result["events"]["injective.exchange.v1beta1.EventOrderFail.flags"][0])

dict = {}
for i, order_hash in enumerate(failed_order_hashes):
hash = "0x" + base64.b64decode(order_hash).hex()
dict[hash] = failed_order_codes[i]

print(dict)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
Expand Down

0 comments on commit 675d71e

Please sign in to comment.