apit212


Nameapit212 JSON
Version 3.0.1 PyPI version JSON
download
home_pagehttps://github.com/Flock92/aPit212
SummaryUnofficial trading212 API
upload_time2023-10-31 21:46:49
maintainer
docs_urlNone
authorFlock92
requires_python>=3.9
licenseMIT
keywords trading trading212 api trade flock92
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # **Apit212**
 
This 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.

I will continue to work on this project and would appriciate any feedback. 

## Requirments
* Selenium
* Requests
* Python3
* Firefox

## Installation

pip install apit212

## Import

to 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.

### Demo account: 

```py

from apit212 import *

api = Apit212()

api.setup(username="flock92@account.api", password="pass******", mode="demo")

```

### Live account:

```py

from apit212 import *

api = Apit212()

api.setup(username="flock92@account.api", password="pass******", mode="live")

```

### Best Practice

It'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/)

```env

USER=flock92@account.api
PASS=password123

```

```py

from dotenv import load_dotenv
from apit212 import *
import os

load_dotenv('.env')

username: str = os.getenv('USER')
password: str = os.getenv('PASS')

api = Apit212()

api.setup(username="flock92@account.api", password="pass******", mode="demo")

```
---

# Correct Ticker

This API is useless without the correct ticker symbol so i've got a solution.

```py

from apit212 import Tickers

ticker = Tickers()

print(ticker.fetch_symbols(symbol='META'))

print(ticker.find_by_name(full_name='tesla'))

```

## console

There 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.

```bash

[{'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}]
[{'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}]


```

### example

```py

from apit212 import Tickers

ticker = Tickers()

meta = ticker.fetch_symbols(symbol='META')

print(len(meta))

print(meta[0]['ticker'])

```

#### console

finding a ticker using the widely used ticker will often return 1 result but on some occasions you may get multiple results
so its good practice to check the len of the string returned.

```bash

1
FB

```

# CFD or Trade Equity

To trade CFD's simply call the CFD class

```py

from apit212 import *

api = Apit212()

api.setup(username="flock92@account.api", password="pass******", mode="demo")

cfd = CFD(cred=api)

```

To trade Equity's simply call the Equity class.

```py

from apit212 import *

client = Apit212(username="flock92@account.api", password="pass******", mode="live")

equity = Equity()

```


## Account data

### Check session

The *auth_validate* function will return account ID and trade type.

```py

validate = cfd.auth_validate()

print(validate)

```

#### Console:

```bash

{'id': '*******-****-****-****-************', 'accountId': ********, 'customerId': *********, 'tradingType': 'CFD', 'customerUuid': '********-****-****-****-************', 'frontend': 'WC4', 'readyToTrade': True, 'deviceUuid': ''}

```

### get_account

The *get_account* function will return your account details.

```py

account = cfd.get_account()

print(account)

```

#### Console

```bash

{'demoAccounts': [{'id': ********, 'type': 'DEMO', 'tradingType': 'CFD', 'customerId': ********,
'createdDate': '2023-01-17T03:20:48.000+00:00', 'status': 'ACTIVE', 'registerSource': 'WC4',
'currencyCode': 'GBP', 'readyToTrade': True}], 'liveAccounts': [{'id': ********, 'type': 'LIVE',
'tradingType': 'CFD', 'customerId': ********, 'createdDate': '2023-01-17T03:20:32.000+00:00',
'status': 'PENDING_ACTIVATION', 'registerSource': 'WC4', 'currencyCode': 'GBP', 'readyToTrade': False}]}

```

### get_funds

The *get_funds* function will return the accounts funds.

```py

funds = cfd.get_funds()

print(funds)

```

#### Console

```bash

{'*******': {'accountId': ********, 'tradingType': 'CFD', 'currency': 'GBP',
'freeForWithdraw': 486.83, 'freeForCfdTransfer': 0, 'total': 486.83,
'lockedCash': {'totalLockedCash': 0, 'lockedCash': []}}}

```

### Get summary

The *get_summary* returns a summary of you account.

```py

summary = cfd.get_summary()

print(summary)

```

#### Console

```bash

'open': {'unfilteredCount': 1, 'items': [{'positionId': '********-****-****-****-************', 'humanId': '********',
'created': '2023-07-03T18:17:46.563+03:00', 'averagePrice': 192.25, 'averagePriceConverted': 150.73025341182984,
'currentPrice': 192.2, 'value': 1054.82, 'investment': 1055.11, 'code': 'AAPL', 'margin': 212.02, 'ppl': -0.28,
'quantity': 7, 'maxBuy': 9.0, 'maxSell': 7, 'maxOpenBuy': 2033.0, 'maxOpenSell': 2040.0, 'swap': -1.06, 'frontend': 'WC4'}]}

```

### Get companies

The *get_companies* returns instruments avaliable to trade on the trading212 platform

```py

companies = cfd.get_companies()

print(companies)

```

#### Console

```bash

[{'ticker': 'SIGTl_EQ', 'isin': 'GB0008769993'}, {'ticker': 'PDYPY_US_EQ', 'isin': 'US3440441026'}...]

```

### Get instrument info

The *get_instruments_info* will return information about an instrument.

```py

info = cfd.get_instruments_info(instrument="TSLA")

print(info)

```

#### Console

```bash

{'code': 'TSLA', 'type': 'STOCK', 'margin': 0.2, 'shortPositionSwap': -0.07030593058663,
'longPositionSwap': -0.27928156941337, 'tsSwapCharges': '1970-01-01T23:00:00.000+02:00',
'marginPercent': '20', 'leverage': '1:5'}

```

### Get order info

The *get_order_info* get 

```py

orderInfo = cfd.get_order_info(instrument="TSLA", quamtity=1.5)

print(orderInfo)

```

#### Console

```bash

{'buyMargin': 40.18, 'sellMargin': 40.18, 'buySwap': -0.2, 'sellSwap': -0.05}

```

### Get deviation

```py

tickers = ["TSLA","AAPL"]

deviation = cfd.get_deviations(instruments=tickers)

print(deviation)

```

