News Event (news wire or story)
This method will be called whenever a news event occurs in a given symbol (as either the main symbol or secondary symbol of the news event).
Interface: def on_news(self,
event,
md,
order,
service,
account):
pass
Name | Type | Information |
---|---|---|
headline | string | News headline. |
hyperlink | string | Web URL to the news story. |
kind | integer | Event enum (5) representing the kind of event. *LIVE AND FORWARD ONLY*, represents the type of event (trade, quote, news, imbalance etc) |
provider_name | string | Name of the news story provider. |
source_instructions | string | Source instructions of news story. |
story_codes | string | Tags relating to story's subject matter |
symbol | string | Event Symbol. In most cases symbol is obvious (self.symbol, md.symbol). If the script has subscribed to multiple symbols events, then event.symbol should be used to identify the symbol. |
symbols | list | List of symbols related to the news story. |
synopsis | string | Summary of the news story. |
timestamp | muts | Timestamp of the event. |
wire_description | string | Human-readable version of the provider_name field. |
- Date ranges?
- Event Symbol. In most cases symbol is obvious (self.symbol, md.symbol). If the script has subscribed to multiple symbols events, then event.symbol should be used to identify the symbol.
Print the attributes of event when on_news() is called.
from cloudquant.interfaces import Strategy
class OnNewsExample(Strategy):
do_once = True
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return symbol == 'SPY'
def on_start(self, md, order, service, account):
if self.__class__.do_once:
print service.time_to_string(service.system_time, '%Y-%m-%d')
self.__class__.do_once = False
print self.symbol
def on_news( self, event, md, order, service, account ):
print '\nin on_news()\n\t%s\n' % service.time_to_string(service.system_time, '%H:%M:%S.%f')
print 'event - NewsEvent\n'
print ' event.headline - ', event.headline
print ' event.hyperlink - ', event.hyperlink
print ' event.kind - ', event.kind
print ' event.provider_name - ', event.provider_name
print ' event.source_instructions - ', event.source_instructions
print ' event.story_codes - ', event.story_codes
print ' event.symbol - ', event.symbol
print ' event.symbols - ', event.symbols
print ' event.synopsis - ', event.synopsis
print ' event.timestamp - ', event.timestamp
print ' event.wire_description - ', event.wire_description
service.terminate()
Console
2015-03-31 XLF in on_news() 10:36:46.403000 event - NewsEvent event.headline - *Financial Select Sector overall volatility at 15, 26-week average is 17 event.hyperlink - event.kind - 5 event.provider_name - FLYWALL_ event.source_instructions - event.story_codes - IS/fin.markets;IS/fin.options;IS/fin;NT/Derivs.Equity;NT/Derivs;NT/Ideas.Options;NT/Ideas;XC/NYSEArca;XC/any.US;XC/any.company;XC/any.public;PS/p.FLYWALL_;PS/s.USEQUITY;PC/t.150331063646144;PS/Live_News_Feed;PS/src.4001.2;PS/.Live_News_Feed;SU/Options;PS/Options_News event.symbol - XLF event.symbols - [] event.synopsis - event.timestamp - 1427812606403000 event.wire_description - TheFlyOnTheWall