Esempio n. 1
0
    def execute(self, job):
        q = Quotation()
        hgt = q.get_hgt_capital()
        hgt_estimate = estimate_to_close(hgt)

        #沪港通指标
        buy = 0
        if hgt > self.HGT_LIM:
            buy = 1
        if get_exchange_time(
        ) > 30 * 60 and hgt_estimate > self.HGT_ESTIMATE_LIM:
            buy = 1

        if buy == 0:
            job.status = 0
            job.result.clear()
            return 0

        if buy == 1:
            job.status = 1

        t = Trader.get_instance(job['trader'])
        position = t.position()
        balance = t.balance()
        enable_balance = balance[0].enable_balance

        codes = []
        for i, v in enumerate(job.result):
            codes.append(v.code)
        quotes = q.get_realtime_quotes(codes)

        temp_result = copy.copy(job.result)
        job.result.clear()
        for i, v in enumerate(temp_result):
            #找到该股的持仓数据
            v_position = ''
            for p in position:
                if p.stock_code == v.code:
                    v_position = p
            #达到持仓上限
            if v_position != '' and v_position.current_amount >= v.amount:
                continue
            #设置买入参数
            v.price = quotes[v.code].buy
            if get_turnover_brokerage(v.price * v.amount) > enable_balance:
                continue
            enable_balance -= get_turnover_brokerage(v.price * v.amount)
            job.result.append(v)

        return 0
    def execute(self, job):
        q = Quotation()
        hgt = q.get_hgt_capital()
        hgt_estimate = estimate_to_close(hgt)

        #沪港通指标
        sell = 0
        if hgt < self.HGT_LIM:
            sell = 1
        if get_exchange_time(
        ) > 30 * 60 and hgt_estimate < self.HGT_ESTIMATE_LIM:
            sell = 1
        if hgt < self.HGT_KEEP_LIM:
            sell = 2
        if get_exchange_time(
        ) > 30 * 60 and hgt_estimate < self.HGT_KEEP_ESTIMATE_LIM:
            sell = 2

        if sell == 0:
            job.status = 0
            job.result.clear()
            return 0

        if sell != 0:
            job.status = 1

        t = Trader.get_instance(job['trader'])
        position = t.position()

        codes = []
        for i, v in enumerate(job.result):
            codes.append(v.code)
        quotes = q.get_realtime_quotes(codes)

        temp_result = copy.copy(job.result)
        job.result.clear()
        for i, v in enumerate(temp_result):
            #找到该股的持仓数据
            v_position = ''
            for p in position:
                if p.stock_code == v.code:
                    v_position = p
            #没有持仓
            if v_position == '':
                continue
            #盈利卖出
            if sell == 1:
                v.price = max(
                    quotes[v.code].buy,
                    round(
                        v_position.keep_cost_price *
                        (1 + self.INCOME_RATION_LIM), 2))
            #保本卖出
            elif sell == 2:
                v.price = v_position.keep_cost_price

            #设置卖出参数
            v.amount = v_position.enable_amount
            job.result.append(v)

        return 0
Esempio n. 3
0
 def test_get_hgt_capital(self):
     q = Quotation()
     d = q.get_hgt_capital()
     self.assertTrue(isinstance(d, float))