Trade cryptocurrencies using the CCXT library via webhooks.
Now only test WORKING for Binance USD-M future.
- Python 3.7+
- FastAPI : a framework handles http requests.
- CCXT Library : connect and trade with cryptocurrency exchanges.
If you need to deploy in AWS Lambda functions.
- Mangum : an adapter for running ASGI applications in AWS Lambda to handle Function URL.
Not necessary to deploy. Just for local testing.
- Uvicorn : an ASGI web server.
Recommand create a virtual environment.
$ pip install -r requirments.txt
Setting all parameters in OS environment variables.
TESTMODE
: switch to testnet. if not set the default value isFalse
.IP_ALLOW
: for whitelist IP.WEBHOOK_TOKEN
: some random key you generate.EXCHANGE
: see ccxt library support list.API_KEY
: your exchange api key.API_SECRET
: your exchange api secret.API_PASSWORD
: some exchange need.
- Edit
account
andiplist
in thesetting.py
file. (testnet
for testing )
SettingTESTMODE
in OS environment variables to switch to testnet. if not set the default value isFalse
.
method 1 has higher priority than method 2.
For all IP allow can set to ['*']
( If TESTMODE
is True
that IP_ALLOW
always set to ['*']
)
$ uvicorn --host localhost main:fast_app
Like this on your terminal:
INFO: Started server process [12345]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)
Below is an order to buy 0.5 BTC at market price. PRICE
has no effect.
{
"TOKEN": "test1234qwer",
"SYMBOL": "BTCUSDT",
"SIDE": "buy",
"PRICE": 12345,
"QUANTITY": 0.5,
}
Additional parameters are as follows.
ORDER_TYPE
: Change order type. By default order type ismarket
REDUCEONLY
: The order is reduce position only or not. By default isFalse
LEVERAGE
: Change leverage ratio. Default will not change.COMMENT
: Any comment you wanna.
Here is an order to buy 0.8 BTC with a limit price of 24680. And change leverage ratio to 5x.
{
"TOKEN": "test1234qwer",
"SYMBOL": "BTCUSDT",
"SIDE": "buy",
"PRICE": 24680,
"QUANTITY": 0.8,
"ORDER_TYPE": "limit",
"REDUCEONLY": False,
"LEVERAGE": 5,
"COMMENT": "test"
}