Skip to content

Commit

Permalink
Merge pull request #7 from jhonabreul/refactor-subscription-validation
Browse files Browse the repository at this point in the history
Use Globals for credentials access for subscription validation
  • Loading branch information
jhonabreul authored Feb 21, 2024
2 parents 7fc7822 + ca51f6c commit d6b409b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions QuantConnect.RBI/RBIBrokerage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class RBIBrokerage : Brokerage
private readonly IOrderProvider _orderProvider;
private readonly IAlgorithm _algorithm;
private readonly LiveNodePacket _job;

private const string _orderEventMessage = "RBI OnOrderEvent";

public RBIBrokerage(
Expand All @@ -69,15 +69,15 @@ public RBIBrokerage(
_fixBrokerageController = new FixBrokerageController();
_fixBrokerageController.ExecutionReport += OnExecutionReport;
_fixBrokerageController.CancelReject += OnCancelReject;

var fixProtocolDirector = new FixMessageHandler(_fixBrokerageController, securityProvider, symbolMapper, config.Account, config.OnBehalfOfCompID);
_fixInstance = new FixInstance(fixProtocolDirector, config, logFixMessages);

_fixInstance.Error += (object? sender, FixError e) =>
{
OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Error, -1, e.Message));
};

ValidateSubscription();
}

Expand All @@ -87,7 +87,7 @@ public RBIBrokerage(
public override bool IsConnected => _fixInstance.IsConnected();

#region Brokerage

/// <summary>
/// Gets all open orders on the account.
/// NOTE: The order objects returned do not have QC order IDs.
Expand All @@ -97,7 +97,7 @@ public override List<Order> GetOpenOrders()
{
return new List<Order>();
}

/// <summary>
/// Gets all holdings for the account
/// </summary>
Expand All @@ -106,7 +106,7 @@ public override List<Holding> GetAccountHoldings()
{
return GetAccountHoldings(_job.BrokerageData, _algorithm.Securities.Values);
}

/// <summary>
/// Gets the current cash balance for each currency held in the brokerage account
/// </summary>
Expand All @@ -115,7 +115,7 @@ public override List<CashAmount> GetCashBalance()
{
return GetCashBalance(_job.BrokerageData, _algorithm.Portfolio.CashBook);
}

/// <summary>
/// Places a new order and assigns a new broker ID to the order
/// </summary>
Expand All @@ -130,7 +130,7 @@ public override bool PlaceOrder(Order order)
}
return _fixBrokerageController.PlaceOrder(order);
}

/// <summary>
/// Updates the order with the same id
/// </summary>
Expand All @@ -140,7 +140,7 @@ public override bool UpdateOrder(Order order)
{
return _fixBrokerageController.UpdateOrder(order);
}

/// <summary>
/// Cancels the order with the specified ID
/// </summary>
Expand All @@ -150,7 +150,7 @@ public override bool CancelOrder(Order order)
{
return _fixBrokerageController.CancelOrder(order);
}

/// <summary>
/// Connects the client to the broker's remote servers
/// </summary>
Expand Down Expand Up @@ -308,18 +308,18 @@ private void OnCancelReject(object sender, OrderCancelReject rejection)
Log.Trace($"RBIBrokerage.OnCancelReject(): Unexpected error {e.Message}");
}
}

/// <summary>
/// Validate the user of this project has permission to be using it via our web API.
/// </summary>
private void ValidateSubscription()
{
try
{
var productId = 297;
var userId = Config.GetInt("job-user-id");
var token = Config.Get("api-access-token");
var organizationId = Config.Get("job-organization-id", null);
const int productId = 297;
var userId = Globals.UserId;
var token = Globals.UserToken;
var organizationId = Globals.OrganizationID;
// Verify we can authenticate with this user and token
var api = new ApiConnection(userId, token);
if (!api.Connected)
Expand Down Expand Up @@ -438,7 +438,7 @@ private void ValidateSubscription()
Environment.Exit(1);
}
}

private class ModulesReadLicenseRead : Api.RestResponse
{
[JsonProperty(PropertyName = "license")]
Expand Down

0 comments on commit d6b409b

Please sign in to comment.