def __init__(self, period): self.period = period self.exchange = Exchange(RebotConfig.access_key, RebotConfig.secret_key) self.exchange.delegate(tushareEXLocal()) # time Time.SetServerTime(self.exchange.getServerTimestamp()) # data. if RebotConfig.data_need_load: self.exchange.loadData(period, RebotConfig.rebot_test_begin) self.exchange.prepare(period, RebotConfig.rebot_test_begin) # markets self.markets = self.exchange.getMarkets() # rule. self.rules = {} # init. self.currenttimestamp = 0 self.Pool = [] self.RecordPools = [] for k, v in enumerate(self.markets): market = v['id'] dk = self.exchange.getK(market, 15, self.period, RebotConfig.rebot_test_begin) r = Turtle() r.Run(dk) lastk = r.KLines.Get(-1) self.rules[market] = r if lastk: self.currenttimestamp = lastk.t
def __init__(self, period): self.period = period self.exchange = Exchange(RebotConfig.access_key, RebotConfig.secret_key) delegate = None if RebotConfig.exchange == 'chbtc': if RebotConfig.rebot_release: delegate = chbtcEX() else: delegate = chbtcEXLocal() if RebotConfig.exchange == 'yunbi': if RebotConfig.rebot_release: delegate = yunbiEX() else: delegate = yunbiEXLocal() if RebotConfig.exchange == "tushare": delegate = tushareEXLocal() if RebotConfig.exchange == "huobi": if RebotConfig.rebot_release: delegate = huobiEX() else: delegate = huobiEXLocal() self.exchange.delegate(delegate) # time Time.SetServerTime(self.exchange.getServerTimestamp()) # data. if RebotConfig.data_need_load: self.exchange.loadData(period, RebotConfig.rebot_test_begin) self.exchange.prepare(period, RebotConfig.rebot_test_begin) # markets self.markets = self.exchange.getMarkets() # rule. self.rules = {} # init. self.currenttimestamp = 0 for k, v in enumerate(self.markets): market = v['id'] if RebotConfig.rebot_is_test: dk = self.exchange.getK(market, 42, self.period, RebotConfig.rebot_test_begin) # 1498838400:2017/7/1 0:0:0; 1496246400:2017/6/1 0:0:0; 1493568000:2017/5/1 0:0:0 else: dk = self.exchange.getK(market, 500, self.period) r = Mood() r.Run(dk) lastk = r.KLines.Get(-1) self.rules[market] = r if lastk: self.currenttimestamp = lastk.t # Log.d('index:%d, start market:%s, begin time %s, current time:%s'%(k, market, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(r.KLines.Get(0).t)), time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(lastk.t)))); self.zuorizhangting = {} self.datas = []
def __init__(self, period, path): self.period = period self.exchange = Exchange(RebotConfig.access_key, RebotConfig.secret_key) self.exchange.delegate(tushareEXLocal()) # time Time.SetServerTime(self.exchange.getServerTimestamp()) # data. if RebotConfig.data_need_load: self.exchange.loadData(period, RebotConfig.rebot_test_begin) self.exchange.prepare(period, RebotConfig.rebot_test_begin) # markets f = open(path, 'r') r = csv.DictReader(f) self.markets = [] for row in r: id = row['code'] self.markets.append({'id': id}) # rule. self.rules = {} # init. self.currenttimestamp = 0 self.Pool = [] print 'markt count ', len(self.markets) for k, v in enumerate(self.markets): market = v['id'] self.exchange.refresh(self.period, market) dk = self.exchange.getK(market, 15, self.period, RebotConfig.rebot_test_begin) r = Turtle() r.Run(dk) lastk = r.KLines.Get(-1) self.rules[market] = r if lastk: self.currenttimestamp = lastk.t
def __init__(self, period, markets): self.period = period self.exchange = Exchange(RebotConfig.access_key, RebotConfig.secret_key) self.exchange.delegate(tushareEXLocal()) # time Time.SetServerTime(self.exchange.getServerTimestamp()) # data. if RebotConfig.data_need_load: self.exchange.loadData(period, RebotConfig.rebot_test_begin) self.exchange.prepare(period, RebotConfig.rebot_test_begin) # markets if markets == None: self.markets = self.exchange.getMarkets() else: self.markets = markets # rule. self.rules = {} # init. self.currenttimestamp = 0 self.Pool = [] for k, v in enumerate(self.markets): market = v['id'] if RebotConfig.rebot_is_test: dk = self.exchange.getK(market, 15, self.period, RebotConfig.rebot_test_begin) # 1498838400:2017/7/1 0:0:0; 1496246400:2017/6/1 0:0:0; 1493568000:2017/5/1 0:0:0 else: dk = self.exchange.getK(market, 500, self.period) r = TrutleAverage() r.Run(dk) lastk = r.KLines.Get(-1) self.rules[market] = r if lastk: self.currenttimestamp = lastk.t
def __init__(self, period): self.period = period self.exchange = Exchange(RebotConfig.access_key, RebotConfig.secret_key) delegate = None if RebotConfig.exchange == 'chbtc': if RebotConfig.rebot_release: delegate = chbtcEX() else: delegate = chbtcEXLocal() if RebotConfig.exchange == 'yunbi': if RebotConfig.rebot_release: delegate = yunbiEX() else: delegate = yunbiEXLocal() if RebotConfig.exchange == "tushare": delegate = tushareEXLocal() if RebotConfig.exchange == "huobi": if RebotConfig.rebot_release: delegate = huobiEX() else: delegate = huobiEXLocal() self.exchange.delegate(delegate) # time Time.SetServerTime(self.exchange.getServerTimestamp()) # data. self.exchange.loadData(period, RebotConfig.rebot_test_begin) self.exchange.prepare(period, RebotConfig.rebot_test_begin) # user. self.user = User() info = self.exchange.getUser() print info # print '-----------------------------------' self.user.updatePositions(info['accounts']) # markets self.markets = self.exchange.getMarkets() # rule. self.rules = {} # init. # for k, v in enumerate(self.markets): market = v['id'] # order. # done in right env. self.user.updateOrder(self.exchange.getOrder(market)) # k line. if RebotConfig.rebot_is_test: dk = self.exchange.getK(market, 42, self.period, RebotConfig.rebot_test_begin) # 1498838400:2017/7/1 0:0:0; 1496246400:2017/6/1 0:0:0; 1493568000:2017/5/1 0:0:0 else: dk = self.exchange.getK(market, 500, self.period) r = WVStats() # r = MutliMovingAverage(); r.Run(dk) lastk = r.KLines.Get(-1) if lastk: currency = market #market[0:len(market)-3]; self.user.updateHigh(currency, lastk.c) # c or high self.user.updateCost(currency, lastk.c) self.rules[market] = r Log.d( 'index:%d, start market:%s, begin time %s, current time:%s' % (k, market, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(r.KLines.Get(0).t)), time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(lastk.t)))) #scale. self.scales = []