Ejemplo n.º 1
0
    def process(args, redis):

        session = Session()

        order = Order()
        order.user_id = args['USER_ID']
        order.p_no = args['P_NO']
        order.direction = Order.OrderDirectionBuy
        order.volume = args['VOLUME']
        order.price = args['PRICE']
        order.status = Order.OrderStatusCommitted
        order.created_at = time.time()

        session.add(order)

        #TODO need to check user's total money
        max_volume = args['MAX_VOLUME']
        money = args['MONEY']

        try:
            session.commit()
        except DBAPIError as e:
            session.rollback()
            session.close()
            return 'failed'
        else:
            redis.publish_json('chan:matching', args)
            redis.publish('chan:updates', 'CMD_GET_DELEGATE_BUY:{}'.format(args['P_NO']))
            return {'ID':order.id,'USER_ID':order.user_id,'P_NO':order.p_no,'DIRECTION':order.direction,'VOLUME':order.volume,'PRICE':order.price,'STATUS':order.status}
Ejemplo n.º 2
0
 def save_to_mysql_by_sql_alchemy(self, prod, status):
     #print('open sqlalchrmy session...')
     db_session = Session()
     try:
         tm = Timer()
         tm.start()
         db_session.add(
             DarenGoodInfo(createTime=prod['createTime'],
                           darenId=prod['userId'],
                           darenNoteId=prod['darenNoteId'],
                           darenNoteUrl=prod['darenNoteUrl'],
                           darenNoteTitle=prod['darenNoteTitle'],
                           darenNoteReason=prod['darenNoteReason'],
                           darenNoteCover=prod['darenNoteCover'],
                           darenNotePubDate=prod['darenNotePubDate'],
                           goodId=prod['goodId'],
                           goodUrl=prod['goodUrl'],
                           goodNoteDetailStep=3))
         db_session.commit()
         self.insert_cot += 1
         tm.end()
         print('{}\tSave {} to mysql: OK. spent {} / {} s'\
               .format(status,prod['darenNoteId'],
               round(tm.gap,2),round(self.db_time/self.thread_cot,2),
               ))
         self.db_time += tm.gap
     except Exception as e:
         print('{}\tSave to mysql ERROR: {}'\
               .format(status,str(e)))
     del tm
     db_session.close()
Ejemplo n.º 3
0
    def update_prodoct_history(p_no, current_price):

        session = Session()
        ph = session.query(PH).filter_by(p_no=p_no,
                                         work_date=datetime.date.today(),
                                         deleted=0).one_or_none()

        if not ph:
            ph = PH()

            ph.work_date = datetime.date.today()
            ph.p_no = p_no
            ph.last_price = Common.get_last_price(session, p_no)
            ph.open_price = current_price  #Common.get_open_price(session, p_no)

            if not operator.eq(current_price, 0):
                ph.current_price = current_price
            else:
                ph.current_price = ph.last_price

            max_price, min_price, total_volume, total_amount = ProductHandler.get_statistic_total(
                p_no)  #Common.get_statistic_total(session, p_no)
            ph.max_price = max_price
            ph.min_price = min_price
            ph.total_volume = total_volume
            ph.total_amount = total_amount

            session.add(ph)
        else:
            if operator.eq(ph.open_price, 0):
                ph.open_price = current_price

            if not operator.eq(current_price, 0):
                ph.current_price = current_price
            elif operator.eq(ph.current_price, 0):
                ph.current_price = ph.last_price

            max_price, min_price, total_volume, total_amount = ProductHandler.get_statistic_total(
                p_no)  #Common.get_statistic_total(session, p_no)
            ph.max_price = max_price
            ph.min_price = min_price
            ph.total_volume = total_volume
            ph.total_amount = total_amount

        try:
            session.commit()
        except DBAPIError as e:
            print(e.arg[0])
        finally:
            session.close()
