{"id":23729990,"url":"https://github.com/athammad/pygcapi","last_synced_at":"2026-02-02T13:39:46.486Z","repository":{"id":269508290,"uuid":"886482242","full_name":"athammad/pygcapi","owner":"athammad","description":"The pygcapi 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-24T06:33:03.000Z","size":1807,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T23:52:32.217Z","etag":null,"topics":["api","forex-data","object-oriented-programming","python","trading","trading-algorithms","trading-strategies"],"latest_commit_sha":null,"homepage":"https://athammad.github.io/pygcapi/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","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":"LICENSE","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-11-11T03:48:48.000Z","updated_at":"2024-12-24T06:33:06.000Z","dependencies_parsed_at":"2024-12-24T04:30:00.152Z","dependency_job_id":"35fed2fa-2eb7-47f2-aba4-a430f7506694","html_url":"https://github.com/athammad/pygcapi","commit_stats":null,"previous_names":["athammad/pygcapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athammad%2Fpygcapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athammad%2Fpygcapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athammad%2Fpygcapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athammad%2Fpygcapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athammad","download_url":"https://codeload.github.com/athammad/pygcapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248497852,"owners_count":21113984,"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","python","trading","trading-algorithms","trading-strategies"],"created_at":"2024-12-31T02:29:57.493Z","updated_at":"2026-02-02T13:39:41.452Z","avatar_url":"https://github.com/athammad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# pygcapi \u003cimg src=\"./logo_pygcapi.png\" align=\"right\" height=\"200\"/\u003e\n\nThe **pygcapi** Python library provides an interface to the **Gain Capital API** (V1 and V2), allowing users to perform various trading operations on [Forex.com](https://forex.com). This library includes functionalities for account management, market information retrieval, trading operations, and historical data extraction. It also includes helper utilities and lookup tables to facilitate the interpretation of API responses.\n\nBy leveraging the extensive Python ecosystem—which includes libraries for data manipulation, scientific computing, and machine learning—**pygcapi** offers a robust solution for traders and data scientists seeking to enhance their trading operations and develop automated trading strategies.\n\n## Features\n\n- **Account Management**: Initialize sessions and manage user accounts.\n- **Market Information**: Retrieve real-time market data and details.\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\n\nYou can install this package directly from PyPI using `pip`:\n\n```bash\npip install pygcapi\n```\nOr from GitHub:\n\n```bash\npip install git+https://github.com/athammad/pygcapi.git\n```\n\n\n# API Credentials\n\nTo access your trading account, you will need credentials provided by Forex.com, including a username, password, and appkey. Once obtained, you can use these credentials to initialize a session with GCapiClient:\n\n\n```python\nfrom pygcapi.core_v2 import GCapiClientV2\n\n# Replace with your actual credentials\nIDLOG = \"your_username\"\nPSWD = \"your_password\"\nAPKEY = \"your_appkey\"\n\nclient = GCapiClientV2(username=IDLOG, password=PSWD, appkey=APKEY)\n```\n\n# Example Usage\n\n\n\n```python\n\n#Retrieve Account Information:\n\naccount_info = client.get_account_info()\nprint(account_info)\n\n# Retrieve a specific field (e.g., TradingAccountId)\n\ntrading_account_id = client.get_account_info(key=\"TradingAccountId\")\nprint(trading_account_id)\n\n#Get Market Information:\n\nmarket_info = client.get_market_info(\"EUR/USD\")\nprint(market_info)\n\nmarket_id = client.get_market_info(\"EUR/USD\", key=\"MarketId\")\nmarket_name = client.get_market_info(\"EUR/USD\", key=\"Name\")\nprint(market_id)\nprint(market_name)\n\n#Retrieve Price Data\n\nimport time\nimport datetime\nfrom datetime import timedelta\n\n# Define time period\n\none_month_ago = int((datetime.datetime.utcnow() - timedelta(days=30)).timestamp())\nnow = int(datetime.datetime.utcnow().timestamp())\n\nprices = client.get_prices(\n    market_id=market_id,\n    num_ticks=100,\n    from_ts=one_month_ago,\n    to_ts=now,\n    price_type=\"MID\"\n)\nprint(prices.head())\n\n#Retrieve OHLC Data\n\none_day_ago = int((datetime.datetime.utcnow() - timedelta(days=1)).timestamp())\n\nohlc = client.get_ohlc(\n    market_id=market_id,\n    num_ticks=4000,\n    interval=\"MINUTE\",\n    span=30,\n    from_ts=one_day_ago,\n    to_ts=now\n)\nprint(ohlc.head())\n\n# Place a Trade Order:\n\npricesB = client.get_prices(market_id=market_id, from_ts=from_ts,to_ts=to_ts, num_ticks=1,price_type=\"BID\")\npricesA=client.get_prices(market_id=market_id, from_ts=from_ts,to_ts=to_ts, num_ticks=1,price_type=\"ASK\")\n\ntrade_resp = client.trade_order(\n    quantity=1020,\n    direction=\"buy\",\n    market_id=market_id,\n    market_name=market_name,\n    bid_price=float(pricesB.Price[0]),  # Convert to scalar float\n    offer_price=float(pricesA.Price[0])  # Convert to scalar float\n)\n\n\n# Close a Trade Order:\nclose_resp = client.trade_order(\n    quantity=1020,\n    direction=\"sell\",\n    close=True,\n    order_id=trade_resp.get('OrderId'),\n    market_id=market_id,\n    market_name=market_name,\n    bid_price=float(pricesB.Price[0]),  # Convert to scalar float\n    offer_price=float(pricesA.Price[0])  # Convert to scalar float\n)\n\n\n#List Open Positions:\n\nopen_positions = client.list_open_positions()\nprint(open_positions)\n\n#Close All Trades:\n\nclose_responses = client.close_all_trades(tolerance=0.0005)\nprint(close_responses)\n\n#Retrieve Trade History:\n\ntrade_history = client.get_trade_history(max_results=50)\nprint(trade_history)\n```\n## Getting Help or Reporting an Issue\n\nTo report bugs/issues/feature requests, please file an [issue](https://github.com/athammad/pygcapi/issues/).\n\n## Author\n`pygcapi` 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## R version\nIf you prefer `R`, you can use the [rgcapi library](https://github.com/athammad/rgcapi/).\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\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathammad%2Fpygcapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathammad%2Fpygcapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathammad%2Fpygcapi/lists"}