使用Python的Gdax蜡烛棒

时间:2018-04-10 07:02:10

标签: python python-3.x

任何人都知道如何在60秒的时间内循环一个不断变化的变量来检查它们的最高,中等,最低和平均值?

然后创建更多过去几分钟的json对象

尝试使用计时器进行自定义线程,似乎它对我不起作用

以下是我的代码。请帮助。

import sys, getopt
import time
from threading import Timer
import main.botlog as botlog
from main.settings import auth_client,product



class BotCandlestick(object):

def __init__(self, period=60, open=None, close=None, high=None, low=None, priceAverage=None):
    self.current = None
    self.open = open
    self.close = close
    self.high = high
    self.low = low
    self.startTime = time.time()
    self.period = period
    BotLog = botlog.BotLog
    self.output = BotLog()
    self.priceAverage = priceAverage


def tick(self, price):
    # while True:

    self.current = float(price)
    if (self.open is None):
        self.open = self.current
        print(self.open)

    if ((self.high is None) or (self.current > self.high)):
        self.high = self.current
        print(self.high)

    if ((self.low is None) or (self.current < self.low)):
        self.low = self.current
        print(self.low)

    if (time.time() >= (self.startTime + self.period)):
        self.close = self.current
        self.priceAverage = (self.high + self.low + self.close) / float(3)
        print(self.priceAverage)

    self.output.log(
        "Open: " + str(self.open) + " Close: " + str(self.close) + " High: " + str(self.high) + " Low: " + str(
            self.low) + " Current: " + str(self.current))



def isClosed(self):
    if (self.close is not None):
        return True
    else:
        return False




def main():
    price = auth_client.get_product_ticker(product)
    prices = float(price.get('price'))
    price = BotCandlestick()
    d = price.tick(prices)
    t = Timer(10.0, d)
    t.start()


if __name__ == '__main__':
    main()

1 个答案:

答案 0 :(得分:0)

我确实找到了解决这个问题的通用方法。请找到下面的代码。它更像是在x时间内找到价值变化的通用代码。

Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);