Finance-FXCM-Simple
view release on metacpan or search on metacpan
lib/Finance/FXCM/Simple.pm view on Meta::CPAN
# The minimum size that can be traded in instrument
$ff->getBaseUnitSize("XAU/USD");
# Open long position in instrument at current market price
$ff->openMarket("EUR/USD", "B", 10000);
# Open short position in instrument at current market price
$ff->openMarket("EUR/GBP", "S", 10000);
# Get list of open positions
my $trades = $ff->getTrades();
foreach my $trade(@$trades) {
# Close existing open position at current market price
$ff->closeMarket($trade->{id}, $trade->{size});
}
# Fetch 100 bars of 5 minute historical data for instrument EUR/USD and save to /tmp/EURUSD
$ff->saveHistoricalDataToFile("/tmp/EURUSD", "EUR/USD", "m5", 100);
=head1 DESCRIPTION
Simple wrapper to FXCM's ForexConnect API, allows you to open/close/query positions in both real or demo FXCM trading accounts, as well as download historical price data for instruments supported by FXCM.
=head1 COMPILING
This module depends on L<FXCM's ForexConnect library|http://fxcodebase.com/wiki/index.php/Download> which is available in binary form only.
By default, only a small subset of tests run. To run the full test suite, you can optionally create a L<FXCM demo account|https://www.fxcm.com/forex-trading-demo/>.
curl http://fxcodebase.com/bin/forexconnect/1.3.2/ForexConnectAPI-1.3.2-Linux-x86_64.tar.gz | tar zxf - -C ~
sudo cp -R ~/ForexConnectAPI-1.3.2-Linux-x86_64/include/* /usr/include/.
sudo cp -R ~/ForexConnectAPI-1.3.2-Linux-x86_64/lib/* /usr/lib64/.
FXCONNECT_HOME=~/ForexConnectAPI-1.3.2-Linux-x86_64
FXCM_USER=DEMO_USERNAME # Optional, only required to run full test suite
FXCM_PASSWORD=DEMO_PWD # Optional, only required to run full test suite
perl Makefile.PL
make
make test
sudo make install
=head2 METHODS
=over 12
=item C<new($username, $password, $type, $url)>
=over 16
=item C<$username>
Your FXCM account username
=item C<$password>
Your FXCM account password
=item C<$type>
The account type the login credentials apply to. Either 'Demo' or 'Real'.
=item C<$url>
The url to connect to, typically this will be 'http://www.fxcorporate.com/Hosts.jsp'
=back
=item C<getAsk($instrument)>
Get current ask price of instrument. This is the price you can buy at. Subscription status must be set, see L</"setSubscriptionStatus($instrument, $status)">
=over 16
=item C<$instrument>
The instrument to fetch ask price for.
=back
=item C<getBid($instrument)>
Get current bid price of instrument. This is the price you can sell at. Subscription status must be set, see L</"setSubscriptionStatus($instrument, $status)">
=over 16
=item C<$instrument>
The instrument to fetch bid price for.
=back
=item C<openMarket($instrument, $direction, amount)>
Opens a position at current market price.
=over 16
=item C<$instrument>
The instrument to open a market position in.
=item C<$direction>
Use 'B' for Buy (long) or 'S' for Sell (short).
=item C<$amount>
An integer representing the size of the position being opened. This must be a multiple of getBaseUnitSize
=back
=item C<closeMarket($tradeID, $amount)>
Close an existing position at current market prices
=over 16
=item C<$tradeID>
( run in 0.501 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )