Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anansi-toolkit

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anansi-toolkit

A tool to analyze data and perform operations in markets

  • 0.1.0
  • PyPI
  • Socket score

Maintainers
1

Anansi

Dependencies

Python, Pip, Poetry.

To install poetry, on osx, linux or bashonwindows terminals, 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 poetry

Consuming on Jupyter notebook

That 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 Operation

Importing Dependencies

from anansi.tradingbot.models import *
from anansi.tradingbot import traders
from anansi.tradingbot.views import create_user, create_default_operation

Add a new user

my_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 operation

my_user = User[1]
create_default_operation(user=my_user)

Instantiating a trader

my_op = Operation.get(id=1)
my_trader = traders.DefaultTrader(operation=my_op)

Run the trader

my_trader.run()

Playing with the database models

Getting all users

users = select(user for user in User)
users.show()
id|first_name|last_name|login_displayed_name|email         
--+----------+---------+--------------------+--------------
1 |John      |Doe      |                    |john@email.com
my_user.first_name
'John'

Some operation attribute

my_op.stop_loss.name
'StopTrailing3T'

Some trader attribute

my_trader.Classifier.parameters.time_frame
'6h'

Updating some attributes

before_update = my_trader.operation.position.side, my_trader.operation.position.exit_reference_price

my_trader.operation.position.update(side="Long", exit_reference_price=1020.94)

after_update = my_trader.operation.position.side, my_trader.operation.position.exit_reference_price

before_update, after_update
(('Zeroed', None), ('Long', 1020.94))

Requesting klines

Klines treated and ready for use, including market indicators methods

The 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, extended with market indicator methods.

from anansi.marketdata.handlers import KlinesFromBroker
BinanceKlines = KlinesFromBroker(
  broker_name="binance", ticker_symbol="BTCUSDT", time_frame="1h")
newest_klines = BinanceKlines.newest(2167)
newest_klines
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
Open_timeOpenHighLowCloseVolume
02020-06-17 11:00:009483.259511.539466.009478.611251.802697
12020-06-17 12:00:009478.619510.889477.359499.251120.426332
22020-06-17 13:00:009499.249565.009432.009443.484401.693008
32020-06-17 14:00:009442.509464.839366.099410.954802.211120
42020-06-17 15:00:009411.279436.549388.439399.242077.135281
.....................
21622020-09-15 13:00:0010907.9410917.9610834.0010834.713326.420940
21632020-09-15 14:00:0010834.7110879.0010736.6310764.194382.021477
21642020-09-15 15:00:0010763.3710815.4710745.6310784.463531.309654
21652020-09-15 16:00:0010785.2310827.6110700.0010784.233348.735166
21662020-09-15 17:00:0010784.2310812.4410738.3310794.841931.035921

2167 rows × 6 columns

Applying simple moving average indicators

indicator = 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
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
Open_timeOpenHighLowCloseVolume
02020-06-17 11:00:009483.259511.539466.009478.611251.802697
12020-06-17 12:00:009478.619510.889477.359499.251120.426332
22020-06-17 13:00:009499.249565.009432.009443.484401.693008
32020-06-17 14:00:009442.509464.839366.099410.954802.211120
42020-06-17 15:00:009411.279436.549388.439399.242077.135281
.....................
21622020-09-15 13:00:0010907.9410917.9610834.0010834.713326.420940
21632020-09-15 14:00:0010834.7110879.0010736.6310764.194382.021477
21642020-09-15 15:00:0010763.3710815.4710745.6310784.463531.309654
21652020-09-15 16:00:0010785.2310827.6110700.0010784.233348.735166
21662020-09-15 17:00:0010784.2310812.4410738.3310794.841931.035921

2167 rows × 6 columns

Same as above, but showing indicator column

indicator = newest_klines.apply_indicator.trend.simple_moving_average(
  number_of_candles=35, indicator_column="SMA_OHLC4_n35")
newest_klines
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
Open_timeOpenHighLowCloseVolumeSMA_OHLC4_n35
02020-06-17 11:00:009483.259511.539466.009478.611251.802697NaN
12020-06-17 12:00:009478.619510.889477.359499.251120.426332NaN
22020-06-17 13:00:009499.249565.009432.009443.484401.693008NaN
32020-06-17 14:00:009442.509464.839366.099410.954802.211120NaN
42020-06-17 15:00:009411.279436.549388.439399.242077.135281NaN
........................
21622020-09-15 13:00:0010907.9410917.9610834.0010834.713326.42094010619.190500
21632020-09-15 14:00:0010834.7110879.0010736.6310764.194382.02147710632.213571
21642020-09-15 15:00:0010763.3710815.4710745.6310784.463531.30965410644.682643
21652020-09-15 16:00:0010785.2310827.6110700.0010784.233348.73516610657.128857
21662020-09-15 17:00:0010784.2310812.4410738.3310794.841931.03592110669.494071

2167 rows × 7 columns

Raw 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.

from anansi.marketdata import data_brokers
BinanceBroker = data_brokers.BinanceDataBroker()
my_klines = BinanceBroker.get_klines(ticker_symbol="BTCUSDT", time_frame="1m")
my_klines
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
Open_timeOpenHighLowCloseVolume
0160016556010688.1210691.1410684.8810684.8821.529835
1160016562010684.8810686.1510681.8410685.9918.487428
2160016568010686.0010687.6510684.9210687.0922.246376
3160016574010687.0910689.5410683.8610687.2618.818481
4160016580010687.2610687.2610683.7110685.7638.281582
.....................
494160019520010762.4310763.4810760.3510760.758.572210
495160019526010760.7510762.4810759.3010759.3111.089815
496160019532010759.3010762.2210755.3910761.2627.070820
497160019538010761.2610761.2610751.7410756.0215.482246
498160019544010755.6110756.5710748.0310748.0461.153777

499 rows × 6 columns

Same as above, but returning all information get from the data broker

my_klines = BinanceBroker.get_klines(ticker_symbol="BTCUSDT", time_frame="1m", show_only_desired_info=False)
my_klines
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
Open_timeOpenHighLowCloseVolumeClose_timeQuote_asset_volumeNumber_of_tradesTaker_buy_base_asset_volumeTaker_buy_quote_asset_volumeIgnore
0160016556010688.1210691.1410684.8810684.8821.5298351600165619230126.587773373.010.279415109864.1498220.0
1160016562010684.8810686.1510681.8410685.9918.4874281600165679197536.180849336.08.25649888223.5660540.0
2160016568010686.0010687.6510684.9210687.0922.2463761600165739237738.839831415.013.378805142975.2432460.0
3160016574010687.0910689.5410683.8610687.2618.8184811600165799201100.293663539.09.06295796849.6118440.0
4160016580010687.2610687.2610683.7110685.7638.2815821600165859409068.511314534.016.799813179523.7085310.0
.......................................
494160019520010762.4310763.4810760.3510760.758.572210160019525992253.016477292.02.39477825771.7154130.0
495160019526010760.7510762.4810759.3010759.3111.0898151600195319119341.014647277.03.06445832976.2565340.0
496160019532010759.3010762.2210755.3910761.2627.0708201600195379291245.877535490.014.654896157679.9267580.0
497160019538010761.2610761.2610751.7410756.0215.4822461600195439166520.446192353.07.39040779491.1609610.0
498160019544010755.6110756.5710748.0310748.0461.1537771600195499657520.935924585.013.436657144474.0846840.0

499 rows × 12 columns

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc