Closed mikazlopes closed 7 years ago
I frequently run the tests with a funded account and they don't execute real trades.
The way it works is that with the USE_REAL_MONEY
environment variable set to anything other than YES
I hit the accounts/:id/orders/preview
endpoint instead of accounts/:id/orders
.
From the TradeKing documentation:
This call will allow you to preview an order prior to actually placing it. This does not place the order.
As an additional precaution you'll notice that any test which may execute an order fails early if the USE_REAL_MONEY
flag is set.
You can search the logs for TradeKing request
and check the URL to verify which endpoint you were hitting.
I confirm what @mikazlopes is reporting.
I believe the variable trading.USE_REAL_MONEY
is set to False
after you export the env. var. Hence, the statement:
assert not USE_REAL_MONEY
in the test test_make_order_request_success
will go through, and hence proceed to the next assertion.
def test_make_order_request_success(trading):
assert not USE_REAL_MONEY
> assert trading.make_order_request((
'<FIXML xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2">'
'<Order TmInForce="0" Typ="2" Side="1" Px="38.32" Acct="%s">'
'<Instrmt SecTyp="CS" Sym="GM"/>'
'<OrdQty Qty="23"/>'
'</Order>'
'</FIXML>' % TRADEKING_ACCOUNT_NUMBER))
Could you elaborate where I can find the logs? I don't see any logs written with the pytest reported by @mikazlopes .
Hi,
I actually ran a test with funds in the account and confirm that it just simulates the transaction of buying GM stock. The API call from @maxbbraun is correct.
I was testing the application and ran the Pytest. Only 2 test fail which is the test_get_balance and the test_make_order_request_success. It's normal because I don't have balance in my trade king account. What worries me is that on the order status dashboard in Tradeking is showing the multiple requests exactly with the same timestamp I ran the Pytest:
Buy 23 GM GENERAL MOTORS CO. Market 37.24 37.24 Day 02/14/17 4:17 PM ET SVR-6031544108 Rejected You have not funded your account yet. Please go to the Transfer Money tab to get started funding your account.
I made sure that I ran
export USE_REAL_MONEY=NO && pytest *.py --verbose
. Even checked through printenv that the variable was set to "NO".My concern is that if I did had balance in the Tradeking account the order would have been accepted. I looked in the code and it does seem to check if USE_REAL_MONEY is YES or NO, but it seems it's trading with real funds independently.