Skip to main content

TradeLocker Algo Trading API support for Python

Project description

TradeLocker Python API Wrapper

This project provides a Python wrapper for TradeLocker's Algo Trading public API. It simplifies the process of making requests to the API by providing Pythonic interfaces.

A full description of the TradeLocker's Algo Trading public API can be found at TradeLocker API Documentation


Table of Contents

  1. Getting Started
  2. Installation
  3. Usage
  4. Contributing
  5. License

Getting Started

To use this Python wrapper, you'll need the username and password that you use to access TradeLocker. If you don't already have access, you need to find a broker that supports TradeLocker and create an account.

Installation

This package requires Python 3.11 or later. The easiest way to install this package is using pip:

pip install tradelocker

Typechecking

By installing TradeLocker with optional typechecking dependencies (typeguard), the package will automatically verify the types of all functions that you call.

Usage

Here's a simple example on how to use the TradeLocker Python API wrapper. The code below initializes a TLAPI object with authentication data. It then: fetches price history and latest price, creates an order that converts into a position, waits for 2 seconds, and finally closes the same position.

from tradelocker import TLAPI
import time, random

# Initialize the API client with the information you use to login
tl = TLAPI(environment = "https://demo.tradelocker.com", username = "user@email.com", password = "YOUR_PASS", server = "SERVER_NAME")

symbol_name = "BTCUSD" # "RANDOM"
all_instruments = tl.get_all_instruments()
if symbol_name == "RANDOM":
	instrument_id = int(random.choice(all_instruments['tradableInstrumentId']))
else:
	instrument_id = tl.get_instrument_id_from_symbol_name(symbol_name)
price_history = tl.get_price_history(instrument_id, resolution="1D", start_timestamp=0, end_timestamp=0,lookback_period="5D")
latest_price = tl.get_latest_asking_price(instrument_id)
order_id = tl.create_order(instrument_id, quantity=0.01, side="buy", type_="market")
if order_id:
	print(f"Placed order with id {order_id}, sleeping for 2 seconds.")
	time.sleep(2)
	tl.close_position(order_id)
	print(f"Closed order with id {order_id}.")
else:
	print("Failed to place order.")

For more detailed examples, see the examples directory.

Contributing

To contribute to the development of this project:

  1. Fork the project.
  2. Create your feature branch (git checkout -b feature/YourFeature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Create a new Merge Request.

License

This project is licensed under the terms of the MIT license. See LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tradelocker-0.38.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tradelocker-0.38.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file tradelocker-0.38.0.tar.gz.

File metadata

  • Download URL: tradelocker-0.38.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.1.0

File hashes

Hashes for tradelocker-0.38.0.tar.gz
Algorithm Hash digest
SHA256 ba358943c296628a2c0d0d8cf5869f1a9c822b49892b9bd6d10fb89793d4fc85
MD5 fb94653e73efc2dc4ff14772259e67f7
BLAKE2b-256 fe9b38d2d8ae0c8b122b05e9f0bf5ee33310180403a55a3401a61958e8611dc4

See more details on using hashes here.

File details

Details for the file tradelocker-0.38.0-py3-none-any.whl.

File metadata

  • Download URL: tradelocker-0.38.0-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.1.0

File hashes

Hashes for tradelocker-0.38.0-py3-none-any.whl
Algorithm Hash digest
SHA256 049a89ae9eacd70ea4fb9d40464b77cdeef31403e2f761e5c69de96eedeb7ee4
MD5 1656b59832e0f55e33417ffa4865d4fa
BLAKE2b-256 127758a12c7067d82eb6576afb836e02c08fd2ef6602d16cd5a0c2cc953fb9d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page