/// <summary> /// Get options from Yahoo API and save to local DB /// </summary> /// <param name="message"></param> /// <returns></returns> public async Task GetOptionsAsync(IScannerMessage message) { using (var connector = new CConnector(EConnector.Yahoo)) { var groups = await connector.GetGroupsAsync(message); foreach (var group in groups) { await Container.AddPartitionAsync(group.Value, group.Key); } } }
/// <summary> /// Get list of records with info about quote and option /// </summary> /// <param name="message"></param> /// <returns></returns> public async Task <Dictionary <string, List <IGroup> > > GetGroupsAsync(IScannerMessage message) { var stop = CType.ToSeconds(message.Stop.Value); var start = CType.ToSeconds(message.Start.Value); var combos = new Dictionary <string, List <IGroup> >(); foreach (var symbol in message.Symbols) { combos[symbol] = new List <IGroup>(); var dates = await GetExpirationsAsync(symbol); foreach (var date in dates) { if (date >= start && date <= stop) { combos[symbol].AddRange(await GetChainAsync(symbol, date)); } } } return(combos); }
/// <summary> /// Convert list of options into a list of possible positions /// </summary> /// <returns></returns> public async Task <IServiceMessage <IScore> > GetCombinationsAsync(IScannerMessage message) { var count = 0L; var scores = new List <IScore>(); var symbols = message.Symbols; foreach (var symbol in symbols) { message.Symbol = symbol; var response = await Combination.GetGroupsAsync(Container, message); var combinations = Combination.GetScores(response.Items); count = Math.Max(count, response.Count); scores.AddRange(combinations); } return(new CServiceMessage <IScore> { Count = count, Items = scores }); }
/// <summary> /// Get all options from local DB /// </summary> /// <param name="container"></param> /// <param name="message"></param> /// <returns></returns> public override async Task <IServiceMessage <IGroup> > GetGroupsAsync(IContainer <IGroup> container, IScannerMessage message) { var order = Builders <IGroup> .Sort; var selector = Builders <IGroup> .Filter; var orders = order.Combine ( order.Descending("Option.Strike") ); var selectorsForCalls = selector.And ( new BsonDocument(new BsonDocument("$where", new BsonJavaScript("this.Option.Strike > this.Quote.Ask"))), selector.Eq("Option.Right", 1), selector.Gt("Option.Bid", 0) ); var selectorsForPuts = selector.And ( new BsonDocument(new BsonDocument("$where", new BsonJavaScript("this.Option.Strike < this.Quote.Bid"))), selector.Eq("Option.Right", 0), selector.Gt("Option.Bid", 0) ); var selectors = selector.Or ( selectorsForPuts, selectorsForCalls ); var query = container .Query <IGroup>(message.Symbol) .Find(selectors); return(new CServiceMessage <IGroup> { Count = await query.CountAsync(), Items = await query .Sort(orders) .Skip((message.Page - 1) * message.Limit) .Limit(message.Limit) .ToListAsync() }); }
/// <summary> /// Get list of plain options from DB /// </summary> /// <param name="message"></param> /// <returns></returns> public virtual Task <IServiceMessage <IGroup> > GetGroupsAsync(IContainer <IGroup> container, IScannerMessage message) { return(null); }
/// <summary> /// Call method that downloads options from relevant connector /// </summary> /// <param name="message"></param> /// <returns></returns> public Task <Dictionary <string, List <IGroup> > > GetGroupsAsync(IScannerMessage message) { return(Instance.GetGroupsAsync(message)); }