🗃
PDF Service
Download Center (bita-pdf-service)
💡 Only constituents, price series and guidebook files are generated when the backtest is finished.
💡 All files are stored on Amazon S3.
🔑 The value of the token property is extracted via the BITACore API.
ℹ To download the generated files, you can go through: [Link]
depending on the environment.
Run Service
There are two ways of executing the project (local):
Option 1 (Recommended):
Step 1: Run RabbitMQ service.
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
Step 2: Go to [Link] (guest/guest)
After logging in we go to the Exchanges tab, remembering to set the name as download_center and the type to fanout
PDF Service 1
Step 3: Execute node server/[Link]
After running the service locally with node or nodemon, the pdf_service queue will be created automatically.
Step 4: Queue management
Select the pdf_service queue
PDF Service 2
We can then send the payloads and view the processing of the files in the console,
PDF Service 3
Step 5: Verify the created files
After the file is generated, if it is a pdf file, it will be saved locally and we will be able to examine it directly, in case it is an excel file
we must download it using the following link [Link]
Subdomain changes depending on environment.
Development Staging Production
[Link] [Link] [Link]
ℹ It is important to note that all generated files are stored in S3, so they can be downloaded using the link.
Option 2 (Not Recommended for local work):
docker build . -t pdfservice/bita && docker run --network host pdfservice/bita
File generation processes
Normal Process
Below is a diagram explaining the normal file generation process from the time the user selects to download a file until it is
downloaded.
PDF Service 4
FTP Process
Below is a diagram explaining how the file generation and saving to a server via FTP protocol works.
PDF Service 5
Project Organization
ℹ For more information on the project scaffolding, please refer to the [Link] file in the repository.
Folder Structure
./bita-pdf-service
├── auth
│ └── [Link]
├── [Link]
├── data_getters
│ ├── company_services.js
│ ├── [Link]
PDF Service 6
│ ├── [Link]
│ └── [Link]
├── [Link]
├── Dockerfile
├── excel_management
│ └── [Link]
├── fonts
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
├── ftp_service
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ └── keys
│ └── [Link]
├── [Link]
├── load_file_yaml.js
├── [Link]
├── [Link]
├── pdf_management
│ ├── handlebars
│ │ └── [Link]
│ ├── helpers
│ │ ├── [Link]
│ │ ├── [Link]
│ │ ├── [Link]
│ │ ├── [Link]
│ │ ├── [Link]
│ │ ├── [Link]
│ │ ├── [Link]
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── [Link]
│ ├── [Link]
│ └── templates
│ ├── assets
│ │ ├── css
│ │ ├── excel
│ │ ├── factsheet
│ │ └── guidebook
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
├── [Link]
└── [Link]
./[Link]: Entry point of the service, here the Rabbit payloads are processed, the corresponding processes are performed and
then the Rabbit signal is returned to download the generated file from S3.
data_getters: This folder contains the logic and variables for the data request.
PDF Service 7
excel_management: This folder contains the logic necessary for the creation of .xlsx, .csv and related files.
pdf_management: This folder contains the logic, helpers, styles and templates needed for PDF creation.
ftp_service: This folder contains the logic and configuration needed to upload files to servers via FTP or even SFTP protocol.
Create or edit reports
For editing or creating reports we must first define the type of file to edit, then based on this we will know how to refer to the Excel or
PDF logic.
Case: New PDF file
For the creation of a new PDF file, we must create a new template inside pdf_management/templates , define the page layout (hbs),
define styles (css), define functionalities and graphics (js). After that, we can generate PDF files using Chromium and
Puppeteer. If necessary please refer to the documentation of each one.
Case: Edit PDF file
Editing files is simpler, we only have to locate the file to edit and then modify the respective files (.hbs, .css and .js).
Case: New Excel o CSV file
To create new calculation files whether they are .xlsx, .xls, .csv, etc. We only have to go to the excel_management/[Link] file and
define new parameters and functions to create these binaries. It is important to note that the tool used is exceljs.
Case: Edit Excel o CSV file
To make edits to the files we only need to locate the function inside excel_management/[Link] that contains the file generation
logic. It is recommended to debug it for easier editing.
Payload Configuration
Properties that receive the service
{
"headers": {
"token": session token
},
"action": name of the action to be executed by the service,
"task_id": autogenerated by the API. It could be any string,
"data": {
"customizable": company ID (optional),
"user_id": user ID,
"licence": licence plan (deprecated),
"index_id": index ID,
"deploy": environment of the datbases (prod, staging, dev),
"timeframe": timeframe value (optional)
}
}
PDF Service 8
List of available options for file generation (action)
factsheet: 'Factsheet creation'
pdf: 'PDF creation'
si_factsheet: 'SI-Factsheet creation'
report: 'Report creation'
excel: 'Excel creation'
price_series: 'PS creation'
risk_constituents: 'RI-Constituent creation'
si_guidebook: 'SI-Guidebook creation'
basket_factsheet: 'BI-Factsheet creation'
basket_report: 'BI-Report creation'
emission_report: 'ESG-Emission creation'
waste_report: 'ESG-Waste creation'
controversy_report: 'ESG-Controversy creation'
ratings_report: 'ESG-Ratings creation'
Payload examples
Factsheet File
{
"headers": {
"channel": "5ed928e36c0e2c16c82fc5a2",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"token": ""
},
"action": "Factsheet creation",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"data": {
"user_id": "5ed928e36c0e2c16c82fc5a2",
"licence": "trial",
"index_id": 5725,
"deploy": "dev"
}
}
Excel Files
{
"headers": {
"channel": "5ed928e36c0e2c16c82fc5a2",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"token": ""
},
"action": "Excel creation",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"data": {
"user_id": "5ed928e36c0e2c16c82fc5a2",
"licence": "trial",
"index_id": 5484,
"deploy": "dev"
}
}
End Date File
{
"headers": {
"channel": "5ed928e36c0e2c16c82fc5a2",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"token": ""
PDF Service 9
},
"action": "Constituents-End-Date creation",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"data": {
"user_id": "5ed928e36c0e2c16c82fc5a2",
"licence": "trial",
"index_id": 5426,
"deploy": "dev"
}
}
Custom factsheet
{
"headers": {
"channel": "61097053662ee2001303fdf2",
"task_id": "hFuuYubqdQkG",
"token": ""
},
"action": "Custom-Factsheet creation",
"task_id": "hFuuYubqdQkG",
"factsheet_info": {
"index_name": "Test Factsheet 1",
"ticker": "BGCANG",
"index_type": "Equity Index",
"index_description": "The BITA Global Cannabis Giants Index captures the Gross Total Return Performance of the 20 largest publicly
"index_methodology": "The BITA Global Cannabis Index is designed to measure the market performance of companies with more than 50%
"company_name": "BITA",
"website": "[Link]",
"company_description": "BITA is a Germany-based Fintech that provides enterprise-grade indexes, data, and infrastructure to institu
"disclaimer": "Please note that the indices published in this factsheet are for demonstration purposes only and cannot be traded di
"index_description_container": true,
"performance_container": true,
"general_statistics_container": true,
"index_characteristics_container": true,
"descriptive_stats_container": true,
"top_sector_country_container": true,
"company_description_container": true,
"index_methodology_container": true,
"disclaimer_container": true,
"custom_parameter": true
},
"output_mode": "default",
"ftp_client": {},
"data": {
"user_id": "61097053662ee2001303fdf2",
"licence": "trial",
"index_id": 5688,
"deploy": "dev",
"customizable": false,
"reconstitution_date": "2020-01-23 (reconstitution)",
"timeframe": false
}
}
PDF Files
{
"headers": {
"channel": "5ed928e36c0e2c16c82fc5a2",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"token": ""
},
"action": "PDF creation",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"output_mode": "ftp",
"data": {
"user_id": "5ed928e36c0e2c16c82fc5a2",
"licence": "trial",
"index_id": 5249,
"deploy": "dev"
}
}
PDF Service 10
FTP Output (any file)
{
"headers": {
"channel": "5ed928e36c0e2c16c82fc5a2",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"token": ""
},
"action": "PDF creation",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"output_mode": "ftp",
"data": {
"user_id": "5ed928e36c0e2c16c82fc5a2",
"licence": "trial",
"index_id": 5249,
"deploy": "dev"
}
}
{
"headers": {
"channel": "5ed928e36c0e2c16c82fc5a2",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"token": ""
},
"action": "Excel creation",
"task_id": "2MT3U-dVrCuV2uqgO10J",
"ftp_client": {
"host": "[Link]",
"port": "2121",
"user": "alejandro",
"password": "alejandro"
},
"data": {
"user_id": "5ed928e36c0e2c16c82fc5a2",
"licence": "trial",
"index_id": 5034,
"deploy": "dev"
}
}
PDF Service 11