Skip to content

Commit 43b4240

Browse files
committed
feature: add bloomberg fix brokerage model
- supports Equity, Option, Future - Market, Limit, StopMarket, StopLimit order types - margin-only account type
1 parent 9046162 commit 43b4240

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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.Orders;
19+
using QuantConnect.Securities;
20+
21+
namespace QuantConnect.Brokerages
22+
{
23+
/// <summary>
24+
/// Provides Bloomberg FixNet HUB specific properties.
25+
/// </summary>
26+
public class BloombergFixBrokerageModel : DefaultBrokerageModel
27+
{
28+
private readonly HashSet<SecurityType> _supportedSecurityTypes = new()
29+
{
30+
SecurityType.Equity,
31+
SecurityType.Option,
32+
SecurityType.Future,
33+
};
34+
35+
private readonly HashSet<OrderType> _supportedOrderTypes = new()
36+
{
37+
OrderType.Market,
38+
OrderType.Limit,
39+
OrderType.StopMarket,
40+
OrderType.StopLimit,
41+
};
42+
43+
/// <summary>
44+
/// Constructor for Bloomberg FIX brokerage model.
45+
/// </summary>
46+
/// <param name="accountType">Cash or Margin</param>
47+
public BloombergFixBrokerageModel(AccountType accountType = AccountType.Margin) : base(accountType)
48+
{
49+
if (accountType == AccountType.Cash)
50+
{
51+
throw new NotSupportedException($"Bloomberg FIX brokerage can only be used with a {AccountType.Margin} account type");
52+
}
53+
}
54+
55+
/// <summary>
56+
/// Returns true if the brokerage could accept this order.
57+
/// </summary>
58+
/// <param name="security">The security of the order</param>
59+
/// <param name="order">The order to be processed</param>
60+
/// <param name="message">If this function returns false, a brokerage message detailing why the order may not be submitted</param>
61+
public override bool CanSubmitOrder(Security security, Order order, out BrokerageMessageEvent message)
62+
{
63+
if (!_supportedSecurityTypes.Contains(security.Type))
64+
{
65+
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
66+
Messages.DefaultBrokerageModel.UnsupportedSecurityType(this, security));
67+
return false;
68+
}
69+
70+
if (!_supportedOrderTypes.Contains(order.Type))
71+
{
72+
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
73+
Messages.DefaultBrokerageModel.UnsupportedOrderType(this, order, _supportedOrderTypes));
74+
return false;
75+
}
76+
77+
if (order.AbsoluteQuantity % 1 != 0)
78+
{
79+
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
80+
$"Order Quantity must be Integer, but provided {order.AbsoluteQuantity}.");
81+
return false;
82+
}
83+
84+
return base.CanSubmitOrder(security, order, out message);
85+
}
86+
87+
/// <summary>
88+
/// Bloomberg FixNet HUB supports cancel/replace (35=G) on order quantity, price, stop price,
89+
/// order type and time in force.
90+
/// </summary>
91+
public override bool CanUpdateOrder(Security security, Order order, UpdateOrderRequest request, out BrokerageMessageEvent message)
92+
{
93+
message = null;
94+
return true;
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)