
{"id":63114,"date":"2025-04-30T12:45:42","date_gmt":"2025-04-30T12:45:42","guid":{"rendered":"https:\/\/mycryptomania.com\/?p=63114"},"modified":"2025-04-30T12:45:42","modified_gmt":"2025-04-30T12:45:42","slug":"generate-a-watchlist-from-fmps-gainers-losers-api-using-a-gpt-prompt","status":"publish","type":"post","link":"https:\/\/mycryptomania.com\/?p=63114","title":{"rendered":"Generate a Watchlist from FMP\u2019s Gainers &amp; Losers API Using a GPT Prompt"},"content":{"rendered":"<h4><strong>Turn Daily Market Movers into Actionable Watchlists Using <\/strong><a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\"><strong>FMP<\/strong><\/a><strong>\u2019s API and GPT Intelligence<\/strong><\/h4>\n<p>Photo by <a href=\"https:\/\/www.pexels.com\/photo\/photo-of-person-holding-smartphone-6802042\/\">Anna Nekrashevich<\/a><\/p>\n<p>Every trader has one key goal: <strong>identify market movers early<\/strong>. Whether it\u2019s a breakout stock surging by double digits or a falling knife catching attention\u200a\u2014\u200a<strong>gainers and losers often lead the narrative<\/strong>. But manually scanning these daily? Not efficient.<\/p>\n<p>That\u2019s where <a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\"><strong>Financial Modeling Prep<\/strong><\/a><strong>\u2019s Gainers &amp; Losers API<\/strong> steps in. It delivers real-time data on stocks with the biggest intraday moves\u200a\u2014\u200astraight to your code. And when paired with a <strong>GPT prompt<\/strong>, this data turns into intelligent watchlists within\u00a0seconds.<\/p>\n<p>In this article, we\u2019ll show how\u00a0to:<\/p>\n<p>\u2022 Fetch market movers using <a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\">FMP<\/a>\u2019s\u00a0API,<\/p>\n<p>\u2022 Process the data using\u00a0Python,<\/p>\n<p>\u2022 And prompt GPT to generate a smart, prioritized watchlist.<\/p>\n<p>No guesswork. Just actionable insight\u200a\u2014\u200aautomated.<\/p>\n<h3><strong>Understanding FMP\u2019s Gainers &amp; Losers\u00a0API<\/strong><\/h3>\n<p>Before we automate watchlist generation, let\u2019s understand the two powerful <a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\">FMP<\/a> endpoints we\u2019ll be working\u00a0with:<\/p>\n<h4><strong>1. Top Gainers\u00a0API<\/strong><\/h4>\n<p><strong>Endpoint:<\/strong><\/p>\n<p><a href=\"https:\/\/financialmodelingprep.com\/api\/v3\/stock_market\/gainers\">https:\/\/financialmodelingprep.com\/api\/v3\/stock_market\/gainers<\/a><\/p>\n<p><strong>Purpose:<\/strong><\/p>\n<p>Fetches stocks with the highest positive price change during the trading\u00a0day.<\/p>\n<p><strong>Key Data Points Returned:<\/strong><\/p>\n<p>\u2022 Ticker symbol (e.g., AAPL)<br \/>\u2022 Company name<br \/>\u2022 Current price<br \/>\u2022 Price change<br \/>\u2022 Percentage change<\/p>\n<h4><strong>2. Top Losers\u00a0API<\/strong><\/h4>\n<p><strong>Endpoint:<\/strong><\/p>\n<p><a href=\"https:\/\/financialmodelingprep.com\/api\/v3\/stock_market\/losers\">https:\/\/financialmodelingprep.com\/api\/v3\/stock_market\/losers<\/a><\/p>\n<p><strong>Purpose:<\/strong><\/p>\n<p>Fetches stocks showing the largest negative price movement.<\/p>\n<p><strong>Key Data Points Returned:<\/strong><\/p>\n<p>Same structure as the Top Gainers\u00a0API.<\/p>\n<p>You\u2019ll need a valid <a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\">FMP API key<\/a> to access this data. Simply append\u00a0?apikey=YOUR_API_KEY to the endpoint\u00a0URL.<\/p>\n<h4><strong>Why These APIs\u00a0Matter<\/strong><\/h4>\n<p>Instead of relying on noisy news articles or slow manual tracking, these APIs\u00a0offer:<\/p>\n<p><strong>Real-time insights<\/strong> into fast\u00a0movers,<strong>Structured, machine-readable<\/strong> data,<strong>Easy integration<\/strong> into Python workflows.<\/p>\n<h3><strong>Fetching and Processing Data with\u00a0Python<\/strong><\/h3>\n<p>Now that we know what the <a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\">FMP<\/a> APIs provide, let\u2019s fetch the data and get it ready for\u00a0GPT.<\/p>\n<h4><strong>Step 1: Install Required Libraries<\/strong><\/h4>\n<p>First, ensure you have these libraries installed:<\/p>\n<p>pip install requests pandas<\/p>\n<h4><strong>Step 2: Fetch Gainers and Losers\u00a0Data<\/strong><\/h4>\n<p>We\u2019ll use Python\u2019s requests library to hit the API and pandas to handle the response.<\/p>\n<p>import requests<br \/>import pandas as pd<\/p>\n<p># Replace with your actual FMP API Key<br \/>API_KEY = &#8216;your_api_key_here&#8217;<br \/># API URLs<br \/>GAINERS_URL = f&#8221;https:\/\/financialmodelingprep.com\/api\/v3\/stock_market\/gainers?apikey={API_KEY}&#8221;<br \/>LOSERS_URL = f&#8221;https:\/\/financialmodelingprep.com\/api\/v3\/stock_market\/losers?apikey={API_KEY}&#8221;<br \/># Fetch data<br \/>gainers_response = requests.get(GAINERS_URL)<br \/>losers_response = requests.get(LOSERS_URL)<br \/># Convert to DataFrame<br \/>gainers_df = pd.DataFrame(gainers_response.json())<br \/>losers_df = pd.DataFrame(losers_response.json())<\/p>\n<h4><strong>Step 3: Quick Look at the\u00a0Data<\/strong><\/h4>\n<p>Let\u2019s check what we received:<\/p>\n<p>print(&#8220;Top Gainers:&#8221;)<br \/>print(gainers_df.head())<\/p>\n<p>print(&#8220;nTop Losers:&#8221;)<br \/>print(losers_df.head())<\/p>\n<p>You\u2019ll see fields\u00a0like:<\/p>\n<p>\u2022 symbol<br \/>\u2022 name<br \/>\u2022 price<br \/>\u2022 changesPercentage<br \/>\u2022 change<\/p>\n<h4><strong>Step 4: Merge and Clean the Data (Optional)<\/strong><\/h4>\n<p>If you want a <strong>combined view<\/strong> for GPT input, you can label the stocks and merge\u00a0them:<\/p>\n<p>gainers_df[&#8216;movement&#8217;] = &#8216;Gainer&#8217;<br \/>losers_df[&#8216;movement&#8217;] = &#8216;Loser&#8217;<\/p>\n<p># Combine<br \/>market_movers_df = pd.concat([gainers_df, losers_df], ignore_index=True)<br \/># Optional: Select only the important columns<br \/>market_movers_df = market_movers_df[[&#8216;symbol&#8217;, &#8216;name&#8217;, &#8216;price&#8217;, &#8216;changesPercentage&#8217;, &#8216;movement&#8217;]]<\/p>\n<p>Now you have a clean dataset ready for GPT to understand!<\/p>\n<h3><strong>Crafting a GPT Prompt for Watchlist Generation<\/strong><\/h3>\n<p>Once we have a clean list of gainers and losers, the next step is to <strong>guide GPT<\/strong> to turn this raw data into a <strong>smart, curated watchlist<\/strong>.<\/p>\n<p>The key\u00a0here?<\/p>\n<p><strong>A good prompt = better\u00a0results.<\/strong><\/p>\n<h4><strong>Step 1: Format the Data for the\u00a0Prompt<\/strong><\/h4>\n<p>Let\u2019s create a simple text format that GPT can easily understand.<\/p>\n<p>def format_for_prompt(df):<br \/>    prompt_text = &#8220;&#8221;<br \/>    for _, row in df.iterrows():<br \/>        prompt_text += f&#8221;{row[&#8216;symbol&#8217;]} ({row[&#8216;name&#8217;]}): {row[&#8216;movement&#8217;]} with {row[&#8216;changesPercentage&#8217;]} changen&#8221;<br \/>    return prompt_text<\/p>\n<p>formatted_data = format_for_prompt(market_movers_df)<br \/>print(formatted_data)<\/p>\n<p>This would produce something like:<\/p>\n<p>AAPL (Apple Inc.): Gainer with +3.5% change<br \/>TSLA (Tesla Inc.): Loser with -2.1% change<br \/>&#8230;<\/p>\n<p>Short, clean, human-readable.<\/p>\n<h4><strong>Step 2: Craft the GPT\u00a0Prompt<\/strong><\/h4>\n<p>Now, embed this formatted data into a clear instruction for\u00a0GPT:<\/p>\n<p>prompt = f&#8221;&#8221;&#8221;<br \/>Based on the following stock movements, generate a watchlist of 5 stocks that seem promising for further research. <br \/>Consider factors like large gains, recovery potential after losses, or big moves worth monitoring.Stock Movements:<br \/>{formatted_data}<br \/>Provide the output in a list format, with a one-line reason for each stock selection.<br \/>&#8220;&#8221;&#8221;<\/p>\n<p>This prompt will nudge GPT\u00a0to:<\/p>\n<p><strong>Analyze<\/strong> both gainers and\u00a0losers,<strong>Pick 5 candidates<\/strong> intelligently,<strong>Give a reason<\/strong> why each stock was selected.<\/p>\n<h4><strong>Step 3: Example of GPT\u00a0Output<\/strong><\/h4>\n<p>Here\u2019s what GPT might\u00a0return:<\/p>\n<p>1. AAPL (Apple Inc.) \u2013 Strong intraday gain indicating potential momentum.<br \/>2. AMZN (Amazon.com Inc.) \u2013 Sharp recovery after recent losses, worth monitoring.<br \/>3. TSLA (Tesla Inc.) \u2013 Significant dip, could be a rebound opportunity.<br \/>4. NVDA (NVIDIA Corporation) \u2013 Continues strong uptrend with consistent gains.<br \/>5. MSFT (Microsoft Corp.) \u2013 Minor loss despite overall market weakness, shows resilience.<\/p>\n<p>Exactly what you want from a smart watchlist\u200a\u2014\u200aactionable and\u00a0concise!<\/p>\n<h3><strong>Automating the\u00a0Workflow<\/strong><\/h3>\n<p>Now that we have all the pieces\u200a\u2014\u200adata fetching, formatting, and GPT prompt creation\u200a\u2014\u200awhy not <strong>automate the entire\u00a0flow<\/strong>?<\/p>\n<p>Here\u2019s how you can build a simple daily watchlist generator.<\/p>\n<h4><strong>Step 1: Full Workflow\u00a0Script<\/strong><\/h4>\n<p>Here\u2019s a Python script that puts everything together:<\/p>\n<p>import requests<br \/>import pandas as pd<\/p>\n<p># Function to fetch market movers<br \/>def fetch_market_movers(api_key):<br \/>    gainers_url = f&#8221;https:\/\/financialmodelingprep.com\/api\/v3\/stock_market\/gainers?apikey={api_key}&#8221;<br \/>    losers_url = f&#8221;https:\/\/financialmodelingprep.com\/api\/v3\/stock_market\/losers?apikey={api_key}&#8221;<\/p>\n<p>    gainers = pd.DataFrame(requests.get(gainers_url).json())<br \/>    losers = pd.DataFrame(requests.get(losers_url).json())<\/p>\n<p>    gainers[&#8216;movement&#8217;] = &#8216;Gainer&#8217;<br \/>    losers[&#8216;movement&#8217;] = &#8216;Loser&#8217;<\/p>\n<p>    combined = pd.concat([gainers, losers], ignore_index=True)<br \/>    return combined[[&#8216;symbol&#8217;, &#8216;name&#8217;, &#8216;price&#8217;, &#8216;changesPercentage&#8217;, &#8216;movement&#8217;]]<\/p>\n<p># Function to format data for GPT prompt<br \/>def format_for_gpt(df):<br \/>    prompt_text = &#8220;&#8221;<br \/>    for _, row in df.iterrows():<br \/>        prompt_text += f&#8221;{row[&#8216;symbol&#8217;]} ({row[&#8216;name&#8217;]}): {row[&#8216;movement&#8217;]} with {row[&#8216;changesPercentage&#8217;]} changen&#8221;<br \/>    return prompt_text<\/p>\n<p># Function to generate final prompt<br \/>def create_watchlist_prompt(formatted_data):<br \/>    return f&#8221;&#8221;&#8221;<br \/>Based on the following stock movements, generate a watchlist of 5 stocks that seem promising for further research. <br \/>Consider factors like large gains, recovery potential after losses, or big moves worth monitoring.<br \/>Stock Movements:<br \/>{formatted_data}<br \/>Provide the output in a list format, with a one-line reason for each stock selection.<br \/>&#8220;&#8221;&#8221;<\/p>\n<p># Main<br \/>if __name__ == &#8220;__main__&#8221;:<br \/>    API_KEY = &#8220;your_api_key_here&#8221;<\/p>\n<p>    market_data = fetch_market_movers(API_KEY)<br \/>    formatted_text = format_for_gpt(market_data)<br \/>    final_prompt = create_watchlist_prompt(formatted_text)<\/p>\n<p>    print(final_prompt)<\/p>\n<p>This script\u00a0will:<\/p>\n<p>Pull fresh gainers and\u00a0losers,Format the\u00a0data,Generate a ready-to-use prompt for\u00a0GPT.<\/p>\n<h4><strong>Step 2: Optional\u200a\u2014\u200aFully Automate It\u00a0Daily<\/strong><\/h4>\n<p>You can automate this script to run <strong>every morning<\/strong>\u00a0using:<\/p>\n<p><strong>Task Scheduler<\/strong> on\u00a0Windows,<strong>Cron Jobs<\/strong> on Mac\/Linux,<strong>Cloud functions<\/strong> if you prefer serverless (AWS Lambda, Google Cloud Functions).<\/p>\n<p>You can even extend it\u00a0to:<\/p>\n<p>Send the prompt to GPT automatically,Email the generated watchlist to yourself,Or save it into a Notion page or a Google\u00a0Sheet!<\/p>\n<p>In just a few lines of code, you create a <strong>personalized, intelligent watchlist generator<\/strong>\u200a\u2014\u200awithout lifting a finger every\u00a0day.<\/p>\n<p><a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\">Free Stock Market API and Financial Statements API&#8230;<\/a><\/p>\n<h3>Conclusion<\/h3>\n<p>Building a smart stock watchlist doesn\u2019t have to be manual or time-consuming.<\/p>\n<p>By combining <a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\"><strong>FMP<\/strong><\/a><strong>\u2019s Gainers &amp; Losers <\/strong><a href=\"https:\/\/site.financialmodelingprep.com\/developer\/docs?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=pranjal47\"><strong>API<\/strong><\/a> with a <strong>simple GPT prompt<\/strong>, you can automate watchlist generation based on real-time market movements.<\/p>\n<p>This approach not only saves time but also ensures you\u2019re always aligned with market trends\u200a\u2014\u200awith just a few lines of\u00a0code.<\/p>\n<p><a href=\"https:\/\/medium.com\/coinmonks\/generate-a-watchlist-from-fmps-gainers-losers-api-using-a-gpt-prompt-c471c6b0b227\">Generate a Watchlist from FMP\u2019s Gainers &amp; Losers API Using a GPT Prompt<\/a> was originally published in <a href=\"https:\/\/medium.com\/coinmonks\">Coinmonks<\/a> on Medium, where people are continuing the conversation by highlighting and responding to this story.<\/p>","protected":false},"excerpt":{"rendered":"<p>Turn Daily Market Movers into Actionable Watchlists Using FMP\u2019s API and GPT Intelligence Photo by Anna Nekrashevich Every trader has one key goal: identify market movers early. Whether it\u2019s a breakout stock surging by double digits or a falling knife catching attention\u200a\u2014\u200againers and losers often lead the narrative. But manually scanning these daily? Not efficient. [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-63114","post","type-post","status-publish","format-standard","hentry","category-interesting"],"_links":{"self":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts\/63114"}],"collection":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=63114"}],"version-history":[{"count":0,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts\/63114\/revisions"}],"wp:attachment":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=63114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=63114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=63114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}