Skip to main content

Asynchronous Crypt Trading Chain: A toolkit for building cryptocurrency trading bots with asynchrnous loosely-couplled modules.

Project description

actchain: Asynchronous Crypto Trading Chain

pytest

Installation

pip install actchain

Requires Python 3.11 or higher.

Usage

# An example of using actchain to compute the weighted mid price of the order book

from typing import AsyncGenerator

import asyncio
import actchain
import ccxt.pro as ccxt_pro


async def loop_binance_orderbook() -> AsyncGenerator[dict, None]:
    exchange = ccxt_pro.binance()
    while True:
        yield await exchange.watch_order_book("BTC/USDT")


async def order_book_feature_computation(event: actchain.Event) -> dict:
    best_ask = event.data["asks"][0]
    best_bid = event.data["bids"][0]

    w_mid = (best_ask[0] * best_ask[1] + best_bid[0] * best_bid[1]) / (
        best_ask[1] + best_bid[1]
    )
    mid = (event.data["asks"][0][0] + event.data["bids"][0][0]) / 2
    return {"w_mid": w_mid, "mid": mid}


async def main() -> None:
    flow = (
        actchain.Flow("main")
        .add(actchain.Loop(loop_binance_orderbook).as_chain())
        .add(actchain.Function(order_book_feature_computation).as_chain())
        .add(actchain.Function(lambda event: print(event.data)).as_chain())
    )

    await flow.run()


if __name__ == "__main__":
    asyncio.run(main())

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

actchain-0.1.2.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

actchain-0.1.2-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file actchain-0.1.2.tar.gz.

File metadata

  • Download URL: actchain-0.1.2.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.0 Darwin/23.0.0

File hashes

Hashes for actchain-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ea65504914a6f66d55654af3f727e9489ced5c1f5e7a71e17b4e570e22f56e71
MD5 34686c9a84b708124849c45ab328d12e
BLAKE2b-256 f2360c313dda898e1fc7b61795d47bdaf83b18a901c1623798b06ced60b3b100

See more details on using hashes here.

File details

Details for the file actchain-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: actchain-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.0 Darwin/23.0.0

File hashes

Hashes for actchain-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d078c3d62731409ecd0b4f8897e1814c1140442eace6521af74d177668f67da5
MD5 5fdfed8a89a504e33133c37575e7bd2b
BLAKE2b-256 26f44f81d6d2aadef2f6667aa441263b68a814301b02b173b9737f47613bd043

See more details on using hashes here.

Supported by

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