43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import os
|
|
import sys
|
|
from dotenv import load_dotenv
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
|
|
|
from strategies.cn_strategy import CN_Strategy
|
|
from strategies.us_strategy import US_Strategy
|
|
|
|
|
|
def get_strategy(market, stock_code, tushare_token=None, av_key=None):
|
|
if market.upper() == 'CN':
|
|
return CN_Strategy(stock_code, tushare_token)
|
|
elif market.upper() == 'US':
|
|
return US_Strategy(stock_code, av_key)
|
|
else:
|
|
raise ValueError(f"Unsupported market: {market}")
|
|
|
|
def main():
|
|
load_dotenv()
|
|
tushare_token = os.getenv('TUSHARE_TOKEN')
|
|
av_key = os.getenv('ALPHA_VANTAGE_KEY')
|
|
|
|
if len(sys.argv) > 2:
|
|
market = sys.argv[1]
|
|
symbol = sys.argv[2]
|
|
strategy = get_strategy(market, symbol, tushare_token, av_key)
|
|
strategy.execute()
|
|
else:
|
|
print("Usage: python main.py <MARKET> <SYMBOL>")
|
|
print("Running default test cases:")
|
|
|
|
# Test CN
|
|
cn_strategy = get_strategy('CN', '600519.SH', tushare_token)
|
|
cn_strategy.execute()
|
|
|
|
# Test US
|
|
us_strategy = get_strategy('US', 'AAPL', av_key=av_key)
|
|
us_strategy.execute()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|