#### Console

```bash

[{'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'}}]

```

### Get position

The *get_position* returns infomation for a given position ID, this ID's can be exstracted from the get_summary function

```py

position = cfd.get_position(position_id=274187113)

print(position)

```

#### Console

```bash

[{'eventType': {'action': 'opened', 'source': 'MARKET_ORDER'}, 
'eventNumber': {'name': 'MO3053019640', 'id': '274187113', 'frontend': 'WC4'}, 'time': '2023-08-02T22:42:54.000+03:00', 
'direction': 'sell', 'quantity': 1.0, 'price': '105.29', 'avgQuantity': 1.0, 'avgPrice': '105.2900', 'modifiedDirection': 
'sell'}]

```

### Get all results

The *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.

```py

results = cfd.get_all_results()

print(results)

```

#### Console

```bash

{'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&onlyFullyClosed=false&page=2', 'currentPage': 'result?perPage=20&onlyFullyClosed=false&page=1', 'totalSize': 133}

```

### Get order History

```py

orderHist = cfd.get_order_hist(page_number=1)

print(orderHist)

```

#### Console

```bash

{'data': [], 'currentPage': 'order?filter=all&perPage=20&from=2023-09-06T02:00:00.000+03:00&to=2023-09-08T01:59:59.173+03:00&page=1', 'totalSize': 0}

```

### Get position History

```py

positionHist = cfd.get_posistion_hist(page_number=1)

print(positionHist)

```

#### Console

```bash

{'data': [], 'currentPage': 'position?perPage=20&from=2023-09-06T02:00:00.000+03:00&to=2023-09-08T01:59:59.173+03:00&page=1', 'totalSize': 0}

```

### fast price

The *fast_price* retruns an instruments price as a float. if the request fails None is returned

```py

price = cfd.fast_price(instrument="TSLA")

print(price)

```

#### console

```bash

253.49

```

### Chart data

The *chart_data* returns a dictionary with the candle date OHLC (open, high, low, close) the period requested. which is set to 1minute by default.

```py

charts = cfd.chart_data(instrument="TSLA", period="ONE_MINUTE")

print(charts)

```

#### Console

```bash

[{'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]

```

### Get multiple price data

The *multi_price* function will return the last qouted price for all passed instruments.

```py

tickers =["TSLA","AAPL","GOOG"]

multiprice = cfd.multi_price(instruments=tickers)

print(multiprice)

```

#### Console

```bash

[{'ticker': 'TSLA', 'price': 251.34}, {'ticker': 'AAPL', 'price': 181.96}, {'ticker': 'GOOG', 'price': 135.18}]

```

## TRADES

### Market order

The *market_order* function submits a market order and requires the current price of the instrument.

```py

targetPrice = cfd.fast_price(instrument="TSLA")

marketOrder = cfd.market_order(instrument="TSLA", target_price=targePrice,
quantity=1.5, take_profit=10, stop_loss=10 )

```

### Limit order

The *limit_order* function submits a limit order

```py

marketOrder = cfd.limit_order(instrument="TSLA", target_price=127,
quantity=1.5, take_profit=10, stop_loss=10)

```

### Set limits

The *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)

```py

limits = cfd.set_limits(position_id=27361748, TP=10, SL=10)

```

### add trailing stop

The *add_trailing_stop* function adds a trailing stop to an existing position

```py

trailing = cfd.add_trailing_stop(position_id=27361748, distance=1)

```

### close position

The *close_position* function is used to close an open position. it will required the current price.

```py

currentPrice = cfd.fast_price(instrument="TSLA")

close = cfd.close_position(position_id=23948174, current_price=currentPrice)

```

### cancel all orders

```py

cancelAll = cfd.cancel_all_orders()

```

### cancel order

The *cancel_order* function is used to cancel a limit order.

```py

cancel = cfd.cancel_order(order_id=**********)

```



### Get ticker price

the *get_live* function will return the current price of a ticker

```py

tickers = ["TSLA", "AAPL"]

prices = cfd.live_price(instruments=tickers)

print(prices)

```

#### Console:

```bash

[{'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'}}]

```

### Get Funds

The *get_funds* function will return your accounts funds.

```py

funds = cfd.get_funds()

print(funds)

```

#### Console:

```bash

{'20434246': {'accountId': ********, 'tradingType': 'CFD', 'currency': 'GBP',
'freeForWithdraw': 486.83, 'freeForCfdTransfer': 0, 'total': 486.83,
'lockedCash': {'totalLockedCash': 0, 'lockedCash': []}}}

```

### Add trailing stop loss

the *trailing_stop* function allows you to add a trailing stop to a open position.

```py

trailing_stop = cfd.trailing_stop(position_id="***-****-***", distance=0.5)

```

### Add/Change stoploss and takeprofit

The *add_limits* function allows you to add a stoploss and takeprofit to an existing position.

```py

update_limits = client.add_limits(position_id="***-****-***", TP=1 , SL=1)

```
To 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.

### Get all position history

The *all_position_hist* function will return the position history.

```py

position_history = cfd.all_position_hist()

```

### Get order history

The *all_order_hist* returns orders data

```py

order_history = cfd.all_order_hist()

```

### Get Insturments info

The *get_instrument* function will retunr information about the instrument. 

```py

tsla_info = cfd.get_instruments_info(instrument='TSLA')

print(tsla_info)

```

#### Console:

```bash

{'code': 'TSLA', 'type': 'STOCK', 'margin': 0.2, 'shortPositionSwap': -0.07030593058663,
'longPositionSwap': -0.27928156941337, 'tsSwapCharges': '1970-01-01T23:00:00.000+02:00',
'marginPercent': '20', 'leverage': '1:5'}

```

### Get position information

The *get_position* function will returns information for the qouted positionID.

```py

position = cfd.get_position(position_id="***-****-***")

print(position)

```

#### console

