Python Package for reading a amibroker database
Project description
ami2py
Python Package for reading and writing from and to an amibroker database.
This package is using construct for defining the binary structures used to access the amibroker database,
see Construct documentation.
The specification of the binary structure was taken from the official amibroker C++ sdk api documentation.
However, this is not an official amibroker database api.
Therefore, no warranty is given and handle with care.
Improvement requests are always welcome.
This module can be used to create a database and write symbol data to that.
However, it seems to be a good idea to use the official quote downloader program for productive usage.
Examples
Creating a Database from scratch and adding symbol data to the database.
To use the underlying constructs in compiled form, use_compiled can be set to True within the
AmiDataBase constructor. This is a more or less experimental feature.
>>> from ami2py import AmiDataBase, SymbolEntry
>>> db = AmiDataBase(db_folder)
>>> db.add_symbol("AAPL")
>>> db.append_data_to_symbol(
"AAPL",
SymbolEntry(
Close=200.0,
High=230.0,
Low=190.0,
Open=210.0,
Volume=200003122.0,
Month=12,
Year=2020,
Day=17,
),
)
>>> db.write_database()
Reading a list of symbols contained in the database.
>>> symbols = db.get_symbols()
>>> symbols
["AAPL"]
Getting values for a symbol in a pandas compatible dicitonary format.
>>> db.get_dict_for_symbol("SPCE")
{
"Open": [20.0,....],
"Close": [200.0,....],
"High": [230.0,.....],
"Low": [190.0,.....],
"Open": [210.0,.......],
"Volume": [200003122.0,.....],
"Month": [12,.......],
"Year": [2020,.......],
"Day": [17,........],
}
Using a list container facade for fast reading of symbol data. The previous mentioned methods to read symbol data from the database use construct to convert the binary array into a hierarchical object structure. Creating those objects during the load process, causes high delay during loading. Therefore a symbol facade called AmiSymbolDataFacade was created to read data only in case it is necessary.
>>> data = db.get_fast_symbol_data("SPCE")
>>> data[0]
{'Year': 2017,
'Month': 9,
'Day': 29,
'Hour': 10,
'Minute': 63,
'Second': 63,
'MilliSec': 258,
'MicroSec': 255,
'Reserved': 1,
'Isfut': 1,
'Close': 10.100000381469727,
'Open': 10.5,
'High': 10.5,
'Low': 10.0,
'Volume': 212769.0,
'AUX1': 0.0,
'AUX2': 0.0,
'TERMINATOR': 0.0
}
>>> newslice=data[0:10]
>>> newslice[0]
{'Year': 2017,
'Month': 9,
......
}
>>> newslice[1]
{'Year': 2017,
'Month': 10,
......
}
Todos
- Write tests for intraday data, currently data structures is able to handle intraday data. But no tests had been written, until now. This is considered mandatory to reach version 1.0.0
- Add docstrings to the source code. This seems to be a minor task.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ami2py-0.8.1.tar.gz
.
File metadata
- Download URL: ami2py-0.8.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b539667f2b9a7cafa74ed5737257a06535645e9018c0868b8ccdc763a881765 |
|
MD5 | 045d0c087cb1ca01f07c71d880d58df5 |
|
BLAKE2b-256 | 38ebe3451aa3eac8ee481104e72a8a157bb09dffb7f0d6985b3860c2e7ca6355 |