Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions check-day-trades/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Kyle Chengqiang Lin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions check-day-trades/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Instructions
input the path to your .csv file for your trades (ex: "C:\Users\NAME\Desktop\PROJECT\logs\MLTrader_2024-07-13_00-29-55_trades.csv") with columns named symbol, time, and side (side indicates 'buy' or 'side')

Run the program with "python check-day-trades\check_day_trades"

if there are no day trades you should get an output like:

Empty DataFrame
Columns: [symbol, date, day_trade]
Index: []

## License

"check_day_trades" is licensed under the MIT License - see the LICENSE file for details.
58 changes: 58 additions & 0 deletions check-day-trades/check_day_trades
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# MIT License
#
# Copyright (c) 2024 Kyle Chengqiang Lin
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import pandas as pd

# Use raw string notation to avoid issues with backslashes
file_path = r'C:\Users\cheng\Desktop\MLTradingBot\logs\MLTrader_2024-08-05_00-14-22_trades.csv'
trades_df = pd.read_csv(file_path)

# Convert the 'time' column to datetime format with UTC handling
trades_df['time'] = pd.to_datetime(trades_df['time'], utc=True, errors='coerce')

# Inspect rows where 'time' conversion failed
failed_conversion = trades_df[trades_df['time'].isna()]
if not failed_conversion.empty:
print("Rows with failed time conversion:")
print(failed_conversion)

# Remove rows where 'time' conversion failed
trades_df = trades_df.dropna(subset=['time'])

# Extract the date from the 'time' column
trades_df['date'] = trades_df['time'].dt.date

# Function to check for day trades
def check_day_trades(group):
has_buy = any(group['side'] == 'buy')
has_sell = any(group['side'] == 'sell')
return pd.Series({'day_trade': has_buy and has_sell})

# Group by symbol and date to find matching buy and sell trades on the same day
day_trades = trades_df.groupby(['symbol', 'date']).apply(check_day_trades).reset_index()

# Filter for day trades
day_trades = day_trades[day_trades['day_trade']]

# Display the day trades
print(day_trades)

24,821 changes: 0 additions & 24,821 deletions logs/MLTrader_2024-01-16_17-02-24_logs.csv

This file was deleted.

1,221 changes: 0 additions & 1,221 deletions logs/MLTrader_2024-01-16_17-02-24_stats.csv

This file was deleted.

Loading