Jeremy

How to check whether a news appears during trading session?

Programming


Hi all, from the technical document, i know that "session=0" refers to trading session for placing orders. Orders will be rejected for other non-trading sessions. 
In fact, my strategy analyze sentiment of news data for making trade decisions. I don't find the "session" attribute for news data. How can I determine if my sentiment prediction is within a trading session? 
Many thanks in advance! 🙏
 
admin

As news are published in 24x7, there won't have the concept of "market session" for news data.

However, you can create a global variable to check current market session.

A simple example as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from AlgoAPI import AlgoAPIUtil, AlgoAPI_Backtest
 
class AlgoEvent:
    def __init__(self):
        self.isTradingSession = False
        
    def start(self, mEvt):
        self.evt = AlgoAPI_Backtest.AlgoEvtHandler(self, mEvt)
        self.evt.start()
 
    def on_marketdatafeed(self, md, ab):
        self.isTradingSession = False
        if md.session==0:
            self.isTradingSession = True
 
    def on_newsdatafeed(self, nd):
        if self.isTradingSession:
            # some order condition checking
            pass
 
Jeremy
Original Posted by - b'admin':

As news are published in 24x7, there won't have the concept of "market session" for news data.

However, you can create a global variable to check current market session.

A simple example as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from AlgoAPI import AlgoAPIUtil, AlgoAPI_Backtest
 
class AlgoEvent:
    def __init__(self):
        self.isTradingSession = False
        
    def start(self, mEvt):
        self.evt = AlgoAPI_Backtest.AlgoEvtHandler(self, mEvt)
        self.evt.start()
 
    def on_marketdatafeed(self, md, ab):
        self.isTradingSession = False
        if md.session==0:
            self.isTradingSession = True
 
    def on_newsdatafeed(self, nd):
        if self.isTradingSession:
            # some order condition checking
            pass
Thank you. It works now!