Having issues when paper accounts are made after 9 30 am

this is what im getting back for a account response

i expect something like
{“id”:“NNNNxxNX-NNxN-NNNN-Nxxx-xNxxNNNNxxNN”,“account_number”:“NNNNNNxxxx”,“status”:“ACTIVE”,“currency”:“USD”,“buying_power”:“2692.35”,“regt_buying_power”:“”,“daytrading_buying_power”:“”,“cash”:“2692.35”,“portfolio_value”:“”,“pattern_day_trader”:false,“trading_blocked”:false,“transfers_blocked”:false,“account_blocked”:false,“created_at”:“2019-09-01T00:00:00.000000Z”,“trade_suspended_by_user”:false,“multiplier”:“2”,“shorting_enabled”:false,“equity”:“2692.35”,“last_equity”:“2700.0000”,“long_market_value”:“12.06”,“short_market_value”:“0”,“initial_margin”:“12.06”,“maintenance_margin”:“12.06”,“last_maintenance_margin”:“0”,“sma”:“33.04”,“daytrade_count”:“0”}

but i get

{“message”:“forbidden.”}

PKDWFOTSKBOJARI9PEN5
DN9ikzaeQcfr6MHyDSW06qfuGEBVcPY20HDdFDrG

weird api responses

Update: it might be an error on my system if the api keys didn’t reset after the account was changed to new defaluts on alpaca, e.x. if it was using old api keys

new update: i tried my system on another account and it works fine so im not sure whos side this is on
{“id”:“607c6703-9cca-4a44-adda-80a78d95090d”,“admin_configurations”:{},“user_configurations”:null,“account_number”:“PA3PZIKOCKG6”,“status”:“ACTIVE”,“crypto_status”:“ACTIVE”,“options_approved_level”:2,“options_trading_level”:2,“currency”:“USD”,“buying_power”:“20000”,“regt_buying_power”:“20000”,“daytrading_buying_power”:“0”,“effective_buying_power”:“20000”,“non_marginable_buying_power”:“10000”,“options_buying_power”:“10000”,“bod_dtbp”:“0”,“cash”:“10000”,“accrued_fees”:“0”,“pending_transfer_in”:“0”,“portfolio_value”:“10000”,“pattern_day_trader”:false,“trading_blocked”:false,“transfers_blocked”:false,“account_blocked”:false,“created_at”:“2024-05-20T20:26:37.99521Z”,“trade_suspended_by_user”:false,“multiplier”:“2”,“shorting_enabled”:true,“equity”:“10000”,“last_equity”:“10000”,“long_market_value”:“0”,“short_market_value”:“0”,“position_market_value”:“0”,“initial_margin”:“0”,“maintenance_margin”:“0”,“last_maintenance_margin”:“0”,“sma”:“0”,“daytrade_count”:0,“balance_asof”:“2024-05-17”,“crypto_tier”:0,“intraday_adjustments”:“0”,“pending_reg_taf_fees”:“0”}

upon further inspection the account traded although it shouldn’t have, since there was only. one way commutation going to alpaca so the server couldn’t react to the trades correctly since there was no data sent back to my end


just wanted to tag you guys in on this since it looks like a bug
@Dan_Whitnable_Alpaca
@hitoshi

