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.1.tar.gz (25.3 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.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: actchain-0.1.1.tar.gz
  • Upload date:
  • Size: 25.3 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.1.tar.gz
Algorithm Hash digest
SHA256 2ae5b1b8a17c67f7839480244aa9ac6040684efc1adaa7422b32793de660aa4e
MD5 22fc3978797df6a18b61e08041a2d537
BLAKE2b-256 4d439ea0514acd8460e7d82cda8478db7a656fe69c9c80cd9ed51aa2d7e0ccfc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: actchain-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c65dd6130ebeae6f28fbc02c08d88aa1096189e332a7d291b7d1f96b35ff3034
MD5 d5926a25c06c89ba61f29173e2ec67db
BLAKE2b-256 44711af5edf43a9ea616b6bf9f29ab1390a186f9cb57bf67b87569927427df38

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