পাইথন সংস্করণ অঙ্কন ক্লাস লাইব্রেরি (সামঞ্জস্যপূর্ণ 2/3)

লেখক:ছোট্ট স্বপ্ন, তারিখঃ ২০১৭-০৪-১০ ১৭ঃ২০ঃ২৬
ট্যাগঃসরঞ্জামপাইথনচার্ট

পলিসি গ্রাফের লাইনগুলির যুক্তিকে সরলীকৃত করা হয়েছে, সরাসরি প্যাকেজড ফাংশনগুলি কল করা যায়

  • একাধিক লাইন আঁকতে সহায়তা করে
  • কে থ্রেড গ্রাফ সমর্থন করে
  • পতাকা ছোট আইকন সমর্থন
  • আপনি আরো গ্রাফিক্স সমর্থন যোগ করতে পারেন

JS সংস্করণের সাথে সামঞ্জস্যপূর্ণ

JS সংস্করণে স্থানান্তরিত

যদি আপনার কোন প্রশ্ন থাকে, তাহলে আমাদের সাথে যোগাযোগ করুন 359706687


# Python 2/3 兼容版本
import time
chart = None
series = []
labelIdx = {}
preBarTime = 0
preFlagTime = 0
preDotTime = {}

cfg = {
    "tooltip" : {
        "xDateFormat" : "%Y-%m-%d %H:%M:%S, %A"
    },
    "legend" : {
        "enabled" : True
    },
    "plotOptions" : {
        "candlestick" : {
            "color" : "#d75442",
            "upColor" : "#6ba583"
        }
    },
    "rangeSelector" : {
        "buttons" : [{
            "type" : "hour",
            "count" : 1,
            "text" : "1h",
        }, {
            "type" : 'hour',
            "count" : 3,
            "text" : "3h"
        }, {
            "type" : "hour",
            "count" : 8,
            "text" : "8h"
        }, {
            "type" : "all",
            "text" : "All"
        }],
        "selected" : 2,
        "inputEnabled" : True
    },
    "series" : series,
}

def GetCfg():
    global cfg
    return cfg

# 画水平线
def PlotHLine(value = None, label = None, color = None, style = None):
    global cfg, chart
    if ("yAxis" in cfg) == False :
        cfg.setdefault("yAxis", {"plotLines" : []})
    elif ("plotLines" in cfg["yAxis"]) == False :
        cfg["yAxis"].setdefault("plotLines", [])
    
    obj = {
        "value" : value,
        "color" : color or "red",
        "width" : 2,
        "dashStyle" : style or "Solid",
        "label" : {
            "text" : label or "",
            "align" : "center"
        }
    }
    found = False
    for i in range(len(cfg["yAxis"]["plotLines"])) : 
        if cfg["yAxis"]["plotLines"][i]["label"]["text"] == label : 
            cfg["yAxis"]["plotLines"][i] = obj
            found = True
    if not found :
        cfg["yAxis"]["plotLines"].append(obj)
    if not chart :
        chart = Chart(cfg)
        chart.update(cfg)    # 更新图表
    else :
        chart.update(cfg)

# 画K线
def PlotRecords(records, title = None):
    global labelIdx, series, preBarTime, chart
    if not chart :
        chart = Chart(cfg)
        chart.reset()
    if ("candlestick" in labelIdx) == False : 
        cfg["__isStock"] = True
        seriesIdx = len(series)
        series.append({
            "type" : "candlestick",
            "name" : "" if title == None else title,
            "id" : "primary",
            "data" : []
            })
        chart.update(cfg)
        labelIdx.setdefault("candlestick", seriesIdx)
    else :
        seriesIdx = labelIdx["candlestick"]
    if isinstance(records, dict) and ("Time" in records) == True :
        Bar = records
        if Bar["Time"] == preBarTime :
            chart.add(seriesIdx, [Bar["Time"], Bar["Open"], Bar["High"], Bar["Low"], Bar["Close"]], -1)
        elif Bar["Time"] > preBarTime : 
            preBarTime = Bar.Time
            chart.add(seriesIdx, [Bar["Time"], Bar["Open"], Bar["High"], Bar["Low"], Bar["Close"]])    
    else :
        for i in range(len(records)) :
            if records[i]["Time"] == preBarTime :
                chart.add(seriesIdx, [records[i]["Time"], records[i]["Open"], records[i]["High"], records[i]["Low"], records[i]["Close"]], -1)
            elif records[i]["Time"] > preBarTime :
                preBarTime = records[i]["Time"]
                chart.add(seriesIdx, [records[i]["Time"], records[i]["Open"], records[i]["High"], records[i]["Low"], records[i]["Close"]])
    return chart

