freqtrade / freqtrade

Free, open source crypto trading bot
https://www.freqtrade.io
GNU General Public License v3.0
27.99k stars 6k forks source link

Support for Binance Futures #2940

Closed mvclaudianobj closed 4 years ago

mvclaudianobj commented 4 years ago

I would like to know if you have plans to include operations for Binance Futures in freqtrade?

graciously

Marcos

xmatthias commented 4 years ago

Technically, it should be possible to use freqtrade with futures already by using the following configuration settings - assuming the ccxt abstraction works as it should.

... 
        "ccxt_config": {
                "enableRateLimit": true, 
                "options": {"defaultType": "future"}
         },
        "ccxt_async_config": {
            "enableRateLimit": true,
            "rateLimit": 200,
            "options": {"defaultType": "future"} // Enable futures
        },
...

Note: the setting MUST be in both config dicts to work.

Now to be very clear - while it should be possible - you're most likely the first to test binance futures with freqtrade - and that's the main reason we don't have any notion about this in our docs.

If you do decide to test this, please do so with small sized trades and monitor the bot and it's actions on the exchange VERY carefully (at least for the first few trades) - and let us know if it does work and if not, which errors you encountered, so we can eventually add this to the documentation (or make it more comfortable to use).

mvclaudianobj commented 4 years ago

Okay, I will do these tests and report the results here for implementations and improvements if necessary.

mvclaudianobj commented 4 years ago

I did the configuration according to this recommendation: https://github.com/ccxt/ccxt/issues/6458

But the behavior is like using the normal Binance market image

Note: I recreated the API key by activating the Futures option

xmatthias commented 4 years ago

Please try (with the configuration snippet i shared above) - and run freqtrade list-pairs --config config_futures.json. It should list the future pairs from Binance (it does for me ...).

Note that I've updated the snippet above to include the correct syntax.

Also - which version of freqtrade are you using? Make sure that it's the correct version from this repository, using uptodate dependencies (especially ccxt should be uptodate).

The above screenshot shows a Spanish (probably Portuguese ... ) Status message - which is something we definitely don't have. Please understand that we do not support any forks - so if it's not working and you're not using the latest develop version, there is nothing we can do for you.

If you want to continue using forked versions, please go to that respective repository and hope they do provide support.

mvclaudianobj commented 4 years ago

I am using the Release 2020.01 version. The language modification I made is a local adaptation for my personal branch, which only translates texts for the telegram and terminal

In the list-pairs command the return was for all binance spot pairs. Could you share your .json configuration for testing?

xmatthias commented 4 years ago

sure

Don't use that config for anything relevant though - it's a test-config i use - but i'm not sure if all other options make sense for trading ...and it's not relevant for this test either.

I've highlighted (with comments) the important section.

{
    "max_open_trades": 3,
    "stake_currency": "BTC",
    "stake_amount": 0.05,
    "fiat_display_currency": "USD",
    "amount_reserve_percent" : 0.05,
    "dry_run": false,
    "ticker_interval": "5m",
    "unfilledtimeout": {
        "buy": 10,
        "sell": 30
    },
    "bid_strategy": {
        "use_order_book": false,
        "ask_last_balance": 0.0,
        "order_book_top": 1,
        "check_depth_of_market": {
            "enabled": false,
            "bids_to_ask_delta": 1
        }
    },
    "ask_strategy":{
        "use_order_book": false,
        "order_book_min": 1,
        "order_book_max": 9,
        "use_sell_signal": true,
        "sell_profit_only": false,
        "ignore_roi_if_buy_signal": false
    },
    "pairlists": [
        {
            "method": "VolumePairList",
            "number_assets": 20,
            "sort_key": "quoteVolume",
            "refresh_period": 1800
        },
        {"method": "PrecisionFilter"},
        {"method": "PriceFilter", "low_price_ratio": 0.01
        }
    ],
    "exchange": {
        "name": "binance",
        "sandbox": false,
        "key": "your_exchange_key",
        "secret": "your_exchange_secret",
        "password": "",
        "ccxt_config": {
        "enableRateLimit": true,
        "options": {"defaultType": "future"},   // This is the important part
        "verify": false
    },
        "ccxt_async_config": {
            "enableRateLimit": false,
            "rateLimit": 500,
            "aiohttp_trust_env": false,
            "options": {"defaultType": "future"},   // This is the important part
        },
        "pair_whitelist": [
            "ETH/BTC",
            "LTC/BTC",
            "ETC/BTC",
            "DASH/BTC",
            "ZEC/BTC",
            "XLM/BTC",
            "NXT/BTC",
            "TRX/BTC",
            "ADA/BTC",
            "XMR/BTC"
        ],
        "pair_blacklist": [
            "DOGE/BTC"
        ],
        "outdated_offset": 5,
        "markets_refresh_interval": 60
    },
    "telegram": {
        "enabled": true,
        "token": "your_telegram_token",
        "chat_id": "your_telegram_chat_id"
    },
    "api_server": {
        "enabled": false,
        "listen_ip_address": "127.0.0.1",
        "listen_port": 8080,
        "username": "freqtrader",
        "password": "SuperSecurePassword"
    },
    "initial_state": "running",
    "forcebuy_enable": false,
    "internals": {
        "process_throttle_secs": 5,
        "heartbeat_interval": 60
    },

}

