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