Howtrader
Howtrader: A crypto quant framework for developing, backtesting, and executing your own trading strategies. Seamlessly integrates with TradingView and other third-party signals. Simply send a post request to automate trading and order placement. Supports Binance and Okex exchanges.
Install / Use
npx skills add 51bitquant/howtraderInstalls into whichever agent you are using.
README
HowTrader
What does Howtrader means? It means how to be a trader, especially a quant trader.
HowTrader crypto quantitative trading framework, and was forked from VNPY, so the core codes、functions and useages are pretty similar to VNPY, but would be more easy to install and use. By the way, Howtrader fixes some bugs, add more functions and strategies to framework. We extend the TradingView signals and grid strategies to Howtrader and more codes.
Binance Spot API Ed25519 Key Configuration Guide
The Binance Spot WebSocket API mandates the use of the Ed25519 asymmetric encryption algorithm for signing. Therefore, you must use a self-generated method when creating API Keys. System-generated keys cannot be used for the Spot WebSocket interface.
Step 1: Create a Self-Generated API Key Log in to the Binance official website, go to Account → API Management, and click Create API. Select the Self-generated key type, as shown in the figure below.

Click Next. You will now need to upload your self-generated Ed25519 public key.
Step 2: Generate an Ed25519 Key Pair Official Binance Tool (Recommended) Download the official asymmetric key generator from: https://github.com/binance/asymmetric-key-generator/releases (Note: This is an external GitHub link. If you cannot access it, please use the OpenSSL command-line method below.) Download and install the version corresponding to your operating system. After opening the software: Select the Ed25519 algorithm type, as shown in the figure below:

