3ff3c1aefd784551e0b5e67f1c708401a7fc9076,QUANTAXIS/QAARP/QAAccountPro.py,QA_AccountPRO,send_order,#QA_AccountPRO#Any#Any#Any#Any#Any#Any#Any#Any#Any#Any#,1434

Before Change


                if self.market_type == MARKET_TYPE.FUTURE_CN:
                    // 如果有负持仓-- 允许卖空的时候
                    if towards == 3: // 多平
                        _hold = self.sell_available.get(code, 0)
                                     // 假设有负持仓:
                                     // amount为下单数量 如  账户原先-3手 现在平1手

                        //left_amount = amount+_hold if _hold < 0 else amount

After Change


        pass

    def send_order(
            self,
            code=None,
            amount=None,
            time=None,
            towards=None,
            price=None,
            money=None,
            order_model=ORDER_MODEL.LIMIT,
            amount_model=AMOUNT_MODEL.BY_AMOUNT,
            order_id=None,
            position_id=None,
            *args,
            **kwargs
    ):

        wrong_reason = None
        assert code is not None and time is not None and towards is not None and order_model is not None and amount_model is not None
        date = str(time)[0:10] if len(str(time)) == 19 else str(time)
        time = str(time) if len(str(time)) == 19 else "{} 09:31:00".format(
            str(time)[0:10]
        )
        if self.allow_margin:
            amount = amount if amount_model is AMOUNT_MODEL.BY_AMOUNT else int(
                money / (
                    self.market_preset.get_unit(code) *
                    self.market_preset.get_frozen(code) * price *
                    (1 + self.commission_coeff)
                ) / 100
            ) * 100
        else:
            amount = amount if amount_model is AMOUNT_MODEL.BY_AMOUNT else int(
                money / (price * (1 + self.commission_coeff)) / 100
            ) * 100

        // 🛠todo 移到Utils类中,  money_to_amount 金额转成交量
        if self.allow_margin:
            money = amount * price * self.market_preset.get_unit(code)*self.market_preset.get_frozen(code) * \
                (1+self.commission_coeff) if amount_model is AMOUNT_MODEL.BY_AMOUNT else money
        else:
            money = amount * price * \
                (1+self.commission_coeff) if amount_model is AMOUNT_MODEL.BY_AMOUNT else money

        // flag 判断买卖 数量和价格以及买卖方向是否正确
        flag = False

        assert (int(towards) != 0)
        if int(towards) in [1, 2, 3]:
            // 是买入的情况(包括买入.买开.买平)
            if self.cash_available >= money:
                if self.market_type == MARKET_TYPE.STOCK_CN:  // 如果是股票 买入的时候有100股的最小限制
                    amount = int(amount / 100) * 100
                    self.cash_available -= money
                    flag = True

                if self.running_environment == RUNNING_ENVIRONMENT.TZERO:

                    if abs(self.buy_available.get(code, 0)) >= amount:
                        flag = True
                        self.cash_available -= money
                        self.buy_available[code] -= amount
                    else:
                        flag = False
                        wrong_reason = "T0交易买入超出限额"

                if self.market_type == MARKET_TYPE.FUTURE_CN:
                    // 如果有负持仓-- 允许卖空的时候
                    if towards == 3:  // 多平
                        pos = self.get_position(code)
                        // 假设有负持仓:
                        // amount为下单数量 如  账户原先-3手 现在平1手

                        //left_amount = amount+_hold if _hold < 0 else amount
                        money_need = abs(
                            float(amount * price * (1 + self.commission_coeff))
                        )

                        if self.cash_available >= money_need:
                            if pos.volume_short > 0:
                                self.cash_available -= money_need

                                flag = True
                            else:
                                wrong_reason = "空单仓位不足"
                        else:
                            wrong_reason = "平多剩余资金不够"
                    if towards == 2:
                        self.cash_available -= money
                        flag = True
            else:
                wrong_reason = "QAACCOUNT: 可用资金不足 cash_available {}  code {} time {} amount {} towards {}".format(
                    self.cash_available,
                    code,
                    time,
                    amount,
                    towards
                )
        elif int(towards) in [-1, -2, -3]:
            // 是卖出的情况(包括卖出,卖出开仓allow_sellopen如果允许. 卖出平仓)
            // print(self.sell_available[code])
            pos = self.get_position(code)  // _hold 是你的持仓

            // 如果你的hold> amount>0
            // 持仓数量>卖出数量

            if towards == -1:
                if pos.volume_long_his >= amount:
                    self.sell_available[code] -= amount
                    // towards = ORDER_DIRECTION.SELL
                    flag = True
            elif towards == -2:
                if self.allow_sellopen:
                    if self.cash_available >= money:  // 卖空的市值小于现金(有担保的卖空), 不允许裸卖空
                                                    // self.cash_available -= money
                        flag = True
                    else:
                        print("sellavailable", _hold)
                        print("amount", amount)
                        print("aqureMoney", money)
                        print("cash", self.cash_available)
                        wrong_reason = "卖空资金不足"
                else:
                    wrong_reason = "不允许卖空"

            else:
                if pos.volume_long >= amount:
                    self.sell_available[code] -= amount
                    // towards = ORDER_DIRECTION.SELL
                    flag = True
                // 如果持仓数量<卖出数量
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 3ff3c1aefd784551e0b5e67f1c708401a7fc9076
Time: 2019-10-16
Author: yutiansut@qq.com
File Name: QUANTAXIS/QAARP/QAAccountPro.py
Class Name: QA_AccountPRO
Method Name: send_order


Project Name: flow-project/flow
Commit Name: 76a15cc5cae3cbd4ed77917d18047a727a86a8d7
Time: 2018-02-26
Author: akreidieh@gmail.com
File Name: flow/core/vehicles.py
Class Name: Vehicles
Method Name: get_position


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 0b8628de208c79bf6ae2efd877ffeb80e819b63d
Time: 2019-10-21
Author: barrettyip@gmail.com
File Name: QUANTAXIS/QAARP/QAAccountPro.py
Class Name: QA_AccountPRO
Method Name: send_order


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 3ff3c1aefd784551e0b5e67f1c708401a7fc9076
Time: 2019-10-16
Author: yutiansut@qq.com
File Name: QUANTAXIS/QAARP/QAAccountPro.py
Class Name: QA_AccountPRO
Method Name: send_order