Skip to content

Commit

Permalink
Revert "started paper trading implementation"
Browse files Browse the repository at this point in the history
  • Loading branch information
r0fls committed Jul 30, 2024
1 parent 436b5a0 commit f44003a
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 416 deletions.
42 changes: 10 additions & 32 deletions brokers/base_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def update_positions(self, session, trade):
quantity=trade.quantity,
latest_price=trade.executed_price,
cost_basis=trade.executed_price * trade.quantity,
paper_trade=trade.paper_trade
)
session.add(position)
elif trade.order_type == 'sell':
Expand Down Expand Up @@ -158,12 +157,7 @@ async def place_future_option_order(self, symbol, quantity, order_type, strategy
logger.info('Placing order', extra={
'symbol': symbol, 'quantity': quantity, 'order_type': order_type, 'strategy': strategy})
try:
if self.paper_trade:
logger.info('Paper trading enabled', extra={'symbol': symbol})
if price is None:
logger.error('Price must be provided for paper trading', extra={'symbol': symbol})
return None
elif asyncio.iscoroutinefunction(self._place_future_option_order):
if asyncio.iscoroutinefunction(self._place_future_option_order):
response = await self._place_future_option_order(symbol, quantity, order_type, price)
else:
response = self._place_future_option_order(
Expand Down Expand Up @@ -191,8 +185,7 @@ async def place_future_option_order(self, symbol, quantity, order_type, strategy
broker=self.broker_name,
strategy=strategy,
profit_loss=0,
success='yes',
paper_trade=self.paper_trade
success='yes'
)
if order_type == 'sell':
profit_loss = self.db_manager.calculate_profit_loss(trade)
Expand Down Expand Up @@ -231,8 +224,7 @@ async def place_future_option_order(self, symbol, quantity, order_type, strategy
strategy=strategy,
type='cash',
balance=new_balance_amount,
timestamp=datetime.now(),
paper_trade=self.paper_trade
timestamp=datetime.now()
)
session.add(new_balance)
session.commit()
Expand All @@ -242,7 +234,7 @@ async def place_future_option_order(self, symbol, quantity, order_type, strategy
return None


async def place_option_order(self, symbol, quantity, order_type, strategy, price=None, paper_trade=False):
async def place_option_order(self, symbol, quantity, order_type, strategy, price=None):
'''Place an order for an option'''
logger.info('Placing order', extra={
'symbol': symbol, 'quantity': quantity, 'order_type': order_type, 'strategy': strategy})
Expand All @@ -254,12 +246,7 @@ async def place_option_order(self, symbol, quantity, order_type, strategy, price
return None

try:
if self.paper_trade:
logger.info('Paper trading enabled', extra={'symbol': symbol})
if price is None:
logger.error('Price must be provided for paper trading', extra={'symbol': symbol})
return None
elif asyncio.iscoroutinefunction(self._place_order):
if asyncio.iscoroutinefunction(self._place_order):
response = await self._place_option_order(symbol, quantity, order_type, price)
else:
response = self._place_option_order(
Expand All @@ -281,8 +268,7 @@ async def place_option_order(self, symbol, quantity, order_type, strategy, price
broker=self.broker_name,
strategy=strategy,
profit_loss=0,
success='yes',
paper_trade=paper_trade
success='yes'
)
if order_type == 'sell':
profit_loss = self.db_manager.calculate_profit_loss(trade)
Expand Down Expand Up @@ -313,8 +299,7 @@ async def place_option_order(self, symbol, quantity, order_type, strategy, price
strategy=strategy,
type='cash',
balance=new_balance_amount,
timestamp=datetime.now(),
paper_trade=paper_trade
timestamp=datetime.now()
)
session.add(new_balance)
session.commit()
Expand Down Expand Up @@ -342,12 +327,7 @@ async def place_order(self, symbol, quantity, order_type, strategy, price=None):
return None

try:
if self.paper_trade:
logger.info('Paper trading enabled', extra={'symbol': symbol})
if price is None:
logger.error('Price must be provided for paper trading', extra={'symbol': symbol})
return None
elif asyncio.iscoroutinefunction(self._place_order):
if asyncio.iscoroutinefunction(self._place_order):
response = await self._place_order(symbol, quantity, order_type, price)
else:
response = self._place_order(
Expand All @@ -366,8 +346,7 @@ async def place_order(self, symbol, quantity, order_type, strategy, price=None):
broker=self.broker_name,
strategy=strategy,
profit_loss=0,
success='yes',
paper_trade=self.paper_trade
success='yes'
)

with self.Session() as session:
Expand All @@ -394,8 +373,7 @@ async def place_order(self, symbol, quantity, order_type, strategy, price=None):
strategy=strategy,
type='cash',
balance=new_balance_amount,
timestamp=datetime.now(),
paper_trade=self.paper_trade
timestamp=datetime.now()
)
session.add(new_balance)
session.commit()
Expand Down
5 changes: 1 addition & 4 deletions database/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, Float, DateTime, create_engine, ForeignKey, PrimaryKeyConstraint, ForeignKeyConstraint, Index, Boolean
from sqlalchemy import Column, Integer, String, Float, DateTime, create_engine, ForeignKey, PrimaryKeyConstraint, ForeignKeyConstraint, Index
from sqlalchemy.orm import sessionmaker, relationship, declarative_base
from datetime import datetime

Expand All @@ -19,7 +19,6 @@ class Trade(Base):
strategy = Column(String, nullable=True)
profit_loss = Column(Float, nullable=True)
success = Column(String, nullable=True)
paper_trade = Column(Boolean, nullable=True, default=False)

class AccountInfo(Base):
__tablename__ = 'account_info'
Expand All @@ -35,7 +34,6 @@ class Balance(Base):
type = Column(String, nullable=False) # 'cash' or 'positions'
balance = Column(Float, default=0.0)
timestamp = Column(DateTime, nullable=False, default=datetime.utcnow)
paper_trade = Column(Boolean, nullable=True, default=False)

positions = relationship("Position", back_populates="balance", foreign_keys="[Position.balance_id]", primaryjoin="and_(Balance.id==Position.balance_id, Balance.type=='positions')")

Expand All @@ -59,7 +57,6 @@ class Position(Base):
last_updated = Column(DateTime, nullable=False, default=datetime.utcnow)
underlying_volatility = Column(Float, nullable=True)
underlying_latest_price = Column(Float, nullable=True)
paper_trade = Column(Boolean, nullable=True, default=False)

balance = relationship("Balance", back_populates="positions", foreign_keys=[balance_id])

Expand Down
16 changes: 0 additions & 16 deletions docs/css/custom.css

This file was deleted.

175 changes: 0 additions & 175 deletions docs/deploying-infrastructure.md

This file was deleted.

3 changes: 1 addition & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SOAD Documentation

Welcome to the SOAD project documentation.

<img src="https://github.com/r0fls/soad/assets/1858004/7369c3af-b4e6-41d9-997c-eaa0b81b969d" alt="soad-mascot" width="300"/>
<img src="https://github.com/r0fls/soad/assets/1858004/1ac6d1c7-5263-4b8a-a643-148ee54c12c1" alt="soad-mascot" width="300"/>

## Overview

Expand All @@ -15,5 +15,4 @@ SOAD (System Of A Dow) is a Python package designed to simplify the process of d

- [Installation](installation.md)
- [Usage](usage.md)
- [Deploying Infrastructure](deploying-infrastructure.md)
- [Contributing](contributing.md)
Loading

0 comments on commit f44003a

Please sign in to comment.