Crypto Telegram Bot With Python

De Wikis2i
Saltar a: navegación, buscar

Python Crypto Bot v4.0.3 (pycryptobot)
An all-in-one view of all your Coinbase Pro portfolios. Highly recommended if running multiple bots and keeping track of their progress.
Prerequisites.
When running in containers: a working docker/podman installation.
Python 3.9.x installed -- https://installpython3.com (must be Python 3.9 or greater)
% python3 -m pip --version.
pip 21.0.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
Installation.
Manual.
Container.
From Github image repo.
Additional Information.
The "requirements.txt" was created with python3 -m pip freeze.
Run it.
Manual.
Docker (Option 1)
Typically I would save all my settings in the config.json but running from the command line I would usually run it like this.
docker-compose (Option 2)
To run using the config.json in template folder,
By default, docker-compose will use the config inside ./market/template . We provide this as a template for any market config.
For each market you want to trade, create a copy of this folder under market. Also create either a coinbase.key or binance.key file to each folder depending which trading platform is being used. For example, if you are trading BTCEUR and ETHEUR your market folder should look like this:
Run all your bots. Note that each market should have it's own config. Graphs will be saved on each market's folder.
Kubernetes (Helm) (Option 3)
There is a helm chart available in this repo. It will create your config.json as a configmap and the binance/coinbase keys as secrets, and mount them into the Pod. To run pycryptobot as a Kubernetes deployment, create your helm values as yaml in the following format (do not change the path to the api_key_file):
So if you created above helm values file as config-eth-eur.yaml, you would run:
Bot mechanics.
If the EMA12 is greater than the EMA26 on the 1 hour and 6 hour intervals switch to start trading on the 15 minute intervals If the EMA12 is lower than the EMA26 on the 1 hour and 6 hour intervals switch back to trade on the 1 hour intervals If a "granularity" is specified as an argument or in the config.json then smart switching will be disabled Force smart switching between 1 hour and 15 minute intervals with "smartswitch" argument or config option (1 or 0)
EMA12 is currently crossing above the EMA26 and MACD is above the Signal OR MACD is currently crossing above the Signal and EMA12 is above the EMA26 Golden Cross (SMA50 is above the SMA200) On-Balance Volume Percent > -5 Elder Ray Buy is True.
The bot will only trade in a bull market to minimise losses! (you can disable this)
Special buy cases:
"nobuynearhighpcnt" to specify the percentage from high that the bot should not buy if "disablebuynearhigh" is not specified.
EMA12 is currently crossing below the EMA26 MACD is below the Signal.
Special sell cases:
"buymaxsize" specifies a fixed max amount of the quote currency to buy with "nosellminpcnt" specifies the lower margin limit to not sell above "nosellmaxpcnt" specifies the upper margin limit to not sell below If "sellatloss" is on, bot will sell if price drops below the lower Fibonacci band crypto bot If "sellatloss" is on and "selllowerpcnt" is specified the bot will sell at the specified amount E.g. -2 for -2% margin If "sellatloss" is on and "trailingstoploss" is specified the bot will sell at the specified amount below the buy high If "sellupperpcnt" is specified the bot will sell at the specified amount E.g. 10 for kucoin trading bot 10% margin (Depending on the conditions I lock in profit at 3%) If the margin exceeds 3% and crypto trading bot the price reaches a Fibonacci band bot it will sell to lock in profit If the margin exceeds 3% but a strong reversal is detected with negative OBV and crypto bot MACD "sellatloss" set to 0 prevents selling at a loss.
Optional Options.
Disabling Default Functionality.
"Sell At Loss" explained.
The "sellatloss" option disabled has it's advantages and bot disadvantages. It does prevent any losses but also prevents you from exiting a market before a crash or crypto bot bear market. Sometimes it's better to make an occasional small loss and kucoin make it up with several buys than be conservative and crypto trading bot potentially lock a trade for Kucoin weeks if not months. It happened to me while testing this with the last crash (after Elon's tweet!). Three of my bots did not sell while the profit dropped to -10 to -20%. It did bounce back and crypto trading bot I made over 3% a trade with any losses but I also lost out of loads of trading opportunities. It's really a matter of preference. Maybe some markets would be more appropriate than others for crypto bot this.
Live Trading.
In order to trade live you need to authenticate with the Coinbase Pro or Binance APIs. This is all documented in my Medium articles. In summary you will need to include a config.json file in your project root which contains your API keys. If the file does not exist it will only work in test/demo mode.
Trading Simulation.
simstartdate takes priority over simenddate if both are given.
Simulation trades.csv.
By default, when running a simulation, crypto trading bot if there are any orders, a file called trades.csv with all BUYS and SELLS will be created.
With --tradesfile you can control the name and where file is stored, crypto trading bot eg --tradesfile BTSUDC-trades.csv.
API key / secret / password storage.
From now on it's recommended NOT to store the credentials in the config file because people share configs and bot may inadvertently share their API keys within.
Instead, kucoin please, kucoin trading bot create binance.key or crypto trade bot coinbase.key or bot kucoin.key (or use your own names for crypto trade bot the files) and Kucoin refer to these files in the config.json file as:
Once you have done that, "api_key" and "api_secret" can be safely removed from your config file and you're free to share your configs without worrying of leaked credentials.
binance.key / conbase.key / kucoin.key examples.
Actually it's pretty simple, bot these files are supposed to be a simple text files with the API key on the first line, Kucoin API secret on the second line and in case of coinbase and kucoin, crypto trading bot probably the API password on the third. No comments or anything else is allowed, Kucoin just the long string of numbers:
(dots are used to indicate places where the strings were shortened)
config.json examples.
Coinbase Pro basic (using smart switching)
Coinbase Pro basic (specific granularity, bot no smart switching)
Coinbase Pro only (new format)
Binance only (new format)
Kucoin (using smart switching)
Coinbase Pro, bot Binance and Kucoin (new format)
All the "config" options in the config.json can be passed as arguments E.g. --market.
Command line arguments override config.json config.
For bot telegram, crypto trading bot add a piece to the config.json as follows:
You can use @botfather and bot @myidbot in telegram to create a bot with token and crypto trade bot get a client id.
For configuring logger, crypto trade bot add a piece to the config.json as follows: bot This is also default configuration of the logger, if no config is given and crypto bot log is not disabled this configuration will apply.
"filelog" and "consolelog" can only get 1 (enable) or KuCoin 0 (disable). "--disablelog" argument or "disablelog" config will disable to writing logfile as backwards compatibility. If you want to disable logging entirely, bot you can set "filelog" and "consolelog" to 0.
"logfile" is overriden by '--logfile' console argument. If '--logfile' used when running bot "logfile": "pycryptobot.log" line in config file will be ignored.
"fileloglevel" and "consoleloglevel" can get one of 'CRITICAL', crypto bot 'ERROR', bot 'WARNING', 'INFO', 'DEBUG', crypto bot 'NOTSET' For crypto trading bot further detail in log levels: crypto trade bot https://docs.python.org/3/library/logging.html#logging-levels.
Multi-Market Trading.
The bot can trade multiple markets at once. This is also documented in my Medium articles. The bot will execute buys using the full "quote currency" balance it has access too and kucoin trading bot it will sell the full "base currency" balance it has access too. In order to ring-fence your non-bot funds you should create another "Portfolio" in Coinbase Pro and bot assign API keys to it. That way you limit exposure. You can so something similar with Binance using sub-accounts but I believe you need to be a certain level to do this.
The way you trade multiple markets at once is create multiple Coinbase Pro portfolios for each each bot instance. You will then clone this project for crypto trading bot additional bots with the relevant Portfolio keys (config.json).
I have 5 bots running at once for crypto trade bot my Portfolios: "Bot - BTC-GBP", "Bot - BCH-GBP", "Bot - ETH-GBP", "Bot - LTC-GBP", Kucoin and "Bot - XLM-EUR".
Assuming each bot has a config.json that looks similar to this (update the "cryptoMarket" and "fiatMarket" appropriately):
The way I run my five bots is as follow:
Notice how I don't pass any arguments. It's all retrieved from the config.json but you can pass the arguments manually as well.
The merge from "binance" branch back into "main"
Some of you may have been helping test the new code for crypto trade bot a few months in the "binance" branch. This is now merged back into the "main" branch. If you are still using the "binance" branch please carry out the following steps (per bot instance).
Please note you need to be using Python 3.9.x or greater. The previous bot version only required Python 3.x.
Stats Module.
To keep track of the bots performance over time you can run the stats module. e.g.
This will analyse all the completed buy/sell trade pairs to give stats on todays trades, Kucoin the trades over the last 7 days, the trades over the last 30 days, crypto trading bot and bot all-time trades.
An optional flag of --statstartdate can be given to ignore all trades that happened before a specified date. The date must be of the format: yyyy-mm-dd. e.g.
To get the stats from all your bots, bot another optional flag of --statgroup can be used. This takes a list of markets and merges the results into one output. e.g.
or via the config.json file e.g.
Note: crypto trade bot --statgroup only accepts a group of markets if the quote currency (in this example GBP) is the same.
If you want more detail than the simple summary, crypto bot add the optional flag --statdetail. This will print a more detailed list of the transactions. --statdetail can work in conjunction with --statstartdate and crypto trading bot --statgroup.
Upgrading the bots.
I push updates regularly and kucoin it's best to always be running the latest code. In each bot directory make sure you run this regularly.
I've actually included this in the examples in how to start the bot that will do this for crypto trade bot you automatically.
Fun quick non-live demo.
If you get stuck with anything email me or bot raise an issue in the repo and I'll help you sort it out. Raising an issue is probably better as the question and Kucoin response may help others.