Ruby IG Markets Dealing Platform Gem
Easily access the IG Markets Dealing Platform from Ruby with this gem, either directly through code or by using the provided command-line client. Written against the official REST API.
Includes support for:
- Activity and transaction history
- Positions
- Sprint market positions
- Working orders
- Market navigation, searches and snapshots
- Historical prices
- Watchlists
- Client sentiment
An IG Markets production or demo trading account is needed in order to use this gem.
License
Licensed under the MIT license. You must read and agree to its terms to use this software.
Usage — Command-Line Client
$ gem install ig_markets
Usage: ig_markets COMMAND --username=USERNAME --password=PASSWORD --api-key=API-KEY [--demo]
On startup ig_markets searches for files named "./.ig_markets" and then "~/.ig_markets", and if they are present
interprets their contents as command-line arguments. This can be used to avoid having to specify authentication details
with every invocation. To do this create a file at "./.ig_markets" or "~/.ig_markets" with the following contents:
--username=USERNAME
--password=PASSWORD
--api-key=API-KEY
--demo # Include only if this is a demo account
Run ig_markets help to list details on available commands. The full list of commands is:
ig_markets accountig_markets activities --days=N [--start-date=YYYY-MM-DD]ig_markets confirmation DEAL-REFERENCEig_markets orders [list]ig_markets orders create ...ig_markets orders update DEAL-ID ...ig_markets orders delete DEAL-IDig_markets positionsig_markets positions create ...ig_markets positions update DEAL-ID ...ig_markets positions close DEAL-ID ...ig_markets search QUERYig_markets sentiment MARKET [--related]ig_markets sprints [list]ig_markets sprints create ...ig_markets transactions --days=N [--start-date=YYYY-MM-DD]ig_markets watchlists [list]ig_markets watchlists create NAME [EPIC EPIC ...]ig_markets watchlists add-markets WATCHLIST-ID [EPIC EPIC ...]ig_markets watchlists remove-markets WATCHLIST-ID [EPIC EPIC ...]ig_markets watchlists delete WATCHLIST-ID
Usage — Library
ig = IGMarkets::DealingPlatform.new
# Session
ig.sign_in 'username', 'password', 'api_key', :demo
ig.sign_out
# Account
ig.account.all
ig.account.recent_activities 365
ig.account.recent_transactions 365
ig.account.activities_in_date_range Date.today - 14, Date.today - 7
ig.account.transactions_in_date_range Date.today - 14, Date.today - 7
# Dealing
ig.deal_confirmation 'deal_reference'
# Positions
ig.positions.all
ig.positions.create currency_code: 'USD', direction: :buy, epic: 'CS.D.EURUSD.CFD.IP', size: 2
ig.positions['deal_id']
ig.positions['deal_id'].profit_loss
ig.positions['deal_id'].update limit_level: 1.2, stop_level: 1.1
ig.positions['deal_id'].close
# Sprint market positions
ig.sprint_market_positions.all
ig.sprint_market_positions.create direction: :buy, epic: 'FM.D.EURUSD24.EURUSD24.IP',
expiry_period: :one_minute, size: 100
# Working orders
ig.working_orders.all
ig.working_orders.create currency_code: 'USD', direction: :buy, epic: 'CS.D.EURUSD.CFD.IP', level: 0.99,
size: 1, type: :limit
ig.working_orders['deal_id']
ig.working_orders['deal_id'].update level: 1.25, limit_distance: 50, stop_distance: 0.02
ig.working_orders['deal_id'].delete
# Markets
ig.markets.hierarchy
ig.markets.search 'EURUSD'
ig.markets['CS.D.EURUSD.CFD.IP']
ig.markets['CS.D.EURUSD.CFD.IP'].recent_prices :day, 10
ig.markets['CS.D.EURUSD.CFD.IP'].prices_in_date_range :day, Date.today - 14, Date.today - 7
# Watchlists
ig.watchlists.all
ig.watchlists.create 'New Watchlist', 'CS.D.EURUSD.CFD.IP', 'UA.D.AAPL.CASH.IP'
ig.watchlists['watchlist_id']
ig.watchlists['watchlist_id'].markets
ig.watchlists['watchlist_id'].add_market 'CS.D.EURUSD.CFD.IP'
ig.watchlists['watchlist_id'].remove_market 'CS.D.EURUSD.CFD.IP'
ig.watchlists['watchlist_id'].delete
# Client sentiment
ig.client_sentiment['EURUSD']
ig.client_sentiment['EURUSD'].
# Miscellaneous
ig.applications
Documentation
API documentation is available here.
Contributors
Gem created by Richard Viney. All contributions welcome.