Skip to main content

GenAI based Trading Package

Project description

GenTrade

The python GenTrade package provide the core functions and agentic trading workflow to support GenAI based algorithms trading for crypto and stock markets.

It can help algorithms traders smoothly transfering from service API programming to prompt based agentic programming.

  • Install the python package

    pip install gentrade
    

    if you want to try the package from source code you can

    set PYTHONPATH=<root of gentrade>/src/
    
  • Then try:

    • Demos: command line based app to show market OHLCV data
    • Tests: test cases for the API and utilities
    • Apps: the application or microservices based on gentrade.

1. Demo

NOTE: please set environment variable like BINANCE_API_KEY, BINANCE_API_SECRET,
OPENAI_API_KEY before running below demos.

1.1 Use traditional API approach for crypto currency or US stock:

  1. Draw the latest 100 hours btcoin's prices (OHLCV)

    cd demo/crypto-cli
    python run_matplot.py -a btc -t 1h -l 100
    

    Output:

  2. Use SMA (Simple Moving Average) to analyze the ETH's prices

    cd demo/crypto-cli
    python run_sma.py -a eth -t 1d -l 200 -g
    

    Output:

    It also support US stock like applying SMA on TESLA (TSLA)'s price:

    cd demo/stock-us-cli
    python run_multiple.py -a TSLA -t 1d -l 200 -g
    
  3. If want try other strategy like RSI

    cd demo/crypto-cli
    python run_multiple.py -s rsi
    

    NOTE: of course you can try more strategies like macd, bb, wma etc

1.2 Use Agentic LLM approaches:

  1. If want ask LLM to select a strategy via a simple prompt like

    • Prompt: Please get past 400 days price for bitcoin, then different strategy to do back testing, and figure out what strategy is the best according to final portfolio value
    • Prompt: 请获取过去300天的以太坊的价格,并使用不同的策略进行回测,最后选出最佳的策略
    cd demo/agent
    python run_auto_strategy.py
    
  2. If want ask LLM to generate strategy according to your idea and do back test, for example:

    • Prompt: "请获取过去300天的以太坊的价格,并使用简单平均移动策略来进行回测,在这个策略中,请设置慢线为9,请设置快线为26"

2. App Services

2.1 OHLCV Data Service

  • Start Server

    # Pull image
    docker pull registry.cn-hangzhou.aliyuncs.com/kenplusplus/gentrade_data_serv
    
    # Create .env file from .env_template
    
    # Run OHLCV datahub service
    docker run -p 8000:8000 \
        --env-file=.env -v <data folder>:/app/cache \
        registry.cn-hangzhou.aliyuncs.com/kenplusplus/gentrade_data_serv
    
  • Client Test

    # Get all supported markets
    curl -X 'GET' \
      'http://127.0.0.1:8000/markets/?market_type=all' \
      -H 'accept: application/json'
    
    # Get all available assets from a specific market
    curl -X 'GET' \
      'http://127.0.0.1:8000/assets/?market_id=b13a4902-ad9d-11ef-a239-00155d3ba217&start=0&max_count=1000' \
      -H 'accept: application/json'
    
    # Get OHLCV for a specific asset
    curl -X 'GET' \
      'http://127.0.0.1:8000/asset/get_ohlcv?market_id=b13a4902-ad9d-11ef-a239-00155d3ba217&asset=BTC_USDT&timeframe=1m&since=-1&limit=10' \
      -H 'accept: application/json'
    
    # Start OHLCV collector threading in the background
    curl -X 'POST' \
      'http://127.0.0.1:8000/asset/start_collect?market_id=b13a4902-ad9d-11ef-a239-00155d3ba217&asset=DOGE_USDT&timeframe=1h&since=1732809600' \
      -H 'accept: application/json' \
      -d ''
    

The cached data can be found at this directory

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

gentrade-0.0.21.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

gentrade-0.0.21-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file gentrade-0.0.21.tar.gz.

File metadata

  • Download URL: gentrade-0.0.21.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for gentrade-0.0.21.tar.gz
Algorithm Hash digest
SHA256 90e9e550755cf9e5706efc71d5e3cdea8d6af2e7112530855bb864a2cbfd95ca
MD5 03276b90c1ef24836e6fe95e461aa516
BLAKE2b-256 4ce52da0c43ee508e1e22bf7185e912cd5f1c7dae63c53dd2b9f5d97dc6cdb50

See more details on using hashes here.

File details

Details for the file gentrade-0.0.21-py3-none-any.whl.

File metadata

  • Download URL: gentrade-0.0.21-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for gentrade-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 c38cd4553f6577b45a683d192b9744d72a046c6a0cb1c7ea86e1c072510e7c41
MD5 0be4bb40db5e22eef54fb66b1542db78
BLAKE2b-256 f58a89b7dcf27b7fa6832717f2c9eadb4361da34015687777e69b58c78763e5f

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