2024-02-23 22:09:36 +00:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
from database.trades import trades
|
|
|
|
|
2024-02-28 03:39:37 +00:00
|
|
|
def average_slippage(date: datetime.date):
|
2024-02-23 22:09:36 +00:00
|
|
|
trade_records = trades(date)
|
|
|
|
|
2024-02-28 03:39:37 +00:00
|
|
|
entry_slippages = []
|
|
|
|
exit_slippages = []
|
2024-02-23 22:09:36 +00:00
|
|
|
for spreads in trade_records['Spreads']:
|
|
|
|
for spread in spreads:
|
|
|
|
if 'Entry Slippage' in spread:
|
2024-02-28 03:39:37 +00:00
|
|
|
entry_slippages.append(spread['Entry Slippage'])
|
|
|
|
if 'Exit Slippage' in spread:
|
|
|
|
exit_slippages.append(spread['Exit Slippage'])
|
2024-02-23 22:09:36 +00:00
|
|
|
|
2024-02-28 03:39:37 +00:00
|
|
|
average_entry_slippage = sum(entry_slippages) / len(entry_slippages) if entry_slippages else None
|
|
|
|
average_exit_slippage = sum(exit_slippages) / len(exit_slippages) if exit_slippages else None
|
|
|
|
|
|
|
|
return average_entry_slippage, average_exit_slippage
|
2024-02-23 22:09:36 +00:00
|
|
|
|
2024-02-24 13:38:44 +00:00
|
|
|
if __name__ == '__main__':
|
2024-02-28 03:39:37 +00:00
|
|
|
target_date = datetime.date(2024, 2, 27)
|
|
|
|
|
|
|
|
entry_slippage, exit_slippage = average_slippage(target_date)
|
2024-02-23 22:09:36 +00:00
|
|
|
|
2024-02-28 03:39:37 +00:00
|
|
|
if entry_slippage is not None:
|
|
|
|
print(f'Average Entry Slippage: {entry_slippage}')
|
2024-02-23 22:09:36 +00:00
|
|
|
|
2024-02-28 03:39:37 +00:00
|
|
|
if exit_slippage is not None:
|
|
|
|
print(f'Average Exit Slippage: {exit_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}.')
|