Skip to content

Commit

Permalink
Merge branch 'release/0.12.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gcarq committed Oct 24, 2017
2 parents 604a888 + ff4fcdc commit 6b15cb9
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 62 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
.gitignore
Dockerfile
.dockerignore
config.json*
*.sqlite
21 changes: 12 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
FROM python:3.6.2

RUN apt-get update
RUN apt-get -y install build-essential
FROM python:3.6.2

# Install TA-lib
RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
RUN tar zxvf ta-lib-0.4.0-src.tar.gz
RUN cd ta-lib && ./configure && make && make install
RUN apt-get update && apt-get -y install build-essential && apt-get clean
RUN curl -L http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz | \
tar xzvf - && \
cd ta-lib && \
./configure && make && make install && \
cd .. && rm -rf ta-lib
ENV LD_LIBRARY_PATH /usr/local/lib

# Prepare environment
RUN mkdir /freqtrade
COPY . /freqtrade/
WORKDIR /freqtrade

# Install dependencies and execute
# Install dependencies
COPY requirements.txt /freqtrade/
RUN pip install -r requirements.txt

# Install and execute
COPY . /freqtrade/
RUN pip install -e .
CMD ["freqtrade"]
60 changes: 51 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ in minutes and the value is the minimum ROI in percent.
See the example below:
```
"minimal_roi": {
"2880": 0.005, # Sell after 48 hours if there is at least 0.5% profit
"1440": 0.01, # Sell after 24 hours if there is at least 1% profit
"720": 0.02, # Sell after 12 hours if there is at least 2% profit
"360": 0.02, # Sell after 6 hours if there is at least 2% profit
"0": 0.025 # Sell immediately if there is at least 2.5% profit
"50": 0.0, # Sell after 30 minutes if the profit is not negative
"40": 0.01, # Sell after 25 minutes if there is at least 1% profit
"30": 0.02, # Sell after 15 minutes if there is at least 2% profit
"0": 0.045 # Sell immediately if there is at least 4.5% profit
},
```

`stoploss` is loss in percentage that should trigger a sale.
`stoploss` is loss in percentage that should trigger a sale.
For example value `-0.10` will cause immediate sell if the
profit dips below -10% for a given trade. This parameter is optional.

Expand All @@ -47,7 +46,9 @@ Possible values are `running` or `stopped`. (default=`running`)
If the value is `stopped` the bot has to be started with `/start` first.

`ask_last_balance` sets the bidding price. Value `0.0` will use `ask` price, `1.0` will
use the `last` price and values between those interpolate between ask and last price. Using `ask` price will guarantee quick success in bid, but bot will also end up paying more then would probably have been necessary.
use the `last` price and values between those interpolate between ask and last
price. Using `ask` price will guarantee quick success in bid, but bot will also
end up paying more then would probably have been necessary.

The other values should be self-explanatory,
if not feel free to raise a github issue.
Expand Down Expand Up @@ -84,16 +85,57 @@ $ pytest
This will by default skip the slow running backtest set. To run backtest set:

```
$ BACKTEST=true pytest
$ BACKTEST=true pytest -s freqtrade/tests/test_backtesting.py
```

#### Docker

Building the image:

```
$ cd freqtrade
$ docker build -t freqtrade .
$ docker run --rm -it freqtrade
```

For security reasons, your configuration file will not be included in the
image, you will need to bind mount it. It is also advised to bind mount
a SQLite database file (see second example) to keep it between updates.

You can run a one-off container that is immediately deleted upon exiting with
the following command (config.json must be in the current working directory):

```
$ docker run --rm -v `pwd`/config.json:/freqtrade/config.json -it freqtrade
```

To run a restartable instance in the background (feel free to place your
configuration and database files wherever it feels comfortable on your
filesystem):

```
$ cd ~/.freq
$ touch tradesv2.sqlite
$ docker run -d \
--name freqtrade \
-v ~/.freq/config.json:/freqtrade/config.json \
-v ~/.freq/tradesv2.sqlite:/freqtrade/tradesv2.sqlite \
freqtrade
```
If you are using `dry_run=True` you need to bind `tradesv2.dry_run.sqlite` instead of `tradesv2.sqlite`.