# 画指标线
def PlotLine(label, dot, Ntime = None):
    global labelIdx, chart, series, preDotTime
    if not chart :
        cfg.setdefault("xAxis", {
            "type" : "datetime"
            })
        chart = Chart(cfg)
        chart.reset()
    if (label in labelIdx) == False :
        seriesIdx = len(series)
        preDotTime.setdefault(str(seriesIdx), 0)
        labelIdx[label] = seriesIdx
        series.append({
            "type" : "line",
            "yAxis" : 0,
            "showInLegend" : True,
            "name" : label,
            "data" : [],
            "tooltip" : {"valueDecimals" : 5}
            })
        chart.update(cfg)
    else :
        seriesIdx = labelIdx[label]
    if Ntime == None :
        Ntime = _N(time.time() * 1000, 0)
    if preDotTime[str(seriesIdx)] != Ntime :
        preDotTime[str(seriesIdx)] = Ntime
        chart.add(seriesIdx, [Ntime, dot])
    else :
        chart.add(seriesIdx, [Ntime, dot], -1)
    return chart

# 画标记
def PlotFlag(time, text, title, shape = "", color = ""):
    global chart, cfg, labelIdx, preFlagTime
    if not chart :
        chart = Chart(cfg)
        chart.reset()
    label = "flag"
    if (label in labelIdx) == False : 
        seriesIdx = len(series)
        labelIdx[label] = seriesIdx
        series.append({
            "type" : "flags",
            "onSeries" : "primary",
            "data" : []
            })
        chart.update(cfg)
    else :
        seriesIdx = labelIdx[label]
    obj = {
        "x" : time,
        "color" : color,
        "shape" : shape,
        "title" : title,
        "text" : text
    }
    if preFlagTime != time : 
        preFlagTime = time
        chart.add(seriesIdx, obj)
    else :
        chart.add(seriesIdx, obj, -1)
    return chart

# 设置图表标题
def PlotTitle(title, chartTitle = None):
    global cfg
    if ("subtitle" in cfg) == True : 
        cfg["subtitle"] = {"text" : title}
    else :
        cfg.setdefault("subtitle", {"text" : title})
    if chartTitle != None :
        if (title in cfg) == True :
            cfg["title"] = {"text" : chartTitle}
        else :
            cfg.setdefault("title", {"text" : chartTitle})
    if chart :
        chart.update(cfg)

# 导出函数
ext.GetCfg = GetCfg
ext.PlotHLine = PlotHLine
ext.PlotRecords = PlotRecords
ext.PlotLine = PlotLine
ext.PlotFlag = PlotFlag
ext.PlotTitle = PlotTitle

# 测试代码
def main():
    isFirst = True
    while True:
        records = exchange.GetRecords()
        if records and len(records) > 0 :
            ext.PlotRecords(records, "BTC")
            if isFirst :
                ext.PlotFlag(records[-1]["Time"], "Start", "S")
                isFirst = False
                ext.PlotHLine(records[-1]["Close"], "Close")
        ticker = exchange.GetTicker()
        if ticker :
            ext.PlotLine("Last", ticker.Last)
            ext.PlotLine("buy", ticker.Buy + 10)
            ext.PlotTitle("Last" + str(ticker.Last))
        Sleep(60000)



সম্পর্কিত

আরো

