-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathuse_alerts.py
More file actions
91 lines (72 loc) · 2.78 KB
/
Copy pathuse_alerts.py
File metadata and controls
91 lines (72 loc) · 2.78 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Example usage of the Alerts service."""
from configparser import ConfigParser
from pprint import pprint
from ibc.client import InteractiveBrokersClient
config = ConfigParser()
config.read('config/config.ini')
account_number = config.get('interactive_brokers_paper', 'paper_account')
ibc_client = InteractiveBrokersClient(
account_number=account_number,
)
ibc_client.authentication.wait_for_login()
alerts_service = ibc_client.alerts
# ---------------------------------------------------------------------------
# Get all available alerts for the account.
# ---------------------------------------------------------------------------
pprint(alerts_service.available_alerts(account_id=ibc_client.account_number))
# Output: [{'alert_id': 12345, 'alert_name': 'Price Alert', ...}]
# ---------------------------------------------------------------------------
# Get MTA (Mobile Trading Assistant) alerts.
# ---------------------------------------------------------------------------
pprint(alerts_service.mta_alerts())
# Output: [{'alert_id': ..., 'alert_name': '...', ...}]
# ---------------------------------------------------------------------------
# Create or modify an alert.
# ---------------------------------------------------------------------------
alert_body = {
'alertName': 'Price Alert',
'alertMessage': 'AAPL crossed 150',
'outsideRth': 1,
'conditions': [
{
'type': 1,
'conidex': '265598',
'operator': '>=',
'triggerMethod': '0',
'value': '150'
}
]
}
pprint(
alerts_service.create_or_modify_alert(
account_id=ibc_client.account_number,
alert=alert_body
)
)
# Output: {'request_id': 123, 'order_id': 456, 'success': True}
# ---------------------------------------------------------------------------
# Activate or deactivate an alert.
# ---------------------------------------------------------------------------
pprint(
alerts_service.activate_alert(
account_id=ibc_client.account_number,
alert_id='12345',
activate=True
)
)
# Output: {'request_id': 123, 'order_id': 456, 'success': True}
# ---------------------------------------------------------------------------
# Get alert details.
# ---------------------------------------------------------------------------
pprint(alerts_service.alert_details(alert_id='12345'))
# Output: {'alert_id': 12345, 'alert_name': 'Price Alert', 'conditions': [...]}
# ---------------------------------------------------------------------------
# Delete an alert.
# ---------------------------------------------------------------------------
pprint(
alerts_service.delete_alert(
account_id=ibc_client.account_number,
alert_id='12345'
)
)
# Output: {'request_id': 123, 'order_id': 456, 'success': True}