Introduction

Documentation Status Discord Build Status Code Style: Black

Graphical representation of the stock movement in candlestick form

https://user-images.githubusercontent.com/34255413/113015855-ef66d280-914b-11eb-9bc4-6b524bcfdef2.png

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.

Usage Example

See scripts in the examples directory of this repository.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Documentation

For information on building library documentation, please check out this guide.

Table of Contents

Simple test

Ensure your device works with this simple test.

examples/candlesticks_simpletest.py
 1# SPDX-FileCopyrightText: 2021 Jose David M.
 2#
 3# SPDX-License-Identifier: MIT
 4#############################
 5"""
 6This is a simple example of the use of the class candlestick.
 7"""
 8
 9# import candlesticks_simpletest
10
11import displayio
12import board
13from candlesticks import Candlestick
14
15display = board.DISPLAY
16
17my_candle = Candlestick(
18    100,
19    60,
20    30,
21    80,
22    5,
23    color_green=0x00FF00,
24    color_red=0xFF0000,
25    screen_ref=180,
26)
27
28my_candle2 = Candlestick(
29    120,
30    43,
31    60,
32    80,
33    25,
34    color_green=0x00FF00,
35    color_red=0xFF0000,
36    screen_ref=180,
37)
38
39my_candle3 = Candlestick(
40    140,
41    10,
42    45,
43    65,
44    25,
45    color_green=0x00FF00,
46    color_red=0xFF0000,
47    screen_ref=180,
48)
49
50my_candle4 = Candlestick(
51    160,
52    85,
53    15,
54    85,
55    15,
56    color_green=0x00FF00,
57    color_red=0xFF0000,
58    screen_ref=180,
59)
60my_candle5 = Candlestick(
61    180,
62    15,
63    25,
64    85,
65    30,
66    color_green=0x00FF00,
67    color_red=0xFF0000,
68    screen_ref=180,
69)
70
71
72main_group = displayio.Group()
73main_group.append(my_candle.my_rep)
74main_group.append(my_candle2.my_rep)
75main_group.append(my_candle3.my_rep)
76main_group.append(my_candle4.my_rep)
77main_group.append(my_candle5.my_rep)
78
79display.show(main_group)
80
81while True:
82    pass

candlesticks

Graphical representation of the stock movement in candlestick form

  • Author(s): Jose David

Implementation Notes

class candlesticks.Candlestick(dist_x: int, openp: int, close: int, high: int, low: int, color_green: int = 65280, color_red: int = 16711680, screen_ref: int = 180)

A graphical candlestick representation

Parameters
  • dist_x (int) – number of segments in each bar

  • openp (int) – Stock open price

  • close (int) – Stock close price

  • high (int) – Stock high price

  • low (int) – Stock low price

  • color_green (int) – When stock close price is higher thant the price opening candlestick are representing by a green color. This allows the selection of the color of your choice

  • color_red (int) – When stock close price is lower thant the price opening candlestick are representing by a red color. This allows the selection of the color of your choice

  • screen_ref (int) – Distance in pixels from the left to the screem to locate the candlestick. This allows to present different candlesticks in the same screen

Quickstart: Importing and using Candlestick

Here is one way of importing the Candlestick class, so you can use it as the name my_candle:

from CircuitPython_Candlesticks.candlesticks import Candlestick as Candlestick

Now you can create a plane at pixel position x=100, open price=60 close price=30 high price=80 low price=5 using:

my_candle = Candlestick(100, 60, 30, 80, 5)

Once you set up your display, you can now add my_candle to your display using:

display.show(my_plane) # add the group to the display

If you want to have multiple display elements, you can create a group and then append the plane and the other elements to the group. Then, you can add the full group to the display as in this example:

my_candle = Candlestick(100, 60, 30, 80, 5)
my_group = displayio.Group() # make a group
my_group.append(my_plane) # Add my_plane to the group

#
# Append other display elements to the group
#

display.show(my_group) # add the group to the display

Summary: Cartesian Features and input variables

The Candlestick class has some options for controlling its position, appearance, through a collection of input variables:

  • position: x

  • color: color_green, color_red

Diagram of layout coordinates

Diagram showing 5 different candlesticks.

Indices and tables