PEP8 python algorithms conversion (#7950)
Benchmarks / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* PEP8 python algorithms conversion * Fix: Get python or c# methods in PythonData as python wrapper * Convert portfolio models to PEP8
This commit is contained in:
@@ -19,35 +19,35 @@ from AlgorithmImports import *
|
||||
### </summary>
|
||||
class OrderTicketAssignmentDemoAlgorithm(QCAlgorithm):
|
||||
'''Demonstration on how to access order tickets right after placing an order.'''
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2013, 10, 7)
|
||||
self.SetEndDate(2013, 10, 11)
|
||||
self.SetCash(100000)
|
||||
def initialize(self):
|
||||
self.set_start_date(2013, 10, 7)
|
||||
self.set_end_date(2013, 10, 11)
|
||||
self.set_cash(100000)
|
||||
|
||||
self.symbol = self.AddEquity("SPY").Symbol
|
||||
self._symbol = self.add_equity("SPY").symbol
|
||||
|
||||
self.trade_count = 0
|
||||
self.Consolidate(self.symbol, timedelta(hours=1), self.HourConsolidator)
|
||||
self.consolidate(self._symbol, timedelta(hours=1), self.hour_consolidator)
|
||||
|
||||
def HourConsolidator(self, bar: TradeBar):
|
||||
def hour_consolidator(self, bar: TradeBar):
|
||||
# Reset self.ticket to None on each new bar
|
||||
self.ticket = None
|
||||
self.ticket = self.MarketOrder(self.symbol, 1, asynchronous=True)
|
||||
self.Debug(f"{self.Time}: Buy: Price {bar.Price}, orderId: {self.ticket.OrderId}")
|
||||
self.ticket = self.market_order(self._symbol, 1, asynchronous=True)
|
||||
self.debug(f"{self.time}: Buy: Price {bar.price}, order_id: {self.ticket.order_id}")
|
||||
self.trade_count += 1
|
||||
|
||||
def OnOrderEvent(self, orderEvent: OrderEvent):
|
||||
def on_order_event(self, order_event: OrderEvent):
|
||||
# We cannot access self.ticket directly because it is assigned asynchronously:
|
||||
# this order event could be triggered before self.ticket is assigned.
|
||||
ticket = orderEvent.Ticket
|
||||
ticket = order_event.ticket
|
||||
if ticket is None:
|
||||
raise Exception("Expected order ticket in order event to not be null")
|
||||
if orderEvent.Status == OrderStatus.Submitted and self.ticket is not None:
|
||||
if order_event.status == OrderStatus.SUBMITTED and self.ticket is not None:
|
||||
raise Exception("Field self.ticket not expected no be assigned on the first order event")
|
||||
|
||||
self.Debug(ticket.ToString())
|
||||
self.debug(ticket.to_string())
|
||||
|
||||
def OnEndOfAlgorithm(self):
|
||||
def on_end_of_algorithm(self):
|
||||
# Just checking that orders were placed
|
||||
if not self.Portfolio.Invested or self.trade_count != self.Transactions.OrdersCount:
|
||||
raise Exception(f"Expected the portfolio to have holdings and to have {self.tradeCount} trades, but had {self.Transactions.OrdersCount}")
|
||||
if not self.portfolio.invested or self.trade_count != self.transactions.orders_count:
|
||||
raise Exception(f"Expected the portfolio to have holdings and to have {self.trade_count} trades, but had {self.transactions.orders_count}")
|
||||
|
||||
Reference in New Issue
Block a user