cointrader package

Submodules

cointrader.bot module

class cointrader.bot.Cointrader(market, strategy, resolution='30m', start=None, end=None, automatic=False)[source]

Bases: sqlalchemy.ext.declarative.api.Base

active
automatic
created
get_last_buy()[source]
get_last_sell()[source]
id
market
start(backtest=False, automatic=False)[source]

Start the bot and begin trading with given amount of BTC.

The bot will trigger a analysis of the chart every N seconds. The default number of seconds is set on initialisation using the resolution option. You can overwrite this setting by using the interval option.

By setting the backtest option the trade will be simulated on real chart data. This is useful for testing to see how good your strategy performs.

Btc:Amount of BTC to start trading with
Backtest:Simulate trading on historic chart data on the given market.
Returns:None
stat(delete_trades=False)[source]

Returns a dictionary with some statistic of the performance of the bot. Performance means how good cointrader performs in comparison to the market movement. Market movement is measured by looking at the start- and end rate of the chart.

The performance of cointrader is measured by looking at the start and end value of the trade. These values are also multiplied with the start and end rate. So if cointrader does some good decisions and increases eater btc or amount of coins of the bot the performance should be better.

strategy
trades
class cointrader.bot.Trade(date, order_type, order_id, trade_id, market, rate, amount, amount_taxed, btc, btc_taxed)[source]

Bases: sqlalchemy.ext.declarative.api.Base

All trades of cointrader are saved in the database. A trade can either be a BUY or SELL.

amount
amount_taxed
bot_id
btc
btc_taxed
date
id
market
order_id
order_type
rate
trade_id
cointrader.bot.create_bot(market, strategy, resolution, start, end, btc, amount)[source]

Will create a new bot instance.

cointrader.bot.get_bot(market, strategy, resolution, start, end, btc, amount)[source]

Will load or create a bot instance. The bot will operate with the given resolution on the market using the specified strategy.

The start and end The bot is equipped with a specified amount of coins and btc for trading. If no btc or amount is specified (None), the bot will be initialised with all available coins on the given market.

Market:Market instance
Strategy:Strategy instance
Resolution:Resolution in seconds the bot will operate on the market.
Start:Datetime where the bot will start to operate
End:Datetime where the bot will end to operate
Btc:Amount of BTC the Bot will be initialised with
Amount:Amount of Coins (eg. Dash, Ripple) the Bot will be initialised with
Returns:
cointrader.bot.init_db()[source]
cointrader.bot.load_bot(market, strategy, resolution, start, end)[source]

Will load an existing bot from the database. While loading the bot will replay its trades from the trade log to set the available btc and coins for further trading.

Beside the btc and amount of coins all other aspects of the coin like the time frame and strategy are defined by the user. They are not loaded from the database.

cointrader.bot.replay_tradelog(trades)[source]

cointrader.chart module

class cointrader.chart.Chart(data, start, end)[source]

Bases: object

The chart provides a unified interface to the chart data. It also gives access so some common indicators like macd, sma and ema.

The data is provided as list of dictionaries where each dictionary represents a single set of data per point in the chart:

{
    u'date': 1500112800,
    u'open': 0.07132169,
    u'close': 0.07162004,
    u'high': 0.07172972,
    u'low': 0.07114623,
    u'volume': 7.49372245,
    u'quoteVolume': 104.69114835,
    u'weightedAverage': 0.07157933,
}

The start and end datetimes define the relevant timeframe of the chart for later profit calculations. This date range is needed as the chart itself cointains more more datapoints than within the given date range. This is because we need more data to ensure that indicators like ema and sma provide sensefull values right on from the begin of the timeframe. So there must be more data available before the start.

close
data
date
ema(window=10)[source]
get_first_point()[source]
get_last_point()[source]
macdh()[source]
sma(window=10)[source]
values(which='close')[source]
cointrader.chart.chart2csv(chart)[source]
cointrader.chart.search_chartdata_by_date(data, dt, le=True)[source]

cointrader.cli module

class cointrader.cli.Context[source]

Bases: object

Docstring for Context.

cointrader.config module

class cointrader.config.Config(configfile=None)[source]

Bases: object

api
cointrader.config.get_path_to_config()[source]

cointrader.exchange module

class cointrader.exchange.BacktestMarket(exchange, name)[source]

Bases: cointrader.exchange.Market

Market to enable backtesting a strategy on the market.

