public OrderGraphType( IFinancialInstrumentRepository instrumentsRepository, IMarketRepository marketRepository, IBrokerRepository brokerRepository, IOrderRepository orderRepository, IDataLoaderContextAccessor dataLoader) { this.AuthorizeWith(PolicyManifest.UserPolicy); this.Field(i => i.Id).Description("Primary key"); this.Field <MarketGraphType>( "market", "Market associated with the order", resolve: context => { var loader = dataLoader.Context.GetOrAddLoader( $"GetMarketById-{context.Source.MarketId}", async() => await marketRepository.GetById(context.Source.MarketId)); return(loader.LoadAsync()); }); this.Field <BrokerGraphType>( "broker", "Broker", resolve: context => { var loader = dataLoader.Context.GetOrAddLoader( $"GetBrokerById-{context.Source.BrokerId}", async() => await brokerRepository.GetById(context.Source.BrokerId)); return(loader.LoadAsync()); }); this.Field(i => i.SecurityId, true).Description("Security Id"); this.Field <FinancialInstrumentGraphType>( "financialInstrument", "Instrument subject to trading in the order", resolve: context => { var loader = dataLoader.Context.GetOrAddLoader( $"GetFinancialInstrumentById-{context.Source.SecurityId}", async() => context.Source.SecurityId.HasValue ? await instrumentsRepository.GetById(context.Source.SecurityId.Value) : null); return(loader.LoadAsync()); }); this.Field(i => i.ClientOrderId, true).Description("Client Order Id"); this.Field(i => i.OrderVersion, true).Description("Order version"); this.Field(i => i.OrderVersionLinkId, true).Description("Order version link id"); this.Field(i => i.OrderGroupId, true).Description("Order group id"); this.Field(i => i.OrderType, true).Description("Order type"); this.Field(i => i.Direction, true).Description("Order direction"); this.Field <OrderDatesGraphType>().Name("orderDates") .Description("Dates of key events in the order life cycle"); this.Field <OrderManagementSystemGraphType>().Name("oms").Description("Order Management System data"); this.Field <OrderTypeGraphType>().Name("orderTypes") .Description("Order type delivered to market i.e. market/limit etc"); this.Field <OrderDirectionGraphType>().Name("orderDirection") .Description("Order direction such as buy/sell short/cover"); this.Field(i => i.Currency, true).Description("Order currency values are denominated in"); this.Field(i => i.SettlementCurrency, true).Description("Order settlement currency"); this.Field(i => i.CleanDirty, true).Description( "Order values quoted clean or dirty (fixed income with or without accrued interest)"); this.Field(i => i.AccumulatedInterest, true).Description("Accumulated interest"); this.Field(i => i.LimitPrice, true).Description("Order limit price (if applicable)"); this.Field(i => i.AverageFillPrice, true).Description("Order average fill price"); this.Field(i => i.OrderedVolume, true).Description("Order volume ordered"); this.Field(i => i.FilledVolume, true) .Description("Order actual filled volume can be larger or smaller than ordered volume"); this.Field <TraderGraphType>().Name("trader").Description("Trader handling the order salient properties"); this.Field(i => i.ClearingAgent, true).Description("Clearing agent used for the trade"); this.Field(i => i.DealingInstructions, true).Description("Instructions for dealer"); this.Field(i => i.OptionStrikePrice, true).Description("The strike price of the option instrument"); this.Field(i => i.OptionExpirationDate, true).Type(new DateTimeGraphType()) .Description("The expiration date of the option instrument"); this.Field(i => i.OptionEuropeanAmerican, true).Description("The category of the option. European or American"); this.Field(i => i.CreatedDate).Type(new DateTimeGraphType()) .Description("The date the system created the order on"); this.Field(i => i.LifeCycleStatus, true).Description("The order status within the life cycle"); this.Field(i => i.Live).Description("Order is live, therefore has corresponding order allocations"); this.Field(i => i.Autoscheduled).Description("Order has been autoscheduled"); this.Field <ListGraphType <FundGraphType> >( "fund", "The fund the order was allocated to", resolve: context => { IQueryable <IOrdersAllocation> FundNameQuery(IQueryable <IOrdersAllocation> i) { return(i.Where(x => x.Fund == context.Source.Fund)); } var loader = dataLoader.Context.GetOrAddLoader( $"GetFundById-{context.Source.Fund}", () => orderRepository.QueryFund(FundNameQuery)); return(loader.LoadAsync()); }); this.Field <ListGraphType <StrategyGraphType> >( "strategy", "The strategy the order was allocated to", resolve: context => { IQueryable <IOrdersAllocation> StrategyNameQuery(IQueryable <IOrdersAllocation> i) { return(i.Where(x => x.Strategy == context.Source.Strategy)); } var loader = dataLoader.Context.GetOrAddLoader( $"GetStrategyById-{context.Source.Strategy}", () => orderRepository.QueryStrategy(StrategyNameQuery)); return(loader.LoadAsync()); }); this.Field <ListGraphType <ClientAccountGraphType> >( "clientAccount", "The client account the order was allocated to", resolve: context => { IQueryable <IOrdersAllocation> ClientAccountQuery(IQueryable <IOrdersAllocation> i) { return(i.Where(x => x.ClientAccountId == context.Source.ClientAccount)); } var loader = dataLoader.Context.GetOrAddLoader( $"GetClientAccountById-{context.Source.ClientAccount}", () => orderRepository.QueryClientAccount(ClientAccountQuery)); return(loader.LoadAsync()); }); this.Field <ListGraphType <OrderAllocationGraphType> >( "orderAllocations", resolve: context => { IQueryable <IOrdersAllocation> OrderAllocationsQuery(IQueryable <IOrdersAllocation> i) { return(i.Where(x => x.OrderId == context.Source.ClientOrderId)); } var loader = dataLoader.Context.GetOrAddLoader( $"GetOrderAllocationsByClientOrderId-{context.Source.ClientOrderId}", () => orderRepository.QueryAllocations(OrderAllocationsQuery)); return(loader.LoadAsync()); }); }
public FinancialInstrumentController(IFinancialInstrumentRepository financialInstrumentRepository) { _financialInstrumentRepository = financialInstrumentRepository; }
public SurveillanceQuery( IRefinitivTickPriceHistoryService refinitivTickPriceHistoryService, IFinancialInstrumentRepository financialInstrumentRepository, IOrderRepository orderRepository, IMarketRepository marketRepository, IBrokerRepository brokerRepository, IRuleBreachRepository ruleBreachRepository, ISystemProcessOperationRuleRunRepository ruleRunRepository, ISystemProcessOperationUploadFileRepository fileUploadRepository, ISystemProcessOperationDataSynchroniserRepository dataSynchroniserRepository, ISystemProcessOperationDistributeRuleRepository distributeRuleRepository, IActiveRulesService ruleService, IDataLoaderContextAccessor dataAccessor, IHttpContextAccessor ctx) { this.Field <ListGraphType <FinancialInstrumentGraphType> >( "financialInstruments", "The financial instruments known to surveillance", new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }), context => { var id = context.GetArgument <int?>("id"); IQueryable <IFinancialInstrument> IdQuery(IQueryable <IFinancialInstrument> i) { return(i.Where(x => id == null || x.Id == id)); } return(financialInstrumentRepository.Query(IdQuery)); }); this.Field <ListGraphType <SystemProcessOperationRuleRunGraphType> >( "ruleRuns", "The rule runs executed by the system", new QueryArguments(new QueryArgument <ListGraphType <StringGraphType> > { Name = "correlationIds" }), context => { var correlationIds = context.GetArgument <List <string> >("correlationIds"); IQueryable <ISystemProcessOperationRuleRun> filter(IQueryable <ISystemProcessOperationRuleRun> i) { return(i.Where(x => correlationIds == null || correlationIds.Contains(x.CorrelationId))); } return(ruleRunRepository.Query(filter)); }); this.Field <ListGraphType <SystemProcessOperationUploadFileGraphType> >( "uploadFiles", "The files uploaded by the system", resolve: context => { var dataLoader = dataAccessor.Context.GetOrAddLoader( "allUploadfiles", fileUploadRepository.GetAllDb); return(dataLoader.LoadAsync()); }); this.Field <ListGraphType <SystemProcessOperationDataSynchroniserRequestGraphType> >( "dataSynchroniser", "The data synchroniser requests logged by the system", resolve: context => { var dataLoader = dataAccessor.Context.GetOrAddLoader( "allDataSynchroniser", dataSynchroniserRepository.GetAllDb); return(dataLoader.LoadAsync()); }); this.Field <ListGraphType <SystemProcessOperationDistributeRuleGraphType> >( "distributeRule", "The rules distributed by the schedule disassembler", resolve: context => { var dataLoader = dataAccessor.Context.GetOrAddLoader( "allDistributeRule", distributeRuleRepository.GetAllDb); return(dataLoader.LoadAsync()); }); this.Field <OrderLedgerGraphType>( "metaLedger", "Consolidated company portfolio incorporating all funds", resolve: context => { var dataLoader = dataAccessor.Context.GetOrAddLoader( "allMetaLedger", orderRepository.QueryUnallocated); return(dataLoader.LoadAsync()); }); this.Field <ListGraphType <FundGraphType> >( "funds", "The list of funds under surveillance", new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), context => { var id = context.GetArgument <string>("id"); IQueryable <IOrdersAllocation> IdQuery(IQueryable <IOrdersAllocation> i) { return(i.Where(x => string.IsNullOrWhiteSpace(id) || x.Fund == id)); } return(orderRepository.QueryFund(IdQuery)); }); this.Field <ListGraphType <StrategyGraphType> >( "strategies", "The list of strategies employed by surveilled orders", new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), context => { var id = context.GetArgument <string>("id"); IQueryable <IOrdersAllocation> IdQuery(IQueryable <IOrdersAllocation> i) { return(i.Where(x => string.IsNullOrWhiteSpace(id) || x.Strategy == id)); } return(orderRepository.QueryStrategy(IdQuery)); }); this.Field <ListGraphType <ClientAccountGraphType> >( "clientAccounts", "The list of client accounts allocated to by surveilled orders", new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), context => { var id = context.GetArgument <string>("id"); IQueryable <IOrdersAllocation> IdQuery(IQueryable <IOrdersAllocation> i) { return(i.Where(x => string.IsNullOrWhiteSpace(id) || x.ClientAccountId == id)); } return(orderRepository.QueryClientAccount(IdQuery)); }); this.Field <ListGraphType <MarketGraphType> >( "markets", "The list of markets that have surveilled orders have been issued against", new QueryArguments(new QueryArgument <StringGraphType> { Name = "mic" }), context => { var id = context.GetArgument <string>("mic"); IQueryable <IMarket> MicQuery(IQueryable <IMarket> i) { return(i.Where(x => id == null || x.MarketId == id)); } return(marketRepository.Query(MicQuery)); }); this.Field <ListGraphType <BrokerGraphType> >( "brokers", "The list of brokers that orders have been placed with", new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), context => { var id = context.GetArgument <int?>("id"); IQueryable <IBroker> IdQuery(IQueryable <IBroker> i) { return(i.Where(x => id == null || x.Id == id)); } return(brokerRepository.Query(IdQuery)); }); this.Field <ListGraphType <RuleBreachGraphType> >( "ruleBreaches", "Policy rule violations detected by the surveillance engine", new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }), context => { var id = context.GetArgument <int?>("id"); IQueryable <IRuleBreach> IdQuery(IQueryable <IRuleBreach> i) { return(i.Where(x => id == null || x.Id == id)); } return(ruleBreachRepository.Query(IdQuery)); }); this.Field <ListGraphType <TraderGraphType> >( "traders", "Traders that have been recorded in the orders file", new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }), context => { var id = context.GetArgument <string>("id"); IQueryable <IOrder> IdQuery(IQueryable <IOrder> i) { return(i.Where(x => id == null || x.TraderId == id)); } return(orderRepository.TradersQuery(IdQuery)); }); this.Field <ListGraphType <OrderGraphType> >( "orders", "Orders uploaded by client", new QueryArguments( new QueryArgument <ListGraphType <IntGraphType> > { Name = "ids" }, new QueryArgument <IntGraphType> { Name = "take" }, new QueryArgument <ListGraphType <StringGraphType> > { Name = "traderIds" }, new QueryArgument <ListGraphType <StringGraphType> > { Name = "excludeTraderIds" }, new QueryArgument <ListGraphType <StringGraphType> > { Name = "reddeerIds" }, new QueryArgument <ListGraphType <IntGraphType> > { Name = "statuses" }, new QueryArgument <ListGraphType <IntGraphType> > { Name = "directions" }, new QueryArgument <ListGraphType <IntGraphType> > { Name = "types" }, new QueryArgument <DateTimeGraphType> { Name = "placedDateFrom" }, new QueryArgument <DateTimeGraphType> { Name = "placedDateTo" }), context => { var options = new OrderQueryOptions { Ids = context.GetArgument <List <int> >("ids"), Take = context.GetArgument <int?>("take"), TraderIds = context.GetArgument <List <string> >("traderIds")?.ToHashSet(), ExcludeTraderIds = context.GetArgument <List <string> >("excludeTraderIds")?.ToHashSet(), ReddeerIds = context.GetArgument <List <string> >("reddeerIds"), Statuses = context.GetArgument <List <int> >("statuses"), Directions = context.GetArgument <List <int> >("directions"), Types = context.GetArgument <List <int> >("types"), PlacedDateFrom = context.GetArgument <DateTime?>("placedDateFrom"), PlacedDateTo = context.GetArgument <DateTime?>("placedDateTo") }; return(orderRepository.Query(options)); }); this.Field <ListGraphType <AggregationGraphType> >( "orderAggregation", "Aggregation of orders uploaded by client", new QueryArguments( new QueryArgument <ListGraphType <IntGraphType> > { Name = "ids" }, new QueryArgument <ListGraphType <StringGraphType> > { Name = "traderIds" }, new QueryArgument <ListGraphType <StringGraphType> > { Name = "excludeTraderIds" }, new QueryArgument <ListGraphType <StringGraphType> > { Name = "reddeerIds" }, new QueryArgument <ListGraphType <IntGraphType> > { Name = "statuses" }, new QueryArgument <ListGraphType <IntGraphType> > { Name = "directions" }, new QueryArgument <ListGraphType <IntGraphType> > { Name = "types" }, new QueryArgument <DateTimeGraphType> { Name = "placedDateFrom" }, new QueryArgument <DateTimeGraphType> { Name = "placedDateTo" }, new QueryArgument <StringGraphType> { Name = "tzName" }), context => { var options = new OrderQueryOptions { Ids = context.GetArgument <List <int> >("ids"), TraderIds = context.GetArgument <List <string> >("traderIds")?.ToHashSet(), ExcludeTraderIds = context.GetArgument <List <string> >("excludeTraderIds")?.ToHashSet(), ReddeerIds = context.GetArgument <List <string> >("reddeerIds"), Statuses = context.GetArgument <List <int> >("statuses"), Directions = context.GetArgument <List <int> >("directions"), Types = context.GetArgument <List <int> >("types"), PlacedDateFrom = context.GetArgument <DateTime?>("placedDateFrom"), PlacedDateTo = context.GetArgument <DateTime?>("placedDateTo"), TzName = context.GetArgument <string>("tzName") }; return(orderRepository.AggregationQuery(options)); }); this.Field <ListGraphType <RulesTypeEnumGraphType> >( "rules", "The category of the rule", resolve: context => ruleService.EnabledRules()); this.Field <ListGraphType <OrganisationTypeEnumGraphType> >( "organisationFactors", "The type of organisation factors", resolve: context => OrganisationalFactors.None.GetEnumPermutations()); this.Field <ListGraphType <OrderTypeGraphType> >( "orderTypes", "The type of the order given to market", resolve: context => OrderTypes.NONE.GetEnumPermutations()); this.Field <ListGraphType <InstrumentTypeGraphType> >( "instrumentTypes", "A primitive perspective on the asset class. To see further details use the CFI code", resolve: context => InstrumentTypes.None.GetEnumPermutations()); this.Field <ListGraphType <TickPriceHistoryTimeBarGraphType> >( "tickPriceHistoryTimeBars", "Tick Price History TimeBar", new QueryArguments( new QueryArgument <ListGraphType <StringGraphType> > { Name = "rics" }, new QueryArgument <DateTimeGraphType> { Name = "startDateTime" }, new QueryArgument <DateTimeGraphType> { Name = "endDateTime" }), context => { var rics = context.GetArgument <List <string> >("rics"); var startDateTime = context.GetArgument <DateTime?>("startDateTime"); var endDateTime = context.GetArgument <DateTime?>("endDateTime"); return(refinitivTickPriceHistoryService.GetEndOfDayTimeBarsAsync(startDateTime, endDateTime, rics)); }); }