/ccxt-webhook-trader

Trade cryptocurrencies using the CCXT library via webhooks.

Primary LanguagePythonMIT LicenseMIT

ccxt-webhook-trader

Trade cryptocurrencies using the CCXT library via webhooks.
Now only test WORKING for Binance USD-M future.


Requirements

  • 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.


Quickstart

Recommand create a virtual environment.

1. Install using pip:

$ pip install -r requirments.txt

2. Setting parameters

method 1 (maybe more security):

Setting all parameters in OS environment variables.

  • TESTMODE: switch to testnet. if not set the default value is False.
  • 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.

method 2:

  • Edit account and iplist in the setting.py file. ( testnet for testing )
    Setting TESTMODE in OS environment variables to switch to testnet. if not set the default value is False.

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 ['*'])

3. Runing uvicorn server:

$ 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)

4. Using HTTP request methods POST to http://localhost:8000/webhook with JSON:

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 is market
  • REDUCEONLY: The order is reduce position only or not. By default is False
  • 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"
}