Package: anansi-toolkit
AnansiDependenciesPython, Pip, Poetry.To installpoetry, on
osx, linux orbashonwindowsterminals, type it:curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -Alternatively, poetry could be installed by pip (supposing you have
python and pip already installed):pip install poetryConsuming on Jupyter notebookThat is only a suggestion, you could run anansi on any python
terminal. Only tested on linux.Perform the commands:poetry install
poetry run python -m ipykernel install --user --name=$(basename $(pwd))
poetry run jupyter notebook > jupyterlog 2>&1 &Straight to the point: Running Default Back Testing OperationImporting Dependenciesfromanansi.tradingbot.modelsimport*fromanansi.tradingbotimporttradersfromanansi.tradingbot.viewsimportcreate_user,create_default_operationAdd a new usermy_user_first_name="John"create_user(first_name=my_user_first_name,last_name="Doe",email="{}@email.com".format(my_user_first_name.lower()))Creating a default operationmy_user=User[1]create_default_operation(user=my_user)Instantiating a tradermy_op=Operation.get(id=1)my_trader=traders.DefaultTrader(operation=my_op)Run the tradermy_trader.run()Playing with the database modelsGetting all usersusers=select(userforuserinUser)users.show()id|first_name|last_name|login_displayed_name|email         
--+----------+---------+--------------------+--------------
1 |John      |Doe      |                    |john@email.commy_user.first_name'John'Some operation attributemy_op.stop_loss.name'StopTrailing3T'Some trader attributemy_trader.Classifier.parameters.time_frame'6h'Updating some attributesbefore_update=my_trader.operation.position.side,my_trader.operation.position.exit_reference_pricemy_trader.operation.position.update(side="Long",exit_reference_price=1020.94)after_update=my_trader.operation.position.side,my_trader.operation.position.exit_reference_pricebefore_update,after_update(('Zeroed', None), ('Long', 1020.94))Requesting klinesKlines treated and ready for use, including market indicators methodsThe example below uses the 'KlinesFromBroker' class from the 'handlers'
module ('marketdata' package), which works as an abstraction over the
data brokers, not only serializing requests (in order to respect
brokers' limits), but also conforming the klines like a pandas
dataframe,extendedwith market indicator methods.fromanansi.marketdata.handlersimportKlinesFromBrokerBinanceKlines=KlinesFromBroker(broker_name="binance",ticker_symbol="BTCUSDT",time_frame="1h")newest_klines=BinanceKlines.newest(2167)newest_klines<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Open_timeOpenHighLowCloseVolume02020-06-17 11:00:009483.259511.539466.009478.611251.80269712020-06-17 12:00:009478.619510.889477.359499.251120.42633222020-06-17 13:00:009499.249565.009432.009443.484401.69300832020-06-17 14:00:009442.509464.839366.099410.954802.21112042020-06-17 15:00:009411.279436.549388.439399.242077.135281.....................21622020-09-15 13:00:0010907.9410917.9610834.0010834.713326.42094021632020-09-15 14:00:0010834.7110879.0010736.6310764.194382.02147721642020-09-15 15:00:0010763.3710815.4710745.6310784.463531.30965421652020-09-15 16:00:0010785.2310827.6110700.0010784.233348.73516621662020-09-15 17:00:0010784.2310812.4410738.3310794.841931.0359212167 rows × 6 columnsApplying simple moving average  indicatorsindicator=newest_klines.apply_indicator.trend.simple_moving_average(number_of_candles=35)indicator.name,indicator.last(),indicator.serie('sma_ohlc4_35',
 10669.49407142858,
 0                NaN
 1                NaN
 2                NaN
 3                NaN
 4                NaN
             ...     
 2162    10619.190500
 2163    10632.213571
 2164    10644.682643
 2165    10657.128857
 2166    10669.494071
 Length: 2167, dtype: float64)newest_klines<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Open_timeOpenHighLowCloseVolume02020-06-17 11:00:009483.259511.539466.009478.611251.80269712020-06-17 12:00:009478.619510.889477.359499.251120.42633222020-06-17 13:00:009499.249565.009432.009443.484401.69300832020-06-17 14:00:009442.509464.839366.099410.954802.21112042020-06-17 15:00:009411.279436.549388.439399.242077.135281.....................21622020-09-15 13:00:0010907.9410917.9610834.0010834.713326.42094021632020-09-15 14:00:0010834.7110879.0010736.6310764.194382.02147721642020-09-15 15:00:0010763.3710815.4710745.6310784.463531.30965421652020-09-15 16:00:0010785.2310827.6110700.0010784.233348.73516621662020-09-15 17:00:0010784.2310812.4410738.3310794.841931.0359212167 rows × 6 columnsSame as above, but showing indicator columnindicator=newest_klines.apply_indicator.trend.simple_moving_average(number_of_candles=35,indicator_column="SMA_OHLC4_n35")newest_klines<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Open_timeOpenHighLowCloseVolumeSMA_OHLC4_n3502020-06-17 11:00:009483.259511.539466.009478.611251.802697NaN12020-06-17 12:00:009478.619510.889477.359499.251120.426332NaN22020-06-17 13:00:009499.249565.009432.009443.484401.693008NaN32020-06-17 14:00:009442.509464.839366.099410.954802.211120NaN42020-06-17 15:00:009411.279436.549388.439399.242077.135281NaN........................21622020-09-15 13:00:0010907.9410917.9610834.0010834.713326.42094010619.19050021632020-09-15 14:00:0010834.7110879.0010736.6310764.194382.02147710632.21357121642020-09-15 15:00:0010763.3710815.4710745.6310784.463531.30965410644.68264321652020-09-15 16:00:0010785.2310827.6110700.0010784.233348.73516610657.12885721662020-09-15 17:00:0010784.2310812.4410738.3310794.841931.03592110669.4940712167 rows × 7 columnsRaw klines, using the low level abstraction module "data_brokers"DISCLAIMER: Requests here are not queued! There is a risk of banning
the IP or even blocking API keys if some limits are exceeded. Use with
caution.fromanansi.marketdataimportdata_brokersBinanceBroker=data_brokers.BinanceDataBroker()my_klines=BinanceBroker.get_klines(ticker_symbol="BTCUSDT",time_frame="1m")my_klines<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Open_timeOpenHighLowCloseVolume0160016556010688.1210691.1410684.8810684.8821.5298351160016562010684.8810686.1510681.8410685.9918.4874282160016568010686.0010687.6510684.9210687.0922.2463763160016574010687.0910689.5410683.8610687.2618.8184814160016580010687.2610687.2610683.7110685.7638.281582.....................494160019520010762.4310763.4810760.3510760.758.572210495160019526010760.7510762.4810759.3010759.3111.089815496160019532010759.3010762.2210755.3910761.2627.070820497160019538010761.2610761.2610751.7410756.0215.482246498160019544010755.6110756.5710748.0310748.0461.153777499 rows × 6 columnsSame as above, but returning all information get from the data brokermy_klines=BinanceBroker.get_klines(ticker_symbol="BTCUSDT",time_frame="1m",show_only_desired_info=False)my_klines<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Open_timeOpenHighLowCloseVolumeClose_timeQuote_asset_volumeNumber_of_tradesTaker_buy_base_asset_volumeTaker_buy_quote_asset_volumeIgnore0160016556010688.1210691.1410684.8810684.8821.5298351600165619230126.587773373.010.279415109864.1498220.01160016562010684.8810686.1510681.8410685.9918.4874281600165679197536.180849336.08.25649888223.5660540.02160016568010686.0010687.6510684.9210687.0922.2463761600165739237738.839831415.013.378805142975.2432460.03160016574010687.0910689.5410683.8610687.2618.8184811600165799201100.293663539.09.06295796849.6118440.04160016580010687.2610687.2610683.7110685.7638.2815821600165859409068.511314534.016.799813179523.7085310.0.......................................494160019520010762.4310763.4810760.3510760.758.572210160019525992253.016477292.02.39477825771.7154130.0495160019526010760.7510762.4810759.3010759.3111.0898151600195319119341.014647277.03.06445832976.2565340.0496160019532010759.3010762.2210755.3910761.2627.0708201600195379291245.877535490.014.654896157679.9267580.0497160019538010761.2610761.2610751.7410756.0215.4822461600195439166520.446192353.07.39040779491.1609610.0498160019544010755.6110756.5710748.0310748.0461.1537771600195499657520.935924585.013.436657144474.0846840.0499 rows × 12 columns