public async Task <ActionResult> Purchase(Buy.Command model) { model.WithUserId(this.User.Identifier()); var r = await _mediator.Send(model); return(this.OkOrError(r)); }
public Task <object> Buy(Buy.Command cmd) { cmd.WithUserId(User.Identifier()); return(ExecTransaction(cmd)); }
public async Task <ActionResult <Unit> > Buy(Buy.Command command) { return(await Mediator.Send(command)); }
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()); }