You'll get a handul (22) pairs - which seems aligned to binance website (at a quick look ...)

mvclaudianobj commented 4 years ago

returned all pairs of the spot, in this configuration above. is it because I'm on the master branch?

hroff-1902 commented 4 years ago

returned all pairs of the spot, in this configuration above. is it because I'm on the master branch?

what do you mean by "all pairs"?

$ git checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.
$ vi config_futures.json # place the content of the config in this new config file
$ freqtrade list-markets -c config_futures.json                                                           
...

Exchange Binance has 22 active markets:
| Id       | Symbol    | Base   | Quote   | Active   | Is pair   |
|:---------|:----------|:-------|:--------|:---------|:----------|
| ADAUSDT  | ADA/USDT  | ADA    | USDT    | True     | True      |
| ATOMUSDT | ATOM/USDT | ATOM   | USDT    | True     | True      |
| BATUSDT  | BAT/USDT  | BAT    | USDT    | True     | True      |
| BCHUSDT  | BCH/USDT  | BCH    | USDT    | True     | True      |
| BNBUSDT  | BNB/USDT  | BNB    | USDT    | True     | True      |
| BTCUSDT  | BTC/USDT  | BTC    | USDT    | True     | True      |
| DASHUSDT | DASH/USDT | DASH   | USDT    | True     | True      |
| EOSUSDT  | EOS/USDT  | EOS    | USDT    | True     | True      |
| ETCUSDT  | ETC/USDT  | ETC    | USDT    | True     | True      |
| ETHUSDT  | ETH/USDT  | ETH    | USDT    | True     | True      |
| IOTAUSDT | IOTA/USDT | IOTA   | USDT    | True     | True      |
| LINKUSDT | LINK/USDT | LINK   | USDT    | True     | True      |
| LTCUSDT  | LTC/USDT  | LTC    | USDT    | True     | True      |
| NEOUSDT  | NEO/USDT  | NEO    | USDT    | True     | True      |
| ONTUSDT  | ONT/USDT  | ONT    | USDT    | True     | True      |
| TRXUSDT  | TRX/USDT  | TRX    | USDT    | True     | True      |
| VETUSDT  | VET/USDT  | VET    | USDT    | True     | True      |
| XLMUSDT  | XLM/USDT  | XLM    | USDT    | True     | True      |
| XMRUSDT  | XMR/USDT  | XMR    | USDT    | True     | True      |
| XRPUSDT  | XRP/USDT  | XRP    | USDT    | True     | True      |
| XTZUSDT  | XTZ/USDT  | XTZ    | USDT    | True     | True      |
| ZECUSDT  | ZEC/USDT  | ZEC    | USDT    | True     | True      |
xmatthias commented 4 years ago

Well best fill out the issue template otherwise we're guessing around and you've probably got some old version of ccxt ...

As said, please try it with our version (as is - no matter if develop or master) - without modifications. We don't know what the modifications are - i trust you've only translated the messages - but what if you didn't / made some sall mistake and introduced some problem with passing parameters to ccxt?

We can't exclude that and honestly, even if your version/branch would be on github, we will not start reviewing what changes you did unless it's in a PR which you intend to merge to our repository.

Also make sure that all dependencies are uptodate (pip install -r requirements.txt).

mvclaudianobj commented 4 years ago

I am very grateful for the effort in wanting to help with this. Follow the data: image

mvclaudianobj commented 4 years ago

(.env) [centos@awake freqtrade]$ python -V Python 3.6.8 (.env) [centos@awake freqtrade]$ pip freeze | grep ccxt ccxt==1.18.1306 (.env) [centos@awake freqtrade]$ git branch develop lang_telegram

hroff-1902 commented 4 years ago

^^ why ccxt is not updating to the version, which is written in the requirements-common.txt for that commit? https://github.com/freqtrade/freqtrade/blob/8371003c05b83cb1c3c99307537932597d9caf4c/requirements-common.txt#L3

mvclaudianobj commented 4 years ago

I also don't understand why the ccxt is out of date

because the installation was done according to the freqtrade manual

