NAME
Finance::FXCM::Simple - A synchronous wrapper to the FXCM ForexConnect API which is simple to use.
SYNOPSIS
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
DESCRIPTION
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.
METHODS
new($username, $password, $type, $url)
getAsk($instrument)
-
Get current ask price of instrument. Subscription status must be set, see "setSubscriptionStatus($instrument, $status)"
getBid($instrument)
-
Get current bid price of instrument. Subscription status must be set, see "setSubscriptionStatus($instrument, $status)"
openMarket($instrument, $direction, amount)
-
Opens a position at current market price.
closeMarket($tradeID, $amount)
-
Close an existing position at current market prices
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.
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
-
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)
SOURCE CODE AND CI
https://github.com/joaocosta/Finance-FXCM-Simple https://travis-ci.org/joaocosta/Finance-FXCM-Simple
AUTHOR
João Costa <joaocosta@zonalivre.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by João Costa.
This is free software, licensed under:
The MIT (X11) License