Click the Generate 1 Key Pair button to generate the key pair. Securely save the generated Public Key and Private Key.
Step 3: Complete API Creation and Configuration Copy the content of your generated public key (all text including -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY-----, removing all line breaks) and paste it into Binance's public key input field. Click Next to generate the API Key.
After that, edit the API permission: Check the Spot & Margin Trading permission.
Mandatorily enable IP whitelisting and add the IP address of the device running howtrader. Only check the necessary permissions. Do not enable high-risk permissions such as withdrawal or transfer. Click Save to complete the configuration.
Fill the API Key generated by Binance and your privately saved Private Key into the Binance Spot configuration in howtrader. Important Notes The Binance Futures API is not subject to this restriction. You can use standard system-generated API Key and Secret normally. If you have any questions about the spot configuration, feel free to consult me at any time.
Howtrader VS VNPY
-
some classes' definition are pretty different: for OrderData 、TradeData、ContractData, we replace float with Decimal to meet the precision, theses classes are defined in howtrader.trader.object module.
-
on_order and on_trade update sequence are different: in VNPY, ,the on_order is always updated before the on_trade if the order was traded. And in the cta strategy, the self.pos(the position data) was calculated in the on_trade callback. So if we want to get the latest self.pos value, we may need to define a variable to calculate the latest position data. To solve this issue, we push the on_trade before the on_order callback. check out the code to find out the details:
def on_order(self, order: OrderData) -> None: """on order update""" order.update_time = generate_datetime(time.time() * 1000) last_order: OrderData = self.get_order(order.orderid) if not last_order: self.orders[order.orderid] = copy(order) super().on_order(copy(order)) else: traded: Decimal = order.traded - last_order.traded if traded < 0: # filter the order is not in sequence return None if traded > 0: trade: TradeData = TradeData( symbol=order.symbol, exchange=order.exchange, orderid=order.orderid, direction=order.direction, price=order.price, volume=traded, datetime=order.update_time, gateway_name=self.gateway_name, ) super().on_trade(trade) if traded == 0 and order.status == last_order.status: return None self.orders[order.orderid] = copy(order) super().on_order(copy(order)) def get_order(self, orderid: str) -> OrderData: """get order by order id""" return self.orders.get(orderid, None) -
gateways are different: solve issues like disconnecting from exchange, and reconnecting.
-
TradingView app to receive other 3rd party signals and algo trading strategies, checkout the module: howtrader.app.tradingview
Installation
the framework depends on pandas, Numpy libraries, so we higly recommend you to install Anaconda.
-
Install Anaconda, the Anaconda download website is here, remember to click "Add Conda to System Path" in the process of Anaconda Installation. If you forget to do so, you might need to unistall and reinstall the Anaconda, or just search how to add conda to you system path, if you encounter the problem of "not found conda command".
If you already install the anaconda before, you can simply update your conda by runing the following command:
conda update conda
conda update anaconda
-
install git
Install git is pretty simple, just download git from [https://git-scm.com/downloads], then install it, remember to add git to your system path. If you're using MacOX, git was integrated into the system, so you may not need to install git. 3. create virtual env by conda
conda create -n mytrader python==3.9
mytrader is the name of your virtual env, if you have the mytrader virtual env before and the version is not 3.9, you can unistall it by following command:
conda remove -n mytrader --all
if you encounter an error, you may need to deactivate the mytrader by the command:
conda deactivate
then remove it:
conda remove -n mytrader --all
- activate your virtual env:
conda activate mytrader
- install howtrader
run the command:
pip install git+https://github.com/51bitquant/howtrader.git
if you want to update to the latest version, use the command:
pip install git+https://github.com/51bitquant/howtrader.git -U
if encounter the failure of installation TA-Lib, checkout the next step.
Install TA-Lib
If you can't install the howtrader in Window system, the main reason may be the TA-Lib, here we go in to the detail of installing TA-Lib:
-
open this url in your browser:https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib
-
search ta-lib in the website and download the TA-Lib.whl file: here we found the TA_Lib‑0.4.24‑cp39‑cp39‑win_amd64.whl in the website and we click download, for the TA_Lib-0.4.24, it means TA-Lib version is 0.4.24, cp39 is the python version is 3.9, amd64 your system version is 64 bit, choose the right one and download it.
-
change your directory to your TA-Lib folder, and remember to activate your virtual env to mytrader(if you use mytrader as your vitrual env), then execute the following command:
pip install TA_Lib‑0.4.24‑cp39‑cp39‑win_amd64.whl
how-to-use
create a python proejct, and create a main.py file,and set your project's interpreter to the mytrader(the virtual env you just create and config).
then copy and paste the following code to main.py and run it, and you will see a howtrader folder beside the main.py, the howtrader folder contains the configs data(like exchange api key)、 your strategy settings and datas etc.
from howtrader.event import EventEngine, Event
from howtrader.trader.event import EVENT_TV_SIGNAL
from howtrader.trader.engine import MainEngine
from howtrader.trader.ui import MainWindow, create_qapp
from howtrader.trader.setting import SETTINGS
from howtrader.gateway.binance import BinanceUsdtGateway, BinanceSpotGateway, BinanceInverseGateway
from howtrader.app.cta_strategy import CtaStrategyApp
# from howtrader.app.data_manager import DataManagerApp
# from howtrader.app.data_recorder import DataRecorderApp
# from howtrader.app.algo_trading import AlgoTradingApp
# from howtrader.app.risk_manager import RiskManagerApp
# from howtrader.app.spread_trading import SpreadTradingApp
from howtrader.app.tradingview import TradingViewApp
from threading import Thread
import json
from flask import Flask, request
# create global event_engine
event_engine: EventEngine = EventEngine()
passphrase = SETTINGS.get("passphrase", "")
port = SETTINGS.get("port", 9999)
app = Flask(__name__)
@app.route('/', methods=['GET'])
def welcome():
return "Hi, this is tv server!"
@app.route('/webhook', methods=['POST'])
def webhook():
try:
data = json.loads(request.data)
if data.get('passphrase', None) != passphrase:
return {"status": "failure", "msg": "passphrase is incorrect"}
del data['passphrase'] # del it for safety.
event:Event = Event(type=EVENT_TV_SIGNAL, data=data)
event_engine.put(event)
return {"status": "success", "msg": ""}
except Exception as error:
return {"status": "error", "msg": str(error)}
def start_tv_server():
app.run(host="127.0.0.1", port=port)
def main():
""""""
qapp = create_qapp()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(BinanceSpotGateway)
main_engine.add_gateway(BinanceUsdtGateway)
main_engine.add_gateway(BinanceInverse
Related Skills
node-connect
385.5kDiagnose OpenClaw Android, iOS, or macOS node pairing, QR/setup code, route, auth, and connection failures.
python-debugpy
385.5kDebug Python with pdb, breakpoint(), post-mortem inspection, and debugpy remote attach.
skill-creator
385.5kCreate, edit, audit, tidy, validate, or restructure AgentSkills and SKILL.md files.
claude-opus-4-5-migration
140.6kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