xmatthias commented 4 years ago

With that version of ccxt it cannot work, as futures support was only added ~2 months ago - but your ccxt version is more than a year old.

please run cat requirements-common.txt and post the output here.

From your logs:

Requirement already satisfied: ccxt==1.18.1306 in ./.env/lib/python3.6/site-packages (from -r requirements-common.txt (line 3)) (1.18.1306)

I suspect that you got somehow a messed up installation / repository.

You may try to grep through the folders (grep "ccxt==" -r) to see where the problem is. it should output only one file - requirements-common.txt:ccxt==1.22.61.

if you have the same result than i do - then, please delete the virtual environment and run through the install again. If that doesn't help, then delete the whole freqtrade folder (including the virtual environment - take care to keep eventually modified strategies / files) - clone the repository again and run through the installation again.

mvclaudianobj commented 4 years ago

There is a divergence between the installed version and that of .env

[centos@awake /]$ pip freeze | grep ccxt ccxt==1.22.66 [centos@awake /]$ cd /www/wwwroot/awake.business/bot/run/freqtrade/ [centos@awake freqtrade]$ source .env/bin/activate (.env) [centos@awake freqtrade]$ pip freeze | grep ccxt ccxt==1.18.1306 (.env) [centos@awake freqtrade]$

hroff-1902 commented 4 years ago

remove (rename) .env and create it again with the script (./setup.sh -i is the easiest way)

mvclaudianobj commented 4 years ago

Thank you very much for your help image

After reinstalling freqtrade and ccxt it started working.

Now, I need your support to start testing for future trades, can we keep these same issues for monitoring?

mvclaudianobj commented 4 years ago

In the first test purchase I already identified that the minimum value is set to> 11.15, but in the future we can open with lower values ​​with leverage x10, x20, x30

2020-02-19 09:42:00,554 - freqtrade.freqtradebot - INFO - Bot heartbeat. PID=7899 2020-02-19 09:42:25,486 - freqtrade.rpc.telegram - INFO - Executing handler: _forcebuy for chat_id: 255800138 /www/wwwroot/awake.business/bot/run/freqtrade/.env/lib64/python3.6/site-packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made to host 'fapi.binance.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning, 2020-02-19 09:42:25,743 - freqtrade.wallets - INFO - Wallets synced. 2020-02-19 09:42:25,745 - freqtrade.freqtradebot - WARNING - Can't open a new trade for BTC/USDT: stake amount is too small (1 < 11.155555555555559)

xmatthias commented 4 years ago

Leverages will not be supported for now. if you want to use futures with freqtrade and it works, that's great - but it'll be without leverage for now.

unrelated to this - you should look into the HTTPS error - it points to a MITM attack (or business proxy) which is inspecting SSL traffic. Both cases are usually problematic - the first will have you lose all your coins to a hacker, and the business proxy part may cost you your job ...

hroff-1902 commented 4 years ago

unrelated to this - you should look into the HTTPS error - it points to a MITM attack (or business proxy) which is inspecting SSL traffic. Both cases are usually problematic - the first will have you lose all your coins to a hacker, and the business proxy part may cost you your job ...

I guess this may be caused by ccxt -- ccxt might be using http (not https) for Binance FAPI...

xmatthias commented 4 years ago

Unverified HTTPS request is being made to host 'fapi.binance.com'

nope - the error is pretty clear. It's an error i get all the time with my corporate proxy (which is ssl inspecting - but i don't do anything on exchanges over that) - it's because the (self-signed) certificate is not installed in pythons certificate store. While i do have a workaround for my environment (adding the cert to the store) - it's not something you'd want to do when using real api keys!

mvclaudianobj commented 4 years ago

Corrected the security flaw and I'm starting the tests with futures, see the first error:

2020-02-19 16:22:11,226 - freqtrade.wallets - INFO - Wallets synced.
2020-02-19 16:22:11,229 - freqtrade.freqtradebot - INFO - Buy signal found: about create a new trade with stake_amount: 1 ...
2020-02-19 16:22:11,230 - freqtrade.freqtradebot - INFO - Using Last Ask / Last Price
2020-02-19 16:22:11,709 - freqtrade.commands.trade_commands - INFO - worker found ... calling exit
2020-02-19 16:22:11,710 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'process died'}
2020-02-19 16:22:11,938 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2020-02-19 16:22:11,939 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
2020-02-19 16:22:39,100 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "./freqtrade/main.py", line 36, in main
    return_code = args['func'](args)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
    worker.run()
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/worker.py", line 70, in run
    state = self._worker(old_state=state)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/worker.py", line 106, in _worker
    self._throttle(func=self._process, min_secs=throttle_secs)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/worker.py", line 119, in _throttle
    result = func(*args, **kwargs)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/worker.py", line 129, in _process
    self.freqtrade.process()
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/freqtradebot.py", line 156, in process
    self.enter_positions()
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/freqtradebot.py", line 227, in enter_positions
    trades_created += self.create_trade(pair)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/freqtradebot.py", line 421, in create_trade
    return self.execute_buy(pair, stake_amount)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/freqtradebot.py", line 454, in execute_buy
    buy_limit_requested = self.get_buy_rate(pair)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/freqtradebot.py", line 256, in get_buy_rate
    ticker = self.exchange.fetch_ticker(pair)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/exchange/common.py", line 113, in wrapper
    return f(*args, **kwargs)
  File "/www/wwwroot/awake.business/bot/run/freqtrade/freqtrade/exchange/exchange.py", line 590, in fetch_ticker
    'bid': float(data['bid']),
