コード例 #1
0
def save_operation_buy_spot(position_dict, spot_order_dict):
    with Session(model.get_engine()) as session:
        with session.begin():
            # spot_order
            order_id = spot_order_dict['orderId']

            spot_order = session.query(
                model.SpotOrder).filter_by(order_id=order_id).first()
            spot_order = model_helper.sync_spot_order(spot_order_dict,
                                                      spot_order)

            # operation
            operation = spot_order.operation

            # position
            position = operation.position if operation else None

            if not position:
                position_id = position_dict['position_id']

                if position_id:
                    position = session.query(model.Position).get(position_id)
                else:
                    position = model.Position()
                    session.add(position)

            position = model_helper.sync_position(
                {
                    **position_dict, 'state': 'CREATED'
                }, position)

            if not operation:
                operation = model.Operation()

                position.operations.append(operation)

                operation.spot_order = spot_order

            operation = model_helper.sync_operation(
                {
                    **position_dict, 'kind': 'OPEN',
                    'state': 'SPOT_BUY'
                }, operation)
コード例 #2
0
 def extract_functions(self, parent, suite):
     for i in suite:
         if type(i) == type(()) and \
             i[0] == symbol.stmt and \
             i[1][0] == symbol.compound_stmt and \
             i[1][1][0] == symbol.funcdef:
             function_def = i[1][1]
             funcname = function_def[2][1]
             op = model.Operation(funcname)
             # function_def[3] is the parameters
             params = filter(
                 lambda x: type(x) == types.TupleType and x[0] == symbol.
                 parameters, function_def)
             self.extract_args(params[0], op)
             #if function_def[3][0] != symbol.parameters:
             #    print function_def[4]
             #self.extract_args(function_def[3], op)
             parent.addOperation(op)
             # function_def[5] is the suite
             op.doc = self.docstring(function_def[5])
コード例 #3
0
def sync_operation(operation_dict: Dict, operation: model.Operation = None) -> model.Operation:

    if not operation:
        operation = model.Operation()

    if operation_dict.get('position_id'):
        operation.position_id = operation_dict['position_id']

    operation.kind = operation_dict['kind']

    operation.future = operation_dict['future_symbol']
    operation.future_price = operation_dict['future_price']

    operation.spot = operation_dict['spot_symbol']
    operation.spot_price = operation_dict['spot_price']

    operation.direct_ratio = operation_dict['direct_ratio']

    operation.hours = operation_dict['hours']
    operation.hour_ratio = operation_dict['hour_ratio']

    operation.days = operation_dict['days']
    operation.year_ratio = operation_dict['year_ratio']

    operation.contract_size = operation_dict['contract_size']
    operation.contract_qty = operation_dict['contract_qty']
    operation.buy_per_contract = operation_dict['buy_per_contract']

    operation.tick_size = operation_dict['tick_size']
    operation.base_asset = operation_dict['base_asset']

    operation.state = operation_dict['state']

    operation.close_reason = operation_dict.get('close_reason')

    return operation
コード例 #4
0
def save_operation(operation_dict: Dict) -> int:
    try:
        with Session(engine) as session:
            with session.begin():

                operation_id = operation_dict.get('operation_id')

                if operation_id:
                    operation = session.query(
                        model.Operation).get(operation_id)
                else:
                    operation = model.Operation()
                    session.add(operation)

                operation = model_helper.sync_operation(
                    operation_dict, operation)

            operation_id = operation.id
    except Exception as ex:
        print(f"Error al guardar Operation = {operation_dict}")
        print(ex)
        traceback.print_stack()

    return operation_id
コード例 #5
0
def p_OperationRest(p):
    """OperationRest : ReturnType OptionalIdentifier "(" ArgumentList ")" ";"
  """
    p[0] = model.Operation(return_type=p[1], name=p[2], arguments=p[4])