2024-02-23 22:09:36 +00:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
from database.trades import trades
|
|
|
|
|
2024-02-24 13:14:31 +00:00
|
|
|
def average_slippage(date: datetime):
|
2024-02-23 22:09:36 +00:00
|
|
|
trade_records = trades(date)
|
|
|
|
|
|
|
|
slippages = []
|
|
|
|
for spreads in trade_records['Spreads']:
|
|
|
|
for spread in spreads:
|
|
|
|
if 'Entry Slippage' in spread:
|
|
|
|
slippages.append(spread['Entry Slippage'])
|
|
|
|
|
|
|
|
if slippages:
|
|
|
|
average_slippage = sum(slippages) / len(slippages)
|
|
|
|
return average_slippage
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2024-02-24 13:38:44 +00:00
|
|
|
if __name__ == '__main__':
|
2024-02-23 22:09:36 +00:00
|
|
|
target_date = datetime.date(2024, 2, 23)
|
|
|
|
|
2024-02-24 13:14:31 +00:00
|
|
|
average_slippage = average_slippage(target_date)
|
2024-02-23 22:09:36 +00:00
|
|
|
|
|
|
|
if average_slippage is not None:
|
2024-02-24 13:38:44 +00:00
|
|
|
print(f'{target_date} Average Entry Slippage: {average_slippage}')
|
2024-02-23 22:09:36 +00:00
|
|
|
else:
|
2024-02-24 13:38:44 +00:00
|
|
|
print(f'No trades found for {target_date}.')
|