trading212 package
Submodules
trading212.http_request module
- class trading212.http_request.Client(api_key: str, domain: str = None, version: str = 'v0')[source]
Bases:
objectTrading212 http client.
- END_POINTS = {'create_pie': '/equity/pies', 'delete_order': '/equity/orders/{id}', 'delete_pie': '/equity/pies/{id}', 'get_account': '/equity/account/info', 'get_account_cash': '/equity/account/cash', 'get_all_open_positions': '/equity/portfolio', 'get_dividends': '/history/dividends', 'get_exchanges': '/equity/metadata/exchanges', 'get_exports': '/history/exports', 'get_exports_as_csv': '/history/exports', 'get_instruments': '/equity/metadata/instruments', 'get_order': '/equity/orders/{id}', 'get_order_history': '/equity/history/orders', 'get_orders': '/equity/orders/', 'get_pie': '/equity/pies/{id}', 'get_pies': '/equity/pies', 'get_position': '/equity/portfolio/{ticker}', 'get_transactions': '/history/transactions', 'place_limit_order': '/equity/orders/limit', 'place_market_order': '/equity/orders/market', 'place_stop_limit_order': '/equity/orders/stop_limit', 'place_stop_order': '/equity/orders/stop', 'search_position_by_ticker': '/equity/portfolio/ticker', 'update_pie': '/equity/pies/{id}'}
- create_pie(dividend_cash_action: str, end_date: str, goal: float, icon: str, instrument_shares: dict, name: str) dict[source]
Creates a new pie.
https://t212public-api-docs.redoc.ly/#operation/create
- Parameters:
dividend_cash_action (str) – The action to take with dividend cash.
end_date (str) – The end date for the pie.
goal (float) – The goal amount for the pie.
icon (str) – The icon for the pie.
instrument_shares (dict) – The shares of instruments in the pie.
name (str) – The name of the pie.
- delete_order(id: int) dict[source]
Delete an existing order for this account.
https://t212public-api-docs.redoc.ly/#operation/cancelOrder
- Parameters:
id (int) – The id of the order.
- delete_pie(id: int) dict[source]
Remove or delete an existing pie created by for this account.
https://t212public-api-docs.redoc.ly/#operation/delete
- Parameters:
id (int) – The id of the pie to delete.
- get_account() dict[source]
Get the account detals. https://t212public-api-docs.redoc.ly/#operation/account
- get_dividends(cursor: int, ticker: str, limit: int) dict[source]
Get a page of dividend payments for a ticker where the page id is the cursor. The number of items in the page is set by the limit variable.
https://t212public-api-docs.redoc.ly/#operation/dividends
- Parameters:
cursor (int) – The cursor for pagination.
ticker (str) – The ticker symbol of the instrument.
limit (int) – The number of items to return per page.
- get_exports_as_csv(data_included: dict, time_from: str, time_to: str) dict[source]
Get export as a csv file. The records in the csv file are for dates between time_from and time_to.
https://t212public-api-docs.redoc.ly/#operation/placeStopLimitOrder
- Parameters:
data_included (dict) – The data to be included in the export.
time_from (str) – The start time for the export.
time_to (str) – The end time for the export.
- get_order(id: int) dict[source]
Get a specific order for this account.
https://t212public-api-docs.redoc.ly/#operation/orders
- Parameters:
id (int) – The id of the order.
- get_order_history(cursor: int, ticker: str, limit: int) dict[source]
Get a page of order history for a ticker where the page id is the cursor. The number of items in the page is set by the limit variable.
https://t212public-api-docs.redoc.ly/#operation/orders_1
- Parameters:
cursor (int) – The cursor for pagination.
ticker (str) – The ticker symbol of the instrument.
limit (int) – The number of items to return per page.
- get_pie(id: int) dict[source]
Gets a specific pie by id.
https://t212public-api-docs.redoc.ly/#operation/getDetailed
- Params int id:
the id of the pie.
- get_position(ticker: str) dict[source]
Get a specific position by id.
https://t212public-api-docs.redoc.ly/#operation/positionByTicker
- Parameters:
ticker (str) – The ticker symbol of the position.
- get_transactions(cursor: int, limit: int) dict[source]
Get a page of transactions data where the page id is cursor. The number of items in the page is set by the limit variable.
https://t212public-api-docs.redoc.ly/#operation/transactions
- Parameters:
cursor (int) – The cursor for pagination.
limit (int) – The number of items to return per page.
- place_limit_order(limit_price: float, quantity: float, ticker: str, time_validity: str) dict[source]
Place a new limit order for an instrument on this account. Limit orders activate when the asset price reaches the limit order price. There is no guarantee that the limit order will fill when volatility is high.
https://t212public-api-docs.redoc.ly/#operation/placeLimitOrder
- Parameters:
limit_price (float) – The limit price for the order.
quantity (float) – The quantity of the instrument to order.
ticker (str) – The ticker symbol of the instrument.
time_validity (str) – The time validity of the order.
- place_market_order(quantity: float, ticker: str) dict[source]
Place a new market order for an instrument on this account. The market order can settle at an unexpected price during volatility.
https://t212public-api-docs.redoc.ly/#operation/placeLimitOrder
- Parameters:
quantity (float) – The quantity of the instrument to order.
ticker (str) – The ticker symbol of the instrument.
- place_stop_limit_order(limit_price: float, stop_price: float, quantity: float, ticker: str, time_validity: str) dict[source]
The stop order will convert to a limit order when the stop price is reached.
https://t212public-api-docs.redoc.ly/#operation/placeStopLimitOrder
- Parameters:
limit_price (float) – The limit price for the order.
stop_price (float) – The stop price for the order.
quantity (float) – The quantity of the instrument to order.
ticker (str) – The ticker symbol of the instrument.
time_validity (str) – The time validity of the order.
- place_stop_order(stop_price: float, quantity: float, ticker: str, time_validity: str) dict[source]
The stop order will convert to a market order when the stop price is reached.
https://t212public-api-docs.redoc.ly/#operation/placeStopOrder
- Parameters:
stop_price (float) – The stop price for the order.
quantity (float) – The quantity of the instrument to order.
ticker (str) – The ticker symbol of the instrument.
time_validity (str) – The time validity of the order.
- update_pie(id: int, dividend_cash_action: str, end_date: str, goal: float, icon: str, instrument_shares: dict, name: str) dict[source]
Save changes and update an existing pie.
https://t212public-api-docs.redoc.ly/#operation/create
- Parameters:
id (int) – The id of the pie to update.
dividend_cash_action (str) – The action to take with dividend cash.
end_date (str) – The end date for the pie.
goal (float) – The goal amount for the pie.
icon (str) – The icon for the pie.
instrument_shares (dict) – The shares of instruments in the pie.
name (str) – The name of the pie.
Module contents
- class trading212.Client(api_key: str, domain: str = None, version: str = 'v0')[source]
Bases:
objectTrading212 http client.
- END_POINTS = {'create_pie': '/equity/pies', 'delete_order': '/equity/orders/{id}', 'delete_pie': '/equity/pies/{id}', 'get_account': '/equity/account/info', 'get_account_cash': '/equity/account/cash', 'get_all_open_positions': '/equity/portfolio', 'get_dividends': '/history/dividends', 'get_exchanges': '/equity/metadata/exchanges', 'get_exports': '/history/exports', 'get_exports_as_csv': '/history/exports', 'get_instruments': '/equity/metadata/instruments', 'get_order': '/equity/orders/{id}', 'get_order_history': '/equity/history/orders', 'get_orders': '/equity/orders/', 'get_pie': '/equity/pies/{id}', 'get_pies': '/equity/pies', 'get_position': '/equity/portfolio/{ticker}', 'get_transactions': '/history/transactions', 'place_limit_order': '/equity/orders/limit', 'place_market_order': '/equity/orders/market', 'place_stop_limit_order': '/equity/orders/stop_limit', 'place_stop_order': '/equity/orders/stop', 'search_position_by_ticker': '/equity/portfolio/ticker', 'update_pie': '/equity/pies/{id}'}
- create_pie(dividend_cash_action: str, end_date: str, goal: float, icon: str, instrument_shares: dict, name: str) dict[source]
Creates a new pie.
https://t212public-api-docs.redoc.ly/#operation/create
- Parameters:
dividend_cash_action (str) – The action to take with dividend cash.
end_date (str) – The end date for the pie.
goal (float) – The goal amount for the pie.
icon (str) – The icon for the pie.
instrument_shares (dict) – The shares of instruments in the pie.
name (str) – The name of the pie.
- delete_order(id: int) dict[source]
Delete an existing order for this account.
https://t212public-api-docs.redoc.ly/#operation/cancelOrder
- Parameters:
id (int) – The id of the order.
- delete_pie(id: int) dict[source]
Remove or delete an existing pie created by for this account.
https://t212public-api-docs.redoc.ly/#operation/delete
- Parameters:
id (int) – The id of the pie to delete.
- get_account() dict[source]
Get the account detals. https://t212public-api-docs.redoc.ly/#operation/account
- get_dividends(cursor: int, ticker: str, limit: int) dict[source]
Get a page of dividend payments for a ticker where the page id is the cursor. The number of items in the page is set by the limit variable.
https://t212public-api-docs.redoc.ly/#operation/dividends
- Parameters:
cursor (int) – The cursor for pagination.
ticker (str) – The ticker symbol of the instrument.
limit (int) – The number of items to return per page.
- get_exports_as_csv(data_included: dict, time_from: str, time_to: str) dict[source]
Get export as a csv file. The records in the csv file are for dates between time_from and time_to.
https://t212public-api-docs.redoc.ly/#operation/placeStopLimitOrder
- Parameters:
data_included (dict) – The data to be included in the export.
time_from (str) – The start time for the export.
time_to (str) – The end time for the export.
- get_order(id: int) dict[source]
Get a specific order for this account.
https://t212public-api-docs.redoc.ly/#operation/orders
- Parameters:
id (int) – The id of the order.
- get_order_history(cursor: int, ticker: str, limit: int) dict[source]
Get a page of order history for a ticker where the page id is the cursor. The number of items in the page is set by the limit variable.
https://t212public-api-docs.redoc.ly/#operation/orders_1
- Parameters:
cursor (int) – The cursor for pagination.
ticker (str) – The ticker symbol of the instrument.
limit (int) – The number of items to return per page.
- get_pie(id: int) dict[source]
Gets a specific pie by id.
https://t212public-api-docs.redoc.ly/#operation/getDetailed
- Params int id:
the id of the pie.
- get_position(ticker: str) dict[source]
Get a specific position by id.
https://t212public-api-docs.redoc.ly/#operation/positionByTicker
- Parameters:
ticker (str) – The ticker symbol of the position.
- get_transactions(cursor: int, limit: int) dict[source]
Get a page of transactions data where the page id is cursor. The number of items in the page is set by the limit variable.
https://t212public-api-docs.redoc.ly/#operation/transactions
- Parameters:
cursor (int) – The cursor for pagination.
limit (int) – The number of items to return per page.
- place_limit_order(limit_price: float, quantity: float, ticker: str, time_validity: str) dict[source]
Place a new limit order for an instrument on this account. Limit orders activate when the asset price reaches the limit order price. There is no guarantee that the limit order will fill when volatility is high.
https://t212public-api-docs.redoc.ly/#operation/placeLimitOrder
- Parameters:
limit_price (float) – The limit price for the order.
quantity (float) – The quantity of the instrument to order.
ticker (str) – The ticker symbol of the instrument.
time_validity (str) – The time validity of the order.
- place_market_order(quantity: float, ticker: str) dict[source]
Place a new market order for an instrument on this account. The market order can settle at an unexpected price during volatility.
https://t212public-api-docs.redoc.ly/#operation/placeLimitOrder
- Parameters:
quantity (float) – The quantity of the instrument to order.
ticker (str) – The ticker symbol of the instrument.
- place_stop_limit_order(limit_price: float, stop_price: float, quantity: float, ticker: str, time_validity: str) dict[source]
The stop order will convert to a limit order when the stop price is reached.
https://t212public-api-docs.redoc.ly/#operation/placeStopLimitOrder
- Parameters:
limit_price (float) – The limit price for the order.
stop_price (float) – The stop price for the order.
quantity (float) – The quantity of the instrument to order.
ticker (str) – The ticker symbol of the instrument.
time_validity (str) – The time validity of the order.
- place_stop_order(stop_price: float, quantity: float, ticker: str, time_validity: str) dict[source]
The stop order will convert to a market order when the stop price is reached.
https://t212public-api-docs.redoc.ly/#operation/placeStopOrder
- Parameters:
stop_price (float) – The stop price for the order.
quantity (float) – The quantity of the instrument to order.
ticker (str) – The ticker symbol of the instrument.
time_validity (str) – The time validity of the order.
- update_pie(id: int, dividend_cash_action: str, end_date: str, goal: float, icon: str, instrument_shares: dict, name: str) dict[source]
Save changes and update an existing pie.
https://t212public-api-docs.redoc.ly/#operation/create
- Parameters:
id (int) – The id of the pie to update.
dividend_cash_action (str) – The action to take with dividend cash.
end_date (str) – The end date for the pie.
goal (float) – The goal amount for the pie.
icon (str) – The icon for the pie.
instrument_shares (dict) – The shares of instruments in the pie.
name (str) – The name of the pie.