Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/n3tc4t/python-xrpl-websocket
XRPL Python Websocket Client
https://github.com/n3tc4t/python-xrpl-websocket
python ripple websocket xrp-ledger
Last synced: 3 months ago
JSON representation
XRPL Python Websocket Client
- Host: GitHub
- URL: https://github.com/n3tc4t/python-xrpl-websocket
- Owner: N3TC4T
- License: apache-2.0
- Created: 2019-11-09T23:44:51.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T19:46:54.000Z (over 3 years ago)
- Last Synced: 2024-11-13T14:55:30.713Z (3 months ago)
- Topics: python, ripple, websocket, xrp-ledger
- Language: Python
- Homepage:
- Size: 54.7 KB
- Stars: 10
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
XRPL Websocket
==============.. image:: https://readthedocs.org/projects/xrpl-websocket/badge/?version=latest
:target: https://xrpl-websocket.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status.. image:: https://badge.fury.io/py/xrpl-websocket.svg
:target: https://badge.fury.io/py/xrpl-websocket================
Websocket client for rippled with reconnecting feature, support both python 2 and 3Installation
============Via pip:
.. code-block:: bash
pip install xrpl_websocket
Examples
========Short-lived connection
----------------------
Simple example to send a payload and wait for response.. code:: python
import json
from xrpl_websocket import Client
if __name__ == "__main__":
# create instance
client = Client()# connect to the websocket
client.connect(nowait=False)# send server info command
resp = client.send(command='server_info')print("Server Info:")
print(json.dumps(resp, indent = 4))# close the connection
client.disconnect()More advanced: Custom class
---------------------------
You can also write your own class for the connection, if you want to handle the nitty-gritty details yourself... code:: python
class Example(Client):
def __init__(self):
super(self.__class__, self).__init__(
log_level=logging.ERROR,
server="wss://xrpl.ws"
)# connect to the websocket
self.connect()def on_transaction(self, data):
print(json.dumps(data, indent = 4))def on_ledger(self,data):
print('on_ledger')def on_open(self, connection):
print("Connection is open")print("Subscribe to ledger transactions")
self.subscribe_transactions()def on_close(self):
print("on_close")def subscribe_transactions(self):
self.send({
'command': 'subscribe',
'streams': ['transactions']
})