本文整理汇总了Python中position.Position.open_str方法的典型用法代码示例。如果您正苦于以下问题:Python Position.open_str方法的具体用法?Python Position.open_str怎么用?Python Position.open_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类position.Position
的用法示例。
在下文中一共展示了Position.open_str方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_orders_to_open
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import open_str [as 别名]
def execute_orders_to_open(self, date):
'''
search the orderQ for orders to open positions
calc execution price
calc margin requirement, and confirm sufficient funds
open position
generate OrderReceipt & place on orderQ
'''
filter = lambda x: (isinstance(x, Order) == True)
orders_to_open = self.orderQ.extract_matching(filter)
for order in orders_to_open:
# calc exec price
exec_price = self.calc_execution_price(order.ins, order.buysell, date)
# calculate margin req
leverage = Decimal(1)
margin = None
if (order.buysell == 'buy'):
margin = (exec_price - order.stop_loss) * leverage
else: # sell
margin = (order.stop_loss - exec_price) * leverage
trader = self.traders[order.trader_id]
# check margin requirement against trader's cash ac
d = margin - trader.ac.cash_bal
if (margin > trader.ac.cash_bal):
receipt = OrderReceipt(order, 'insufficient_cash_bal', 0, date, 0)
else:
# sequester margin amount from client cash account
trader.ac.margin_bal += margin
trader.ac.cash_bal -= margin
receipt = OrderReceipt(order, 'opened', exec_price, date, margin)
position = Position(receipt)
receipt.position_id = position.id
self.open_positions.append(position)
self.positions[position.id] = position
# cash_bal, margin_bal, net_booked_position
#print('s - ' + s)
l = '%s,%s,%s,%s,%s' % (str(date), trader.ac.cash_bal, trader.ac.margin_bal, trader.ac.net_booked_position, position.open_str())
#logging.info(l)
# for handling by trader
self.receiptQ.put(receipt)
return len(orders_to_open)