Welcome to babao’s documentation!

babao package

Subpackages

babao.inputs package

Subpackages
babao.inputs.ledger package
Submodules
babao.inputs.ledger.fakeLedgerInput module

Handle logging in database all our fake transactions (dry-run)

class babao.inputs.ledger.fakeLedgerInput.ABCFakeLedgerInput(log_to_file=True, temp=False)[source]

Bases: babao.inputs.ledger.ledgerInputBase.ABCLedgerInput

Base class for any fake ledger

asset

Overide this method with the desired CryptoEnum / QuoteEnum ex: self.asset = CryptoEnum.XBT

buy(ledger, volume_spent, price, timestamp=None)[source]

Buy with the current ledger asset the asset of the given ´ledger´

(If the current ledger is a quote, this is a buy)
´volume_spent´ quantity spent (including fees)
deposit(ledger, volume, timestamp=None)[source]

Deposit from the current ledger to the given ´ledger´

fetch()[source]

Return a time-serie DataFrame fetched from the internets

This data will be stored on database for later use (and eventual resampling). Data can be continuous. Index must be nanosecond timestamps.

logTransaction(typ, volume, refid, fee=0, product=0, timestamp=None)[source]

Log transaction in database if ´timestamp´ is not given, the current time will be used

This should’nt be used outside of this class

sell(ledger, volume_spent, price, timestamp=None)[source]

Buy with the asset of the given ´ledger´ the current ledger asset

(If the current ledger is a quote, this is a sell)
´volume_spent´ quantity spent (including fees)
withdraw(ledger, volume, timestamp=None)[source]

Withdraw from the current ledger to the given ´ledger´

babao.inputs.ledger.krakenLedgerInput module

Handle logging in database all our real transactions on kraken api (wet-run) Also fetch from kraken api the history of your past transactions

class babao.inputs.ledger.krakenLedgerInput.ABCKrakenLedgerInput(log_to_file=True, unused_temp=False)[source]

Bases: babao.inputs.ledger.ledgerInputBase.ABCLedgerInput, babao.inputs.krakenInputBase.ABCKrakenInput

Base class for any kraken ledger

buy(ledger, volume_spent, price, timestamp=None)[source]

Buy with the current ledger asset the asset of the given ´ledger´

(If the current ledger is a quote, this is a buy)
´volume_spent´ quantity spent (including fees)
deposit(ledger, volume, timestamp=None)[source]

Deposit from the current ledger to the given ´ledger´

fetch()[source]

Return a time-serie DataFrame fetched from the internets

This data will be stored on database for later use (and eventual resampling). Data can be continuous. Index must be nanosecond timestamps.

sell(ledger, volume_spent, price, timestamp=None)[source]

Buy with the asset of the given ´ledger´ the current ledger asset

(If the current ledger is a quote, this is a sell)
´volume_spent´ quantity spent (including fees)
withdraw(ledger, volume, timestamp=None)[source]

Withdraw from the current ledger to the given ´ledger´

babao.inputs.ledger.ledgerInputBase module

Handle logging in database all our transactions

TODO: It is really not obvious how you’re gonna link the transaction across various ledgers… kraken doesn’t give you anything else than an “order id”, so you still have to iterate over all entries in all ledgers to find the matching one :/ The good new is, I don’t know when we’ll need that! Anyway, I’ll leave an empty column “product”, which reference another ledger; this could be used for later indexing?

class babao.inputs.ledger.ledgerInputBase.ABCLedgerInput[source]

Bases: babao.inputs.inputBase.ABCInput

Base class for any ledger

asset

Overide this method with the desired CryptoEnum / QuoteEnum ex: self.asset = CryptoEnum.XBT

buy(ledger, volume_spent, price, timestamp=None)[source]

Buy with the current ledger asset the asset of the given ´ledger´

(If the current ledger is a quote, this is a buy)
´volume_spent´ quantity spent (including fees)
deposit(ledger, volume, timestamp=None)[source]

Deposit from the current ledger to the given ´ledger´

fillMissing(resampled_data)[source]

