GithubHelp home page GithubHelp logo

trading212-rest's Introduction

Rest API client for Trading212

Based on the new REST API of Trading212.

Installation

pip install trading212-rest

Usage

from trading212_rest import Trading212

client = Trading212(api_key="your_api_token", demo=False)

orders = client.orders()

dividends = client.dividends()

This is just a small selection of functions. Most endpoints are already implemented.

For a full documentation on Trading212 endpoint paramaters see https://t212public-api-docs.redoc.ly/

trading212-rest's People

Contributors

ms32035 avatar

Stargazers

Phil avatar George Saker avatar  avatar

Watchers

 avatar  avatar  avatar

trading212-rest's Issues

Syntax error !?

Hi, trying to use the code in a AWS Lambda function running Python 3.7
I get the below error. Would you know what it could be?

{
"errorMessage": "Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line 70)",
"errorType": "Runtime.UserCodeSyntaxError",
"stackTrace": [
" File "/var/task/lambda_function.py" Line 70\n while next_page := response.get("nextPagePath"):\n"
]
}

Please add unittest and / or unittest.mock

Please add unittest and / or unittest.mock.

  • setUp method: Initializes an instance of Trading212 with a test API key.
  • patch decorator: Use @patch('requests.get') to mock the requests.get method.
  • mock_get: The mock of the requests.get method.
  • mock_response.json.return_value: Sets the return value of the json() method of the mock response object.
  • assert_called_once_with: Checks whether the requests.get method was called with the correct URL and headers.
  • assertEqual: Checks whether the response from the API client is equal to the expected value.

This approach allows you to test all the functions in your API client without making any actual API calls. This ensures that your tests are fast and reliable.

This structure and scripts allow you to easily test the functionality of your Trading212 API client. Run the tests with the following command from the root directory (trading212-rest):

$ python -m unittest discover -s tests

This command searches for all test files in the tests directory and runs the tests

arguments

Hi.
the code usage says
client = Trading212(token="your_api_token", demo=False)

but the class init says
def init(self, api_key: str, demo: bool = True):

token should be api_key

The missing features from the API are: 1. Equity Orders, 2. Pies

The current Python script is missing all functions under the Equity Orders and Pies categories. If you need this functionality, you should implement these functions according to the API documentation.

Missing features:

  1. Equity Orders:
  • orders: Not implemented
  • placeLimitOrder: Not implemented
  • placeMarketOrder: Not implemented
  • placeStopOrder_1: Not implemented
  • placeStopOrder: Not implemented
  • cancelOrder: Not implemented
  • orderById: Not implemented
  1. Pies:
  • getAll: Not implemented
  • create: Not implemented
  • delete: Not implemented

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.