The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Finance::Robinhood::Order - Order to buy or sell a security

SYNOPSIS

    use Finance::Robinhood;

    my $rh    = Finance::Robinhood->new( token => ... );
    my $acct  = $rh->accounts()->[0];
    my $bill  = $rh->instrument('MSFT');
    my $order = Finance::Robinhood::Order->new(
        account       => $acct,
        instrument    => $bill,
        side          => 'buy',
        type          => 'market',
        trigger       => 'immediate',
        time_in_force => 'gfd',
        quantity      => 300
    );
    $order->cancel(); # Oh, wait!

DESCRIPTION

This class represents a single buy or sell order. These are returned by the locate_order( ... ) and list_order( ... ) methods of Finance::Robinhood.

Of course, you may place new orders with the new( ... ) constructor of this class.

METHODS

This class has several getters and a few methods as follows...

new( ... )

The main event!

Odds are, this is what you installed Finance::Robinhood to do: buy ad sell.

Please note that if the call to new( ... ) fails for any reason (not enough buying power, etc.) this will confess( ... ) so it's probably a good idea to wrap this in an eval or something.

There are some keys that are required for all orders and then there are some that only apply for certain types of orders like stop loss and stop limit.

These are the required keys for all orders:

account

A Finance::Robinhood::Account.

instrument

A Finance::Robinhood::Instrument

type

String which may be one of the following:

stop
market
limit
trigger

Which may be one of the following:

immediate
stop
on_close
time_in_force

Which may be one of the following:

gfd

Good For Day

gtc

Good 'Till Cancelled

fok

Fill or Kill

ioc

Immediate or Cancel

opg

Opening

side

This indicates whether you would like to...

buy
sell
quantity

Is the number of shares this order covers. How many you would like to buy or sell.

Market Sell Order

When placed, market sell orders get whatever the current asking price is when triggered.

# NAME TYPE SIDE REQUIREMENTS # market market buy trigger=immediate, type=market # limit limit buy trigger=immediate, type=limit # stop_limit limit buy trigger=stop, stop_price=%d, type=market # stop_loss # stop_limit limit sell price={minimum}, stop_price=%d, trigger=stop, type=limt

account( )

    my $acct = $order->account();

Returns the Finance::Robinhood::Account object related to this order.

executions( )

Returns order executions as a list of hashes which contain the following keys:

    price              The exact price per share
    quantity           The number of shares transfered in this execution
    settlement_date    Date on which the funds of this transaction will settle
    timestamp          When this execution took place

cancel( )

    $order->cancel( ); # Nm! I want to keep these!

If the order can be cancelled (has not be executed in completion, etc.), you may cancel it with this.

position( )

Returns a Finance::Robinhood::Position object related to this order's security.

average_price( )

Average price paid for all shares executed in this order.

id( )

    my $id = $order->id();
    # ...later...
    my $order = $rh->order( $id );

The order ID for this particular order. Use this for locating the order again.

fees( )

Total amount of fees related to this order.

price( )

Total current value of the order.

quantity( )

Total number of shares ordered or put up for sale.

cumulative_quantity

Total number of shares which have executed so far.

reject_reason( )

If the order was rejected (see state( )), the reason will be here.

side( )

Indicates which side of the deal you were on: buy or sell.

state( )

The current state of the order. For example, completly executed orders have a filled state. The current state may be any of the following:

    queued
    unconfirmed
    confirmed
    partially_filled
    filled
    rejected
    cancelled
    failed

stop_price( )

Stop limit and stop loss orders will have a defined stop price.

time_in_force( )

This may be one of the following:

    gfd     Good For Day
    gtc     Good Til Cancelled
    fok     Fill or Kill
    ioc     Immediate or Cancel
    opg

trigger( )

May be one of the following:

    immediate
    on_close
    stop

Note: Support for opg orders may indicate support for loo and moo triggers but I have yet to test it.

type( )

May be one of the following:

    market
    limit
    stop_limit
    stop_loss

created_at( )

The timestamp when the order was placed.

last_transaction_at( )

The timestamp of the most recent execution.

upated_at( )

Timestamp of the last change made to this order.

LEGAL

This is a simple wrapper around the API used in the official apps. The author provides no investment, legal, or tax advice and is not responsible for any damages incured while using this software. Neither this software nor its author are affiliated with Robinhood Financial LLC in any way.

For Robinhood's terms and disclosures, please see their website at http://robinhood.com/

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. Please refer to the LEGAL section.

AUTHOR

Sanko Robinson <sanko@cpan.org>