def accounts_account_id_orders_order_id_get(accountId, orderId):  # noqa: E501
    """accounts_account_id_orders_order_id_get

    Get an order for an account. It can be an active or historical order. # noqa: E501

    :param accountId: The account identifier.
    :type accountId: str
    :param orderId: Order ID.
    :type orderId: str

    :rtype: InlineResponse2006
    """
    splits = orderId.split(':', 1)
    ecn = splits[0]
    id_ = splits[1]

    try:
        gwy = getGateway(ecn)
    except NoSuchEcnError as e:
        return InlineResponse2006(Status.ERROR, e.msg)
    gwy.establishSession()

    order = gwy.getOrder(accountId, id_)
    if order:
        return InlineResponse2006(Status.OK, None, order)
    else:
        return InlineResponse2006(Status.ERROR,
                                  'Failed to get order - ' + orderId)
def accounts_account_id_orders_order_id_delete(accountId,
                                               orderId):  # noqa: E501
    """accounts_account_id_orders_order_id_delete

    Cancel an existing order. # noqa: E501

    :param accountId: The account identifier.
    :type accountId: str
    :param orderId: Order ID.
    :type orderId: str

    :rtype: InlineResponse2007
    """
    splits = orderId.split(':', 1)
    ecn = splits[0]
    id_ = splits[1]

    try:
        gwy = getGateway(ecn)
    except NoSuchEcnError as e:
        return InlineResponse2007(Status.ERROR, e.msg)
    gwy.establishSession()

    cancelled = gwy.cancelOrder(accountId, id_)
    if cancelled:
        return InlineResponse2007(Status.OK, None)
    else:
        return InlineResponse2007(Status.ERROR,
                                  'Failed to cancel order - ' + orderId)
def accounts_account_id_orders_order_id_put(
        accountId,
        orderId,
        qty,
        limitPrice=None,
        stopPrice=None,
        stopLoss=None,
        takeProfit=None,
        digitalSignature=None):  # noqa: E501
    """accounts_account_id_orders_order_id_put

    Modify an existing order. # noqa: E501

    :param accountId: The account identifier.
    :type accountId: str
    :param orderId: Order ID.
    :type orderId: str
    :param qty: Number of units.
    :type qty: 
    :param limitPrice: Limit Price for Limit or StopLimit order.
    :type limitPrice: 
    :param stopPrice: Stop Price for Stop or StopLimit order.
    :type stopPrice: 
    :param stopLoss: StopLoss price (if supported).
    :type stopLoss: 
    :param takeProfit: TakeProfit price (if supported).
    :type takeProfit: 
    :param digitalSignature: Digital signature (if supported).
    :type digitalSignature: str

    :rtype: InlineResponse2007
    """
    splits = orderId.split(':', 1)
    ecn = splits[0]
    id_ = splits[1]

    try:
        gwy = getGateway(ecn)
    except NoSuchEcnError as e:
        return InlineResponse2007(Status.ERROR, e.msg)
    gwy.establishSession()

    modified = gwy.modifyOrder(accountId, id_, qty, limitPrice, stopPrice,
                               stopLoss, takeProfit, digitalSignature)
    if modified:
        return InlineResponse2007(Status.OK, None)
    else:
        return InlineResponse2007(Status.ERROR,
                                  'Failed to modify order - ' + orderId)
Пример #4
0
 def test_getGateway(self):
     x = getGateway('Binance')
     self.assertTrue(isinstance(x, BinanceGwy))
Пример #5
0
 def test_getGateway_SameInstance(self):
     x = getGateway('Binance')
     y = getGateway('Binance')
     self.assertIs(x, y)
Пример #6
0
 def test_getGateway_NoSuchECN(self):
     with self.assertRaises(NoSuchEcnError) as cm:
         getGateway('Nonsense')
     self.assertEqual(cm.exception.msg,
                      'No such gateway for ecn : Nonsense')
def accounts_account_id_orders_post(accountId,
                                    instrument,
                                    qty,
                                    side,
                                    type,
                                    limitPrice=None,
                                    stopPrice=None,
                                    durationType=None,
                                    durationDateTime=None,
                                    stopLoss=None,
                                    takeProfit=None,
                                    digitalSignature=None,
                                    requestId=None):  # noqa: E501
    """accounts_account_id_orders_post

    Create a new order. # noqa: E501

    :param accountId: The account identifier.
    :type accountId: str
    :param instrument: Instrument to open the order on.
    :type instrument: str
    :param qty: The number of units to open order for.
    :type qty: 
    :param side: Side. Possible values – `buy` and `sell`.
    :type side: str
    :param type: Type. Possible values – `market`, `stop`, `limit`, `stoplimit`.
    :type type: str
    :param limitPrice: Limit Price for Limit or StopLimit order.
    :type limitPrice: 
    :param stopPrice: Stop Price for Stop or StopLimit order.
    :type stopPrice: 
    :param durationType: Duration ID (if supported).
    :type durationType: str
    :param durationDateTime: Expiration datetime UNIX timestamp (if supported by duration type).
    :type durationDateTime: 
    :param stopLoss: StopLoss price (if supported).
    :type stopLoss: 
    :param takeProfit: TakeProfit price (if supported).
    :type takeProfit: 
    :param digitalSignature: Digital signature (if supported).
    :type digitalSignature: str
    :param requestId: Unique identifier for a request.
    :type requestId: str

    :rtype: InlineResponse2005
    """
    splits = instrument.split(':', 1)
    ecn = splits[0]
    inst = splits[1]

    try:
        gwy = getGateway(ecn)
    except NoSuchEcnError as e:
        return InlineResponse2005(Status.ERROR, e.msg)
    gwy.establishSession()

    try:
        orderId = gwy.createOrder(accountId, inst, qty, side, type, limitPrice,
                                  stopPrice, durationType, durationDateTime,
                                  stopLoss, takeProfit, digitalSignature,
                                  requestId)
    except AccountPermissionError as e:
        return InlineResponse2005(Status.ERROR, e.msg)

    return InlineResponse2005(Status.OK, None, InlineResponse2005D(orderId))