Fill missing values (np.nan/np.inf) in ´resampled_data´

raw_columns = ['volume', 'balance', 'fee', 'refid', 'type', 'product']
resampled_columns = ['balance']
sell(ledger, volume_spent, price, timestamp=None)[source]

Buy with the asset of the given ´ledger´ the current ledger asset

(If the current ledger is a quote, this is a sell)
´volume_spent´ quantity spent (including fees)
withdraw(ledger, volume, timestamp=None)[source]

Withdraw from the current ledger to the given ´ledger´

babao.inputs.ledger.ledgerManager module

Manage all the ledgers and give some utils functions to check balance or buy/sell

babao.inputs.ledger.ledgerManager.buy(crypto_enum, volume)[source]

Buy the given ´volume´ of ´crypto_enum´

babao.inputs.ledger.ledgerManager.buyOrSell(action_enum, crypto_enum, volume=None)[source]

Decide wether to buy or sell (or not) ´volume´ the ´crypto_enum´ based on the given ´action_enum´

It will consider the current ´ledger.BALANCE´, and evenutally update it.

babao.inputs.ledger.ledgerManager.gameOver()[source]

Check if you’re broke

babao.inputs.ledger.ledgerManager.getBalanceInQuote(crypto_enum)[source]

Convert to quote the balance of the LEDGERS[crypto_enum]

babao.inputs.ledger.ledgerManager.getGlobalBalanceInQuote()[source]

Sum and convert to quote the balance of all your LEDGERS

babao.inputs.ledger.ledgerManager.getLastTx()[source]

Return the timestamp of the last transaction in all LEDGERS

babao.inputs.ledger.ledgerManager.initLedgers()[source]

Instantiate all the ledgers and corresponding trade-inputs needed by conf.CRYPTOS / conf.QUOTE

babao.inputs.ledger.ledgerManager.sell(crypto_enum, volume)[source]

Sell the given ´volume´ of ´crypto_enum´

Module contents
babao.inputs.trades package
Submodules
babao.inputs.trades.krakenTradesInput module

Concrete class for kraken trade inputs

We could have defined all these with the following commentend out snippet, but for explicitness reasons we’ll keep them this way. This also allows linter to understand what’s going on.

class babao.inputs.trades.krakenTradesInput.KrakenTradesBCHEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for CHE crypto vs R quote

crypto = -1
pair = 'BCHEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesBCHUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for CHU crypto vs D quote

crypto = -1
pair = 'BCHUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesDASHEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ASH crypto vs UR quote

crypto = -2
pair = 'DASHEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesDASHUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ASH crypto vs SD quote

crypto = -2
pair = 'DASHUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesEOSEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for OSE crypto vs R quote

crypto = -3
pair = 'EOSEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesEOSUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for OSU crypto vs D quote

crypto = -3
pair = 'EOSUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesGNOEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for NOE crypto vs R quote

crypto = -4
pair = 'GNOEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesGNOUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for NOU crypto vs D quote

crypto = -4
pair = 'GNOUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETCZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETC crypto vs CAD quote

crypto = -5
pair = 'XETCZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETCZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETC crypto vs EUR quote

crypto = -5
pair = 'XETCZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETCZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETC crypto vs GBP quote

crypto = -5
pair = 'XETCZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETCZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETC crypto vs JPY quote

crypto = -5
pair = 'XETCZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETCZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETC crypto vs USD quote

crypto = -5
pair = 'XETCZUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETHZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETH crypto vs CAD quote

crypto = -6
pair = 'XETHZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETHZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETH crypto vs EUR quote

crypto = -6
pair = 'XETHZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETHZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETH crypto vs GBP quote

crypto = -6
pair = 'XETHZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETHZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETH crypto vs JPY quote

crypto = -6
pair = 'XETHZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXETHZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ETH crypto vs USD quote

crypto = -6
pair = 'XETHZUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXLTCZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for LTC crypto vs CAD quote

