Skip to main content

BinanceTrading

BinanceTrading is a custom trading library using the Binance API for executing or backtesting trading strategies. It is hardcoded to only trade coins against USD Tether.

Installation

Use the package manager pip to install.

pip install binancetrading

If you are on windows, follow these instructions to be able to use Binance websocket client.

Usage

To use this library it is necesary to have Binance API keys, it is also possible to work with Binance Testnet keys. Here we store them as environment variables.

Get the current coin balances in the account.

import os
from binancetrading import Account

API = os.environ.get('BINANCE_API')
SECRET = os.environ.get('BINANCE_SECRET')

account = Account(API, SECRET, paper_trade=False, apiurl='https://api.binance.com')
balances = account.account_balances()

print(balances)

Print the last ten 1 minute candlesticks of BTCUSDT.

from binancetrading import Exchange

exchange = Exchange()
data = exchange.kline_df('BTC', '1m', 10)

print(data)

See more examples.

Modules

Account

The account class is where all the relevant account data is stored like cash and token positions. It has methods to retrieve balances and these are updated if a trade is made.

Exchange

The exchange module is responsible for retrieving data from the Binance API using websockets and requests. It is also responsible for executing trades.

Trading bot

To trade and test stragies it is necessary to create an instance of an trading bot, which will retrieve data from the exchange and execute orders given by the strategy. These trades are made by an account instance.

Strategies

The strategies module contains the trading strategies to use. These are basic starting points and it is encouraged to implement own strategies. These should follow the TradingStrategy abstract base class.

Backtesting

The backtesting module is to make an event driven trading strategy backtest. It also prints price charts with entry and exit points given by the strategy.

Further development

Include an strategy optimizer module to optimize the parameters of a trading strategy using backtest results.

Make order size a percentage of current holdings or dependant on the trading strategy.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Metadata

Release files for binancetrading 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for binancetrading 0.0.1
File Size Uploaded Provenance Actions
binancetrading-0.0.1.tar.gz 13.4 kB Without provenance Details for binancetrading-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for binancetrading 0.0.1
File Interpreter ABI Platform Actions
binancetrading-0.0.1-py3-none-any.whl Python 3 none any Details for binancetrading-0.0.1-py3-none-any.whl

Total release size: 28.4 kB

Release files / binancetrading-0.0.1.tar.gz

Download URL binancetrading-0.0.1.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3f08cbd5ea3ccc43bbf582d1de7771d363360920ad5acb0152a32f55d85f5255
BLAKE2b-256 checksum
How to use checksums
ff5c0ae05302837427b4e8dd8407a7d23dad04aa53e59be2553264669f2c52e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / binancetrading-0.0.1-py3-none-any.whl

Download URL binancetrading-0.0.1-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc28e29d4d5c44f73614b9a91c0afdae693975c257431d860242248784d4fab6
BLAKE2b-256 checksum
How to use checksums
e6409d4cd63778dc250d298826c072691e12bc62589c4949047e011fa565383a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for binancetrading 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page