Lean
$LEAN_TAG$
IBrokerage.cs
1
/*
2
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
16
using
System;
17
using
System.Collections.Generic;
18
using
QuantConnect
.
Brokerages
;
19
using
QuantConnect
.
Data
;
20
using
QuantConnect
.
Orders
;
21
using
QuantConnect
.
Securities
;
22
23
namespace
QuantConnect.Interfaces
24
{
25
/// <summary>
26
/// Brokerage interface that defines the operations all brokerages must implement. The IBrokerage implementation
27
/// must have a matching IBrokerageFactory implementation.
28
/// </summary>
29
public
interface
IBrokerage
:
IBrokerageCashSynchronizer
, IDisposable
30
{
31
/// <summary>
32
/// Event that fires each time the brokerage order id changes
33
/// </summary>
34
event
EventHandler<BrokerageOrderIdChangedEvent>
OrderIdChanged
;
35
36
/// <summary>
37
/// Event that fires each time the status for a list of orders change
38
/// </summary>
39
event
EventHandler<List<OrderEvent>>
OrdersStatusChanged
;
40
41
/// <summary>
42
/// Event that fires each time an order is updated in the brokerage side
43
/// </summary>
44
/// <remarks>
45
/// These are not status changes but mainly price changes, like the stop price of a trailing stop order
46
/// </remarks>
47
event
EventHandler<OrderUpdateEvent>
OrderUpdated
;
48
49
/// <summary>
50
/// Event that fires each time a short option position is assigned
51
/// </summary>
52
event
EventHandler<OrderEvent>
OptionPositionAssigned
;
53
54
/// <summary>
55
/// Event that fires each time an option position has changed
56
/// </summary>
57
event
EventHandler<OptionNotificationEventArgs>
OptionNotification
;
58
59
/// <summary>
60
/// Event that fires each time there's a brokerage side generated order
61
/// </summary>
62
event
EventHandler<NewBrokerageOrderNotificationEventArgs>
NewBrokerageOrderNotification
;
63
64
/// <summary>
65
/// Event that fires each time a delisting occurs
66
/// </summary>
67
/// <remarks>TODO: Wire brokerages to call this event to process delistings</remarks>
68
event
EventHandler<DelistingNotificationEventArgs>
DelistingNotification
;
69
70
/// <summary>
71
/// Event that fires each time a user's brokerage account is changed
72
/// </summary>
73
event
EventHandler<AccountEvent>
AccountChanged
;
74
75
/// <summary>
76
/// Event that fires when a message is received from the brokerage
77
/// </summary>
78
event
EventHandler<BrokerageMessageEvent>
Message
;
79
80
/// <summary>
81
/// Gets the name of the brokerage
82
/// </summary>
83
string
Name
{
get
; }
84
85
/// <summary>
86
/// Returns true if we're currently connected to the broker
87
/// </summary>
88
bool
IsConnected
{
get
; }
89
90
/// <summary>
91
/// Gets all open orders on the account
92
/// </summary>
93
/// <returns>The open orders returned from IB</returns>
94
List<Order>
GetOpenOrders
();
95
96
/// <summary>
97
/// Gets all holdings for the account
98
/// </summary>
99
/// <returns>The current holdings from the account</returns>
100
List<Holding>
GetAccountHoldings
();
101
102
/// <summary>
103
/// Gets the current cash balance for each currency held in the brokerage account
104
/// </summary>
105
/// <returns>The current cash balance for each currency available for trading</returns>
106
List<CashAmount>
GetCashBalance
();
107
108
/// <summary>
109
/// Places a new order and assigns a new broker ID to the order
110
/// </summary>
111
/// <param name="order">The order to be placed</param>
112
/// <returns>True if the request for a new order has been placed, false otherwise</returns>
113
bool
PlaceOrder
(
Order
order);
114
115
/// <summary>
116
/// Updates the order with the same id
117
/// </summary>
118
/// <param name="order">The new order information</param>
119
/// <returns>True if the request was made for the order to be updated, false otherwise</returns>
120
bool
UpdateOrder
(
Order
order);
121
122
/// <summary>
123
/// Cancels the order with the specified ID
124
/// </summary>
125
/// <param name="order">The order to cancel</param>
126
/// <returns>True if the request was made for the order to be canceled, false otherwise</returns>
127
bool
CancelOrder
(
Order
order);
128
129
/// <summary>
130
/// Connects the client to the broker's remote servers
131
/// </summary>
132
void
Connect
();
133
134
/// <summary>
135
/// Disconnects the client from the broker's remote servers
136
/// </summary>
137
void
Disconnect
();
138
139
/// <summary>
140
/// Specifies whether the brokerage will instantly update account balances
141
/// </summary>
142
bool
AccountInstantlyUpdated
{
get
; }
143
144
/// <summary>
145
/// Returns the brokerage account's base currency
146
/// </summary>
147
string
AccountBaseCurrency
{
get
; }
148
149
/// <summary>
150
/// Gets the history for the requested security
151
/// </summary>
152
/// <param name="request">The historical data request</param>
153
/// <returns>An enumerable of bars covering the span specified in the request</returns>
154
IEnumerable<BaseData>
GetHistory
(
HistoryRequest
request);
155
}
156
}
Common
Interfaces
IBrokerage.cs
Generated by
1.8.17