crypto = -7
pair = 'XLTCZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXLTCZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for LTC crypto vs EUR quote

crypto = -7
pair = 'XLTCZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXLTCZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for LTC crypto vs GBP quote

crypto = -7
pair = 'XLTCZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXLTCZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for LTC crypto vs JPY quote

crypto = -7
pair = 'XLTCZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXLTCZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for LTC crypto vs USD quote

crypto = -7
pair = 'XLTCZUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXREPZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for REP crypto vs CAD quote

crypto = -8
pair = 'XREPZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXREPZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for REP crypto vs EUR quote

crypto = -8
pair = 'XREPZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXREPZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for REP crypto vs GBP quote

crypto = -8
pair = 'XREPZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXREPZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for REP crypto vs JPY quote

crypto = -8
pair = 'XREPZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXREPZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for REP crypto vs USD quote

crypto = -8
pair = 'XREPZUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXBTZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XBT crypto vs CAD quote

crypto = -9
pair = 'XXBTZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXBTZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XBT crypto vs EUR quote

crypto = -9
pair = 'XXBTZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXBTZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XBT crypto vs GBP quote

crypto = -9
pair = 'XXBTZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXBTZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XBT crypto vs JPY quote

crypto = -9
pair = 'XXBTZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXBTZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XBT crypto vs USD quote

crypto = -9
pair = 'XXBTZUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXLMZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XLM crypto vs CAD quote

crypto = -10
pair = 'XXLMZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXLMZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XLM crypto vs EUR quote

crypto = -10
pair = 'XXLMZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXLMZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XLM crypto vs GBP quote

crypto = -10
pair = 'XXLMZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXLMZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XLM crypto vs JPY quote

crypto = -10
pair = 'XXLMZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXLMZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XLM crypto vs USD quote

crypto = -10
pair = 'XXLMZUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXMRZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XMR crypto vs CAD quote

crypto = -11
pair = 'XXMRZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXMRZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XMR crypto vs EUR quote

crypto = -11
pair = 'XXMRZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXMRZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XMR crypto vs GBP quote

crypto = -11
pair = 'XXMRZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXMRZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XMR crypto vs JPY quote

crypto = -11
pair = 'XXMRZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXMRZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XMR crypto vs USD quote

crypto = -11
pair = 'XXMRZUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXRPZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XRP crypto vs CAD quote

crypto = -12
pair = 'XXRPZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXRPZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XRP crypto vs EUR quote

crypto = -12
pair = 'XXRPZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXRPZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XRP crypto vs GBP quote

crypto = -12
pair = 'XXRPZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXRPZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XRP crypto vs JPY quote

crypto = -12
pair = 'XXRPZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXXRPZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for XRP crypto vs USD quote

crypto = -12
pair = 'XXRPZUSD'
quote = 5
class babao.inputs.trades.krakenTradesInput.KrakenTradesXZECZCADInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ZEC crypto vs CAD quote

crypto = -13
pair = 'XZECZCAD'
quote = 1
class babao.inputs.trades.krakenTradesInput.KrakenTradesXZECZEURInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ZEC crypto vs EUR quote

crypto = -13
pair = 'XZECZEUR'
quote = 2
class babao.inputs.trades.krakenTradesInput.KrakenTradesXZECZGBPInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ZEC crypto vs GBP quote

crypto = -13
pair = 'XZECZGBP'
quote = 3
class babao.inputs.trades.krakenTradesInput.KrakenTradesXZECZJPYInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ZEC crypto vs JPY quote

crypto = -13
pair = 'XZECZJPY'
quote = 4
class babao.inputs.trades.krakenTradesInput.KrakenTradesXZECZUSDInput[source]

Bases: babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput

Kraken trade input for ZEC crypto vs USD quote

crypto = -13
pair = 'XZECZUSD'
quote = 5
babao.inputs.trades.krakenTradesInputBase module

Module containing base class for any kraken trades input

