Skip to main content

3commas websocket stream assist

Project description

three-commas-websocket-assist

GNU General Public License v3.0

pip install three-commas-websocket-assist

Import

from three-commas-websocket-assist import ThreeCommasWebsocketHandler

Supports seperate threading. pass seperate_thread=True to start_listener() to run it on a seperate thread (i.e. when running along side flask or mutliple streams)

1. Setting up the listener

Pass 3commas api key/secret and the channel you desire to ThreeCommasWebsocketHandler:

st = ThreeCommasWebsocketHandler(
    api_key=API_KEY,
    api_secret=API_SECRET,
    channel="DealsChannel",
)
st.start_listener()

ThreeCommasWebsocketHandler automatically generates the stream identifier and uses that for the stream

2. Handle event

Pass a custom event handler to the ThreeCommasWebsocketHandler to handle any event based on your deal channel: Event handler is Callable[[Dict], None]

st = ThreeCommasWebsocketHandler(
    api_key=API_KEY,
    api_secret=API_SECRET,
    channel="DealsChannel",
    external_event_handler=sample_event_handler
)
st.start_listener()

Sample event handler:

def sample_event_handler(data:Dict) -> None:
    """
    Sample Event Handler for websocket
    """
    _LOGGER.debug("Bot_id: %s", data['bot_id'])

    # Do something with the data here

3. Run it on seperate thread:

st = ThreeCommasWebsocketHandler(
    api_key=API_KEY,
    api_secret=API_SECRET,
    channel="DealsChannel",
    external_event_handler=sample_event_handler
)
st.start_listener(seperate_thread=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

three-commas-websocket-assist-0.2.1.tar.gz (16.6 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page