Add example algorithm on brokerage activities (#7214)

* Add example algorithm on brokerage activities

* Add brokerage activities event handlers on live feature algorithm

* add boolean flag
This commit is contained in:
Louis Szeto
2023-04-28 01:17:58 +08:00
committed by GitHub
parent 4d5e0fb73a
commit baf2dbcefa
4 changed files with 180 additions and 0 deletions
+17
View File
@@ -41,6 +41,9 @@ class LiveTradingFeaturesAlgorithm(QCAlgorithm):
##Custom/Bitcoin Live Data: 24/7
self.AddData(Bitcoin, 'BTC', Resolution.Second, TimeZones.Utc)
##if the algorithm is connected to the brokerage
self.is_connected = True
### New Bitcoin Data Event
@@ -64,6 +67,20 @@ class LiveTradingFeaturesAlgorithm(QCAlgorithm):
self.MarketOrder('IBM',quantity)
self.Debug('Purchased IBM on ' + str(self.Time.strftime("%m/%d/%Y")))
self.Notify.Email("myemail@gmail.com", "Test", "Test Body", "test attachment")
# Brokerage message event handler. This method is called for all types of brokerage messages.
def OnBrokerageMessage(self, messageEvent):
self.Debug(f"Brokerage meesage received - {messageEvent.ToString()}")
# Brokerage disconnected event handler. This method is called when the brokerage connection is lost.
def OnBrokerageDisconnect(self):
self.is_connected = False
self.Debug(f"Brokerage disconnected!")
# Brokerage reconnected event handler. This method is called when the brokerage connection is restored after a disconnection.
def OnBrokerageReconnect(self):
self.is_connected = True
self.Debug(f"Brokerage reconnected!")
###Custom Data Type: Bitcoin data from Quandl - http://www.quandl.com/help/api-for-bitcoin-data
class Bitcoin(PythonData):