class babao.inputs.trades.krakenTradesInputBase.ABCKrakenTradesInput[source]

Bases: babao.inputs.trades.tradesInputBase.ABCTradesInput, babao.inputs.krakenInputBase.ABCKrakenInput

Base class for any kraken trades input

fetch()[source]

Return a time-serie DataFrame fetched from the internets

This data will be stored on database for later use (and eventual resampling). Data can be continuous. Index must be nanosecond timestamps.

pair

Overide this method with the desired asset pair as string ex: self.pair = “XXBTZEUR”

babao.inputs.trades.tradesInputBase module

Module containing base class for any trades input

class babao.inputs.trades.tradesInputBase.ABCTradesInput[source]

Bases: babao.inputs.inputBase.ABCInput

Base class for any trades input

crypto

Overide this method with the desired CryptoEnum ex: self.crypto = CryptoEnum.XBT

fetch()[source]

Return a time-serie DataFrame fetched from the internets

This data will be stored on database for later use (and eventual resampling). Data can be continuous. Index must be nanosecond timestamps.

fillMissing(resampled_data)[source]

Fill missing values (np.nan/np.inf) in ´resampled_data´

quote

Overide this method with the desired QuoteEnum ex: self.quote = QuoteEnum.EUR

raw_columns = ['price', 'volume']
resampled_columns = ['open', 'high', 'low', 'close', 'vwap', 'volume', 'count']
Module contents
Submodules
babao.inputs.inputBase module

Base class for any input

class babao.inputs.inputBase.ABCInput[source]

Bases: abc.ABC

Base class for any input

Your subclass should at least implement: * fetch : self -> DataFrame * raw_columns : List[str]

And eventually: (if you want self.resample to works) * _resample : self -> DataFrame -> DataFrame * fillMissing : self -> DataFrame -> DataFrame * resampled_columns : List[str]

(cf. specific method doc-string in this class)

cache(fresh_data=None, since=None, till=None)[source]

Save some data to cache

If ´fresh_data´ is given, append it to cache, otherwise read in database from ´since´ to ´till´ and cache it

fetch()[source]

Return a time-serie DataFrame fetched from the internets

This data will be stored on database for later use (and eventual resampling). Data can be continuous. Index must be nanosecond timestamps.

fillMissing(resampled_data)[source]

Fill missing values (np.nan/np.inf) in ´resampled_data´

raw_columns

The columns names of your raw data (as fetched and stored in database)

read(since=None, till=None)[source]

Read data in database or cache from ´since´ to ´till´

refreshCache()[source]

Make sure the cache is up to date

resample(raw_data)[source]

Return the DataFrame ´raw_data´ as a continuous time-serie

This is a wrapper around _resample and fillMissing

resampled_columns

The columns names of your resampled data (from raw data)

updateCurrentRow(current_row=None, timestamp=None)[source]

Update the property self.current_row, useful for time travel

write(raw_data)[source]

Write the given raw_data to the database, and cache it if needed

babao.inputs.inputBase.resampleSerie(s)[source]

Call Serie.resample on s with preset parameters (the serie’s index must be datetime)

babao.inputs.inputManager module

Common interface to inputs to call methods on all of them at once

babao.inputs.inputManager.fetchInputs()[source]

Fetch all the INPUTS in a pool thread

The raw data resulting is then wrote to database.

babao.inputs.inputManager.readInputs(input_list: Optional[List[babao.inputs.inputBase.ABCInput]] = None, since=None)[source]

Read all INPUTS from ´since´ and resample them with matching time base

