MyNixOS website logo
Description

Access the 'IG Trading REST API'.

Provides functions to fetch market data, search historical prices, execute trades, and get account details from the 'IG Trading REST API' <https://labs.ig.com>. Returns tidy tibbles for easy analysis. Trading contracts for difference (CFDs), options and spread bets carries a high risk of losing money. This package is not financial or trading advice.

igfetchr

igfetchr is a lightweight R wrapper for the [IG Trading REST API] (https://labs.ig.com/). It provides beginner-friendly functions to fetch market data, search historical prices, execute trades, and get account details from the [IG Trading REST API] (https://labs.ig.com/).

Important: Trading CFDs and spread bets carries a high risk of losing money. This package is not financial advice.

Installation

Install the package from GitHub (development):

# install.packages("remotes")
remotes::install_github("sawsimeon/igfetchr")

Quick example (mocked / offline)

The package supports an offline "testing" mode so examples and tests run without network calls. Set the environment variable IGFETCHR_TESTING = "true" to enable mock behavior.

Sys.setenv(IGFETCHR_TESTING = "true")

# Mock authentication (returns mock tokens)
auth <- igfetchr::ig_auth(
  username = "demo_user",
  password = "demo_pass",
  api_key = "demo_api_key",
  acc_type = "DEMO",
  acc_number = "ABC123"
)

# Use mock_response to simulate endpoints
markets <- igfetchr::ig_search_markets(
  search_term = "USD/CHF",
  auth = auth,
  mock_response = data.frame(
    epic = "CS.D.USDCHF.CFD.IP",
    instrumentName = "USD/CHF",
    stringsAsFactors = FALSE
  )
)

print(markets)

# Clear testing mode
Sys.unsetenv("IGFETCHR_TESTING")

Vignette

See the vignette vignettes/getting-started.Rmd for a short guided demo that uses mock responses so it runs offline during CRAN checks.

Real API Usage

For live API calls, set environment variables for security and use ig_auth() without testing mode.

Sys.setenv(IG_SERVICE_USERNAME = "your_username")
Sys.setenv(IG_SERVICE_PASSWORD = "your_password")
Sys.setenv(IG_SERVICE_API_KEY = "your_api_key")
Sys.setenv(IG_SERVICE_ACC_TYPE = "DEMO")
Sys.setenv(IG_SERVICE_ACC_NUMBER = "ABC123")

auth <- igfetchr::ig_auth()
hist <- igfetchr::ig_get_historical(
  epic = "CS.D.USDCHF.CFD.IP",
  from = "2020-01-01",
  to = "2020-12-31",
  resolution = "D",
  auth = auth
)
print(hist)

Contributing

Please open issues or pull requests on the GitHub repository: https://github.com/sawsimeon/igfetchr

License

GPL-3 License — see LICENSE file.

Metadata

Version

0.1.0

License

Unknown

Platforms (78)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows