forked from MaxxRK/firstrade-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
73 lines (60 loc) · 2.06 KB
/
test.py
File metadata and controls
73 lines (60 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from firstrade import account, order, symbols
from firstrade.order import get_orders
# Create a session
ft_ss = account.FTSession(username="", password="", pin="")
# Get account data
ft_accounts = account.FTAccountData(ft_ss)
if len(ft_accounts.account_numbers) < 1:
raise Exception("No accounts found or an error occured exiting...")
# Print ALL account data
print(ft_accounts.all_accounts)
# Print 1st account number.
print(ft_accounts.account_numbers[0])
# Print ALL accounts market values.
print(ft_accounts.account_balances)
# Get quote for INTC
quote = symbols.SymbolQuote(ft_ss, "INTC")
print(f"Symbol: {quote.symbol}")
print(f"Exchange: {quote.exchange}")
print(f"Bid: {quote.bid}")
print(f"Ask: {quote.ask}")
print(f"Last: {quote.last}")
print(f"Change: {quote.change}")
print(f"High: {quote.high}")
print(f"Low: {quote.low}")
print(f"Volume: {quote.volume}")
print(f"Company Name: {quote.company_name}")
# Get positions and print them out for an account.
positions = ft_accounts.get_positions(account=ft_accounts.account_numbers[1])
for key in ft_accounts.securities_held:
print(
f"Quantity {ft_accounts.securities_held[key]['quantity']} of security {key} held in account {ft_accounts.account_numbers[1]}"
)
# Create an order object.
ft_order = order.Order(ft_ss)
# Place order and print out order confirmation data.
ft_order.place_order(
ft_accounts.account_numbers[0],
symbol="INTC",
price_type=order.PriceType.MARKET,
order_type=order.OrderType.BUY,
quantity=1,
duration=order.Duration.DAY,
dry_run=True,
)
# Print Order data Dict
print(ft_order.order_confirmation)
# Check if order was successful
if ft_order.order_confirmation["success"] == "Yes":
print("Order placed successfully.")
# Print Order ID
print(f"Order ID: {ft_order.order_confirmation['orderid']}.")
else:
print("Failed to place order.")
# Print errormessage
print(ft_order.order_confirmation["actiondata"])
# Check orders
current_orders = get_orders(ft_ss, ft_accounts.account_numbers[0])
print(current_orders)
# Delete cookies
ft_ss.delete_cookies()