Skip to main content

Public API for Tradernet

Project description

tradernet-sdk

Python Software Development Kit for Tradernet.

Installation

Installing tradernet with pip is straightforward:
python -m pip install tradernet-sdk
Instead of python you can use here and further pypy3 depending on your preferences.

Usage

Import the client library into your script:
from tradernet import Tradernet as tn
Initialize it with your credentials:
connection = tn("public_key", "private_key")
or create a config file tradernet.ini with the following content:

[auth]
public   = public_key
private  = private_key

and initialize the client with connection = tn.from_config("tradernet.ini")
Call any of its public methods, for example:
connection.user_info()

How to trade

Import and instantiate Tradernet class as usual:

from tradernet import Tradernet as tn


connection = tn.from_config("tradernet.ini")

Now let's buy 1 share of FRHC.US at the market price:

connection.buy("FRHC.US")

Trading bonds, structured products, and other instruments without electronic execution is conducted via so-called voice orders:

connection.send_voice_order("T.4.75.051555.BND")

a structured product requires specifying an order type:

connection.send_voice_order("PHX9999.JUN26", type="structured_product")

Websockets

Websocket API can be accessed via another class TradernetWebsocket. It implements the asynchronous interface for Tradernet API, and its usage is a bit more complicated. First of all, it uses an instance of the Core or its subclass, for example, Tradernet for authentication. So it should be created first:
connection = Core.from_config("tradernet.ini")
Second, the TradernetWebsocket class should be used as a context manager within a coroutine as in the example below:

from asyncio import run
from tradernet import Tradernet as tn, TradernetWebsocket as tnws


async def main(connection: tn) -> None:    # coroutine
    async with tnws(connection) as wscon:  # type: tnws
        async for quote in wscon.market_depth("FRHC.US"):
            print(quote)


if __name__ == "__main__":
    core = tn.from_config('tradernet.ini')
    run(main(core))

Password authentication

Password authentication has been completely disabled since version 2.0.0.

Options

The notation of options in Tradernet now can easily be deciphered:

from tradernet import TradernetOption as tno


option = tno("+FRHC.16SEP2022.C55")
print(option)  # FRHC.US @ 55 Call 2022-09-16

Wrapping market data

Another feature is to get handy pandas.DataFrame objects with market data:

from pandas import DataFrame
from tradernet import TradernetSymbol as tns, Tradernet as tn


connection = tn("public_key", "private_key")
symbol = tns("AAPL.US", connection).get_data()
market_data = DataFrame(
    symbol.candles,
    index=symbol.timestamps,
    columns=["high", "low", "open", "close"]
)
print(market_data.head().to_markdown())
# | date                |     high |      low |     open |    close |
# |:--------------------|---------:|---------:|---------:|---------:|
# | 1980-12-12 00:00:00 | 0.128876 | 0.12834  | 0.12834  | 0.12834  |
# | 1980-12-15 00:00:00 | 0.122224 | 0.121644 | 0.122224 | 0.121644 |
# | 1980-12-16 00:00:00 | 0.113252 | 0.112716 | 0.113252 | 0.112716 |
# | 1980-12-17 00:00:00 | 0.116064 | 0.115484 | 0.115484 | 0.115484 |
# | 1980-12-18 00:00:00 | 0.119412 | 0.118876 | 0.118876 | 0.118876 |

Support

Write a ticket in the Member Area of Tradernet in order to get access to the Slack support channel. The channel is devoted to API questions only, any other support requests are not accepted.

License

The package is licensed under permissive MIT License. See the LICENSE file in the top directory for the full license text.

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

tradernet_sdk-2.1.2.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

tradernet_sdk-2.1.2-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file tradernet_sdk-2.1.2.tar.gz.

File metadata

  • Download URL: tradernet_sdk-2.1.2.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.13 Linux/5.15.0-124-generic

File hashes

Hashes for tradernet_sdk-2.1.2.tar.gz
Algorithm Hash digest
SHA256 341a4765f173985e7c70ce0e7816e544a75322ade393f3edeb675b6526d7f4f4
MD5 d7b3e82eb325127ade8a856f6aeef4eb
BLAKE2b-256 edb58a6d0c836262f153c4b7f995608c9210a40dd17dc861ca4a5f990a65f6d6

See more details on using hashes here.

File details

Details for the file tradernet_sdk-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: tradernet_sdk-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.13 Linux/5.15.0-124-generic

File hashes

Hashes for tradernet_sdk-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 155908ff5f038c1f5aec59ec2c99756c9b8e340c7195a3a82e294300cea0f7fb
MD5 97462d09bd6d003eb77042f111db90fb
BLAKE2b-256 8172fe1a8c85cb31481e9c05dbecae8d59788de5babb089e2c6e14fea7618472

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