Example #1
0
    def test__order_replace(self, mock_get):
        """test replacing an order."""
        orderID = "2125"
        # to replace with
        tmp = {
            "order": {
                "units": "-50000",
                "type": "LIMIT",
                "instrument": "EUR_USD",
                "price": "1.25",
            }
        }

        uri = 'https://test.com/v3/accounts/{}/orders/{}'.format(
            accountID, orderID)
        resp = responses["_v3_accounts_accountID_order_replace"]['response']
        text = json.dumps(resp)
        r = orders.OrderReplace(accountID, orderID, data=tmp)
        mock_get.register_uri('PUT',
                              uri,
                              text=text,
                              status_code=r._expected_status)
        result = api.request(r)
        self.assertTrue(
            len(result['orders']) == 1
            and result['orders'][0]['units'] == tmp["order"]["units"])
Example #2
0
    def test__order_replace_wrong_status_exception(self, mock_get):
        """test replacing an order with success but wrong status_code."""
        orderID = "2125"
        # to replace with
        tmp = {
            "order": {
                "units": "-50000",
                "type": "LIMIT",
                "instrument": "EUR_USD",
                "price": "1.25",
            }
        }

        uri = 'https://test.com/v3/accounts/{}/orders/{}'.format(
            accountID, orderID)
        resp = responses["_v3_accounts_accountID_order_replace"]['response']
        text = json.dumps(resp)
        r = orders.OrderReplace(accountID, orderID, data=tmp)
        # force the wrong status code
        mock_get.register_uri('PUT', uri, text=text, status_code=200)
        with self.assertRaises(ValueError) as err:
            result = api.request(r)

        self.assertTrue("200" in "{}".format(err.exception)
                        and r.status_code is None)
Example #3
0
def amend_order(order, price=None, units=None):
    if price is None:
        price = order['price']
    if units is None:
        units = order['units']
    data = {
        "order": {
            "price": "{0:.5f}".format(price),
            "units": units,
            "type": order['type'],
            "timeInForce": order['timeInForce'],
            "instrument": order['instrument']
        }
    }

    r = orders.OrderReplace(account_id, order['id'], data)
    client.request(r)

    return r.response
Example #4
0
 def test__order_replace(self, mock_put):
     """replace an order."""
     orderID = "2304"
     # to replace with data
     tid = "_v3_accounts_accountID_order_replace"
     resp, data = fetchTestData(responses, tid)
     r = orders.OrderReplace(accountID, orderID, data=data)
     mock_put.register_uri('PUT',
                           "{}/{}".format(api.api_url, r),
                           text=json.dumps(resp),
                           status_code=r.expected_status)
     result = api.request(r)
     self.assertTrue(
       "orderCreateTransaction" in result and
       "orderCancelTransaction" in result and
       result["orderCancelTransaction"]["orderID"] == orderID and
       result["orderCreateTransaction"]["replacesOrderID"] == orderID and
       result["orderCreateTransaction"]["units"] ==
       data["order"]['units'] and
       result["orderCreateTransaction"]["price"] ==
       data["order"]['price'])
Example #5
0
single_order_details = r.response
print(single_order_details)
"""
# 5 Replace an Order in an Account by simultaneously cancelling it and creating a replacement Order.
"""
replacement_order_data = {
    "order": {
        "units": "-500000",
        "instrument": "EUR_USD",
        "price": "1.25000",
        "type": "LIMIT"
    }
}

r = orders.OrderReplace(accountID=accountID,
                        orderID=last_order_id,
                        data=replacement_order_data)
client.request(r)
print(r.response)

# store lastTransactionID here because it will be used below for cancellation
last_order_id = r.response['lastTransactionID']
"""
# 6 Cancel a pending Order in an Account.
"""
client.request(r)
r = orders.OrderCancel(accountID=accountID,
                       orderID=last_order_id)  # taken from above
print(r.response)
"""
# 7 Execute A Market Order
Example #6
0
def OrdersOrderReplace(access_token, accountID, orderID, data=None):
    'Replace an Order in an Account by simultaneously cancelling it and creating a replacement Order.'
    r = orders.OrderReplace(accountID=accountID, orderID=orderID, data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)