The return is one dataframe containing all concatened columns (so they will be renamed with the input name as prefix

babao.inputs.inputManager.refreshInputs(input_list: Optional[List[babao.inputs.inputBase.ABCInput]] = None)[source]

Make sure the cache is up to date on the given inputs (or all the INPUTS)

babao.inputs.inputManager.timeTravel(timestamp)[source]

Travel to the specified timestamp, for simulation purposes

babao.inputs.krakenInputBase module

This module define the base class and methods for kraken inputs

class babao.inputs.krakenInputBase.ABCKrakenInput[source]

Bases: babao.inputs.inputBase.ABCInput

Base class for any kraken input

fetch()[source]

Return a time-serie DataFrame fetched from the internets

This data will be stored on database for later use (and eventual resampling). Data can be continuous. Index must be nanosecond timestamps.

Module contents

babao.models package

Subpackages
babao.models.tree package
Submodules
babao.models.tree.extremaModel module

The idea of that model is to find local extrema, then classify them as minimum/nop/maximum (-1/0/1) using a knn classifier (sklearn)

class babao.models.tree.extremaModel.ExtremaModel[source]

Bases: babao.models.modelBase.ABCModel

A stupid simple model finding local extrema

dependencies_class = [<class 'babao.inputs.trades.krakenTradesInput.KrakenTradesXXBTZEURInput'>]
load()[source]

Load the model from self.model_file

need_training = True
plot(since)[source]

Plot the model predictions from ´since´ timestamp

predict(since)[source]

Return a dataframe of prediction starting from ´since´ timestamp

save()[source]

Save the model to self.model_file

train(since)[source]

Train the model with data starting from ´since´ timestamp

Return the score of model.

babao.models.tree.macdModel module

Simple macd based model, with a very elegant algorithm (aka: brute-force)

class babao.models.tree.macdModel.MacdModel[source]

Bases: babao.models.modelBase.ABCModel

Simple macd based model

dependencies_class = [<class 'babao.inputs.trades.krakenTradesInput.KrakenTradesXXBTZEURInput'>]
load()[source]

Load the model from self.model_file

need_training = True
plot(since)[source]

Plot the model predictions from ´since´ timestamp

predict(since)[source]

Return a dataframe of prediction starting from ´since´ timestamp

save()[source]

Save the model to self.model_file

train(since)[source]

Train the model with data starting from ´since´ timestamp

Return the score of model.

babao.models.tree.tendencyModel module
Module contents
Submodules
babao.models.modelBase module

Base class for any model

class babao.models.modelBase.ABCModel[source]

Bases: abc.ABC

Base class for any model

dependencies_class

List of models or inputs needed by the current model

These should be class, not instances!

load()[source]

Load the model from self.model_file

need_training

Specify if the current model need to be trained

plot(since)[source]

Plot the model predictions from ´since´ timestamp

predict(since)[source]

Return a dataframe of prediction starting from ´since´ timestamp

save()[source]

Save the model to self.model_file

train(since)[source]

Train the model with data starting from ´since´ timestamp

Return the score of model.

babao.models.modelBase.addLookbacks(df, look_back)[source]

Add lookback(s) (shifted columns) to each df columns

babao.models.modelBase.addLookbacks3d(arr, look_back)[source]

Add lookback(s) (shifted columns) to each df columns Reshape the features to be keras-proof (3d)

babao.models.modelBase.getVerbose() → int[source]

Transform our verbose level to match keras one

babao.models.modelBase.reshape(arr)[source]

Reshape the features to be keras-proof

babao.models.modelManager module

The idea here is to give a common interface to all the models so you can use these wrappers to call all of them at once.

babao.models.modelManager.plotModels(since)[source]

Plot all models

babao.models.modelManager.predictModelsMaybeTrade(since)[source]

Call predict on the root model, then eventually trade based on the preduction

babao.models.modelManager.trainModels(since)[source]

Train all models and save the awesome result

babao.models.rootModel module

Root Model, base of the models tree

class babao.models.rootModel.RootModel[source]

Bases: babao.models.modelBase.ABCModel

Root Model, base of the models tree

Not modeling much, but handle the call of the dependencies predictions

dependencies_class = [<class 'babao.models.tree.extremaModel.ExtremaModel'>]
load()[source]

Load the model from self.model_file

need_training = False
plot(since)[source]

Plot the model predictions from ´since´ timestamp

predict(since)[source]

Call predict on the dependencies, then somehow merge the results

save()[source]

Save the model to self.model_file

train(since)[source]

Train the model with data starting from ´since´ timestamp

Return the score of model.

Module contents

babao.utils package

Submodules
babao.utils.date module

Some utils functions for date handling and time traveling

class babao.utils.date.TimeTraveler[source]

Bases: object

Class handling time travel tricks

getTime(force=False)[source]

Return the current time in nanoseconds

Used for time traveling purpose, so this might be a date in the past matching the current simulation state, unless ´force´ is set to True.

nowMinus(years=0, weeks=0, days=0, hours=0, minutes=0)[source]

Return the current timestamp (nanoseconds) minus the given parameters

This will take into account time traveling tricks.

setTime(now)[source]

Set time to the given ´now´ nanoseconds

Used for time traveling purpose

babao.utils.date.nanoToSec(nano)[source]

Convert nanoseconds to seconds

babao.utils.date.secToNano(sec)[source]

Convert seconds to nanoseconds Just trying to avoid float rounding…

babao.utils.date.toDatetime(df)[source]

Convert the index of the given dataframe to datetime

Also works directly on a dataframe index.

babao.utils.date.toStr(t)[source]

Return the string representation of timestamp

´t´ can be a nanoseconds timestamp, or a panda datetime object.

babao.utils.date.toTimestamp(df)[source]

Convert the index of the given dataframe to nanoseconds

Also works directly on a dataframe index.

babao.utils.enum module

Enums describing positions and assets.

class babao.utils.enum.ActionEnum[source]

Bases: enum.Enum

Enum describing a transaction action

BUY = 1
DEPOSIT = 2
FEE = -3
HODL = 0
SELL = -1
WITHDRAW = -2
class babao.utils.enum.CryptoEnum[source]

Bases: enum.Enum

Enum describing a crypto asset

BCH = -1
DASH = -2
EOS = -3
ETC = -5
ETH = -6
GNO = -4
LTC = -7
REP = -8
XBT = -9
XLM = -10
XMR = -11
XRP = -12
ZEC = -13
class babao.utils.enum.QuoteEnum[source]

Bases: enum.Enum

Enum describing a quote asset

CAD = 1
EUR = 2
GBP = 3
JPY = 4
USD = 5
class babao.utils.enum.TradeEnum[source]

Bases: enum.Enum

Enum describing a transaction on a given asset

BUY_BCH = 1
BUY_DASH = 2
BUY_EOS = 3
BUY_ETC = 5
BUY_ETH = 6
BUY_GNO = 4
BUY_LTC = 7
BUY_REP = 8
BUY_XBT = 9
BUY_XLM = 10
BUY_XMR = 11
BUY_XRP = 12
BUY_ZEC = 13
HODL = 0
SELL_BCH = -1
SELL_DASH = -2
SELL_EOS = -3
SELL_ETC = -5
SELL_ETH = -6
SELL_GNO = -4
SELL_LTC = -7
SELL_REP = -8
SELL_XBT = -9
SELL_XLM = -10
SELL_XMR = -11
SELL_XRP = -12
SELL_ZEC = -13
babao.utils.enum.cryptoAndActionTotrade(crypto_enum_val, action_enum_val)[source]

Convert a crypto enum and an action enum to the matching trade enum

babao.utils.enum.floatToTrade(f)[source]

Round a float value to the nearest trade enum

babao.utils.enum.tradeToAction(trade_enum_val)[source]

Extract an action enum from a trade enum

babao.utils.enum.tradeToCrypto(trade_enum_val)[source]

Extract a crypto enum from a trade enum

babao.utils.file module

Some utils functions for hdf handling

babao.utils.file.closeStore()[source]

Close the hdf database

babao.utils.file.delete(frame)[source]

Remove the given ´frame´ entry (key) from the hdf database

Thread Safe!

babao.utils.file.getLastRows(frame, nrows)[source]

Return ´nrows´ rows from a ´frame´ (key) in the hdf database as a DataFrame

babao.utils.file.initStore(filename)[source]

Open the hdf database from ´filename´

babao.utils.file.maintenance()[source]

Maintenance routine on the hdf database

Create table index for each table, and make sure everything is sorted.

babao.utils.file.read(frame, where=None)[source]

Read a ´frame´ (key) from the hdf database

´where´ can be use to specify search criteria. Thread Safe!

babao.utils.file.setLock(lock)[source]

Store the given ´lock´ object for later use in database processing

babao.utils.file.write(frame, df)[source]

Append the given ´df´ dataframe to the ´frame´ entry (key) in the hdf database

Thread Safe!

babao.utils.indicators module

Various indicators which can be added to any serie

//www.quantinsti.com/blog/build-technical-indicators-in-python

babao.utils.indicators.ewma(serie, look_back_delay)[source]

Exponentially-weighted Moving Average

babao.utils.indicators.get(df, columns)[source]

Add indicators specified by columns to the given df

Expected ´columns´ format: [“sma_vwap_42”, “ewma_volume_12”]

babao.utils.indicators.macd(serie, fast_delay, slow_delay, signal_delay, full=False)[source]

Moving Average Convergence/Divergence Oscillator

babao.utils.indicators.ppo(serie, fast_delay, slow_delay, signal_delay, full=False)[source]

Percentage Price Oscillator

Same as macd, but we do (a-b)/b instead of a-b, so the final value does not depend on input scale (it’s a percentage!)

babao.utils.indicators.sma(serie, look_back_delay)[source]

Simple Moving Average

babao.utils.lock module

Some utils functions for lock file handling

babao.utils.lock.isLocked(lockfile)[source]

Check if the ´lockfile´ exists

babao.utils.lock.tryLock(lockfile)[source]

Create the given ´lockfile´

Return false if it already exists

babao.utils.lock.tryUnlock(lockfile)[source]

Remove the given ´lockfile´

Return false if it doesn’t exist

babao.utils.log module

Some utils functions for logging

babao.utils.log.debug(*args)[source]

Log a debug (magenta)

babao.utils.log.error(*args)[source]

Log an error (red)

babao.utils.log.info(*args)[source]

Log a simple message (blue)

babao.utils.log.initLogLevel(verbose, quiet)[source]

Initialize log level based on verbose flag

babao.utils.log.setLock(lock)[source]

Store the given ´lock´ object for later use in logging

babao.utils.log.warning(*args)[source]

Log a warning (yellow)

babao.utils.scale module

Scaler

class babao.utils.scale.Scaler[source]

Bases: object

Basic min/max scaler

fit(arr)[source]

Init scaler

scale(arr)[source]

Scale features before train/predict

scaleFit(arr)[source]

Scale n Fit

unscale(arr)[source]

Unscale features after train/predict

babao.utils.signal module

Signal handling

babao.utils.signal.catchSignal()[source]

Catch signal INT/TERM, so we won’t exit while playing with data files

babao.utils.signal.restoreSignal()[source]

Restore the previous signal handler

Module contents

Submodules

babao.arg module

Argv parsing

babao.arg.parseArgv(args)[source]

Parse argv ´args´

babao.babao module

Module that contains the command line app.

Why does this file exist, and why not put this in __main__?

You might be tempted to import things from __main__ later, but that will cause problems: the code will get executed twice:

  • When you run python -mbabao python will execute __main__.py as a script. That means there won’t be any babao.__main__ in sys.modules.
  • When you import __main__ it will get executed again (as a module) because there’s no babao.__main__ in sys.modules.

Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration

babao.babao.main(args=None)[source]

Babao entry point

babao.commands module

Commands launched by parseArgv

babao.commands.backtest(args)[source]

Just a naive backtester

It will call the trained strategies on each test data point

babao.commands.dryRun(unused_args)[source]

Real-time bot simulation

babao.commands.fetch(unused_args)[source]

Fetch raw trade data since the beginning of times

babao.commands.train(args)[source]

Train the various (awesome) algorithms

babao.commands.wetRun(unused_args)[source]

Dummy

babao.config module

Here we’ll handle the config file and the various file/dir paths

babao.config.readConfigFile(cmd_name='dry-run')[source]

Read config file and initialize global config variables

babao.graph module

Module contents

Indices and tables