You can then use the following commands to monitor and manage your container:

```
$ docker logs freqtrade
$ docker logs -f freqtrade
$ docker restart freqtrade
$ docker stop freqtrade
$ docker start freqtrade
```

You do not need to rebuild the image for configuration
changes, it will suffice to edit `config.json` and restart the container.

#### Contributing

Feel like our bot is missing a feature? We welcome your pull requests! Few pointers for contributions:
Expand Down
8 changes: 4 additions & 4 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"stake_amount": 0.05,
"dry_run": false,
"minimal_roi": {
"60": 0.0,
"40": 0.01,
"20": 0.02,
"0": 0.03
"50": 0.0,
"40": 0.01,
"30": 0.02,
"0": 0.045
},
"stoploss": -0.40,
"bid_strategy": {
Expand Down
2 changes: 1 addition & 1 deletion freqtrade/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.11.0'
__version__ = '0.12.0'

from . import main
34 changes: 20 additions & 14 deletions freqtrade/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import talib.abstract as ta
from pandas import DataFrame

from freqtrade.exchange import get_ticker_history
from freqtrade import exchange
from freqtrade.exchange import Bittrex, get_ticker_history

logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
Expand All @@ -23,23 +24,23 @@ def parse_ticker_dataframe(ticker: list, minimum_date: arrow.Arrow) -> DataFrame
.drop('BV', 1) \
.rename(columns={'C':'close', 'V':'volume', 'O':'open', 'H':'high', 'L':'low', 'T':'date'}) \
.sort_values('date')
return df[df['date'].map(arrow.get) > minimum_date]
return df


def populate_indicators(dataframe: DataFrame) -> DataFrame:
"""
Adds several different TA indicators to the given DataFrame
"""
dataframe['sar'] = ta.SAR(dataframe, 0.02, 0.22)
dataframe['sar'] = ta.SAR(dataframe)
dataframe['adx'] = ta.ADX(dataframe)
stoch = ta.STOCHF(dataframe)
dataframe['fastd'] = stoch['fastd']
dataframe['fastk'] = stoch['fastk']
dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband']
dataframe['cci'] = ta.CCI(dataframe, timeperiod=5)
dataframe['sma'] = ta.SMA(dataframe, timeperiod=100)
dataframe['tema'] = ta.TEMA(dataframe, timeperiod=4)
dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)
dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
dataframe['mfi'] = ta.MFI(dataframe)
dataframe['cci'] = ta.CCI(dataframe)
return dataframe


