# -*- coding: utf-8 -*-
import airflow
from intraday_pd import *
from airflow import DAG
from airflow.operators.python_operator import PythonOperator, ShortCircuitOperator
# -------------------------------------------------------------------------------
# dag
# these args will get passed on to each operator
# you can override them on a per-task basis during operator initialization
default_args = {
'owner': 'TongYu',
'catchup': False,
'start_date': airflow.utils.dates.days_ago(1),
}
dag = DAG(
'real_time_portfolio_risk_dag',
catchup=False,
default_args=default_args,
schedule_interval=None,
dagrun_timeout=timedelta(minutes=15),
description='real_time_portfolio_risk_task dag')
basic_position_operator = PythonOperator(
task_id='basic_position_task',
python_callable=basic_position_pd_run,
execution_timeout=timedelta(minutes=5),
dag=dag)
basic_risks_operator = PythonOperator(
task_id='basic_risks_task',
python_callable=basic_risks_pd_run,
execution_timeout=timedelta(minutes=5),
dag=dag)
basic_portfolio_trades_operator = PythonOperator(
task_id='basic_portfolio_risk_task',
python_callable=basic_portfolio_trades_pd_run,
execution_timeout=timedelta(minutes=5),
dag=dag)
real_time_portfolio_trades_operator = PythonOperator(
task_id='real_time_portfolio_trades_task',
python_callable=real_time_portfolio_trades_pd_run,
execution_timeout=timedelta(minutes=5),
dag=dag)
portfolio_risk_notification_operator = PythonOperator(
task_id='real_time_portfolio_risk_notification_task',
python_callable=intraday_portfolio_risk_report_notifier,
execution_timeout=timedelta(minutes=5),
dag=dag)
# -------------------------------------------------------------------------------
# Operator Dependency Relationship
basic_risks_operator.set_upstream(basic_position_operator)
real_time_portfolio_trades_operator.set_upstream(basic_risks_operator)
real_time_portfolio_trades_operator.set_upstream(basic_portfolio_trades_operator)
real_time_portfolio_trades_operator.set_downstream(portfolio_risk_notification_operator)