예제 #1
0
    def loop_new_price(self):
        run_times = 0

        while (True):
            self.one_round_price()
            time.sleep(60)
            run_times = run_times + 1
            # 每运行10次检查一下是不是需要发通知
            if run_times % 10 == 0:
                for market in self.__market_list:
                    for coin_pair in self.__coin_pair_list:
                        try:
                            buy_flag = self.match_alert_percent(coin_pair)
                            # 达到警示价格的进行持续买入操作
                            if buy_flag is True:
                                pass
                                # 目前测试半个月左右,没有能实现盈利,本方法优化不够,暂时停止执行,发现新的方法后再来测试
                                # self.coin_trans(market,coin_pair)
                            # 检查成交状态及进行止损检查
                            self.update_order_status(market, coin_pair)
                            # 对交易进行初始化处理
                            if self.cointrans_handler is None:
                                self.cointrans_handler = cointrans.CoinTrans(
                                    market)
                            elif self.cointrans_handler.market != market:
                                self.cointrans_handler = cointrans.CoinTrans(
                                    market)
                            # 对买入的订单进行加价卖出
                            self.cointrans_handler.sell_check()
                        except Exception as e:
                            print('Call failed:{0}'.format(str(e)))
예제 #2
0
 def update_order_status(self, market, coin_pair):
     priceitem = self.getpriceitem(market, coin_pair)
     # 对交易进行初始化处理
     if self.cointrans_handler is None:
         self.cointrans_handler = cointrans.CoinTrans(market)
     elif self.cointrans_handler.market != market:
         self.cointrans_handler = cointrans.CoinTrans(market)
     # 更新订单状态状态
     self.cointrans_handler.update_order_status()
     # 止损操作
     self.cointrans_handler.stop_lost(priceitem)
예제 #3
0
    def coin_trans(self, market, coin_pair):
        priceitem = self.getpriceitem(market, coin_pair)
        # 对交易进行初始化处理
        if self.cointrans_handler is None:
            self.cointrans_handler = cointrans.CoinTrans(market)
        elif self.cointrans_handler.market != market:
            self.cointrans_handler = cointrans.CoinTrans(market)

        # 买入操作
        self.cointrans_handler.coin_trans(market, 'buy', priceitem.buy_price,
                                          priceitem)
        # 对买入的订单进行加价卖出
        self.cointrans_handler.sell_check()
        # 更新订单状态状态
        self.cointrans_handler.update_order_status()
        # 止损操作
        self.cointrans_handler.stop_lost(priceitem)
        pass
예제 #4
0
    def __init__(self, market, priceitem=None, save_log_flag=True):
        # 保存执行过的价格列表
        self.price_buffer = []
        # 保存那些预测为买入的记录
        self.price_forecast_list = []
        # 市场
        self.market = market
        # 初始化常用的常量值
        self.__initconst()
        # 暂停开始时间
        self.__pause_start_time = None

        # 设置影响判断条件的公共参数
        # 上升趋势时,价格深度比较强的百分比
        # self.__PRICE_TREND_STRONG_PERCENTAGE=1.5
        # 买入趋势比较弱的百分比
        # self.__PRICE_TREND_WEAK_PERCENTAGE=0.6
        # 买入指数判断的时间范围,初始为按1小时内的价格进行判断,单位为秒
        # self.__PRICE_TREND_RANGE=3600
        # 价格buffer中保存的最大的价格记录数
        self.__PRICE_BUFF_MAX = 2000
        # 止盈卖出的比例,用来确认预测买入的是不是符合要求
        # self.sell_profit_rate = 0.009
        # 默认的买入间隔,在50%之前
        self.__DEFAULT_BUY_PAUSE_SECONDS = 60
        #

        # 买入的标准指数
        # self.__BUY_INDEX_STANDARD=1.2

        # 调整公共参数, 设置默认的参数
        self.adjust_params(0.8, 0.6, 0.7, 3600)
        # 是否需要写log, 在进行研究的时候不需要写LOG
        self.save_log_flag = save_log_flag

        # 测试基准时间,用于从文件读取时设置一个基准时间进行循环测试
        self.basetime = None
        # 处理交易类初始化
        # self.cointrans_handler = cointrans.CoinTrans(market)
        self.cointrans_handler = cointrans.CoinTrans(market)

        if priceitem is not None:
            # 把处理好的价格加入到价格BUFFER列表
            self.newprice(priceitem)
        # 控制的price buffer list
        self.__pricebuffer_list = {}
        # 止损暂停秒数
        self.__pause_seconds_stop_lost = 0
        # 暂停秒数
        self.__pause_seconds = 0
        # 暂停的状态
        self.pause_status = False