TypeError: float() argument must be a string or a number, not 'NoneType'
hroff-1902 commented 4 years ago

(^^ formatted)

we already fixed something similar: https://github.com/freqtrade/freqtrade/issues/2515

@mvclaudianobj can you test it with the current develop branch (since you are trying to use some experimental configurations, so the result can be affected by some bugfixes/changes recently merged into develop)

mvclaudianobj commented 4 years ago

tks

xmatthias commented 4 years ago

I'll close this as #3162 shows that Binance Futures do not work out of the box.

To me, supporting futures is currently not a priority (especially considering that it's usage without leverage is very limited) - and therefore many other issues need to be taken on before thinking of supporting Binance futures.

willwillis commented 4 years ago
 "pair_whitelist": [
            "ETH/BTC",
            "LTC/BTC",
            "ETC/BTC",
            "DASH/BTC",
            "ZEC/BTC",
            "XLM/BTC",
            "NXT/BTC",
            "TRX/BTC",
            "ADA/BTC",
            "XMR/BTC"
        ],

I realize this is an old thread, but wouldn't all futures pairs be denominated in USDT? I didn't look too deeply into the logs posted here, but that is one thing that sticks out to me that may be causing issues.

xmatthias commented 4 years ago

to reiterate what was said above - futures do NOT work with freqtrade currently - so what you put into your pairlist is irrelevant - as it will cause problems (even if buying may work - it will most likely not be able to sell correctly).

gring0-cripto commented 3 years ago

Any updates on freqtrade working with futures? I found a way to get it to buy with leverage, it's kinda a work around. Usually binance futures have "default settings" between isolated and cross and choosing the leverage, if the bot buys normally with futures, it will go with Leverage as you set it. But does freqtrade support it now or do we have any update about this?

xmatthias commented 3 years ago

since ccxt does not unify futures yet (unification = same interface for all exchanges), freqtrade does also not work with them currently - and there's currently no plans in this regard, at least not until ccxt has futures unified.

xmatthias commented 3 years ago

@dream2541 first of all - please stick to english.

Then - this is a very misleading and dangerous configuration - which will NOT work to trade futures correctly. Freqtrade may be able to enter trades - but not to exit trades, therefore i advise anyone NOT to use this configuration.

Sam00078 commented 3 years ago

Technically, it should be possible to use freqtrade with futures already by using the following configuration settings - assuming the ccxt abstraction works as it should.

... 
        "ccxt_config": {
                "enableRateLimit": true, 
                "options": {"defaultType": "future"}
         },
        "ccxt_async_config": {
            "enableRateLimit": true,
            "rateLimit": 200,
            "options": {"defaultType": "future"} // Enable futures
        },
...

Note: the setting MUST be in both config dicts to work.

Now to be very clear - while it should be possible - you're most likely the first to test binance futures with freqtrade - and that's the main reason we don't have any notion about this in our docs.

If you do decide to test this, please do so with small sized trades and monitor the bot and it's actions on the exchange VERY carefully (at least for the first few trades) - and let us know if it does work and if not, which errors you encountered, so we can eventually add this to the documentation (or make it more comfortable to use).

Thank u! I want to have a try, would u tell me if this can work or some info in future ?

TheJoeSchr commented 3 years ago

@Sam00078 did you read through this issue? I think @xmatthias already answered that...

Sam00078 commented 3 years ago

@Sam00078 did you read through this issue? I think @xmatthias already answered that...

readed done now my bot lost more money in bear market, so sad! thanks freqtrade's contributor, anyway. I do more about futrues trade, let me bot to survive in the bearmarket with BTC ETH and more coin

sinaban commented 3 years ago

How can open a short position in futures?

Kelows commented 3 years ago

Hello,

i think this PR implements binance futures on ccxt ? https://github.com/ccxt/ccxt/pull/9793