areed1192 / python-trading-robot

A trading robot, that can submit basic orders in an automated fashion using the TD API.
MIT License
535 stars 312 forks source link

get_positions returns same equity for each #4

Closed tmcquaig closed 4 years ago

tmcquaig commented 4 years ago

Bot connected etc first print gives me specified account information. Second print gives me 20 entries for the same equity instead of the 20 different equity positions in the account.

Code:

trading_robot_accounts = trading_robot.get_accounts(account_number=ACCOUNT)

pprint.pprint(trading_robot_accounts)

trading_robot_positions = trading_robot.get_positions(account_number=ACCOUNT)

pprint.pprint(trading_robot_positions)

OUTPUT: [{'account_number': '123', 'account_type': 'MARGIN', 'available_funds': 11.31, 'buying_power': 122.62, 'cash_available_for_trading': 0.0, 'cash_available_for_withdrawl': 0.0, 'cash_balance': 0.0, 'day_trading_buying_power': 0.0, 'long_market_value': 113.05, 'maintenance_call': 0.0, 'maintenance_requirement': 365.92, 'short_balance': 0.0, 'short_margin_value': 0.0, 'short_market_value': 0.0}] [{'account_number': '123', 'asset_type': 'EQUITY', 'average_price': 125.51974, 'current_day_profit_loss': 54.723030000001, 'current_day_profit_loss_percentage': 0.57, 'cusip': '123', 'description': '', 'long_quantity': 43.089, 'market_value': 91.16, 'settled_long_quantity': 43.089, 'settled_short_quantity': 0.0, 'short_quantity': 0.0, 'sub_asset_type': '', 'symbol': 'VUG', 'type': ''}, {'account_number': '123',

It continues but I cut it there.

charleswwilson commented 4 years ago

If you look at the pull request I put in you can see I was having the same issue. I came up with a work around for it that I posted there but I don't think he has reviewed it yet.

tmcquaig commented 4 years ago

If you look at the pull request I put in you can see I was having the same issue. I came up with a work around for it that I posted there but I don't think he has reviewed it yet.

I have tested this and it works. The for loop correctly advances through all of the positions.

Thank you!

charleswwilson commented 4 years ago

Your welcome I'm happy it worked for you too.

areed1192 commented 4 years ago

Fix has been integrated, closing this issue.

aminegg commented 1 year ago

PLEASE DEAR ALEX HOW CAN I WRITE THE CODE SOO THE BOT CAN PLACE A BUY AND SELL TRADE AT THE SAME TIME WITH A 4 PIPS STOP LOSS IN PYTHON TNX UU IN ADVANCE

aminegg commented 1 year ago

HEY ALEX I REALLY LOVED WATCHING YOUR VIDEOS ON YOUTUBE THEY ARE VERY EDUCATIVE BUT I HAVE A QUESTION FOR U HOW CAN REPROGRAMMED MY BOT TO EXIT A TRADE ONCE PRICE REACH 4 PIPS STOP LOSS I REALLY APPRECIATE THE HELP