예제 #5
0
    def monitor_coin_list(self, market, coin_list):

        runtime = 0
        maxruntime = 10000
        while (True):
            time.sleep(5)
            for coin_pair in coin_list:
                try:
                    self.monitor_coin(market, coin_pair)
                    runtime = runtime + 1
                    # 很运行10次检查一下交易的状态
                    if runtime % 10 == 0:
                        cointrans_data = cointrans.CoinTrans(market)
                        # print(len(publicparameters.ORDER_LIST))
                        # 对OPEN订单进行卖出检查
                        cointrans_data.sell_check()
                        # 获取当前的价格
                        pricebuffer = PriceBuffer(market, save_log_flag=False)
                        newpriceitem = pricebuffer.getpriceitem(
                            market, coin_pair)
                        # 止损检查,如果价格下降低于预定的止损值则执行卖出操作
                        # stop_lost_status = cointrans_data.stop_lost(newpriceitem)
                        # 对超时的买单取消
                        # cointrans_data.cancle_ot_buy_order(publicparameters.CANCEL_DURATION)

                        cointrans_data.update_order_status()
                        cointrans_data.cancle_ot_buy_order(
                            publicparameters.CANCEL_DURATION)
                        # 增加把网站的成交记录保存到表中以便进行统计盈利情况
                        cointrans_data.save_aex_trans(coin_pair)
                    if runtime % 100 == 0:
                        print('Run {0}, 目前还未完成的订单有:{1}'.format(
                            runtime, ormmysql.openordercount()))
                        # 获取当前COIN中预测可以买入的列表
                        forecast_list = self.__pricebuffer_list.get(
                            coin_pair).price_forecast_list
                        verified_count = 0
                        # 判断当前预测的列表中哪些达到了预期的盈利目标
                        for forecast_item in forecast_list:
                            if forecast_item.price_buy_forecast_verify is True:
                                verified_count = verified_count + 1
                        # 输出每个COIN中预测的情况,多少达到了预期盈利
                        # if len(forecast_list) > 0:
                        #     print('%s: verified:%d, total:%d for coin:%s'\
                        #           %(common.CommonFunction.get_curr_time(), verified_count, len(forecast_list), coin_pair))
                    if runtime % 100 == 0:
                        # 把预测中的列表输出出来
                        sorted_forecast_list = self.output_forecast_list(
                            market, coin_list)
                        # # 大鱼检查
                        # self.bigfish.get_big_fish_list()
                        # each_big_fish_list =self.bigfish.big_fish_list
                        # # 取每次列表的
                        # # self.big_fish_list = self.big_fish_list + each_big_fish_list
                        # # print('big fish list of all: {0}'.format(each_big_fish_list))
                        # # big fish 列表写入
                        # if len(each_big_fish_list) != 0:
                        #     bigfishfile = open('bigfish.txt','w')
                        #     bigfishfile.write('{0}:{1}\n'.format(common.get_curr_time_str(),each_big_fish_list))
                        #     bigfishfile.close()

                    # 增加定时输出报表的功能
                    if runtime % 1000 == 0:
                        daily_summary = DailySummary([market])
                        # 获取当前时间的余额信息
                        daily_summary.get_balance()

                except Exception as e:
                    excepterror = str(e)
                    print('处理{0}时出现错误:{1}'.format(coin_pair, excepterror))
        # return sorted_forecast_list
        pass