```bash

[{'eventType': {'action': 'opened', 'source': 'MARKET_ORDER'}, 
'eventNumber': {'name': 'MO3053019640', 'id': '274187113', 'frontend': 'WC4'}, 'time': '2023-08-02T22:42:54.000+03:00', 
'direction': 'sell', 'quantity': 1.0, 'price': '105.29', 'avgQuantity': 1.0, 'avgPrice': '105.2900', 'modifiedDirection': 
'sell'}]

```

### Get Summary

The *get_summary* function will return the account summary. this function can also be used to get order ID's and there current PPL

```py

summary = cfd.get_summary()

print(summary)

```

#### Example:

```bash
'open': {'unfilteredCount': 1, 'items': [{'positionId': '********-****-****-****-************', 'humanId': '********',
'created': '2023-07-03T18:17:46.563+03:00', 'averagePrice': 192.25, 'averagePriceConverted': 150.73025341182984,
'currentPrice': 192.2, 'value': 1054.82, 'investment': 1055.11, 'code': 'AAPL', 'margin': 212.02, 'ppl': -0.28,
'quantity': 7, 'maxBuy': 9.0, 'maxSell': 7, 'maxOpenBuy': 2033.0, 'maxOpenSell': 2040.0, 'swap': -1.06, 'frontend': 'WC4'}]}

```

### Get live Price

The *live_price* function will return the current ask price for the passed instrument.

```py

ticker = ["TSLA","AAPL","GOOG"]

live_price = cfd.live_price(instruments=ticker)

print(live_price)


```

#### console:

```bash

[{'ticker': 'TSLA', 'price': 253.49}, {'ticker': 'AAPL', 'price': 182.08}, {'ticker': 'GOOG', 'price': 128.44}]


```

### Get fast price

The *fast_price* function will return the last qouted chart price as a float

```py

price = cfd.fast_price(instrument="TSLA")

print(price)


```

#### console:

```bash

253.49

```

### Get chart data

the *chart_data* function will return the lastest chart data for passed instrument

```py

chart = cfd.chart_data(instrument="TSLA")

print(chart)

```

#### console:

```bash

[{'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]

```

### Get price deviations

The *get_deviations* function will return price deviations

```py

ticker = ["TSLA","AAPL","GOOG"]

deviations = cfd.get_deviations(instruments=ticker)

print(deviations)

```

#### console:

```bash

[{'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'}}]

```

### Get Companies

The *get_companies* function will return companies currently listed on T212 & their respective isin ID.


```py


companies = cfd.get_companies()

print(companies)


```

#### console:

```bash

[{'ticker': 'SIGTl_EQ', 'isin': 'GB0008769993'}, {'ticker': 'PDYPY_US_EQ', 'isin': 'US3440441026'}...]

```

### Limit Order

The *limit_order* function submit a limit order and takes quantity, target_price, take_profit & stop_loss parms.

```py

limit_order = cfd.limit_order(instrument="TSLA",
quantity=5, target_price=129, take_profit=130, stop_loss=128)

```

#### Console:

```

{'account': {'dealer': 'AVUSUK', 'positions': [{'positionId': '********-****-****-****-************',
'humanId': '**********', 'created': '2023-07-03T18:17:46.563+03:00' ...

```

### Market Order
The *market_order* function submit a market order and takes quantity, target_price, take_profit & stop_loss parms.

```py

market_order = cfd.market_order(instrument="TSLA",
quantity=5, target_price=129, take_profit=130, stop_loss=128)


```

### Cancel order
The *cancel_order* function will cancel a pending order it requires a orderID.

```py

cancel_order = cfd.cancel_order(order_id)


```

You can also use the *cancel_all_orders* to cancel all pending limits orders.


```py

cancel_all = cfd.cancel_all_orders()

```

### Close Position
The *close_position* function will submit a request to cancel a open position.

```py


close_position = cfd.close_position(position_id='ordexxxxx', current_price=current_price)


```

## CODE EXAMPLES


```py

username = "flock92@account.api"
password = "password132"

api = Apit212()

api.setup(username=username, password=password, mode="demo")

cfd = CFD(cred=api)

target_price = 128

while True:

    sleep(60)

    price = cfd.fast_price("TSLA")

    if price <= target_price:

        marketOrder = cfd.market_order(instrument="TSLA",           target_price=price, quantity=1, take_profit=10, 
        stop_loss=10)

        break

```

# Trade Exceptions

When 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.

below is a list of **some** exceptions you might come across when carrying out a trade.

## BusinessException

* MinQuantityExceeded
* NoPriceException
* InstrumentNotSupported
* SpreadIsBiggerThanMinDistance
* InstrumentDisabled
* StopLossMustBeBelowCurrentPrice
* InsufficientFundsMaxBuy
* InsufficientFundsMaxSell
* MarketStillNotOpen
* QuantityPrecisionMismatch

## InternalError

Just stop making the request if you get this response

# Using trading212 official API

This 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.

## Setup

In 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.

```py

from apit212 import *

key = "20557******************************"

client = Apitkey()

info = client.Equity(api_key=key, mode="live")

```

### Functions

Here are the functions avalible using the trading212 API-token.

