jin10.py
Overview
The jin10.py module provides an interface to access various Jin10 financial data APIs within the InfiniFlow system. Jin10 is a popular financial data provider specializing in real-time market flash news, economic calendars, symbols information, and financial news. This module defines a component (Jin10) and its parameter class (Jin10Param) to fetch and process such data, encapsulating the API communication and response formatting.
The primary purpose of this file is to enable seamless integration of Jin10 data into the InfiniFlow agent framework, allowing downstream components or workflows to utilize Jin10's market insights programmatically.
Classes and Functions
Class: Jin10Param
class Jin10Param(ComponentParamBase)
Description:
Defines and validates configuration parameters for the Jin10 component. These parameters control which type of Jin10 data to fetch and how to filter or categorize it.
Properties (Attributes)
Property | Type | Default | Description |
|---|---|---|---|
| str | "flash" | The type of Jin10 data to retrieve. Allowed values: |
| str | "xxx" | API secret key to authorize requests to Jin10. |
| str | '1' | Category for flash news. Allowed values: |
| str | 'cj' | Economic calendar region/type. Allowed: |
| str | 'data' | Type of calendar data. Allowed: |
| str | 'GOODS' | Symbol category. Allowed: |
| str | 'symbols' | Type of symbols data. Allowed: |
| str | "" | Filter parameter to contain specific keywords in results (used in flash/news API calls). |
| str | "" | Additional filter parameter for API queries, e.g., to filter flash/news items. |
Methods
check() -> None
Validates that the parameter values conform to allowed options. Raises exceptions or asserts if invalid values are found.
Usage Example
param = Jin10Param()
param.type = "calendar"
param.calendar_type = "us"
param.calendar_datatype = "holiday"
param.check() # Validates parameters before use
Class: Jin10
class Jin10(ComponentBase, ABC)
Description:
Implements the Jin10 data fetching component. This class uses the parameters defined in Jin10Param to query the Jin10 API endpoints and process the responses into pandas DataFrame or text outputs formatted for the InfiniFlow agent system.
Class Attributes
component_name(str): Identifier name for this component, set to"Jin10".
Methods
_run(self, history, **kwargs) -> pd.DataFrame or str
Main execution method invoked by the agent framework. It performs the following steps:Retrieves input content from upstream components.
Based on the parameter
type, makes a corresponding HTTP GET request to the Jin10 API with appropriate headers and parameters.Parses and processes the JSON response:
For
flashtype: Extract flash news content.For
calendartype: Convert calendar data to Markdown-formatted tables.For
symbolstype: Normalize symbol or quote data fields, then format as Markdown tables.For
newstype: Convert news data to Markdown tables.
Handles exceptions gracefully and returns error messages if the API call or processing fails.
Returns the processed data as a pandas DataFrame or an empty output if no data is available.
Parameters
history: (Unused in current implementation but conventionally used for historical context in agent components.)**kwargs: Additional keyword arguments (not used here).
Returns
pandas.DataFramecontaining the processed Jin10 data in Markdown table format, orstrwith an error message or empty output if no data is fetched.
Usage Example
jin10_component = Jin10()
jin10_component._param = Jin10Param()
jin10_component._param.type = "flash"
jin10_component._param.flash_type = "3"
jin10_component._param.secret_key = "your_secret_key"
result_df_or_str = jin10_component._run(history=None)
print(result_df_or_str)
Implementation Details and Algorithms
The component uses the
requestslibrary to perform HTTP GET requests to different Jin10 API endpoints depending on the data type requested.API endpoints are constructed dynamically based on parameters such as
type,flash_type,calendar_type, etc.The request headers include a
'secret-key'for authentication.Responses are expected in JSON format. Data extraction logic adapts to the structure of each API endpoint.
For
symbolsdata, the component renames cryptic JSON keys (like'c','e','n','t') to descriptive column names before converting to Markdown.The output is typically a Markdown-formatted table within a pandas DataFrame, suitable for display or further processing in the InfiniFlow framework.
Exception handling wraps all network and parsing operations to catch and return errors without crashing the system.
Interaction with Other System Components
Base Classes:
Jin10ParamextendsComponentParamBase, andJin10extendsComponentBaseandABCfrom the agent framework. This inheritance implies integration with InfiniFlow's component lifecycle and parameter management.Input/Output:
The_runmethod fetches its input by callingself.get_input(), likely provided by the base class, indicating a pipeline or agent context where this component receives upstream data.External APIs:
This component exclusively interacts with the Jin10 open-data APIs over HTTPS. The API responses are transformed into formats usable by the InfiniFlow agent or downstream components.Data Handling:
Outputs are pandas DataFrames or strings which can be consumed by other components for visualization, storage, or further analytics.
Visual Diagram
classDiagram
class Jin10Param {
+type: str
+secret_key: str
+flash_type: str
+calendar_type: str
+calendar_datatype: str
+symbols_type: str
+symbols_datatype: str
+contain: str
+filter: str
+check()
}
class Jin10 {
+component_name: str
+_run(history, **kwargs)
-_param: Jin10Param
+get_input()
+be_output(data)
}
Jin10 ..> Jin10Param : uses
Jin10 --> ComponentBase
Jin10Param --> ComponentParamBase
Summary
The jin10.py file encapsulates Jin10 financial data API access into an InfiniFlow agent component. It abstracts away API details, parameter validation, and data formatting to present clean, ready-to-use financial data such as flash market news, economic calendars, symbols information, and news items. This modular design ensures maintainability and extensibility while providing critical market insights to the broader InfiniFlow ecosystem.