@kris The error “forbidden” when calling the account endpoint can only be one (or more) of four things

  1. incorrect API key
  2. incorrect API Secret Key
  3. incorrect base url (ie one must use https://paper-api.alpaca.markets when accessing a paper account and https://api.alpaca.markets for a live account)
  4. trying to access an old paper account which has been reset (using the old paper account keys).

Often, if storing keys in a OS system variable or file, these values may not be updated properly especially if one resets the paper account and simply edits the keys. One may need to restart the system to bring in the updated variables. For debugging and see if this is the issue, put a log or print statement immediately before the line of code where the trading client is instantiated to verify the keys which are being used. For example

print(API_KEY, SECRET_KEY)
trading_client = TradingClient(API_KEY, SECRET_KEY)

I would suggest verifying the API key and Secret key are correct and associated with the account you are expecting to work with.

thank you ill put keys in the log for if it happens again, it was the first time i reset a account around 9 33 am and seen that out come, im thinking it might just have been that the api keys never updated on my end

im not sure though how since the system would need the new api keys to send the order flow but on the off chance that im wrong, i think it was a key mix up but on the api side that makes the keys since the server did send trades and the account reflects that.

if i was to say from my input it kind of looks like its on your end

also api keys are stored in a file a like thus
with php

 		$ACC_SETING = "$WEB_DIR/API/ALPACA_TYPE.DATA"; // I was running the code on localhost, and hence the path!
	$api_acc_type = file_get_contents($ACC_SETING);

		$key_file = "$WEB_DIR/API/alpaca.KEY"; // I was running the code on localhost, and hence the path!
		$key_secret = "$WEB_DIR/API/alpaca.SECRET"; // I was running the code on localhost, and hence the path!
	$api_key = file_get_contents($key_file);
	$api_secret = file_get_contents($key_secret);

$mode = $_GET['save'];
if ($mode == "do"){
	
		$secret = $_POST['secret'];
		$SET_ACC_type = $_POST['type'];
		file_put_contents($ACC_SETING, $SET_ACC_type);
		
	file_put_contents($key_secret, $secret);
	$current = $_POST['key'];
	file_put_contents($key_file, $current);
	$api_key = file_get_contents($key_file);
	$api_secret = file_get_contents($key_secret);
	$api_acc_type = file_get_contents($ACC_SETING);

if the key was incorrect there would be no trades right??

also note there is no JNLC

@kris I’ll be the first person to say “anything can happen”, however the fetching accounts and submitting orders APIs are very solid. There are literally millions of accounts using those APIs every day without an issue. If you can recreate a specific issue it may be easier to debug.

ill give it a try tomorrow

ill re set this account

{“id”:“d88bf0d6-a3af-4228-af3b-4c716389b708”,“admin_configurations”:{},“user_configurations”:null,“account_number”:“PA31ZRLQF2P9”,“status”:“ACTIVE”,“crypto_status”:“ACTIVE”,“options_approved_level”:2,“options_trading_level”:2,“currency”:“USD”,“buying_power”:“5200”,“regt_buying_power”:“5200”,“daytrading_buying_power”:“0”,“effective_buying_power”:“5200”,“non_marginable_buying_power”:“2600”,“options_buying_power”:“2600”,“bod_dtbp”:“0”,“cash”:“2600”,“accrued_fees”:“0”,“pending_transfer_in”:“0”,“portfolio_value”:“2600”,“pattern_day_trader”:false,“trading_blocked”:false,“transfers_blocked”:false,“account_blocked”:false,“created_at”:“2024-05-12T23:09:52.102698Z”,“trade_suspended_by_user”:false,“multiplier”:“2”,“shorting_enabled”:true,“equity”:“2600”,“last_equity”:“2600”,“long_market_value”:“0”,“short_market_value”:“0”,“position_market_value”:“0”,“initial_margin”:“0”,“maintenance_margin”:“0”,“last_maintenance_margin”:“0”,“sma”:“2600”,“daytrade_count”:0,“balance_asof”:“2024-05-17”,“crypto_tier”:1,“intraday_adjustments”:“0”,“pending_reg_taf_fees”:“0”}

same time tomorrow and ill post the result.

1 Like

@kris One thing which you are probably aware but I do want to reiterate. Resetting an account creates a completely new account (which is why new API keys are required).

Additionally, when resetting an account, to the system it looks like the account was just opened (exactly as in live trading). The first day an account is opened it will not have any day trading buying power. This is because day trade buying power is calculated from the previous end of day equity. Since the previous end of day equity was $0 the day trade buying power will be $0.

status update: untested ill keep you posted

ill be running the test today, ill keep you posted est 9 33 - 9 34

update: unrelated to alpaca

@kris Glad you seemed to have gotten it resolved!

Update the same account reset at 9 30 am was re set last night at 11:30 pm and today at 7AM account balance information looks to be incorrect at the moment


{“id”:“ea3c6d0f-a244-4345-a086-93705093dfa5”,“admin_configurations”:{},“user_configurations”:null,“account_number”:“PA3E2SDQZ79Y”,“status”:“ACTIVE”,“crypto_status”:“ACTIVE”,“options_approved_level”:2,“options_trading_level”:2,“currency”:“USD”,“buying_power”:“0”,“regt_buying_power”:“0”,“daytrading_buying_power”:“0”,“effective_buying_power”:“0”,“non_marginable_buying_power”:“0”,“options_buying_power”:“0”,“bod_dtbp”:“0”,“cash”:“0”,“accrued_fees”:“0”,“pending_transfer_in”:“0”,“portfolio_value”:“0”,“pattern_day_trader”:false,“trading_blocked”:false,“transfers_blocked”:false,“account_blocked”:false,“created_at”:“2024-05-23T03:26:33.074323Z”,“trade_suspended_by_user”:false,“multiplier”:“1”,“shorting_enabled”:false,“equity”:“0”,“last_equity”:“0”,“long_market_value”:“0”,“short_market_value”:“0”,“position_market_value”:“0”,“initial_margin”:“0”,“maintenance_margin”:“0”,“last_maintenance_margin”:“0”,“sma”:“0”,“daytrade_count”:0,“balance_asof”:“2024-05-22”,“crypto_tier”:1,“intraday_adjustments”:“0”,“pending_reg_taf_fees”:“0”}

“buying_power”:“0”
“equity”:“0”
it was reset just last night

@kris The first issue to get straightened out is the screenshot is for account PA3W92QHU6G5 however the account data is for account PA3E2SDQZ79Y. Could that be the discrepancy you are seeing?

no its 2 issues
1 the api key seems to change twice after it is reset but access to the old one still gives wright access to send orders but wont send account info in the api i get null for bp and null for e this only happens some times as the api keys are set up on the server after the balance has been reset not sure why

2 when the buying power is set the account resets itsleff to $0.00 again not sure why

@kris You stated “the api key seems to change twice after it is reset”. What are you observing which makes you feel that is the case. Immediately when a paper account is reset, the new account api keys are null. They only get set if and when the user regenerates them from the dashboard.

Not sure what you mean by “when the buying power is set”. Do you mean when resetting an account to a specific initial equity? If that’s the case, then after resetting an account, as mentioned above, the first day an account is opened it will not have any day trading buying power. This is because day trade buying power is calculated from the previous end of day equity. Since the previous end of day equity was $0 the day trade buying power will be $0. Is that the question?

oh my god yes I’ve been trying to finger this out

now the thing is i reset the equity to i think to 2500 but it reset it self again after this morning back to $0 om not sure why

i had to reset it after to get it working

this might have to do with when the previous end of day equity is calculated and when the account is reset
some times im doing this at 1 am (resetting the account)

@kris If you see equity in a paper account drop to $0 it is most likely that you are looking at an ‘old’ account. When resetting an account, the original “old” account may still exist for awhile though ultimately one will get a “forbidden” error as old accounts are deleted. Ensure you are using the most up to date keys for the most recent reset of the account.

@Dan_Whitnable_Alpaca look at the image, i would think that the keys dont change after i reset then click the generate keys button, therefore it cant be related to me.

also on keys that get a response from alpaca of forbidden some how alpaca is taking (buy / sell) orders with the keys if you look above

trust me id rather the bug be on my end so i can fix it…

no i test on more then one account at the moment i was testing on 2 different ones

i try to ignore back handed comments like this, but think about it for a moment, im only asking for help.