Skip to main content

Public API for TraderNet

Project description

tradernet-sdk

Public Python API 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 TraderNetAPI
Initialize it with your credentials:
api = TraderNetAPI('public_key', 'private_key', 'login', 'passwd')
or create a config file tradernet.ini with the following content:

[auth]
public   = public_key
private  = private_key
login    = login
password = passwd

and initialize the client with api = TraderNetAPI.from_config('tradernet.ini')
Call any of its public methods, for example:
api.user_info()

How to trade

Usage of the trading interface is similar to common API. Import and instantiate Trading class:

from tradernet import Trading


order = Trading.from_config('tradernet.ini')

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

order.buy('FRHC.US')

Advanced techniques

One can import the core class to write their own methods:

from tradernet import TraderNetCore


class MyTNAPI(TraderNetCore):
    pass

This allows using sophisticated request methods for TN API like TraderNetCore.authorized_request.

One can have several instances of the API serving different purposes:

config = TraderNetCore.from_config('tradernet.ini')
order = Trading.from_instance(config)

The instance config stores the credentials, and order can be used to trade and may be destroyed after trades completed while config is still can be used to instantiate other classes.

Websockets

Websocket API can be accessed via another class TraderNetWSAPI. It implements asynchronous interface for TraderNet API, and its usage is a bit more complicated:

from tradernet import TraderNetCore, TraderNetWSAPI


async def main() -> None:
    api = TraderNetCore.from_config('tradernet.ini')
    async with TraderNetWSAPI(api) as wsapi:  # type: TraderNetWSAPI
        async for quote in wsapi.market_depth('FRHC.US'):
            print(quote)

Legacy API

The library also has the legacy PublicApiClient.py which provides almost the same functionality as most of TraderNet users used to:

from tradernet import NtApi


pub_ = '[public Api key]'
sec_ = '[secret Api key]'
cmd_ = 'getPositionJson'
res = NtApi(pub_, sec_, NtApi.V2)
print(res.sendRequest(cmd_))

The only difference is that one doesn't have to decode the content of the response as before.

Options

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

from tradernet import TraderNetOption


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

or the scary old notation:

from tradernet import DasOption


option = DasOption('+FRHC^C7F45.US')
print(option)  # FRHC.US @ 45 Call 2022-07-15

Wrapping market data

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

from tradernet import TraderNetSymbol, TraderNetAPI


api = TraderNetAPI('public_key', 'private_key', 'login', 'passwd')
symbol = TraderNetSymbol('AAPL.US', api)
symbol.get_data()
print(symbol.market_data.head().to_markdown())
# | date                |     high |      low |     open |    close |      volume |
# |:--------------------|---------:|---------:|---------:|---------:|------------:|
# | 1980-12-12 00:00:00 | 0.128876 | 0.12834  | 0.12834  | 0.12834  | 1.17258e+08 |
# | 1980-12-15 00:00:00 | 0.122224 | 0.121644 | 0.122224 | 0.121644 | 4.39712e+07 |
# | 1980-12-16 00:00:00 | 0.113252 | 0.112716 | 0.113252 | 0.112716 | 2.6432e+07  |
# | 1980-12-17 00:00:00 | 0.116064 | 0.115484 | 0.115484 | 0.115484 | 2.16104e+07 |
# | 1980-12-18 00:00:00 | 0.119412 | 0.118876 | 0.118876 | 0.118876 | 1.83624e+07 |

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-0.3.7.tar.gz (24.3 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-0.3.7-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tradernet_sdk-0.3.7.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/4.15.0-210-generic

File hashes

Hashes for tradernet_sdk-0.3.7.tar.gz
Algorithm Hash digest
SHA256 2539b944f459d3967da513c7ad2e3b948fc6896d3c8daebddc7ac6c26b4eaa9a
MD5 eb81ad4af00037a2f5201775c5befe70
BLAKE2b-256 536a599488acdb4d95d568d7064cdfc067c488dfe2ac6035fd30d3d99b1cc2a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tradernet_sdk-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/4.15.0-210-generic

File hashes

Hashes for tradernet_sdk-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 940fc1c1c5db50f0502293130d37197d54ac5f56e07810e39d0fbb54387361e6
MD5 87b1dc98c67093e5ec033a431b363709
BLAKE2b-256 1ce897ac348f345e8975967aab91ea8bf11b734a7fcc22ccef78d80672c34f71

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