NAME

Finance::Alpaca::Struct::TradeUpdate - A Single Streamed Data Object

SYNOPSIS

use Finance::Alpaca;
my $stream = Finance::Alpaca->new( ... )->trade_stream(
    sub ($event) {
        ...
    }
 );
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

DESCRIPTION

Alpaca’s API offers WebSocket streaming for account and order updates. When subscribed, events returned from Alpaca will be coerced into Finance::Alpaca::Struct::Stream objects.

Properties

The fields present in a message depend on the type of event they are communicating. All messages contain an event type and an order field, which is the same as the order object that is returned from the REST API. Potential event types and additional fields that will be in their messages are listed below.

Common events

These are the events that are the expected results of actions you may have taken by sending API requests.

new - Sent when an order has been routed to exchanges for execution
fill - Sent when your order has been completely filled
timestamp - The time at which the order was filled
price The average price per share at which the order was filled
position_qty The size of your total position, after this fill event, in shares. Positive for long positions, negative for short positions
partial_fill Sent when a number of shares less than the total remaining quantity on your order has been filled.
timestamp The time at which the shares were filled
price The average price per share at which the shares were filled
position_qty The size of your total position, after this fill event, in shares. Positive for long positions, negative for short positions
canceled Sent when your requested cancelation of an order is processed
timestamp The time at which the order was canceled
expired Sent when an order has reached the end of its lifespan, as determined by the order’s time in force value
timestamp The time at which the order expired
done_for_day Sent when the order is done executing for the day, and will not receive further updates until the next trading day
replaced Sent when your requested replacement of an order is processed
timestamp The time at which the order was replaced.

Rarer events

These are events that may rarely be sent due to unexpected circumstances on the exchanges. It is unlikely you will need to design your code around them, but you may still wish to account for the possibility that they will occur.

rejected - Sent when your order has been rejected
timestamp - The time at which the rejection occurred
pending_new - Sent when the order has been received by Alpaca and routed to the exchanges, but has not yet been accepted for execution
stopped - Sent when your order has been stopped, and a trade is guaranteed for the order, usually at a stated price or better, but has not yet occurred
pending_cancel - Sent when the order is awaiting cancelation. Most cancelations will occur without the order entering this state
pending_replace - Sent when the order is awaiting replacement
calculated - Sent when the order has been completed for the day - it is either “filled” or “done_for_day” - but remaining settlement calculations are still pending
suspended - Sent when the order has been suspended and is not eligible for trading
order_replace_rejected - Sent when the order replace has been rejected
order_cancel_rejected - Sent when the order cancel has been rejected

LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted through this module.

AUTHOR

Sanko Robinson <sanko@cpan.org>