{"id":23425764,"url":"https://github.com/athammad/rgcapi","last_synced_at":"2025-04-09T11:46:39.208Z","repository":{"id":268993793,"uuid":"836036394","full_name":"athammad/rgcapi","owner":"athammad","description":"The rgcapi R package provides an interface to the Gain Capital API V1 and V2, enabling users to perform various trading operations on Forex.com.","archived":false,"fork":false,"pushed_at":"2024-12-20T06:56:54.000Z","size":3701,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T05:44:53.279Z","etag":null,"topics":["api","forex-data","object-oriented-programming","r","trading","trading-algorithms","trading-strategy"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/athammad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-31T03:19:25.000Z","updated_at":"2024-12-20T06:56:57.000Z","dependencies_parsed_at":"2024-12-20T07:35:31.067Z","dependency_job_id":"feceaae5-182e-4757-994c-505eac39188b","html_url":"https://github.com/athammad/rgcapi","commit_stats":null,"previous_names":["athammad/rgcapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athammad%2Frgcapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athammad%2Frgcapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athammad%2Frgcapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athammad%2Frgcapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athammad","download_url":"https://codeload.github.com/athammad/rgcapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248034778,"owners_count":21037052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","forex-data","object-oriented-programming","r","trading","trading-algorithms","trading-strategy"],"created_at":"2024-12-23T05:14:13.096Z","updated_at":"2025-04-09T11:46:39.182Z","avatar_url":"https://github.com/athammad.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rgcapi \u003cimg src=\"./logo_rgcapi.png\" align=\"right\" height=\"200\"/\u003e\n\nThe [rgcapi](https://github.com/athammad/rgcapi) R package provides an interface to the **Gain Capital API** V1 and V2, enabling users to perform various trading operations on [Forex.com](https://forex.com). This package includes functionalities for account management, market information retrieval, trading operations, and historical data extraction. It also includes helper functions and lookup tables to facilitate the interpretation of API responses. The library is implemented using `R6`, an encapsulated object-oriented programming paradigm in R, which offers advantages such as modularity, reusability, and the ability to maintain state across function calls.\n\nNotably, the [rgcapi](https://github.com/athammad/rgcapi) package is the only library within the R ecosystem that facilitates connectivity with the Gain Capital API. This makes it an indispensable tool for the automated management of trading accounts and the implementation of automated trading strategies. By leveraging the extensive statistical, data science, and machine learning capabilities of the R ecosystem, [rgcapi](https://github.com/athammad/rgcapi) offers a robust solution for traders and data scientists seeking to enhance their trading operations.\n\n## Features\n\n- **Account Management**: Initialize sessions and manage user accounts.\n- **Market Information**: Retrieve real-time market data and information.\n- **Trading Operations**: Execute trades, manage orders, and track positions.\n- **Historical Data**: Extract and analyze historical market data.\n- **Helper Functions**: Utilize various helper functions and lookup tables for easier API response interpretation.\n\n## Installation\n\nYou can install this package directly from GitHub using `devtools`:\n\n```r\n# Install devtools if you haven't already\ninstall.packages(\"devtools\")\n\n# Install rgcapi from GitHub\ndevtools::install_github(\"athammad/rgcapi\")\n```\n\n## API Credentials\n\nTo access your credentials, you will need to contact Forex.com, which will provide you with an *Id*, *Apikey*, and *Password*. Once you have them, you can use them to connect to your account as follows:\n\n```r\n# Replace with your actual credentials\nIDLOG \u003c- \"your_username\"\nPSWD \u003c- \"your_password\"\nAPKEY \u003c- \"your_appkey\"\n\nclient \u003c- GCapiClientV2$new(username = IDLOG, password = PSWD, appkey = APKEY)\n```\n\nThe `R6` interface is the same between V1 and V2; only the class names are different.\n\n\n## Example usage\n\n```r\naccount_info \u003c- client$get_account_info()\nprint(account_info)\n\n#EUR/USD','EUR/SGD','EUR/HKD\n#[402044081, 401203172, 401203168]\nmarket_info \u003c- client$get_market_info(\"EUR/USD\")\nprint(market_info)\n\n# Retrieve specific information (e.g., MarketId)\nmarket_id \u003c- client$get_market_info(\"EUR/USD\", get = \"MarketId\")\nmarket_name \u003c- client$get_market_info(\"EUR/USD\", get = \"Name\")\nprint(market_id)\nprint(market_name)\n\n# Get price data for a market\nfromA \u003c- as.integer(as.POSIXct(Sys.Date(), tz=\"UTC\") - months(1))\ntoB \u003c- as.integer(as.POSIXct(Sys.time(), tz=\"UTC\"))\nprices \u003c- client$get_prices(market_id = market_id, num_ticks = 1, from_ts = fromA, to_ts = toB, price_type = \"MID\")\nprint(prices)\n\n# Get OHLC data for a market\nfromA \u003c- as.integer(as.POSIXct(Sys.Date(), tz=\"UTC\") - days(1))\ntoB \u003c- as.integer(as.POSIXct(Sys.time(), tz=\"UTC\"))\nohlc \u003c- client$get_ohlc(market_id = market_id, num_ticks = 4000, interval = \"MINUTE\", span = 30, from_ts = fromA, to_ts = toB)\nprint(ohlc)\n\n# Place a new trade order\ntrade_resp \u003c- client$trade_order(\n  quantity = 1020,\n  offer_price = prices$Price,\n  direction = \"buy\",\n  trading_acc_id = client$trading_account_id,\n  market_id = market_id,\n  market_name = market_name,\n  stop_loss = 1.060000,\n  take_profit = 1.080000,\n  tolerance = 0.0005\n)\n\n\n# List open positions\nopen_positions \u003c- client$list_open_positions()\nprint(open_positions)\n\n\n# Close a trade order\nclose_resp \u003c- client$trade_order(\n  quantity = 1020,\n  offer_price = prices$Price,\n  direction = \"sell\",\n  trading_acc_id = client$trading_account_id,\n  market_id = market_id,\n  market_name = market_name,\n  close = TRUE,\n  order_id = open_positions$OrderId[1]\n)\n\n\n# Get trade history\ntrade_history \u003c- client$get_trade_history()\n\n```\n\n## Getting Help or Reporting an Issue\n\nTo report bugs/issues/feature requests, please file an [issue](https://github.com/athammad/rgcapi/issues/).\n\n## Author\n`rgcapi` is written by [Ahmed T. Hammad](https://athsas.com/) and is under active development. Please feel free to contribute by submitting any issues or requests—or by solving any current issues!\n\n## Python version\nIf you prefer `Python`, you can use the [pygcapi library](https://github.com/athammad/pygcapi/).\n\n## Disclaimer\nThis package is not supported by `Forex.com`, and the author does not hold any responsibility for how users decide to use the library. Use it at your own risk.\n\n\n## Official API documentation\n\nhttps://docs.labs.gaincapital.com/index.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathammad%2Frgcapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathammad%2Frgcapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathammad%2Frgcapi/lists"}