sqlcandlestick

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 9 Imported by: 0

README

go-sqlcandlestick

Run Tests Go Reference

Tiny go package for serving candlestick chart for relational database.

Installation

go get -u github.com/ranjanrak/go-sqlcandlestick

Usage

package main
import (
	"log"

	sqlcandlestick "github.com/ranjanrak/go-sqlcandlestick"
)

func main() {
    client, err := sqlcandlestick.New(sqlcandlestick.ClientParam{
                    DriverName: sqlcandlestick.Clickhouse,
                    DSN: "tcp://127.0.0.1:9000?debug=true"})
    if err != nil {
        log.Fatalf("Error connecting to db: %v", err)
    }
    // Prepare sql statement
    queryStatement := `SELECT date,
                        open,
                        close
                        max(price) AS high,
                        min(price) AS low
                        FROM candle_data
                        GROUP BY date
                        ORDER BY date ASC`

    // Serve the candlestick chart
    client.ServeChart(queryStatement, "", nil)
}
Default candlestick chart

image

Create your own candlestick pattern

You can create your own candlestick chart types and pass the chart config to ServeChart(..., chart *charts.Kline). Few example chart config are shown under examples folder.

  1. Candlestick OCLH chart along with volume movement image

  2. Candlestick OCLH chart with EMA and SMA lines image

Run unit tests
go test -v

Documentation

Index

Constants

View Source
const (
	Clickhouse = "clickhouse"
	Postgres   = "postgres"
	Mysql      = "mysql"
)

Supported database drivers

Variables

This section is empty.

Functions

This section is empty.

Types

type AxisValues

type AxisValues struct {
	XAxis []string
	YAxis []opts.KlineData
}

AxisValues represents X and Y-axis values

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents database driver client

func New

func New(userParam ClientParam) (*Client, error)

New creates new data-base connection interface

func (*Client) FetchAxisValue

func (c *Client) FetchAxisValue(sqlStatement string) (AxisValues, error)

Fetch rows data using sql query statement to plot X-Y Axis candlestick

func (*Client) ServeChart

func (c *Client) ServeChart(queryStatement string, addr string, klineChart *charts.Kline)

ServeChart serves candlestick chart on the given address

type ClientParam

type ClientParam struct {
	DriverName string
	DSN        string
}

ClientParam represents interface to connect to sqldb

type HttpInput

type HttpInput struct {
	Client     Client
	SqlStmt    string
	KlineChart *charts.Kline
}

HttpInput represents input data for rendering candle stick chart

func (*HttpInput) DefaultKlineChart

func (h *HttpInput) DefaultKlineChart(w http.ResponseWriter)

Default candle stick chart

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL