{"id":15288948,"url":"https://github.com/flock92/trading212-api","last_synced_at":"2025-11-17T02:01:28.667Z","repository":{"id":176282937,"uuid":"604328411","full_name":"Flock92/Trading212-API","owner":"Flock92","description":"trading212 API","archived":false,"fork":false,"pushed_at":"2025-02-04T23:04:57.000Z","size":806,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-08-27T03:37:08.570Z","etag":null,"topics":["api","apit212","cfd","python","requests","selenium-webdriver","trading","trading212","trading212api"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/apit212/","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/Flock92.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,"zenodo":null}},"created_at":"2023-02-20T20:34:58.000Z","updated_at":"2025-08-19T06:18:18.000Z","dependencies_parsed_at":"2023-11-12T12:37:51.655Z","dependency_job_id":"6edde477-0c7f-4a9c-910d-3766be744dc9","html_url":"https://github.com/Flock92/Trading212-API","commit_stats":{"total_commits":130,"total_committers":1,"mean_commits":130.0,"dds":0.0,"last_synced_commit":"32c50941132146ba19ff973476b9d3ac7ff9e4f7"},"previous_names":["flock92/apit212"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Flock92/Trading212-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flock92%2FTrading212-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flock92%2FTrading212-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flock92%2FTrading212-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flock92%2FTrading212-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flock92","download_url":"https://codeload.github.com/Flock92/Trading212-API/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flock92%2FTrading212-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284807785,"owners_count":27066464,"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","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","apit212","cfd","python","requests","selenium-webdriver","trading","trading212","trading212api"],"created_at":"2024-09-30T15:54:44.798Z","updated_at":"2025-11-17T02:01:28.625Z","avatar_url":"https://github.com/Flock92.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Apit212**\n \nThis is a Pyhton based API using selenium and requests to get information from the trading212 Platform, please note that either myself or trading212 take responsibility for the outcomes related to the uses of this API.\n\nI will continue to work on this project and would appriciate any feedback. \n\n## Requirments\n* Selenium\n* Requests\n* Python3\n* Firefox\n\n## Installation\n\npip install apit212\n\n## Import\n\nto start using this API you will first need to login to the account using **apit212** you will then be able to use all the functions and create your own trading bot or use it to scarpe data from the trading212 platform.\n\n### Demo account: \n\n```py\n\nfrom apit212 import *\n\napi = Apit212()\n\napi.setup(username=\"flock92@account.api\", password=\"pass******\", mode=\"demo\")\n\n```\n\n### Live account:\n\n```py\n\nfrom apit212 import *\n\napi = Apit212()\n\napi.setup(username=\"flock92@account.api\", password=\"pass******\", mode=\"live\")\n\n```\n\n### Best Practice\n\nIt's good practice to set up an env file to save sensitive informaton like your user name or password. *Here is a useful link* [.env](https://pypi.org/project/python-dotenv/)\n\n```env\n\nUSER=flock92@account.api\nPASS=password123\n\n```\n\n```py\n\nfrom dotenv import load_dotenv\nfrom apit212 import *\nimport os\n\nload_dotenv('.env')\n\nusername: str = os.getenv('USER')\npassword: str = os.getenv('PASS')\n\napi = Apit212()\n\napi.setup(username=\"flock92@account.api\", password=\"pass******\", mode=\"demo\")\n\n```\n---\n\n# Correct Ticker\n\nThis API is useless without the correct ticker symbol so i've got a solution.\n\n```py\n\nfrom apit212 import Tickers\n\nticker = Tickers()\n\nprint(ticker.fetch_symbols(symbol='META'))\n\nprint(ticker.find_by_name(full_name='tesla'))\n\n```\n\n## console\n\nThere is quite a bit of data to read through but the key you are after is *ticker* this will return the symbol used by the trading212 platform.\n\n```bash\n\n[{'ticker': 'FB', 'type': 'STOCK', 'currency': 'USD', 'shortName': 'META', 'fullName': 'Meta Platforms', 'description': 'Meta Platforms Inc', 'minTrade': 0.1, 'digitsPrecision': 2, 'exchangeId': 68, 'tradable': True, 'underlyingInstrumentTicker': 'FB_US_EQ', 'underlyingLeverageCoefficient': 1.0, 'dealerExclusions': [], 'maxOpenLong': 1121, 'leverage': '1:5', 'insignificantDigits': 0, 'baseTicker': nan, 'expiryDate': nan, 'minTradeSizeCoefficient': 10.0, 'isin': 'US30303M1027', 'countryOfOrigin': 'US', 'quantityPrecision': 1.0, 'priorityIndex': 25.0, 'maxTrade': nan, 'conditionalVisibility': nan, 'suspended': nan}]\n[{'ticker': 'TSLA', 'type': 'STOCK', 'currency': 'USD', 'shortName': 'TSLA', 'fullName': 'Tesla', 'description': 'Tesla, Inc.', 'minTrade': 0.1, 'digitsPrecision': 2, 'exchangeId': 68, 'tradable': True, 'underlyingInstrumentTicker': 'TSLA_US_EQ', 'underlyingLeverageCoefficient': 1.0, 'dealerExclusions': [], 'maxOpenLong': 1405, 'leverage': '1:5', 'insignificantDigits': 0, 'baseTicker': nan, 'expiryDate': nan, 'minTradeSizeCoefficient': 10.0, 'isin': 'US88160R1014', 'countryOfOrigin': 'US', 'quantityPrecision': 1.0, 'priorityIndex': 100.0, 'maxTrade': nan, 'conditionalVisibility': nan, 'suspended': nan}]\n\n\n```\n\n### example\n\n```py\n\nfrom apit212 import Tickers\n\nticker = Tickers()\n\nmeta = ticker.fetch_symbols(symbol='META')\n\nprint(len(meta))\n\nprint(meta[0]['ticker'])\n\n```\n\n#### console\n\nfinding a ticker using the widely used ticker will often return 1 result but on some occasions you may get multiple results\nso its good practice to check the len of the string returned.\n\n```bash\n\n1\nFB\n\n```\n\n# CFD or Trade Equity\n\nTo trade CFD's simply call the CFD class\n\n```py\n\nfrom apit212 import *\n\napi = Apit212()\n\napi.setup(username=\"flock92@account.api\", password=\"pass******\", mode=\"demo\")\n\ncfd = CFD(cred=api)\n\n```\n\nTo trade Equity's simply call the Equity class.\n\n```py\n\nfrom apit212 import *\n\nclient = Apit212(username=\"flock92@account.api\", password=\"pass******\", mode=\"live\")\n\nequity = Equity()\n\n```\n\n\n## Account data\n\n### Check session\n\nThe *auth_validate* function will return account ID and trade type.\n\n```py\n\nvalidate = cfd.auth_validate()\n\nprint(validate)\n\n```\n\n#### Console:\n\n```bash\n\n{'id': '*******-****-****-****-************', 'accountId': ********, 'customerId': *********, 'tradingType': 'CFD', 'customerUuid': '********-****-****-****-************', 'frontend': 'WC4', 'readyToTrade': True, 'deviceUuid': ''}\n\n```\n\n### get_account\n\nThe *get_account* function will return your account details.\n\n```py\n\naccount = cfd.get_account()\n\nprint(account)\n\n```\n\n#### Console\n\n```bash\n\n{'demoAccounts': [{'id': ********, 'type': 'DEMO', 'tradingType': 'CFD', 'customerId': ********,\n'createdDate': '2023-01-17T03:20:48.000+00:00', 'status': 'ACTIVE', 'registerSource': 'WC4',\n'currencyCode': 'GBP', 'readyToTrade': True}], 'liveAccounts': [{'id': ********, 'type': 'LIVE',\n'tradingType': 'CFD', 'customerId': ********, 'createdDate': '2023-01-17T03:20:32.000+00:00',\n'status': 'PENDING_ACTIVATION', 'registerSource': 'WC4', 'currencyCode': 'GBP', 'readyToTrade': False}]}\n\n```\n\n### get_funds\n\nThe *get_funds* function will return the accounts funds.\n\n```py\n\nfunds = cfd.get_funds()\n\nprint(funds)\n\n```\n\n#### Console\n\n```bash\n\n{'*******': {'accountId': ********, 'tradingType': 'CFD', 'currency': 'GBP',\n'freeForWithdraw': 486.83, 'freeForCfdTransfer': 0, 'total': 486.83,\n'lockedCash': {'totalLockedCash': 0, 'lockedCash': []}}}\n\n```\n\n### Get summary\n\nThe *get_summary* returns a summary of you account.\n\n```py\n\nsummary = cfd.get_summary()\n\nprint(summary)\n\n```\n\n#### Console\n\n```bash\n\n'open': {'unfilteredCount': 1, 'items': [{'positionId': '********-****-****-****-************', 'humanId': '********',\n'created': '2023-07-03T18:17:46.563+03:00', 'averagePrice': 192.25, 'averagePriceConverted': 150.73025341182984,\n'currentPrice': 192.2, 'value': 1054.82, 'investment': 1055.11, 'code': 'AAPL', 'margin': 212.02, 'ppl': -0.28,\n'quantity': 7, 'maxBuy': 9.0, 'maxSell': 7, 'maxOpenBuy': 2033.0, 'maxOpenSell': 2040.0, 'swap': -1.06, 'frontend': 'WC4'}]}\n\n```\n\n### Get companies\n\nThe *get_companies* returns instruments avaliable to trade on the trading212 platform\n\n```py\n\ncompanies = cfd.get_companies()\n\nprint(companies)\n\n```\n\n#### Console\n\n```bash\n\n[{'ticker': 'SIGTl_EQ', 'isin': 'GB0008769993'}, {'ticker': 'PDYPY_US_EQ', 'isin': 'US3440441026'}...]\n\n```\n\n### Get instrument info\n\nThe *get_instruments_info* will return information about an instrument.\n\n```py\n\ninfo = cfd.get_instruments_info(instrument=\"TSLA\")\n\nprint(info)\n\n```\n\n#### Console\n\n```bash\n\n{'code': 'TSLA', 'type': 'STOCK', 'margin': 0.2, 'shortPositionSwap': -0.07030593058663,\n'longPositionSwap': -0.27928156941337, 'tsSwapCharges': '1970-01-01T23:00:00.000+02:00',\n'marginPercent': '20', 'leverage': '1:5'}\n\n```\n\n### Get order info\n\nThe *get_order_info* get \n\n```py\n\norderInfo = cfd.get_order_info(instrument=\"TSLA\", quamtity=1.5)\n\nprint(orderInfo)\n\n```\n\n#### Console\n\n```bash\n\n{'buyMargin': 40.18, 'sellMargin': 40.18, 'buySwap': -0.2, 'sellSwap': -0.05}\n\n```\n\n### Get deviation\n\n```py\n\ntickers = [\"TSLA\",\"AAPL\"]\n\ndeviation = cfd.get_deviations(instruments=tickers)\n\nprint(deviation)\n\n```\n\n#### Console\n\n```bash\n\n[{'request': {'ticker': 'TSLA', 'useAskPrice': False}, 'response': {'timestamp': 1694073610000, 'price': 250.68, 'period': 'd1'}}, {'request': {'ticker': 'AAPL', 'useAskPrice': False}, 'response': {'timestamp': 1694073610000, 'price': 178.18, 'period': 'd1'}}]\n\n```\n\n### Get position\n\nThe *get_position* returns infomation for a given position ID, this ID's can be exstracted from the get_summary function\n\n```py\n\nposition = cfd.get_position(position_id=274187113)\n\nprint(position)\n\n```\n\n#### Console\n\n```bash\n\n[{'eventType': {'action': 'opened', 'source': 'MARKET_ORDER'}, \n'eventNumber': {'name': 'MO3053019640', 'id': '274187113', 'frontend': 'WC4'}, 'time': '2023-08-02T22:42:54.000+03:00', \n'direction': 'sell', 'quantity': 1.0, 'price': '105.29', 'avgQuantity': 1.0, 'avgPrice': '105.2900', 'modifiedDirection': \n'sell'}]\n\n```\n\n### Get all results\n\nThe *get_all_result* function will return a list of all your trading results. you will need to request each page. you may also need to pass your timezone.\n\n```py\n\nresults = cfd.get_all_results()\n\nprint(results)\n\n```\n\n#### Console\n\n```bash\n\n{'data': [{'direction': 'buy', 'code': 'AAPL', 'quantity': 0.1, 'orderNumber': {'name': 'P************', 'link': 'positionHistory/********-****-****-****-************', 'id': '********-****-****-****-************', 'frontend': 'WC4'}, 'price': '176.6700', 'closePrice': '181.98', 'result': '0.42', 'eventNumber': {'name': 'PO3062546222', 'id': '********-****-****-****-************'}, 'eventType': 'closed', 'time': '2023-08-29T17:15:55.000+03:00', 'openingTime': '2023-08-25T11:51:15.000+03:00'}, ...], 'nextPage': 'result?perPage=20\u0026onlyFullyClosed=false\u0026page=2', 'currentPage': 'result?perPage=20\u0026onlyFullyClosed=false\u0026page=1', 'totalSize': 133}\n\n```\n\n### Get order History\n\n```py\n\norderHist = cfd.get_order_hist(page_number=1)\n\nprint(orderHist)\n\n```\n\n#### Console\n\n```bash\n\n{'data': [], 'currentPage': 'order?filter=all\u0026perPage=20\u0026from=2023-09-06T02:00:00.000+03:00\u0026to=2023-09-08T01:59:59.173+03:00\u0026page=1', 'totalSize': 0}\n\n```\n\n### Get position History\n\n```py\n\npositionHist = cfd.get_posistion_hist(page_number=1)\n\nprint(positionHist)\n\n```\n\n#### Console\n\n```bash\n\n{'data': [], 'currentPage': 'position?perPage=20\u0026from=2023-09-06T02:00:00.000+03:00\u0026to=2023-09-08T01:59:59.173+03:00\u0026page=1', 'totalSize': 0}\n\n```\n\n### fast price\n\nThe *fast_price* retruns an instruments price as a float. if the request fails None is returned\n\n```py\n\nprice = cfd.fast_price(instrument=\"TSLA\")\n\nprint(price)\n\n```\n\n#### console\n\n```bash\n\n253.49\n\n```\n\n### Chart data\n\nThe *chart_data* returns a dictionary with the candle date OHLC (open, high, low, close) the period requested. which is set to 1minute by default.\n\n```py\n\ncharts = cfd.chart_data(instrument=\"TSLA\", period=\"ONE_MINUTE\")\n\nprint(charts)\n\n```\n\n#### Console\n\n```bash\n\n[{'request': {'ticker': 'TSLA', 'period': 'ONE_MINUTE', 'size': 500, 'useAskPrice': False}, 'response': {'candles': [[1691152740000, 259.6, 259.97, 259.43, 259.49, 47], [1691152800000, 259.38, 259.94, 259.17, 259.56, 58], [1691152860000, 259.62, 260.34, 259.62, 260.19, 42]\n\n```\n\n### Get multiple price data\n\nThe *multi_price* function will return the last qouted price for all passed instruments.\n\n```py\n\ntickers =[\"TSLA\",\"AAPL\",\"GOOG\"]\n\nmultiprice = cfd.multi_price(instruments=tickers)\n\nprint(multiprice)\n\n```\n\n#### Console\n\n```bash\n\n[{'ticker': 'TSLA', 'price': 251.34}, {'ticker': 'AAPL', 'price': 181.96}, {'ticker': 'GOOG', 'price': 135.18}]\n\n```\n\n## TRADES\n\n### Market order\n\nThe *market_order* function submits a market order and requires the current price of the instrument.\n\n```py\n\ntargetPrice = cfd.fast_price(instrument=\"TSLA\")\n\nmarketOrder = cfd.market_order(instrument=\"TSLA\", target_price=targePrice,\nquantity=1.5, take_profit=10, stop_loss=10 )\n\n```\n\n### Limit order\n\nThe *limit_order* function submits a limit order\n\n```py\n\nmarketOrder = cfd.limit_order(instrument=\"TSLA\", target_price=127,\nquantity=1.5, take_profit=10, stop_loss=10)\n\n```\n\n### Set limits\n\nThe *set_limits* function allows you to modify or add a stoploss or takeprofit to an existing postion (the positionID is required to carry out this function)\n\n```py\n\nlimits = cfd.set_limits(position_id=27361748, TP=10, SL=10)\n\n```\n\n### add trailing stop\n\nThe *add_trailing_stop* function adds a trailing stop to an existing position\n\n```py\n\ntrailing = cfd.add_trailing_stop(position_id=27361748, distance=1)\n\n```\n\n### close position\n\nThe *close_position* function is used to close an open position. it will required the current price.\n\n```py\n\ncurrentPrice = cfd.fast_price(instrument=\"TSLA\")\n\nclose = cfd.close_position(position_id=23948174, current_price=currentPrice)\n\n```\n\n### cancel all orders\n\n```py\n\ncancelAll = cfd.cancel_all_orders()\n\n```\n\n### cancel order\n\nThe *cancel_order* function is used to cancel a limit order.\n\n```py\n\ncancel = cfd.cancel_order(order_id=**********)\n\n```\n\n\n\n### Get ticker price\n\nthe *get_live* function will return the current price of a ticker\n\n```py\n\ntickers = [\"TSLA\", \"AAPL\"]\n\nprices = cfd.live_price(instruments=tickers)\n\nprint(prices)\n\n```\n\n#### Console:\n\n```bash\n\n[{'request': {'ticker': 'TSLA', 'useAskPrice': False}, 'response': {'timestamp': 1690531210000, 'price': 255.8, 'period': 'd1'}}, {'request': {'ticker': 'AAPL', 'useAskPrice': False}, 'response': {'timestamp': 1690531210000, 'price': 193.29, 'period': 'd1'}}]\n\n```\n\n### Get Funds\n\nThe *get_funds* function will return your accounts funds.\n\n```py\n\nfunds = cfd.get_funds()\n\nprint(funds)\n\n```\n\n#### Console:\n\n```bash\n\n{'20434246': {'accountId': ********, 'tradingType': 'CFD', 'currency': 'GBP',\n'freeForWithdraw': 486.83, 'freeForCfdTransfer': 0, 'total': 486.83,\n'lockedCash': {'totalLockedCash': 0, 'lockedCash': []}}}\n\n```\n\n### Add trailing stop loss\n\nthe *trailing_stop* function allows you to add a trailing stop to a open position.\n\n```py\n\ntrailing_stop = cfd.trailing_stop(position_id=\"***-****-***\", distance=0.5)\n\n```\n\n### Add/Change stoploss and takeprofit\n\nThe *add_limits* function allows you to add a stoploss and takeprofit to an existing position.\n\n```py\n\nupdate_limits = client.add_limits(position_id=\"***-****-***\", TP=1 , SL=1)\n\n```\nTo set a new stoploss or takeprofit just pass the distance to the TP (take profit) or SL (stop loss) params. The function will get the current price and apply the distance.\n\n### Get all position history\n\nThe *all_position_hist* function will return the position history.\n\n```py\n\nposition_history = cfd.all_position_hist()\n\n```\n\n### Get order history\n\nThe *all_order_hist* returns orders data\n\n```py\n\norder_history = cfd.all_order_hist()\n\n```\n\n### Get Insturments info\n\nThe *get_instrument* function will retunr information about the instrument. \n\n```py\n\ntsla_info = cfd.get_instruments_info(instrument='TSLA')\n\nprint(tsla_info)\n\n```\n\n#### Console:\n\n```bash\n\n{'code': 'TSLA', 'type': 'STOCK', 'margin': 0.2, 'shortPositionSwap': -0.07030593058663,\n'longPositionSwap': -0.27928156941337, 'tsSwapCharges': '1970-01-01T23:00:00.000+02:00',\n'marginPercent': '20', 'leverage': '1:5'}\n\n```\n\n### Get position information\n\nThe *get_position* function will returns information for the qouted positionID.\n\n```py\n\nposition = cfd.get_position(position_id=\"***-****-***\")\n\nprint(position)\n\n```\n\n#### console\n\n```bash\n\n[{'eventType': {'action': 'opened', 'source': 'MARKET_ORDER'}, \n'eventNumber': {'name': 'MO3053019640', 'id': '274187113', 'frontend': 'WC4'}, 'time': '2023-08-02T22:42:54.000+03:00', \n'direction': 'sell', 'quantity': 1.0, 'price': '105.29', 'avgQuantity': 1.0, 'avgPrice': '105.2900', 'modifiedDirection': \n'sell'}]\n\n```\n\n### Get Summary\n\nThe *get_summary* function will return the account summary. this function can also be used to get order ID's and there current PPL\n\n```py\n\nsummary = cfd.get_summary()\n\nprint(summary)\n\n```\n\n#### Example:\n\n```bash\n'open': {'unfilteredCount': 1, 'items': [{'positionId': '********-****-****-****-************', 'humanId': '********',\n'created': '2023-07-03T18:17:46.563+03:00', 'averagePrice': 192.25, 'averagePriceConverted': 150.73025341182984,\n'currentPrice': 192.2, 'value': 1054.82, 'investment': 1055.11, 'code': 'AAPL', 'margin': 212.02, 'ppl': -0.28,\n'quantity': 7, 'maxBuy': 9.0, 'maxSell': 7, 'maxOpenBuy': 2033.0, 'maxOpenSell': 2040.0, 'swap': -1.06, 'frontend': 'WC4'}]}\n\n```\n\n### Get live Price\n\nThe *live_price* function will return the current ask price for the passed instrument.\n\n```py\n\nticker = [\"TSLA\",\"AAPL\",\"GOOG\"]\n\nlive_price = cfd.live_price(instruments=ticker)\n\nprint(live_price)\n\n\n```\n\n#### console:\n\n```bash\n\n[{'ticker': 'TSLA', 'price': 253.49}, {'ticker': 'AAPL', 'price': 182.08}, {'ticker': 'GOOG', 'price': 128.44}]\n\n\n```\n\n### Get fast price\n\nThe *fast_price* function will return the last qouted chart price as a float\n\n```py\n\nprice = cfd.fast_price(instrument=\"TSLA\")\n\nprint(price)\n\n\n```\n\n#### console:\n\n```bash\n\n253.49\n\n```\n\n### Get chart data\n\nthe *chart_data* function will return the lastest chart data for passed instrument\n\n```py\n\nchart = cfd.chart_data(instrument=\"TSLA\")\n\nprint(chart)\n\n```\n\n#### console:\n\n```bash\n\n[{'request': {'ticker': 'TSLA', 'period': 'ONE_MINUTE', 'size': 500, 'useAskPrice': False}, 'response': {'candles': [[1691152740000, 259.6, 259.97, 259.43, 259.49, 47], [1691152800000, 259.38, 259.94, 259.17, 259.56, 58], [1691152860000, 259.62, 260.34, 259.62, 260.19, 42]\n\n```\n\n### Get price deviations\n\nThe *get_deviations* function will return price deviations\n\n```py\n\nticker = [\"TSLA\",\"AAPL\",\"GOOG\"]\n\ndeviations = cfd.get_deviations(instruments=ticker)\n\nprint(deviations)\n\n```\n\n#### console:\n\n```bash\n\n[{'request': {'ticker': 'TSLA', 'useAskPrice': False}, 'response': {'timestamp': 1691136010000, 'price': 259.38, 'period': 'd1'}}, {'request': {'ticker': 'AAPL', 'useAskPrice': False}, 'response': {'timestamp': 1691136010000, 'price': 188.99, 'period': 'd1'}}, {'request': {'ticker': 'GOOG', 'useAskPrice': False}, 'response': {'timestamp': 1691136010000, 'price': 129.05, 'period': 'd1'}}]\n\n```\n\n### Get Companies\n\nThe *get_companies* function will return companies currently listed on T212 \u0026 their respective isin ID.\n\n\n```py\n\n\ncompanies = cfd.get_companies()\n\nprint(companies)\n\n\n```\n\n#### console:\n\n```bash\n\n[{'ticker': 'SIGTl_EQ', 'isin': 'GB0008769993'}, {'ticker': 'PDYPY_US_EQ', 'isin': 'US3440441026'}...]\n\n```\n\n### Limit Order\n\nThe *limit_order* function submit a limit order and takes quantity, target_price, take_profit \u0026 stop_loss parms.\n\n```py\n\nlimit_order = cfd.limit_order(instrument=\"TSLA\",\nquantity=5, target_price=129, take_profit=130, stop_loss=128)\n\n```\n\n#### Console:\n\n```\n\n{'account': {'dealer': 'AVUSUK', 'positions': [{'positionId': '********-****-****-****-************',\n'humanId': '**********', 'created': '2023-07-03T18:17:46.563+03:00' ...\n\n```\n\n### Market Order\nThe *market_order* function submit a market order and takes quantity, target_price, take_profit \u0026 stop_loss parms.\n\n```py\n\nmarket_order = cfd.market_order(instrument=\"TSLA\",\nquantity=5, target_price=129, take_profit=130, stop_loss=128)\n\n\n```\n\n### Cancel order\nThe *cancel_order* function will cancel a pending order it requires a orderID.\n\n```py\n\ncancel_order = cfd.cancel_order(order_id)\n\n\n```\n\nYou can also use the *cancel_all_orders* to cancel all pending limits orders.\n\n\n```py\n\ncancel_all = cfd.cancel_all_orders()\n\n```\n\n### Close Position\nThe *close_position* function will submit a request to cancel a open position.\n\n```py\n\n\nclose_position = cfd.close_position(position_id='ordexxxxx', current_price=current_price)\n\n\n```\n\n## CODE EXAMPLES\n\n\n```py\n\nusername = \"flock92@account.api\"\npassword = \"password132\"\n\napi = Apit212()\n\napi.setup(username=username, password=password, mode=\"demo\")\n\ncfd = CFD(cred=api)\n\ntarget_price = 128\n\nwhile True:\n\n    sleep(60)\n\n    price = cfd.fast_price(\"TSLA\")\n\n    if price \u003c= target_price:\n\n        marketOrder = cfd.market_order(instrument=\"TSLA\",           target_price=price, quantity=1, take_profit=10, \n        stop_loss=10)\n\n        break\n\n```\n\n# Trade Exceptions\n\nWhen carrying out a trade you might run into issues and it's always good to have protocols in place to deal with these issues when they arise.\n\nbelow is a list of **some** exceptions you might come across when carrying out a trade.\n\n## BusinessException\n\n* MinQuantityExceeded\n* NoPriceException\n* InstrumentNotSupported\n* SpreadIsBiggerThanMinDistance\n* InstrumentDisabled\n* StopLossMustBeBelowCurrentPrice\n* InsufficientFundsMaxBuy\n* InsufficientFundsMaxSell\n* MarketStillNotOpen\n* QuantityPrecisionMismatch\n\n## InternalError\n\nJust stop making the request if you get this response\n\n# Using trading212 official API\n\nThis is currently only working with equity accounts and you can only submit trades on your demo account. please read the official documentation to get a better understanding and limitations of the API.\n\n## Setup\n\nIn order to use the official API you will need to generate a key using the trading212 app. /settings/API(Beta) then simply generate a new Key and pass it to the *Apitkey().Equity()* Class.\n\n```py\n\nfrom apit212 import *\n\nkey = \"20557******************************\"\n\nclient = Apitkey()\n\ninfo = client.Equity(api_key=key, mode=\"live\")\n\n```\n\n### Functions\n\nHere are the functions avalible using the trading212 API-token.\n\n* [exchange_list](https://t212public-api-docs.redoc.ly/#operation/exchanges)\n* [instrument_list](https://t212public-api-docs.redoc.ly/#operation/instruments)\n* [pies](https://t212public-api-docs.redoc.ly/#tag/Pies)\n* [create_pie](https://t212public-api-docs.redoc.ly/#operation/create)\n* [delete_pie](https://t212public-api-docs.redoc.ly/#operation/delete)\n* [fetch_pie](https://t212public-api-docs.redoc.ly/#operation/getDetailed)\n* [update_pie](https://t212public-api-docs.redoc.ly/#operation/update)\n* [equity_orders](https://t212public-api-docs.redoc.ly/#operation/orders) \n* [limit_order](https://t212public-api-docs.redoc.ly/#operation/placeLimitOrder)\n* [market_order](https://t212public-api-docs.redoc.ly/#operation/placeMarketOrder) \n* [stop_oder](https://t212public-api-docs.redoc.ly/#operation/placeStopOrder_1) \n* [stop_limit_order](https://t212public-api-docs.redoc.ly/#operation/placeStopOrder) \n* [cancel_order](https://t212public-api-docs.redoc.ly/#operation/cancelOrder)\n* [fetch_order](https://t212public-api-docs.redoc.ly/#operation/orderById)\n* [account_data](https://t212public-api-docs.redoc.ly/#operation/accountCash)\n* [account_meta](https://t212public-api-docs.redoc.ly/#operation/account)\n* [fetch_all_posistions](https://t212public-api-docs.redoc.ly/#operation/portfolio)\n* [fetch_position](https://t212public-api-docs.redoc.ly/#operation/positionByTicker)\n* [order_history](https://t212public-api-docs.redoc.ly/#operation/orders_1)\n* [paid_out_dividends](https://t212public-api-docs.redoc.ly/#operation/dividends)\n* [export_list](https://t212public-api-docs.redoc.ly/#operation/getReports)\n* [export_csv](https://t212public-api-docs.redoc.ly/#operation/requestReport)\n* [transactions](https://t212public-api-docs.redoc.ly/#operation/transactions)\n\n# Disclaimer\n\nThis is an unofficial API \u0026 either myself of trading212 are responsible for the use of this API. It is strongly advised that you use a practice account before moving onto real money. *apit212 is **not** a trading bot*\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflock92%2Ftrading212-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflock92%2Ftrading212-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflock92%2Ftrading212-api/lists"}