buy(btc, price=None)[source]

Will buy coins on the market for the given amount of BTC. On default we will make a market order which means we will try to buy for the best price available. If price is given the order will be placed for at the given price. You can optionally provide some options. See cointrader.exchanges.poloniex.api for more details.

Btc:Amount of BTC
Price:Optionally price for which you want to buy
Option:Optionally some buy options
Returns:Dict witch details on the order.
continue_backtest()[source]
get_chart(resolution='30m', start=None, end=None)[source]

Will return a chart of the market.

You can provide a resolution of the chart. On default the chart will have a resolution of 30m.

You can define a different timeframe by providing a start and end point. On default the the chart will include the last recent data.

Resolution:Resolution of the chart (Default 30m)
Start:Start of the chart data (Default Now)
End:End of the chart data (Default Now)
Returns:Chart instance.
sell(amount, price=None)[source]
class cointrader.exchange.Coin(name, quantity, btc_value=None)[source]

Bases: object

Docstring for Coin.

value
class cointrader.exchange.Exchange(config, api=None)[source]

Bases: object

Baseclass for all exchanges

get_top_markets(markets, limit=10)[source]
get_top_profit_markets(markets=None, limit=10)[source]
get_top_volume_markets(markets=None, limit=10)[source]
is_valid_market(market)[source]
is_valid_resolution(resolution)[source]
markets
resolution2seconds(resolution)[source]
resolutions = {'15m': 900, '24h': 86400, '2h': 7200, '30m': 1800, '4h': 14400, '5m': 300}
total_btc_value
total_euro_value
url
exception cointrader.exchange.ExchangeException[source]

Bases: exceptions.Exception

class cointrader.exchange.Market(exchange, name, dry_run=False)[source]

Bases: object

Docstring for Market.

buy(btc, price=None, option=None)[source]

Will buy coins on the market for the given amount of BTC. On default we will make a market order which means we will try to buy for the best price available. If price is given the order will be placed for at the given price. You can optionally provide some options. See cointrader.exchanges.poloniex.api for more details.

Btc:Amount of BTC
Price:Optionally price for which you want to buy
Option:Optionally some buy options
Returns:Dict witch details on the order.
currency
get_chart(resolution='30m', start=None, end=None)[source]

Will return a chart of the market.

You can provide a resolution of the chart. On default the chart will have a resolution of 30m.

You can define a different timeframe by providing a start and end point. On default the the chart will include the last recent data.

Resolution:Resolution of the chart (Default 30m)
Start:Start of the chart data (Default Now)
End:End of the chart data (Default Now)
Returns:Chart instance.
sell(amount, price=None, option=None)[source]
url
class cointrader.exchange.Poloniex(config)[source]

Bases: cointrader.exchange.Exchange

btc2dollar(amount)[source]
dollar2btc(amount)[source]
get_balance(currency=None)[source]
url
cointrader.exchange.add_fee(btc, fee=0.025)[source]
cointrader.exchange.get_market_name(market)[source]

cointrader.helpers module

cointrader.helpers.colorize_value(value)[source]
cointrader.helpers.render_bot_statistic(stat)[source]
cointrader.helpers.render_bot_title(bot, market, chart)[source]
cointrader.helpers.render_bot_tradelog(trades)[source]
cointrader.helpers.render_signal_detail(signal)[source]
cointrader.helpers.render_user_options(options)[source]

cointrader.strategy module

class cointrader.strategy.Followtrend[source]

Bases: cointrader.strategy.Strategy

Simple trend follow strategie.

signal(chart)[source]

Will return either a BUY, SELL or WAIT signal for the given market

class cointrader.strategy.Klondike[source]

Bases: cointrader.strategy.Strategy

signal(chart)[source]

Will return either a BUY, SELL or WAIT signal for the given market

class cointrader.strategy.NullStrategy[source]

Bases: cointrader.strategy.Strategy

The NullStrategy does nothing than WAIT. It will emit not BUY or SELL signal and is therefor the default strategy when starting cointrader to protect the user from loosing money by accident.

signal(chart)[source]

Will return either a BUY, SELL or WAIT signal for the given market

class cointrader.strategy.Strategy[source]

Bases: object

Docstring for Strategy.

signal(chart)[source]

Will return either a BUY, SELL or WAIT signal for the given market

signals = None

Dictionary with details on the signal(s) {“indicator”: {“signal”: 1, “details”: Foo}}

Module contents