candlestick-chart


Namecandlestick-chart JSON
Version 3.1.0 PyPI version JSON
download
home_pageNone
SummaryDraw candlesticks charts right into your terminal, using Python!
upload_time2024-11-02 16:54:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2022-2024, Mickaël 'Tiger-222' Schoentgen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords candle candlestick chart cli console crypto options stock stock-market terminal trading
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python Candlesticks Chart

📈 Draw candlesticks charts right into your terminal, using Python!

![Preview](examples/screenshot.png)

This is a portage from the great [cli-candlestick-chart](https://github.com/Julien-R44/cli-candlestick-chart) (developed by [Julien-R44](https://github.com/Julien-R44), written in Rust).
You are looking at the Python 3.10+ version.

Note: not tested on macOS, nor Windows (it will likely fail to render colors).

**Table of contents**:
- [Python Candlesticks Chart](#python-candlesticks-chart)
  - [Features](#features)
  - [Installation](#installation)
  - [Demonstration](#demonstration)
- [Binary Usage](#binary-usage)
- [Examples](#examples)
  - [API](#api)
  - [Binary](#binary)
    - [Read CSV from file](#read-csv-from-file)
    - [Read JSON from file](#read-json-from-file)
    - [Read from stdin](#read-from-stdin)
  - [Developers](#developers)

## Features

- Auto-fit to terminal size
- Practical formatting for big, and tiny, numbers
- Integration with [Rich](https://github.com/Textualize/rich)
- Simple, yet customizable, API
- Exact same API as the [Rust version](https://github.com/Julien-R44/cli-candlestick-chart), plus some [sugar](#demonstration)
- Simple installation, no external dependencies

## Installation

```bash
$ python -m pip install -U candlestick-chart
```

## Demonstration

```python
from candlestick_chart import Candle, Chart


# Add some candles
candles = [
    Candle(open=133.520004, close=133.610001, high=126.760002, low=129.410004),
    Candle(open=128.889999, close=131.740005, high=128.429993, low=131.009995),
    Candle(open=127.720001, close=131.050003, high=126.379997, low=126.599998),
    Candle(open=128.360001, close=131.630005, high=127.860001, low=130.919998),
    Candle(open=132.429993, close=132.630005, high=130.229996, low=132.050003),
]

# Create and display the chart
# Optional keyword arguments: title, width, height
chart = Chart(candles, title="Optional title")

# Set the chart title
chart.set_name("BTC/USDT")

# Set customs colors
chart.set_bear_color(1, 205, 254)
chart.set_bull_color(255, 107, 153)
chart.set_vol_bull_color(1, 205, 254)
chart.set_vol_bear_color(255, 107, 153)

# Set custom labels (empty string => label not displayed)
chart.set_label("highest", "ATH")
chart.set_label("lowest", "ATL")
chart.set_label("average", "")
chart.set_label("volume", "")

# Volume pane settings
chart.set_volume_pane_height(6)
chart.set_volume_pane_enabled(False)

# And, it is also responsive!
new_width = 200
new_height = 150
chart.update_size(new_width, new_height)

# By the way, did you know that you can add more candles in real-time?
chart.update_candles(candles[:3])
# Or completely replace current candles
chart.update_candles(candles[:3], reset=True)

# Set a custom color at price 52,348.63
chart.set_highlight(fnum(52_348.63), "red")
chart.set_highlight(fnum(52_348.63), (255, 0, 0))
chart.set_highlight(fnum(52_348.63), "91m")
chart.set_highlight(fnum(52_348.63), "91;47m")

chart.draw()
```

# Binary Usage

When installing the library, an executable is made available (`candlestick-chart`):

```bash
candlestick-chart --help

options:
  -h, --help            show this help message and exit
  -m {stdin,csv-file,json-file}, --mode {stdin,csv-file,json-file}
                        Select the method for retrieving the candles.
  -f FILE, --file FILE  [MODE:*-file] File to read candles from.
  --chart-name CHART_NAME
                        Sets the chart name.
  --bear-color BEAR_COLOR
                        Sets the descending candles color in hexadecimal.
  --bull-color BULL_COLOR
                        Sets the ascending candles color in hexadecimal.
  --version             show program's version number and exit
```

When requesting the JSON or stdin mode, the library expects a JSON with the following format: 

```json
[
    {
        "open": 28994.009766,
        "high": 29600.626953,
        "low": 28803.585938,
        "close": 29374.152344
    },
    ...
]
```

For all requests, here are supported fields:

```python
"open": float  # mandatory
"close": float  # mandatory
"high": float  # mandatory
"low": float  # mandatory
"volume": float
"timestamp": float
```

# Examples

## API 

- [Basic example with CSV parsing](examples/basic_from_csv_file.py): run with `$ python examples/basic_from_csv_file.py`
- [Basic example with JSON parsing](examples/basic_from_json_file.py): run with `$ python examples/basic_from_json_file.py`
- [Basic example with stdin parsing](examples/basic_from_stdin.sh): run with `$ ./examples/basic_from_stdin.sh`
- [Fetch candles from Binance](examples/fetch_from_binance.py): run with `$ python examples/fetch_from_binance.py`
- [Integration with Rich](examples/integrate_with_rich.py): run with `$ python examples/integrate_with_rich.py`
- [Using a custom chart renderer class](examples/custom_renderer_class.py): run with `$ python examples/custom_renderer_class.py`

## Binary 

### Read CSV from file

```bash
candlestick-chart \
    --mode=csv-file \
    --file='./examples/BTC-USD.csv' \
    --chart-name='My BTC Chart' \
    --bear-color='#b967ff' \
    --bull-color='ff6b99'
```
### Read JSON from file

```bash
candlestick-chart \
    --mode=json-file \
    --file='./examples/BTC-chart.json' \
    --chart-name='My BTC Chart' \
    --bear-color='#b967ff' \
    --bull-color='ff6b99'
```

### Read from stdin

```bash
echo '[
  {
    "open": 28994.009766,
    "high": 29600.626953,
    "low": 28803.585938,
    "close": 29374.152344
  },
  {
    "open": 29376.455078,
    "high": 33155.117188,
    "low": 29091.181641,
    "close": 32127.267578
  }
]' | candlestick-chart \
    --mode=stdin \
    --chart-name='My BTC Chart' \
    --bear-color='#b967ff' \
    --bull-color='ff6b99'
```

## Developers

Setup:

```shell
python -m venv venv
. venv/bin/activate
python -m pip install -U pip
```

Install:

```shell
python -m pip install -e '.[test]'
```

Test:

```shell
python -m pytest
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "candlestick-chart",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Micka\u00ebl Schoentgen <contact@tiger-222.fr>",
    "keywords": "candle, candlestick, chart, cli, console, crypto, options, stock, stock-market, terminal, trading",
    "author": null,
    "author_email": "Micka\u00ebl Schoentgen <contact@tiger-222.fr>",
    "download_url": "https://files.pythonhosted.org/packages/26/de/73ec825191e4dbca8867cf752fb18103abe7fbdfc4b3730dd77dff492bcf/candlestick_chart-3.1.0.tar.gz",
    "platform": null,
    "description": "# Python Candlesticks Chart\n\n\ud83d\udcc8 Draw candlesticks charts right into your terminal, using Python!\n\n![Preview](examples/screenshot.png)\n\nThis is a portage from the great [cli-candlestick-chart](https://github.com/Julien-R44/cli-candlestick-chart) (developed by [Julien-R44](https://github.com/Julien-R44), written in Rust).\nYou are looking at the Python 3.10+ version.\n\nNote: not tested on macOS, nor Windows (it will likely fail to render colors).\n\n**Table of contents**:\n- [Python Candlesticks Chart](#python-candlesticks-chart)\n  - [Features](#features)\n  - [Installation](#installation)\n  - [Demonstration](#demonstration)\n- [Binary Usage](#binary-usage)\n- [Examples](#examples)\n  - [API](#api)\n  - [Binary](#binary)\n    - [Read CSV from file](#read-csv-from-file)\n    - [Read JSON from file](#read-json-from-file)\n    - [Read from stdin](#read-from-stdin)\n  - [Developers](#developers)\n\n## Features\n\n- Auto-fit to terminal size\n- Practical formatting for big, and tiny, numbers\n- Integration with [Rich](https://github.com/Textualize/rich)\n- Simple, yet customizable, API\n- Exact same API as the [Rust version](https://github.com/Julien-R44/cli-candlestick-chart), plus some [sugar](#demonstration)\n- Simple installation, no external dependencies\n\n## Installation\n\n```bash\n$ python -m pip install -U candlestick-chart\n```\n\n## Demonstration\n\n```python\nfrom candlestick_chart import Candle, Chart\n\n\n# Add some candles\ncandles = [\n    Candle(open=133.520004, close=133.610001, high=126.760002, low=129.410004),\n    Candle(open=128.889999, close=131.740005, high=128.429993, low=131.009995),\n    Candle(open=127.720001, close=131.050003, high=126.379997, low=126.599998),\n    Candle(open=128.360001, close=131.630005, high=127.860001, low=130.919998),\n    Candle(open=132.429993, close=132.630005, high=130.229996, low=132.050003),\n]\n\n# Create and display the chart\n# Optional keyword arguments: title, width, height\nchart = Chart(candles, title=\"Optional title\")\n\n# Set the chart title\nchart.set_name(\"BTC/USDT\")\n\n# Set customs colors\nchart.set_bear_color(1, 205, 254)\nchart.set_bull_color(255, 107, 153)\nchart.set_vol_bull_color(1, 205, 254)\nchart.set_vol_bear_color(255, 107, 153)\n\n# Set custom labels (empty string => label not displayed)\nchart.set_label(\"highest\", \"ATH\")\nchart.set_label(\"lowest\", \"ATL\")\nchart.set_label(\"average\", \"\")\nchart.set_label(\"volume\", \"\")\n\n# Volume pane settings\nchart.set_volume_pane_height(6)\nchart.set_volume_pane_enabled(False)\n\n# And, it is also responsive!\nnew_width = 200\nnew_height = 150\nchart.update_size(new_width, new_height)\n\n# By the way, did you know that you can add more candles in real-time?\nchart.update_candles(candles[:3])\n# Or completely replace current candles\nchart.update_candles(candles[:3], reset=True)\n\n# Set a custom color at price 52,348.63\nchart.set_highlight(fnum(52_348.63), \"red\")\nchart.set_highlight(fnum(52_348.63), (255, 0, 0))\nchart.set_highlight(fnum(52_348.63), \"91m\")\nchart.set_highlight(fnum(52_348.63), \"91;47m\")\n\nchart.draw()\n```\n\n# Binary Usage\n\nWhen installing the library, an executable is made available (`candlestick-chart`):\n\n```bash\ncandlestick-chart --help\n\noptions:\n  -h, --help            show this help message and exit\n  -m {stdin,csv-file,json-file}, --mode {stdin,csv-file,json-file}\n                        Select the method for retrieving the candles.\n  -f FILE, --file FILE  [MODE:*-file] File to read candles from.\n  --chart-name CHART_NAME\n                        Sets the chart name.\n  --bear-color BEAR_COLOR\n                        Sets the descending candles color in hexadecimal.\n  --bull-color BULL_COLOR\n                        Sets the ascending candles color in hexadecimal.\n  --version             show program's version number and exit\n```\n\nWhen requesting the JSON or stdin mode, the library expects a JSON with the following format: \n\n```json\n[\n    {\n        \"open\": 28994.009766,\n        \"high\": 29600.626953,\n        \"low\": 28803.585938,\n        \"close\": 29374.152344\n    },\n    ...\n]\n```\n\nFor all requests, here are supported fields:\n\n```python\n\"open\": float  # mandatory\n\"close\": float  # mandatory\n\"high\": float  # mandatory\n\"low\": float  # mandatory\n\"volume\": float\n\"timestamp\": float\n```\n\n# Examples\n\n## API \n\n- [Basic example with CSV parsing](examples/basic_from_csv_file.py): run with `$ python examples/basic_from_csv_file.py`\n- [Basic example with JSON parsing](examples/basic_from_json_file.py): run with `$ python examples/basic_from_json_file.py`\n- [Basic example with stdin parsing](examples/basic_from_stdin.sh): run with `$ ./examples/basic_from_stdin.sh`\n- [Fetch candles from Binance](examples/fetch_from_binance.py): run with `$ python examples/fetch_from_binance.py`\n- [Integration with Rich](examples/integrate_with_rich.py): run with `$ python examples/integrate_with_rich.py`\n- [Using a custom chart renderer class](examples/custom_renderer_class.py): run with `$ python examples/custom_renderer_class.py`\n\n## Binary \n\n### Read CSV from file\n\n```bash\ncandlestick-chart \\\n    --mode=csv-file \\\n    --file='./examples/BTC-USD.csv' \\\n    --chart-name='My BTC Chart' \\\n    --bear-color='#b967ff' \\\n    --bull-color='ff6b99'\n```\n### Read JSON from file\n\n```bash\ncandlestick-chart \\\n    --mode=json-file \\\n    --file='./examples/BTC-chart.json' \\\n    --chart-name='My BTC Chart' \\\n    --bear-color='#b967ff' \\\n    --bull-color='ff6b99'\n```\n\n### Read from stdin\n\n```bash\necho '[\n  {\n    \"open\": 28994.009766,\n    \"high\": 29600.626953,\n    \"low\": 28803.585938,\n    \"close\": 29374.152344\n  },\n  {\n    \"open\": 29376.455078,\n    \"high\": 33155.117188,\n    \"low\": 29091.181641,\n    \"close\": 32127.267578\n  }\n]' | candlestick-chart \\\n    --mode=stdin \\\n    --chart-name='My BTC Chart' \\\n    --bear-color='#b967ff' \\\n    --bull-color='ff6b99'\n```\n\n## Developers\n\nSetup:\n\n```shell\npython -m venv venv\n. venv/bin/activate\npython -m pip install -U pip\n```\n\nInstall:\n\n```shell\npython -m pip install -e '.[test]'\n```\n\nTest:\n\n```shell\npython -m pytest\n```\n",
    "bugtrack_url": null,
    "license": "MIT License Copyright (c) 2022-2024, Micka\u00ebl 'Tiger-222' Schoentgen  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Draw candlesticks charts right into your terminal, using Python!",
    "version": "3.1.0",
    "project_urls": {
        "Changelog": "https://github.com/BoboTiG/py-candlestick-chart/blob/main/CHANGELOG.md",
        "Homepage": "https://pypi.org/project/py-candlestick-chart",
        "Released Versions": "https://github.com/BoboTiG/py-candlestick-chart/releases",
        "Source": "https://github.com/BoboTiG/py-candlestick-chart",
        "Sponsor": "https://github.com/sponsors/BoboTiG",
        "Tracker": "https://github.com/BoboTiG/py-candlestick-chart/issues"
    },
    "split_keywords": [
        "candle",
        " candlestick",
        " chart",
        " cli",
        " console",
        " crypto",
        " options",
        " stock",
        " stock-market",
        " terminal",
        " trading"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01c7d215d2f328f7f1a6577368d6ef4aff3731d9fc38438c5d08d0e095f7a099",
                "md5": "3398e672527e3d2e30234c8b814d8574",
                "sha256": "7c73336155292bd375fffc91410b00b7ff1cee93de7b6459b753151059aa9583"
            },
            "downloads": -1,
            "filename": "candlestick_chart-3.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3398e672527e3d2e30234c8b814d8574",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 17940,
            "upload_time": "2024-11-02T16:54:11",
            "upload_time_iso_8601": "2024-11-02T16:54:11.603790Z",
            "url": "https://files.pythonhosted.org/packages/01/c7/d215d2f328f7f1a6577368d6ef4aff3731d9fc38438c5d08d0e095f7a099/candlestick_chart-3.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26de73ec825191e4dbca8867cf752fb18103abe7fbdfc4b3730dd77dff492bcf",
                "md5": "d4190f44c53108e29dfc652f72ca7da7",
                "sha256": "0721146baf2511adc404a735ce1111a297dde5b08e542883a89bfcd053e6284d"
            },
            "downloads": -1,
            "filename": "candlestick_chart-3.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d4190f44c53108e29dfc652f72ca7da7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 68209,
            "upload_time": "2024-11-02T16:54:13",
            "upload_time_iso_8601": "2024-11-02T16:54:13.403250Z",
            "url": "https://files.pythonhosted.org/packages/26/de/73ec825191e4dbca8867cf752fb18103abe7fbdfc4b3730dd77dff492bcf/candlestick_chart-3.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-02 16:54:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "BoboTiG",
    "github_project": "py-candlestick-chart",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "candlestick-chart"
}
        
Elapsed time: 0.46896s