public async Task <ActionResult> Sell(Sell.Command model) { model.WithUserId(this.User.Identifier()); var r = await _mediator.Send(model); return(this.OkOrError(r)); }
public static Sell.Command CreateSellCommand() { var cmd = new Sell.Command { Ticker = Ticker, NumberOfContracts = 1, Premium = 10, StrikePrice = 20, OptionType = OptionType.PUT.ToString(), ExpirationDate = DateTimeOffset.UtcNow.AddDays(10), Filled = DateTimeOffset.UtcNow }; cmd.WithUserId(User.Id); return(cmd); }
public Task <object> Sell(Sell.Command cmd) { cmd.WithUserId(User.Identifier()); return(ExecTransaction(cmd)); }
private async Task <CommandResponse> ProcessLine(OptionRecord record, Guid userId) { RequestWithUserIdBase cmd = null; if (record.type == "sell") { cmd = new Sell.Command(); } else if (record.type == "buy") { cmd = new Buy.Command(); } else if (record.type == "expired") { var exp = new Expire.Command(); exp.Assigned = false; cmd = exp; } else if (record.type == "assigned") { var exp = new Expire.Command(); exp.Assigned = true; cmd = exp; } if (cmd is OptionTransaction ot) { ot.ExpirationDate = record.expiration; ot.Filled = record.filled; ot.NumberOfContracts = record.amount; ot.OptionType = record.optiontype; ot.Premium = record.premium; ot.StrikePrice = record.strike; ot.Ticker = record.ticker; ot.WithUserId(userId); if (record.type == "buy") { ot.Premium = -1 * ot.Premium; } var r = await _mediator.Send(ot); if (r.Error != null) { return(r); } } if (cmd is Expire.Command ec) { var opts = await _storage.GetOwnedOptions(userId); var optType = (OptionType)Enum.Parse(typeof(OptionType), record.optiontype); var opt = opts.SingleOrDefault(o => o.IsMatch(record.ticker, record.strike, optType, record.expiration.Value) ); if (opt == null) { return(CommandResponse.Failed( $"Unable to find option to expire for {record.ticker} {record.strike} {record.optiontype} {record.expiration}" )); } ec.Id = opt.Id; ec.WithUserId(userId); var er = await _mediator.Send(ec); if (er.Error != null) { return(er); } } return(CommandResponse.Success()); }