* [exchange_list](https://t212public-api-docs.redoc.ly/#operation/exchanges)
* [instrument_list](https://t212public-api-docs.redoc.ly/#operation/instruments)
* [pies](https://t212public-api-docs.redoc.ly/#tag/Pies)
* [create_pie](https://t212public-api-docs.redoc.ly/#operation/create)
* [delete_pie](https://t212public-api-docs.redoc.ly/#operation/delete)
* [fetch_pie](https://t212public-api-docs.redoc.ly/#operation/getDetailed)
* [update_pie](https://t212public-api-docs.redoc.ly/#operation/update)
* [equity_orders](https://t212public-api-docs.redoc.ly/#operation/orders) 
* [limit_order](https://t212public-api-docs.redoc.ly/#operation/placeLimitOrder)
* [market_order](https://t212public-api-docs.redoc.ly/#operation/placeMarketOrder) 
* [stop_oder](https://t212public-api-docs.redoc.ly/#operation/placeStopOrder_1) 
* [stop_limit_order](https://t212public-api-docs.redoc.ly/#operation/placeStopOrder) 
* [cancel_order](https://t212public-api-docs.redoc.ly/#operation/cancelOrder)
* [fetch_order](https://t212public-api-docs.redoc.ly/#operation/orderById)
* [account_data](https://t212public-api-docs.redoc.ly/#operation/accountCash)
* [account_meta](https://t212public-api-docs.redoc.ly/#operation/account)
* [fetch_all_posistions](https://t212public-api-docs.redoc.ly/#operation/portfolio)
* [fetch_position](https://t212public-api-docs.redoc.ly/#operation/positionByTicker)
* [order_history](https://t212public-api-docs.redoc.ly/#operation/orders_1)
* [paid_out_dividends](https://t212public-api-docs.redoc.ly/#operation/dividends)
* [export_list](https://t212public-api-docs.redoc.ly/#operation/getReports)
* [export_csv](https://t212public-api-docs.redoc.ly/#operation/requestReport)
* [transactions](https://t212public-api-docs.redoc.ly/#operation/transactions)

# Disclaimer

This is an unofficial API & 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*


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Flock92/aPit212",
    "name": "apit212",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Flock92 <stuwe_3000@outlook.com>",
    "keywords": "trading,trading212,api,trade,flock92",
    "author": "Flock92",
    "author_email": "Flock92 <stuwe_3000@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/47/4e/894f34a363bb59ebd47bf94f6d3bec460fb6fd35a9eb03806dc41ae5788f/apit212-3.0.1.tar.gz",
    "platform": null,
    "description": "# **Apit212**\r\n \r\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.\r\n\r\nI will continue to work on this project and would appriciate any feedback. \r\n\r\n## Requirments\r\n* Selenium\r\n* Requests\r\n* Python3\r\n* Firefox\r\n\r\n## Installation\r\n\r\npip install apit212\r\n\r\n## Import\r\n\r\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.\r\n\r\n### Demo account: \r\n\r\n```py\r\n\r\nfrom apit212 import *\r\n\r\napi = Apit212()\r\n\r\napi.setup(username=\"flock92@account.api\", password=\"pass******\", mode=\"demo\")\r\n\r\n```\r\n\r\n### Live account:\r\n\r\n```py\r\n\r\nfrom apit212 import *\r\n\r\napi = Apit212()\r\n\r\napi.setup(username=\"flock92@account.api\", password=\"pass******\", mode=\"live\")\r\n\r\n```\r\n\r\n### Best Practice\r\n\r\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/)\r\n\r\n```env\r\n\r\nUSER=flock92@account.api\r\nPASS=password123\r\n\r\n```\r\n\r\n```py\r\n\r\nfrom dotenv import load_dotenv\r\nfrom apit212 import *\r\nimport os\r\n\r\nload_dotenv('.env')\r\n\r\nusername: str = os.getenv('USER')\r\npassword: str = os.getenv('PASS')\r\n\r\napi = Apit212()\r\n\r\napi.setup(username=\"flock92@account.api\", password=\"pass******\", mode=\"demo\")\r\n\r\n```\r\n---\r\n\r\n# Correct Ticker\r\n\r\nThis API is useless without the correct ticker symbol so i've got a solution.\r\n\r\n```py\r\n\r\nfrom apit212 import Tickers\r\n\r\nticker = Tickers()\r\n\r\nprint(ticker.fetch_symbols(symbol='META'))\r\n\r\nprint(ticker.find_by_name(full_name='tesla'))\r\n\r\n```\r\n\r\n## console\r\n\r\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.\r\n\r\n```bash\r\n\r\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}]\r\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}]\r\n\r\n\r\n```\r\n\r\n### example\r\n\r\n```py\r\n\r\nfrom apit212 import Tickers\r\n\r\nticker = Tickers()\r\n\r\nmeta = ticker.fetch_symbols(symbol='META')\r\n\r\nprint(len(meta))\r\n\r\nprint(meta[0]['ticker'])\r\n\r\n```\r\n\r\n#### console\r\n\r\nfinding a ticker using the widely used ticker will often return 1 result but on some occasions you may get multiple results\r\nso its good practice to check the len of the string returned.\r\n\r\n```bash\r\n\r\n1\r\nFB\r\n\r\n```\r\n\r\n# CFD or Trade Equity\r\n\r\nTo trade CFD's simply call the CFD class\r\n\r\n```py\r\n\r\nfrom apit212 import *\r\n\r\napi = Apit212()\r\n\r\napi.setup(username=\"flock92@account.api\", password=\"pass******\", mode=\"demo\")\r\n\r\ncfd = CFD(cred=api)\r\n\r\n```\r\n\r\nTo trade Equity's simply call the Equity class.\r\n\r\n```py\r\n\r\nfrom apit212 import *\r\n\r\nclient = Apit212(username=\"flock92@account.api\", password=\"pass******\", mode=\"live\")\r\n\r\nequity = Equity()\r\n\r\n```\r\n\r\n\r\n## Account data\r\n\r\n### Check session\r\n\r\nThe *auth_validate* function will return account ID and trade type.\r\n\r\n```py\r\n\r\nvalidate = cfd.auth_validate()\r\n\r\nprint(validate)\r\n\r\n```\r\n\r\n#### Console:\r\n\r\n```bash\r\n\r\n{'id': '*******-****-****-****-************', 'accountId': ********, 'customerId': *********, 'tradingType': 'CFD', 'customerUuid': '********-****-****-****-************', 'frontend': 'WC4', 'readyToTrade': True, 'deviceUuid': ''}\r\n\r\n```\r\n\r\n### get_account\r\n\r\nThe *get_account* function will return your account details.\r\n\r\n```py\r\n\r\naccount = cfd.get_account()\r\n\r\nprint(account)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n{'demoAccounts': [{'id': ********, 'type': 'DEMO', 'tradingType': 'CFD', 'customerId': ********,\r\n'createdDate': '2023-01-17T03:20:48.000+00:00', 'status': 'ACTIVE', 'registerSource': 'WC4',\r\n'currencyCode': 'GBP', 'readyToTrade': True}], 'liveAccounts': [{'id': ********, 'type': 'LIVE',\r\n'tradingType': 'CFD', 'customerId': ********, 'createdDate': '2023-01-17T03:20:32.000+00:00',\r\n'status': 'PENDING_ACTIVATION', 'registerSource': 'WC4', 'currencyCode': 'GBP', 'readyToTrade': False}]}\r\n\r\n```\r\n\r\n### get_funds\r\n\r\nThe *get_funds* function will return the accounts funds.\r\n\r\n```py\r\n\r\nfunds = cfd.get_funds()\r\n\r\nprint(funds)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n{'*******': {'accountId': ********, 'tradingType': 'CFD', 'currency': 'GBP',\r\n'freeForWithdraw': 486.83, 'freeForCfdTransfer': 0, 'total': 486.83,\r\n'lockedCash': {'totalLockedCash': 0, 'lockedCash': []}}}\r\n\r\n```\r\n\r\n### Get summary\r\n\r\nThe *get_summary* returns a summary of you account.\r\n\r\n```py\r\n\r\nsummary = cfd.get_summary()\r\n\r\nprint(summary)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n'open': {'unfilteredCount': 1, 'items': [{'positionId': '********-****-****-****-************', 'humanId': '********',\r\n'created': '2023-07-03T18:17:46.563+03:00', 'averagePrice': 192.25, 'averagePriceConverted': 150.73025341182984,\r\n'currentPrice': 192.2, 'value': 1054.82, 'investment': 1055.11, 'code': 'AAPL', 'margin': 212.02, 'ppl': -0.28,\r\n'quantity': 7, 'maxBuy': 9.0, 'maxSell': 7, 'maxOpenBuy': 2033.0, 'maxOpenSell': 2040.0, 'swap': -1.06, 'frontend': 'WC4'}]}\r\n\r\n```\r\n\r\n### Get companies\r\n\r\nThe *get_companies* returns instruments avaliable to trade on the trading212 platform\r\n\r\n```py\r\n\r\ncompanies = cfd.get_companies()\r\n\r\nprint(companies)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n[{'ticker': 'SIGTl_EQ', 'isin': 'GB0008769993'}, {'ticker': 'PDYPY_US_EQ', 'isin': 'US3440441026'}...]\r\n\r\n```\r\n\r\n### Get instrument info\r\n\r\nThe *get_instruments_info* will return information about an instrument.\r\n\r\n```py\r\n\r\ninfo = cfd.get_instruments_info(instrument=\"TSLA\")\r\n\r\nprint(info)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n{'code': 'TSLA', 'type': 'STOCK', 'margin': 0.2, 'shortPositionSwap': -0.07030593058663,\r\n'longPositionSwap': -0.27928156941337, 'tsSwapCharges': '1970-01-01T23:00:00.000+02:00',\r\n'marginPercent': '20', 'leverage': '1:5'}\r\n\r\n```\r\n\r\n### Get order info\r\n\r\nThe *get_order_info* get \r\n\r\n```py\r\n\r\norderInfo = cfd.get_order_info(instrument=\"TSLA\", quamtity=1.5)\r\n\r\nprint(orderInfo)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n{'buyMargin': 40.18, 'sellMargin': 40.18, 'buySwap': -0.2, 'sellSwap': -0.05}\r\n\r\n```\r\n\r\n### Get deviation\r\n\r\n```py\r\n\r\ntickers = [\"TSLA\",\"AAPL\"]\r\n\r\ndeviation = cfd.get_deviations(instruments=tickers)\r\n\r\nprint(deviation)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\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'}}]\r\n\r\n```\r\n\r\n### Get position\r\n\r\nThe *get_position* returns infomation for a given position ID, this ID's can be exstracted from the get_summary function\r\n\r\n```py\r\n\r\nposition = cfd.get_position(position_id=274187113)\r\n\r\nprint(position)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n[{'eventType': {'action': 'opened', 'source': 'MARKET_ORDER'}, \r\n'eventNumber': {'name': 'MO3053019640', 'id': '274187113', 'frontend': 'WC4'}, 'time': '2023-08-02T22:42:54.000+03:00', \r\n'direction': 'sell', 'quantity': 1.0, 'price': '105.29', 'avgQuantity': 1.0, 'avgPrice': '105.2900', 'modifiedDirection': \r\n'sell'}]\r\n\r\n```\r\n\r\n### Get all results\r\n\r\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.\r\n\r\n```py\r\n\r\nresults = cfd.get_all_results()\r\n\r\nprint(results)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\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&onlyFullyClosed=false&page=2', 'currentPage': 'result?perPage=20&onlyFullyClosed=false&page=1', 'totalSize': 133}\r\n\r\n```\r\n\r\n### Get order History\r\n\r\n```py\r\n\r\norderHist = cfd.get_order_hist(page_number=1)\r\n\r\nprint(orderHist)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n{'data': [], 'currentPage': 'order?filter=all&perPage=20&from=2023-09-06T02:00:00.000+03:00&to=2023-09-08T01:59:59.173+03:00&page=1', 'totalSize': 0}\r\n\r\n```\r\n\r\n### Get position History\r\n\r\n```py\r\n\r\npositionHist = cfd.get_posistion_hist(page_number=1)\r\n\r\nprint(positionHist)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n{'data': [], 'currentPage': 'position?perPage=20&from=2023-09-06T02:00:00.000+03:00&to=2023-09-08T01:59:59.173+03:00&page=1', 'totalSize': 0}\r\n\r\n```\r\n\r\n### fast price\r\n\r\nThe *fast_price* retruns an instruments price as a float. if the request fails None is returned\r\n\r\n```py\r\n\r\nprice = cfd.fast_price(instrument=\"TSLA\")\r\n\r\nprint(price)\r\n\r\n```\r\n\r\n#### console\r\n\r\n```bash\r\n\r\n253.49\r\n\r\n```\r\n\r\n### Chart data\r\n\r\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.\r\n\r\n```py\r\n\r\ncharts = cfd.chart_data(instrument=\"TSLA\", period=\"ONE_MINUTE\")\r\n\r\nprint(charts)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\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]\r\n\r\n```\r\n\r\n### Get multiple price data\r\n\r\nThe *multi_price* function will return the last qouted price for all passed instruments.\r\n\r\n```py\r\n\r\ntickers =[\"TSLA\",\"AAPL\",\"GOOG\"]\r\n\r\nmultiprice = cfd.multi_price(instruments=tickers)\r\n\r\nprint(multiprice)\r\n\r\n```\r\n\r\n#### Console\r\n\r\n```bash\r\n\r\n[{'ticker': 'TSLA', 'price': 251.34}, {'ticker': 'AAPL', 'price': 181.96}, {'ticker': 'GOOG', 'price': 135.18}]\r\n\r\n```\r\n\r\n## TRADES\r\n\r\n### Market order\r\n\r\nThe *market_order* function submits a market order and requires the current price of the instrument.\r\n\r\n```py\r\n\r\ntargetPrice = cfd.fast_price(instrument=\"TSLA\")\r\n\r\nmarketOrder = cfd.market_order(instrument=\"TSLA\", target_price=targePrice,\r\nquantity=1.5, take_profit=10, stop_loss=10 )\r\n\r\n```\r\n\r\n### Limit order\r\n\r\nThe *limit_order* function submits a limit order\r\n\r\n```py\r\n\r\nmarketOrder = cfd.limit_order(instrument=\"TSLA\", target_price=127,\r\nquantity=1.5, take_profit=10, stop_loss=10)\r\n\r\n```\r\n\r\n### Set limits\r\n\r\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)\r\n\r\n```py\r\n\r\nlimits = cfd.set_limits(position_id=27361748, TP=10, SL=10)\r\n\r\n```\r\n\r\n### add trailing stop\r\n\r\nThe *add_trailing_stop* function adds a trailing stop to an existing position\r\n\r\n```py\r\n\r\ntrailing = cfd.add_trailing_stop(position_id=27361748, distance=1)\r\n\r\n```\r\n\r\n### close position\r\n\r\nThe *close_position* function is used to close an open position. it will required the current price.\r\n\r\n```py\r\n\r\ncurrentPrice = cfd.fast_price(instrument=\"TSLA\")\r\n\r\nclose = cfd.close_position(position_id=23948174, current_price=currentPrice)\r\n\r\n```\r\n\r\n### cancel all orders\r\n\r\n```py\r\n\r\ncancelAll = cfd.cancel_all_orders()\r\n\r\n```\r\n\r\n### cancel order\r\n\r\nThe *cancel_order* function is used to cancel a limit order.\r\n\r\n```py\r\n\r\ncancel = cfd.cancel_order(order_id=**********)\r\n\r\n```\r\n\r\n\r\n\r\n### Get ticker price\r\n\r\nthe *get_live* function will return the current price of a ticker\r\n\r\n```py\r\n\r\ntickers = [\"TSLA\", \"AAPL\"]\r\n\r\nprices = cfd.live_price(instruments=tickers)\r\n\r\nprint(prices)\r\n\r\n```\r\n\r\n#### Console:\r\n\r\n```bash\r\n\r\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'}}]\r\n\r\n```\r\n\r\n### Get Funds\r\n\r\nThe *get_funds* function will return your accounts funds.\r\n\r\n```py\r\n\r\nfunds = cfd.get_funds()\r\n\r\nprint(funds)\r\n\r\n```\r\n\r\n#### Console:\r\n\r\n```bash\r\n\r\n{'20434246': {'accountId': ********, 'tradingType': 'CFD', 'currency': 'GBP',\r\n'freeForWithdraw': 486.83, 'freeForCfdTransfer': 0, 'total': 486.83,\r\n'lockedCash': {'totalLockedCash': 0, 'lockedCash': []}}}\r\n\r\n```\r\n\r\n### Add trailing stop loss\r\n\r\nthe *trailing_stop* function allows you to add a trailing stop to a open position.\r\n\r\n```py\r\n\r\ntrailing_stop = cfd.trailing_stop(position_id=\"***-****-***\", distance=0.5)\r\n\r\n```\r\n\r\n### Add/Change stoploss and takeprofit\r\n\r\nThe *add_limits* function allows you to add a stoploss and takeprofit to an existing position.\r\n\r\n```py\r\n\r\nupdate_limits = client.add_limits(position_id=\"***-****-***\", TP=1 , SL=1)\r\n\r\n```\r\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.\r\n\r\n### Get all position history\r\n\r\nThe *all_position_hist* function will return the position history.\r\n\r\n```py\r\n\r\nposition_history = cfd.all_position_hist()\r\n\r\n```\r\n\r\n### Get order history\r\n\r\nThe *all_order_hist* returns orders data\r\n\r\n```py\r\n\r\norder_history = cfd.all_order_hist()\r\n\r\n```\r\n\r\n### Get Insturments info\r\n\r\nThe *get_instrument* function will retunr information about the instrument. \r\n\r\n```py\r\n\r\ntsla_info = cfd.get_instruments_info(instrument='TSLA')\r\n\r\nprint(tsla_info)\r\n\r\n```\r\n\r\n#### Console:\r\n\r\n```bash\r\n\r\n{'code': 'TSLA', 'type': 'STOCK', 'margin': 0.2, 'shortPositionSwap': -0.07030593058663,\r\n'longPositionSwap': -0.27928156941337, 'tsSwapCharges': '1970-01-01T23:00:00.000+02:00',\r\n'marginPercent': '20', 'leverage': '1:5'}\r\n\r\n```\r\n\r\n### Get position information\r\n\r\nThe *get_position* function will returns information for the qouted positionID.\r\n\r\n```py\r\n\r\nposition = cfd.get_position(position_id=\"***-****-***\")\r\n\r\nprint(position)\r\n\r\n```\r\n\r\n#### console\r\n\r\n```bash\r\n\r\n[{'eventType': {'action': 'opened', 'source': 'MARKET_ORDER'}, \r\n'eventNumber': {'name': 'MO3053019640', 'id': '274187113', 'frontend': 'WC4'}, 'time': '2023-08-02T22:42:54.000+03:00', \r\n'direction': 'sell', 'quantity': 1.0, 'price': '105.29', 'avgQuantity': 1.0, 'avgPrice': '105.2900', 'modifiedDirection': \r\n'sell'}]\r\n\r\n```\r\n\r\n### Get Summary\r\n\r\nThe *get_summary* function will return the account summary. this function can also be used to get order ID's and there current PPL\r\n\r\n```py\r\n\r\nsummary = cfd.get_summary()\r\n\r\nprint(summary)\r\n\r\n```\r\n\r\n#### Example:\r\n\r\n```bash\r\n'open': {'unfilteredCount': 1, 'items': [{'positionId': '********-****-****-****-************', 'humanId': '********',\r\n'created': '2023-07-03T18:17:46.563+03:00', 'averagePrice': 192.25, 'averagePriceConverted': 150.73025341182984,\r\n'currentPrice': 192.2, 'value': 1054.82, 'investment': 1055.11, 'code': 'AAPL', 'margin': 212.02, 'ppl': -0.28,\r\n'quantity': 7, 'maxBuy': 9.0, 'maxSell': 7, 'maxOpenBuy': 2033.0, 'maxOpenSell': 2040.0, 'swap': -1.06, 'frontend': 'WC4'}]}\r\n\r\n```\r\n\r\n### Get live Price\r\n\r\nThe *live_price* function will return the current ask price for the passed instrument.\r\n\r\n```py\r\n\r\nticker = [\"TSLA\",\"AAPL\",\"GOOG\"]\r\n\r\nlive_price = cfd.live_price(instruments=ticker)\r\n\r\nprint(live_price)\r\n\r\n\r\n```\r\n\r\n#### console:\r\n\r\n```bash\r\n\r\n[{'ticker': 'TSLA', 'price': 253.49}, {'ticker': 'AAPL', 'price': 182.08}, {'ticker': 'GOOG', 'price': 128.44}]\r\n\r\n\r\n```\r\n\r\n### Get fast price\r\n\r\nThe *fast_price* function will return the last qouted chart price as a float\r\n\r\n```py\r\n\r\nprice = cfd.fast_price(instrument=\"TSLA\")\r\n\r\nprint(price)\r\n\r\n\r\n```\r\n\r\n#### console:\r\n\r\n```bash\r\n\r\n253.49\r\n\r\n```\r\n\r\n### Get chart data\r\n\r\nthe *chart_data* function will return the lastest chart data for passed instrument\r\n\r\n```py\r\n\r\nchart = cfd.chart_data(instrument=\"TSLA\")\r\n\r\nprint(chart)\r\n\r\n```\r\n\r\n#### console:\r\n\r\n```bash\r\n\r\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]\r\n\r\n```\r\n\r\n### Get price deviations\r\n\r\nThe *get_deviations* function will return price deviations\r\n\r\n```py\r\n\r\nticker = [\"TSLA\",\"AAPL\",\"GOOG\"]\r\n\r\ndeviations = cfd.get_deviations(instruments=ticker)\r\n\r\nprint(deviations)\r\n\r\n```\r\n\r\n#### console:\r\n\r\n```bash\r\n\r\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'}}]\r\n\r\n```\r\n\r\n### Get Companies\r\n\r\nThe *get_companies* function will return companies currently listed on T212 & their respective isin ID.\r\n\r\n\r\n```py\r\n\r\n\r\ncompanies = cfd.get_companies()\r\n\r\nprint(companies)\r\n\r\n\r\n```\r\n\r\n#### console:\r\n\r\n```bash\r\n\r\n[{'ticker': 'SIGTl_EQ', 'isin': 'GB0008769993'}, {'ticker': 'PDYPY_US_EQ', 'isin': 'US3440441026'}...]\r\n\r\n```\r\n\r\n### Limit Order\r\n\r\nThe *limit_order* function submit a limit order and takes quantity, target_price, take_profit & stop_loss parms.\r\n\r\n```py\r\n\r\nlimit_order = cfd.limit_order(instrument=\"TSLA\",\r\nquantity=5, target_price=129, take_profit=130, stop_loss=128)\r\n\r\n```\r\n\r\n#### Console:\r\n\r\n```\r\n\r\n{'account': {'dealer': 'AVUSUK', 'positions': [{'positionId': '********-****-****-****-************',\r\n'humanId': '**********', 'created': '2023-07-03T18:17:46.563+03:00' ...\r\n\r\n```\r\n\r\n### Market Order\r\nThe *market_order* function submit a market order and takes quantity, target_price, take_profit & stop_loss parms.\r\n\r\n```py\r\n\r\nmarket_order = cfd.market_order(instrument=\"TSLA\",\r\nquantity=5, target_price=129, take_profit=130, stop_loss=128)\r\n\r\n\r\n```\r\n\r\n### Cancel order\r\nThe *cancel_order* function will cancel a pending order it requires a orderID.\r\n\r\n```py\r\n\r\ncancel_order = cfd.cancel_order(order_id)\r\n\r\n\r\n```\r\n\r\nYou can also use the *cancel_all_orders* to cancel all pending limits orders.\r\n\r\n\r\n```py\r\n\r\ncancel_all = cfd.cancel_all_orders()\r\n\r\n```\r\n\r\n### Close Position\r\nThe *close_position* function will submit a request to cancel a open position.\r\n\r\n```py\r\n\r\n\r\nclose_position = cfd.close_position(position_id='ordexxxxx', current_price=current_price)\r\n\r\n\r\n```\r\n\r\n## CODE EXAMPLES\r\n\r\n\r\n```py\r\n\r\nusername = \"flock92@account.api\"\r\npassword = \"password132\"\r\n\r\napi = Apit212()\r\n\r\napi.setup(username=username, password=password, mode=\"demo\")\r\n\r\ncfd = CFD(cred=api)\r\n\r\ntarget_price = 128\r\n\r\nwhile True:\r\n\r\n    sleep(60)\r\n\r\n    price = cfd.fast_price(\"TSLA\")\r\n\r\n    if price <= target_price:\r\n\r\n        marketOrder = cfd.market_order(instrument=\"TSLA\",           target_price=price, quantity=1, take_profit=10, \r\n        stop_loss=10)\r\n\r\n        break\r\n\r\n```\r\n\r\n# Trade Exceptions\r\n\r\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.\r\n\r\nbelow is a list of **some** exceptions you might come across when carrying out a trade.\r\n\r\n## BusinessException\r\n\r\n* MinQuantityExceeded\r\n* NoPriceException\r\n* InstrumentNotSupported\r\n* SpreadIsBiggerThanMinDistance\r\n* InstrumentDisabled\r\n* StopLossMustBeBelowCurrentPrice\r\n* InsufficientFundsMaxBuy\r\n* InsufficientFundsMaxSell\r\n* MarketStillNotOpen\r\n* QuantityPrecisionMismatch\r\n\r\n## InternalError\r\n\r\nJust stop making the request if you get this response\r\n\r\n# Using trading212 official API\r\n\r\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.\r\n\r\n## Setup\r\n\r\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.\r\n\r\n```py\r\n\r\nfrom apit212 import *\r\n\r\nkey = \"20557******************************\"\r\n\r\nclient = Apitkey()\r\n\r\ninfo = client.Equity(api_key=key, mode=\"live\")\r\n\r\n```\r\n\r\n### Functions\r\n\r\nHere are the functions avalible using the trading212 API-token.\r\n\r\n* [exchange_list](https://t212public-api-docs.redoc.ly/#operation/exchanges)\r\n* [instrument_list](https://t212public-api-docs.redoc.ly/#operation/instruments)\r\n* [pies](https://t212public-api-docs.redoc.ly/#tag/Pies)\r\n* [create_pie](https://t212public-api-docs.redoc.ly/#operation/create)\r\n* [delete_pie](https://t212public-api-docs.redoc.ly/#operation/delete)\r\n* [fetch_pie](https://t212public-api-docs.redoc.ly/#operation/getDetailed)\r\n* [update_pie](https://t212public-api-docs.redoc.ly/#operation/update)\r\n* [equity_orders](https://t212public-api-docs.redoc.ly/#operation/orders) \r\n* [limit_order](https://t212public-api-docs.redoc.ly/#operation/placeLimitOrder)\r\n* [market_order](https://t212public-api-docs.redoc.ly/#operation/placeMarketOrder) \r\n* [stop_oder](https://t212public-api-docs.redoc.ly/#operation/placeStopOrder_1) \r\n* [stop_limit_order](https://t212public-api-docs.redoc.ly/#operation/placeStopOrder) \r\n* [cancel_order](https://t212public-api-docs.redoc.ly/#operation/cancelOrder)\r\n* [fetch_order](https://t212public-api-docs.redoc.ly/#operation/orderById)\r\n* [account_data](https://t212public-api-docs.redoc.ly/#operation/accountCash)\r\n* [account_meta](https://t212public-api-docs.redoc.ly/#operation/account)\r\n* [fetch_all_posistions](https://t212public-api-docs.redoc.ly/#operation/portfolio)\r\n* [fetch_position](https://t212public-api-docs.redoc.ly/#operation/positionByTicker)\r\n* [order_history](https://t212public-api-docs.redoc.ly/#operation/orders_1)\r\n* [paid_out_dividends](https://t212public-api-docs.redoc.ly/#operation/dividends)\r\n* [export_list](https://t212public-api-docs.redoc.ly/#operation/getReports)\r\n* [export_csv](https://t212public-api-docs.redoc.ly/#operation/requestReport)\r\n* [transactions](https://t212public-api-docs.redoc.ly/#operation/transactions)\r\n\r\n# Disclaimer\r\n\r\nThis is an unofficial API & 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*\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Unofficial trading212 API",
    "version": "3.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/Flock92/apit212/issues",
        "Homepage": "https://github.com/Flock92/apit212"
    },
    "split_keywords": [
        "trading",
        "trading212",
        "api",
        "trade",
        "flock92"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86c698858116173df419a327b50a6a11e719f297ea995101b56af85ba019b1d7",
                "md5": "28861c9bc0f18d6499d52f0b5e89c9f0",
                "sha256": "dbf0231d2ee98e25f2c62fec78af84d410019aa58be9a6f90f9fe339f9fa9584"
            },
            "downloads": -1,
            "filename": "apit212-3.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "28861c9bc0f18d6499d52f0b5e89c9f0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 19180,
            "upload_time": "2023-10-31T21:46:42",
            "upload_time_iso_8601": "2023-10-31T21:46:42.968193Z",
            "url": "https://files.pythonhosted.org/packages/86/c6/98858116173df419a327b50a6a11e719f297ea995101b56af85ba019b1d7/apit212-3.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "474e894f34a363bb59ebd47bf94f6d3bec460fb6fd35a9eb03806dc41ae5788f",
                "md5": "08c00e584ab403e91dd5c0f22646faa1",
                "sha256": "1f33bc3484aca76b5ae400ab17af874e6b443bf895d3bfd2a29cad6e4c2d256a"
            },
            "downloads": -1,
            "filename": "apit212-3.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "08c00e584ab403e91dd5c0f22646faa1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 25137,
            "upload_time": "2023-10-31T21:46:49",
            "upload_time_iso_8601": "2023-10-31T21:46:49.529398Z",
            "url": "https://files.pythonhosted.org/packages/47/4e/894f34a363bb59ebd47bf94f6d3bec460fb6fd35a9eb03806dc41ae5788f/apit212-3.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-31 21:46:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Flock92",
    "github_project": "aPit212",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "apit212"
}
        
Elapsed time: 0.12837s