示例#1
0
 def on_new_order(self, transaction_hash: str, token_address: str,
                  exchange_address: str, order_id: int,
                  account_address: str, counterpart_address: str,
                  is_buy: bool, price: int, amount: int, agent_address: str,
                  order_timestamp: datetime):
     order = self.__get_order(exchange_address, order_id)
     if order is None:
         LOG.debug(
             f"NewOrder: exchange_address={exchange_address}, order_id={order_id}"
         )
         order = Order()
         order.transaction_hash = transaction_hash
         order.token_address = token_address
         order.exchange_address = exchange_address
         order.order_id = order_id
         order.unique_order_id = exchange_address + "_" + str(order_id)
         order.account_address = account_address
         order.counterpart_address = counterpart_address
         order.is_buy = is_buy
         order.price = price
         order.amount = amount
         order.agent_address = agent_address
         order.is_cancelled = False
         order.order_timestamp = order_timestamp
         self.db.merge(order)
示例#2
0
def create_order():
    print "creating order..."
    orders = [('Chair x 1000 Orders', 1, 1000),
              ('Round Table x 2000 Orders', 2, 2000)]
    for o in orders:
        order = Order()
        order.name = o[0]
        order.product_id = o[1]
        order.quantity = o[2]
        db.session.add(order)
示例#3
0
def order_process(id: str):
    """
    represents order processing url
    """

    pieces = request.form.get("pieces")
    address = request.form.get("address")

    try:
        order = Order(pieces, address)
        order.set_object_member(current_user.id)
        order.set_object_product(id)
        order.save()
    except Exception as Error:
        flash("error", Error.__str__())
    else:
        flash("success", "sukses order barang, silahkan edit info pembayaran")

    return redirect(url_for("order.order_unpaid"))
示例#4
0
def order():
    # 接收参数
    dict = request.form
    house_id = int(dict.get('house_id'))
    start_date = datetime.strptime(dict.get('start_date'), '%Y-%m-%d')
    end_date = datetime.strptime(dict.get('end_date'), '%Y-%m-%d')

    # 验证有效性
    if not all([house_id, start_date, end_date]):
        return jsonify(status_code.PARAMS_ERROR)

    if start_date > end_date:
        return jsonify(status_code.ORDER_START_END_TIME_ERROR)

    # 查询房屋对象
    try:
        house = House.query.get(house_id)
    except:
        return jsonify(status_code.DATABASE_ERROR)
    # 创建订单对象
    order = Order()
    order.user_id = session['user_id']
    order.house_id = house_id
    order.begin_date = start_date
    order.end_date = end_date
    order.days = (end_date - start_date).days + 1
    order.house_price = house.price
    order.amount = order.days * order.house_price

    try:
        order.add_update()
    except:
        return jsonify(status_code.DATABASE_ERROR)

    # 返回信息
    return jsonify(code='200')
示例#5
0
    def _insert_test_data(self, session):
        self.session = session

        # Order Record
        o = Order()
        o.exchange_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        o.token_address = '0xa4CEe3b909751204AA151860ebBE8E7A851c2A1a'
        o.order_id = 1
        o.unique_order_id = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb' + "_" + str(1)
        o.counterpart_address = ''
        o.price = 70
        o.amount = 5
        o.is_buy = True
        o.is_cancelled = False
        session.add(o)

        o = Order()
        o.exchange_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        o.token_address = '0xa4CEe3b909751204AA151860ebBE8E7A851c2A1a'
        o.order_id = 2
        o.unique_order_id = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb' + "_" + str(2)
        o.counterpart_address = ''
        o.price = 80
        o.amount = 5
        o.is_buy = True
        o.is_cancelled = False
        session.add(o)

        # Agreement Record
        a = Agreement()
        a.order_id = 1
        a.agreement_id = 101
        a.exchange_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.unique_order_id = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb' + "_" + str(1)
        a.buyer_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.seller_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.amount = 3
        a.status = 1
        a.settlement_timestamp = '2019-11-13 16:23:14.183706'
        a.created = '2019-11-13 16:26:14.183706'
        session.add(a)

        a = Agreement()
        a.order_id = 2
        a.agreement_id = 102
        a.exchange_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.unique_order_id = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb' + "_" + str(2)
        a.buyer_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.seller_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.amount = 3
        a.status = 1
        a.settlement_timestamp = '2019-11-13 16:24:14.183706'
        a.created = '2019-11-13 16:26:14.183706'
        session.add(a)

        # Order Record (other exchange)
        o = Order()
        o.exchange_address = '0x1234567890123456789012345678901234567890'
        o.token_address = '0xa4CEe3b909751204AA151860ebBE8E7A851c2A1a'
        o.order_id = 1
        o.unique_order_id = '0x1234567890123456789012345678901234567890' + "_" + str(1)
        o.counterpart_address = ''
        o.price = 70
        o.amount = 5
        o.is_buy = True
        o.is_cancelled = False
        session.add(o)