Ejemplo n.º 4
0
def raw_data():

    session = Session()

    user = User()
    user.login_name = 'caoxuewei'
    user.login_pass = User.encrypt_pass('123456')
    user.display_name = 'caoxuewei'
    user.status = User.UserStatusActive
    user.real_name = '曹学玮'
    user.mobile = '15050593772'
    user.id_no = '321084199305020824'

    session.add(user)
    session.commit()

    '''
    publisher = Publisher()
    publisher.name = '吾品玉艺'.encode('utf-8')
    publisher.bank_no = '8888888888888'
    publisher.status = Publisher.PublisherStatusActive

    session.add(publisher)
    session.commit()

    catalog = Catalog()
    catalog.name = 'Jade'
    catalog.status = Catalog.ProductCatalogStatusPublished

    session.add(catalog)

    product = Product()
    product.name = '万盟玉栈3号'.encode('utf-8')
    product.pub_id = publisher.id
    product.p_no = '720003'
    product.issue_price = 500.00
    product.unit = 'g'
    product.qty = 100000
    product.turn_qty = 70000
    product.status = Product.ProductStatusActive

    session.add(product)
    session.commit()
    '''

    '''
Ejemplo n.º 5
0
def raw_data():

    session = Session()

    user = User()
    user.login_name = 'victor299'
    user.login_pass = User.encrypt_pass('123456')
    user.display_name = 'lizhensheng'
    user.status = User.UserStatusActive
    user.real_name = '王大可'
    user.mobile = '18112605920'
    user.id_no = '963258741'

    session.add(user)
    session.commit()
    '''
    publisher = Publisher()
    publisher.name = '吾品玉艺'.encode('utf-8')
    publisher.bank_no = '8888888888888'
    publisher.status = Publisher.PublisherStatusActive

    session.add(publisher)
    session.commit()

    catalog = Catalog()
    catalog.name = 'Jade'
    catalog.status = Catalog.ProductCatalogStatusPublished

    session.add(catalog)

    product = Product()
    product.name = '万盟玉栈3号'.encode('utf-8')
    product.pub_id = publisher.id
    product.p_no = '720003'
    product.issue_price = 500.00
    product.unit = 'g'
    product.qty = 100000
    product.turn_qty = 70000
    product.status = Product.ProductStatusActive

    session.add(product)
    session.commit()
    '''
    '''
Ejemplo n.º 6
0
def update_prodoct_history(p_no, current_price, max_price, min_price,
                           total_volume, total_amount):
    session = Session()
    ph = session.query(ProductHistory).filter_by(
        p_no=p_no, work_date=datetime.date.today()).order_by(
            ProductHistory.id.desc()).first()

    print(ph)

    if not ph:
        ph = ProductHistory()

        ph.work_date = datetime.date.today()
        ph.p_no = p_no
        ph.last_price = OrderDeal.get_last_price(p_no)
        ph.open_price = OrderDeal.get_open_price(p_no)

        ph.current_price = current_price
        ph.max_price = max_price
        ph.min_price = min_price
        ph.total_volume = total_volume
        ph.total_amount = total_amount

        session.add(ph)
    else:
        ph.current_price = current_price
        ph.max_price = max_price
        ph.min_price = min_price
        ph.total_volume = total_volume
        ph.total_amount = total_amount

    try:
        session.commit()
    except DBAPIError as e:
        print(e.args[0])
    finally:
        session.close()
Ejemplo n.º 7
0
    def insert_sale_order(user_id, p_no, volume, price):

        if not ProductHandler.is_in_exchange(p_no):
            return False, '非交易时间不允许委托'

        ups = ProductHandler.get_up_stop_price(p_no)
        dps = ProductHandler.get_down_stop_price(p_no)

        if operator.lt(float(price), dps) or operator.gt(float(price), ups):
            return False, '委托价格有误'

        #assets = UserHandler.get_can_sold_assets(user_id, p_no)
        assets = UserHandler.get_can_sale_asset_volume(user_id, p_no)
        if operator.gt(int(volume), assets) or operator.le(int(volume), 0):
            return False, '委托数量有误'

        order = Order()
        order.user_id = user_id
        order.p_no = p_no
        order.direction = Order.OrderDirectionSale
        order.volume = volume
        order.price = price
        order.status = Order.OrderStatusCommitted
        order.created_at = time.time()

        session = Session()
        session.add(order)

        try:
            session.commit()
        except:
            session.rollback()
            session.close()
            return False, '系统出错'
        else:
            session.close()
            return True, 'success'
Ejemplo n.º 8
0
    #UserWithdraw.install(engine)

    p = Product()
    p.p_no = 'CZQH'
    p.name = '启航'
    p.pub_id = 1
    p.issue_price = 5.00
    p.unit = 'h'
    p.qty = 10000000
    p.turn_qty = 8000000
    p.status = Product.ProductStatusCreated
    p.ex_from = '2017-12-01'
    p.ex_end = '2018-12-31'

    session = Session()
    session.add(p)
    session.commit()
    session.close()
    '''
    UserMeta.install(engine)
    Publisher.install(engine)
    Catalog.install(engine)
    Product.install(engine)
    Order.install(engine)
    OrderDeal.install(engine)
    UserMoney.install(engine)
    UserAssets.install(engine)

    '''
    ##raw_data()