Finance::FXCM::Simple - A synchronous wrapper to the FXCM ForexConnect API which is simple to use.
my $ff = Finance::FXCM::Simple->new($ENV{FXCM_USER}, $ENV{FXCM_PASSWORD}, "Demo", "http://www.fxcorporate.com/Hosts.jsp"); $ff->setSubscriptionStatus('EUR/CAD', 'D'); # Don't receive data updates to EUR/CAD $ff->setSubscriptionStatus('EUR/USD', 'T'); # Receive data updates to EUR/USD my $offers_hash = $ff->getOffersHash(); # Hash of data subscription status keyed on instrument $ff->getAsk("EUR/USD"); # Get current ask price for instrument $ff->getBid("EUR/USD"); # Get current bid price for instrument $ff->getBalance(); # Get current account balance $ff->getBaseUnitSize("XAU/USD"); # The minimum size that can be traded in instrument $ff->openMarket("EUR/USD", "B", 10000); # Open long position in instrument at current market price $ff->openMarket("EUR/GBP", "S", 10000); # Open short position in instrument at current market price my $trades = $ff->getTrades(); # Get list of open positions foreach my $trade(@$trades) { $ff->closeMarket($trade->{id}, $trade->{size}); # Close existing open position at current market price } $ff->saveHistoricalDataToFile("/tmp/EURUSD", "EUR/USD", "m5", 100); # Fetch 100 bars of 5 minute historical data for instrument EUR/USD and save to /tmp/EURUSD
This module 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.
new($username, $password, $type, $url)
$username
Your FXCM account username
$password
Your FXCM account password
$type
The account type the login credentials apply to. Either 'Demo' or 'Real'.
$url
The url to connect to, typically this will be 'http://www.fxcorporate.com/Hosts.jsp'
getAsk($instrument)
Get current ask price of instrument. Subscription status must be set, see "setSubscriptionStatus($instrument, $status)"
$instrument
The instrument to fetch ask price for.
getBid($instrument)
Get current bid price of instrument. Subscription status must be set, see "setSubscriptionStatus($instrument, $status)"
The instrument to fetch bid price for.
openMarket($instrument, $direction, amount)
Opens a position at current market price.
The instrument to open a market position in.
$direction
Use 'B' for Buy (long) or 'S' for Sell (short).
$amount
An integer representing the size of the position being opened. This must be a multiple of getBaseUnitSize
closeMarket($tradeID, $amount)
Close an existing position at current market prices
$tradeID
Unique identifier representing a trade. This can be obtained by calling getTrades.
An integer representing the size of the position to be closed. This can either be partial or the full position. Must be a multiple of getBaseUnitSize.
getTrades()
Returns a reference to a list of currently opened trades. Each element in the list is an reference to an hash with the following keys:
direction
Either "long" or "short".
symbol
openPrice
openDate
pl
Current profit/loss of the position, expressed in the account base currency.
id
Unique trade identifier. This is necessary to close the position with closeMarket.
size
getBalance()
Current account balance, expressed in the account base currency.
getBaseUnitSize($instrument)
Returns an integer representing the base position size for $instrument. Positions opened in $instrument must have a size which is a multiple of this value.
The instrument to fetch base unit size for.
saveHistoricalDataToFile($filename, $instrument, $tf, $numberOfItems)
Fetches historical data for instrument in a given timeframe and saves it to a file on disk.
$filename
Filename where to save data to.
Instrument for which to fetch data.
$tf
Timeframe which to fetch data in. This can be one of:
m1
One minute
m5
Five minutes
m15
Fifteen minutes
m30
Thirty minutes
H1
Hourly
D1
Daily
W1
Weekly
$numberOfItems
An integer representing number of items of historical data to download.
getOffersHash()
Returns a reference to an hash where the key is an instrument code and the value is that code's current subscription status. You can only call getBid and getAsk on currently subscribed instruments.
setSubscriptionStatus($instrument, $status)
Instrument to set subscription status for
$status
Value indicating wether subscription should be set or unset. Use 'T' to subscribe, 'D' to ubsubscribe.
João Costa <joaocosta@zonalivre.org>
This software is Copyright (c) 2012 by João Costa. This is free software, licensed under: The MIT (X11) License
ForexConnect API documentation
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'João'. Assuming UTF-8
To install Finance::FXCM::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Finance::FXCM::Simple
CPAN shell
perl -MCPAN -e shell install Finance::FXCM::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.