Esempio n. 1
0
        internal void Apply(OptionPurchased purchased)
        {
            this.NumberOfContracts += purchased.NumberOfContracts;

            var debit = purchased.NumberOfContracts * purchased.Premium;

            this.Debit += debit;

            this.Buys.Add(purchased);

            this.Transactions.Add(
                Transaction.DebitTx(
                    this.Ticker,
                    $"Bought {purchased.NumberOfContracts} x ${this.StrikePrice} {this.OptionType} {this.Expiration.ToString("MM/dd")} contracts for ${purchased.Premium}/contract",
                    debit,
                    purchased.When,
                    true
                    )
                );

            if (this.NumberOfContracts == 0)
            {
                this.Transactions.Add(
                    Transaction.PLTx(
                        this.Ticker,
                        $"Closed out option contract",
                        this.Credit - this.Debit,
                        purchased.When,
                        true
                        )
                    );
            }
        }
        public async Task Handle(OptionPurchased e, CancellationToken cancellationToken)
        {
            var o = await _storage.GetOwnedOption(e.AggregateId, e.UserId);

            if (o == null)
            {
                return;
            }

            var when   = e.When;
            var notes  = e.Notes;
            var ticker = o.State.Ticker;

            await CreateNote(e.UserId, when, notes, ticker);
        }
Esempio n. 3
0
        internal void ApplyInternal(OptionPurchased purchased)
        {
            if (FirstFill == null)
            {
                ApplyFirstTransactionLogic(false, purchased.When);
            }

            if (Deleted == true)
            {
                Deleted = false;
            }

            if (NumberOfContracts == 0)
            {
                PremiumReceived = 0;
                PremiumPaid     = 0;
            }

            AddNoteIfNotEmpty(purchased.Notes);

            NumberOfContracts += purchased.NumberOfContracts;

            var debit = purchased.NumberOfContracts * purchased.Premium;

            PremiumPaid += debit;

            Buys.Add(purchased);

            var description = $"Bought {purchased.NumberOfContracts} x ${StrikePrice} {OptionType} {Expiration.ToString("MM/dd")} contracts for ${purchased.Premium}/contract";

            Transactions.Add(
                Transaction.DebitTx(
                    Id,
                    purchased.Id,
                    Ticker,
                    description,
                    debit,
                    purchased.When,
                    true
                    )
                );

            ApplyClosedLogicIfApplicable(purchased.When, purchased.Id);
        }
Esempio n. 4
0
 protected void ApplyInternal(OptionPurchased purchased)
 {
     this.State.Apply(purchased);
 }