@@ -34,25 +34,33 @@ async def main_stream():
3434
3535 stream_client .stop ()
3636
37+
3738def main ():
3839 client = APIClient () # Initialize the API client
3940 accounts_api = Accounts (client )
4041 orders_api = Orders (client )
4142
4243 # Get account numbers for linked accounts
43- # print(accounts_api.get_account_numbers()) # working
44+ client .account_numbers = accounts_api .get_account_numbers () # working
45+ print (client .account_numbers )
4446
4547 # Get positions for linked accounts
46- # print(accounts_api.get_all_accounts()) # working
48+ print (accounts_api .get_all_accounts ()) # working
4749
48- sample_account = client .account_numbers [0 ]
49- account_hash = sample_account ['accountHash' ]
50+ sample_account = client .account_numbers [0 ] # working
51+ print (sample_account )
52+ account_hash = sample_account ['hashValue' ] # working
53+ print (account_hash )
5054
5155 # Get specific account positions
52- # print(accounts_api.get_account(fields="positions"))
56+ print (accounts_api .get_account (account_hash = account_hash , fields = "positions" ))
5357
5458 # Get up to 3000 orders for an account for the past week
55- print (orders_api .get_orders (3000 , datetime .now () - timedelta (days = 7 ), datetime .now ()).json ())
59+ print (orders_api .get_orders (account_hash = account_hash ,
60+ max_results = 3000 ,
61+ from_entered_time = datetime .now () - timedelta (days = 7 ),
62+ to_entered_time = datetime .now ())
63+ )
5664
5765 # Example to place an order (commented out for safety)
5866 """
@@ -75,11 +83,16 @@ def main():
7583 # print(orders_api.get_order('account_hash', order_id).json())
7684
7785 # Get up to 3000 orders for all accounts for the past week
78- print (orders_api .get_orders (account_hash = account_hash , max_results = 3000 , from_entered_time = datetime .now () - timedelta (days = 7 ), to_entered_time = datetime .now ()))
86+ for account in client .account_numbers :
87+ account_hash = account ['hashValue' ]
88+ print (orders_api .get_orders (account_hash = account_hash , max_results = 3000 , from_entered_time = datetime .now () - timedelta (days = 7 ), to_entered_time = datetime .now ()))
7989
8090 # Get all transactions for an account
81- print (accounts_api .get_account_transactions ('account_hash' , datetime .now () - timedelta (days = 7 ), datetime .now (),
82- "TRADE" ).json ())
91+ print (accounts_api .get_account_transactions (account_hash = account_hash ,
92+ start_date = datetime .now () - timedelta (days = 7 ),
93+ end_date = datetime .now (),
94+ types = "TRADE" )
95+ )
8396
8497 # Market-data-related requests
8598 quotes = Quotes (client )
@@ -98,6 +111,9 @@ def main():
98111 # Get an option expiration chain
99112 print (options .get_chains ("AAPL" ).json ())
100113
114+ # Get price history for a symbol
115+ print (price_history .by_symbol ("AAPL" , period_type = "day" , period = 1 , frequency_type = "minute" , frequency = 5 ).json ())
116+
101117 # Get movers for an index
102118 print (movers .get_movers ("$DJI" ).json ())
103119
@@ -117,6 +133,6 @@ def main():
117133if __name__ == '__main__' :
118134 print ("Welcome to the unofficial Schwab API interface!\n "
119135 "GitHub: https://github.com/Patch-Code-Prosperity/Pythonic-Schwab-API" )
120- loop = get_event_loop ()
121- loop .run_until_complete (main_stream ())
122- # main()
136+ # loop = get_event_loop()
137+ # loop.run_until_complete(main_stream())
138+ main ()
0 commit comments