Skip to content

Commit

Permalink
장 개시 이후에도 실행가능하게함
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowyPainter committed Jun 4, 2024
1 parent 1a29ec1 commit 94d8367
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions ASP/asp_invest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
import invest
import os
import configparser
from datetime import datetime, timedelta
import pytz

def is_market_open(nyse):
if nyse:
tz = pytz.timezone('America/New_York')
else:
tz = pytz.timezone('Asia/Seoul')
now = datetime.now(tz)
if nyse:
return (now.hour == 9 and now.minute >= 30) or (9 < now.hour < 16) or (now.hour == 16 and now.minute == 0)
else:
return (now.hour == 9 and now.minute >= 0) or (9 < now.hour < 15) or (now.hour == 15 and now.minute <= 30)

def task(strategy1, symbol_nyse):
now = datetime.now()
if is_market_open(symbol_nyse) or (symbol_nyse and now.hour < 22 or (now.hour == 22 and now.minute < 30)) or (not symbol_nyse and symbol_nyse and now.hour <= 9):
strategy1.run()

def main():
config = configparser.ConfigParser()
Expand All @@ -29,15 +47,13 @@ def main():

af_nyse = config['STOCK']['IsAffectiveNyse'] == 'yes'
symbol_nyse = config['STOCK']['IsSymbolsNyse'] == 'yes'
start_time = "22:30" if symbol_nyse else "09:00"
strategy1 = invest.ASPInvest(config['ACCOUNT']['APIKEY'], config['ACCOUNT']['APISECRET'], config['ACCOUNT']['ACCNO'], False, config['SETTINGS']['PATH'], af_nyse, symbol_nyse,"실전투자")

#strategy1.run()

print(f"This program run investing algorithm every {start_time}")
print("The log will be written at this directory.")

schedule.every().day.at(start_time).do(strategy1.run)
schedule.every().minute.at(":30").do(task, strategy1, symbol_nyse)

while True:
schedule.run_pending()
Expand Down

0 comments on commit 94d8367

Please sign in to comment.