Expand All @@ -49,14 +50,12 @@ def populate_buy_trend(dataframe: DataFrame) -> DataFrame:
:param dataframe: DataFrame
:return: DataFrame with buy column
"""

dataframe.loc[
(dataframe['close'] < dataframe['sma']) &
(dataframe['cci'] < -100) &
(dataframe['tema'] <= dataframe['blower']) &
(dataframe['mfi'] < 30) &
(dataframe['fastd'] < 20) &
(dataframe['adx'] > 20),
(dataframe['mfi'] < 25) &
(dataframe['fastd'] < 25) &
(dataframe['adx'] > 30),
'buy'] = 1
dataframe.loc[dataframe['buy'] == 1, 'buy_price'] = dataframe['close']

Expand Down Expand Up @@ -119,20 +118,26 @@ def plot_dataframe(dataframe: DataFrame, pair: str) -> None:
import matplotlib.pyplot as plt

# Two subplots sharing x axis
fig, (ax1, ax2) = plt.subplots(2, sharex=True)
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
fig.suptitle(pair, fontsize=14, fontweight='bold')
ax1.plot(dataframe.index.values, dataframe['sar'], 'g_', label='pSAR')
ax1.plot(dataframe.index.values, dataframe['close'], label='close')
# ax1.plot(dataframe.index.values, dataframe['sell'], 'ro', label='sell')
ax1.plot(dataframe.index.values, dataframe['sma'], '--', label='SMA')
ax1.plot(dataframe.index.values, dataframe['tema'], ':', label='TEMA')
ax1.plot(dataframe.index.values, dataframe['blower'], '-.', label='BB low')
ax1.plot(dataframe.index.values, dataframe['buy_price'], 'bo', label='buy')
ax1.legend()

# ax2.plot(dataframe.index.values, dataframe['adx'], label='ADX')
ax2.plot(dataframe.index.values, dataframe['adx'], label='ADX')
ax2.plot(dataframe.index.values, dataframe['mfi'], label='MFI')
# ax2.plot(dataframe.index.values, [25] * len(dataframe.index.values))
ax2.legend()

ax3.plot(dataframe.index.values, dataframe['fastk'], label='k')
ax3.plot(dataframe.index.values, dataframe['fastd'], label='d')
ax3.plot(dataframe.index.values, [20] * len(dataframe.index.values))
ax3.legend()

# Fine-tune figure; make subplots close to each other and hide x ticks for
# all but bottom plot.
fig.subplots_adjust(hspace=0)
Expand All @@ -143,6 +148,7 @@ def plot_dataframe(dataframe: DataFrame, pair: str) -> None:
if __name__ == '__main__':
# Install PYQT5==5.9 manually if you want to test this helper function
while True:
exchange.EXCHANGE = Bittrex({'key': '', 'secret': ''})
test_pair = 'BTC_ETH'
# for pair in ['BTC_ANT', 'BTC_ETH', 'BTC_GNT', 'BTC_ETC']:
# get_buy_signal(pair)
Expand Down
11 changes: 0 additions & 11 deletions freqtrade/exchange/bittrex.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class Bittrex(Exchange):
# Sleep time to avoid rate limits, used in the main loop
SLEEP_TIME: float = 25

@property
def name(self) -> str:
return self.__class__.__name__

@property
def sleep_time(self) -> float:
return self.SLEEP_TIME
Expand All @@ -40,13 +36,6 @@ def __init__(self, config: dict) -> None:
_EXCHANGE_CONF.update(config)
_API = _Bittrex(api_key=_EXCHANGE_CONF['key'], api_secret=_EXCHANGE_CONF['secret'])

# Check if all pairs are available
markets = self.get_markets()
exchange_name = self.name
for pair in _EXCHANGE_CONF['pair_whitelist']:
if pair not in markets:
raise RuntimeError('Pair {} is not available at {}'.format(pair, exchange_name))

def buy(self, pair: str, rate: float, amount: float) -> str:
data = _API.buy_limit(pair.replace('_', '-'), amount, rate)
if not data['success']:
Expand Down
22 changes: 22 additions & 0 deletions freqtrade/rpc/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def init(config: dict) -> None:
CommandHandler('stop', _stop),
CommandHandler('forcesell', _forcesell),
CommandHandler('performance', _performance),
CommandHandler('help', _help),
]
for handle in handles:
_updater.dispatcher.add_handler(handle)
Expand Down Expand Up @@ -301,6 +302,27 @@ def _performance(bot: Bot, update: Update) -> None:
send_msg(message, parse_mode=ParseMode.HTML)


@authorized_only
def _help(bot: Bot, update: Update) -> None:
"""
Handler for /help.
Show commands of the bot
:param bot: telegram bot
:param update: message update
:return: None
"""
message = """
*/start:* `Starts the trader`
*/stop:* `Stops the trader`
*/status:* `Lists all open trades`
*/profit:* `Lists cumulative profit from all finished trades`
*/forcesell <trade_id>:* `Instantly sells the given trade, regardless of profit`
*/performance:* `Show performance of each finished trade grouped by pair`
*/help:* `This help message`
"""
send_msg(message, bot=bot)


def send_msg(msg: str, bot: Bot = None, parse_mode: ParseMode = ParseMode.MARKDOWN) -> None:
"""
Send given markdown message
Expand Down
8 changes: 4 additions & 4 deletions freqtrade/tests/test_backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def print_results(results):
len(results.index),
results.profit.mean() * 100.0,
results.profit.sum(),
results.duration.mean()*5
results.duration.mean() * 5
))

@pytest.fixture
Expand All @@ -30,10 +30,10 @@ def pairs():
def conf():
return {
"minimal_roi": {
"60": 0.0,
"50": 0.0,
"40": 0.01,
"20": 0.02,
"0": 0.03
"30": 0.02,
"0": 0.045
},
"stoploss": -0.40
}
Expand Down

0 comments on commit 6b15cb9

Please sign in to comment.