চার্চিল্সিহ্যালো, আমি প্লটফ্লেগ কল করার সময়, পৃষ্ঠা রিফ্রেশ করার পরে, আমি প্রায়শই পেইন্টিং করা পতাকা হারিয়ে ফেলি, দয়া করে আমাকে জিজ্ঞাসা করুন, এর সমাধান আছে কি?

চার্চিল্সিপ্রশ্নঃ আপনি কি একটি চার্টে একাধিক k-লাইন একত্রিত করতে পারেন? উদাহরণস্বরূপঃ বিটিসি এর K-লাইন + ইটিএইচ এর K-লাইন

m0606এটি দেখতে প্রায় দুই-তৃতীয়াংশ পাইথন সামঞ্জস্যপূর্ণ একটি অঙ্কন লাইন ক্লাস লাইব্রেরি মনে হয়।

আইভিসি৮৭শিক্ষক, এই টেমপ্লেট ফাংশন ব্যবহারের জন্য কোন নির্দেশনা আছে?

হাওরেনআপনি কি একটি ট্রেডিং চার্ট কাস্টমাইজ করতে পারেন? একাধিক k লাইন এক আইকনে একত্রিত করুন; উদাহরণস্বরূপঃ বিটিসি মূল্য লাইন + এলটিসি মূল্য লাইন + ইথ মূল্য লাইন + বহু-মুদ্রা সমন্বিত মূল্য লাইন ইত্যাদি, কয়েকটি লাইন একটি চার্টে প্রদর্শিত হবে, যেমন k লাইনের কয়েকটি সমতুল্য মূল্য লাইন একই চার্টে প্রদর্শিত হবে

লোগাপ্রশংসা!

ছোট্ট স্বপ্নওহ, কিছু প্যারামিটার ভুল হতে পারে।

চার্চিল্সিসমস্যা সমাধান হয়েছে, শিরোনামের সংখ্যা সীমিত, টেক্সট সমৃদ্ধ হতে পারে, উল্টোপাল্টা করা যাবে না, ধন্যবাদ

ছোট্ট স্বপ্নযে চিহ্নটি আঁকা হয়েছিল, যা বলা হয়েছিল যে এটি হারিয়ে যাবে না, এটি আঁকা হয়েছিল, আপনি যদি এটি পরিবর্তন না করেন তবে এটি পরিবর্তন হবে না, এটি স্থায়ী।

ছোট্ট স্বপ্নআপনি উপরে যে চিত্রটি চিহ্নিত করেছেন তা কেবলমাত্র এফএমজেড পৃষ্ঠায় প্রদর্শিত হবে, প্রতিটি বিভাগে কতগুলি ডেটা প্রদর্শিত হবে, একটি চার্ট যদি 100,000 ডেটা থাকে, আপনি এখানে প্রতিটি বিভাগে 10,000 ডেটা প্রদর্শন করার জন্য সেট করুন, এই 100,000 ডেটা 10 পৃষ্ঠাগুলি প্রদর্শন করবে। এই সেটিংটি আপনার কোড ডিজাইনের সাথে সম্পর্কিত নয়। এটি কেবলমাত্র এফএমজেড পৃষ্ঠাগুলি প্রদর্শনের নিয়ন্ত্রণ।

চার্চিল্সিঅনুগ্রহ করে এখানে প্রতি পৃষ্ঠায় ডেটা সীমা কি? যদি আমার ডেটা এই সীমা অতিক্রম করে তবে আমি কীভাবে প্রদর্শন করব? /upload/asset/245f7442dfa3212019b47.png

ছোট্ট স্বপ্নসর্বশেষতম মাল্টি-চার্ট লাইন ক্লাসের সাথে আঁকতে পারেন। এই ক্লাসটি কেবলমাত্র একক আঁকতে পারে।

ছোট্ট স্বপ্নটেমপ্লেটের মধ্যে main ফাংশন হল ব্যবহারের উদাহরণ, দেখুন।

ছোট্ট স্বপ্নধন্যবাদ সমর্থনের জন্য! কোন প্রশ্ন থাকলে মন্তব্য করতে পারেন।