cointrader package¶
Subpackages¶
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
¶
-
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
instanceStrategy: Strategy
instanceResolution: 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.
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.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
¶
-
cointrader.config module¶
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.
-
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.
-
-
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
-
markets
¶
-
resolutions
= {'15m': 900, '24h': 86400, '2h': 7200, '30m': 1800, '4h': 14400, '5m': 300}¶
-
total_btc_value
¶
-
total_euro_value
¶
-
url
¶
-
-
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.
-
url
¶
-
-
class
cointrader.exchange.
Poloniex
(config)[source]¶ Bases:
cointrader.exchange.Exchange
-
url
¶
-
cointrader.helpers module¶
cointrader.strategy module¶
-
class
cointrader.strategy.
Followtrend
[source]¶ Bases:
cointrader.strategy.Strategy
Simple trend follow strategie.
-
class
cointrader.strategy.
Klondike
[source]¶ Bases:
cointrader.strategy.Strategy
-
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.