<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: katka</title>
    <description>The latest articles on DEV Community by katka (@katka).</description>
    <link>https://dev.to/katka</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F921947%2Fb7cff706-a254-4690-8a7c-2e896283544a.jpg</url>
      <title>DEV Community: katka</title>
      <link>https://dev.to/katka</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/katka"/>
    <language>en</language>
    <item>
      <title>Ship finance 50% faster with Yuzu API</title>
      <dc:creator>katka</dc:creator>
      <pubDate>Fri, 11 Nov 2022 17:45:47 +0000</pubDate>
      <link>https://dev.to/yuzuapi/ship-finance-50-faster-with-yuzu-api-2d8f</link>
      <guid>https://dev.to/yuzuapi/ship-finance-50-faster-with-yuzu-api-2d8f</guid>
      <description>&lt;p&gt;&lt;a href="https://yuzu.dev"&gt;Yuzu&lt;/a&gt; is the fastest way to build with market and investment data like stock and crypto prices, company fundamentals, ETF details, forex and more. &lt;/p&gt;

&lt;p&gt;Providing innovative GraphQL and SQL APIs for both frontend and backend development, Yuzu removes the data engineering overhead traditionally associated with market data.  &lt;/p&gt;

&lt;p&gt;Learn more at our new wesbite:&lt;br&gt;
&lt;a href="https://yuzu.dev"&gt;https://yuzu.dev&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Questions? &lt;a href="https://discord.com/invite/U4FqcA5hpc"&gt;Hop in our Discord&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u7d42Bag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16oy3m77gnn5i62cw4pv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u7d42Bag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16oy3m77gnn5i62cw4pv.png" alt="Yuzu Screenshot" width="880" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>news</category>
      <category>webdev</category>
      <category>api</category>
      <category>graphql</category>
    </item>
    <item>
      <title>Build ETF Screener with Free API covering 28,000+ funds</title>
      <dc:creator>katka</dc:creator>
      <pubDate>Mon, 31 Oct 2022 17:22:11 +0000</pubDate>
      <link>https://dev.to/yuzuapi/build-etf-screener-with-free-api-covering-28000-funds-3c3m</link>
      <guid>https://dev.to/yuzuapi/build-etf-screener-with-free-api-covering-28000-funds-3c3m</guid>
      <description>&lt;p&gt;Hello fintech devs and finance nerds!&lt;/p&gt;

&lt;p&gt;We're excited to announce we launched a new &lt;br&gt;
&lt;a href="https://www.yuzu.dev/datasets/funds"&gt;GraphQL API focused on ETF* and Mutual Funds&lt;/a&gt;&lt;br&gt;
*Exchange-traded funds&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The API provides 15+ key attributes for each fund such as:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Latest Price (Updates daily for Mutual Funds, and intraday for ETFs)&lt;/li&gt;
&lt;li&gt;Expense ratio (Gross &amp;amp; Net)&lt;/li&gt;
&lt;li&gt;NAV (Net Asset Value)&lt;/li&gt;
&lt;li&gt;Management style (Active / Passsive)&lt;/li&gt;
&lt;li&gt;Asset focus (Equity, Bonds ...)&lt;/li&gt;
&lt;li&gt;Sector focus&lt;/li&gt;
&lt;li&gt;ESG flag
And more!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🍕 Free access via API (No card required)&lt;br&gt;
🕹 Play with the real data in our &lt;a href="https://graph.yuzu.dev/playground?state=eyJxdWVyeSI6IntcbiAgc2VjdXJpdGllcyhpbnB1dDoge3N5bWJvbHM6IFwiQlVHXCJ9KSB7XG4gICAgaWRcbiAgICBzZWN1cml0eVR5cGVcbiAgICBmdW5kRGV0YWlsIHtcbiAgICAgIHNlcmllc0lkXG4gICAgICBjbGFzc0lkXG4gICAgICBzdGF0dXNcbiAgICAgIGluY2VwdGlvbkRhdGVcbiAgICAgIG1hbmFnZW1lbnRTdHlsZVxuICAgICAgYXNzZXRGb2N1c1xuICAgICAgc2VjdG9yRm9jdXNcbiAgICAgIHRhcmdldERhdGVcbiAgICAgIGlzRXNnXG4gICAgICBuZXRFeHBlbnNlUmF0aW9cbiAgICAgIGdyb3NzRXhwZW5zZVJhdGlvXG4gICAgICBleHBlbnNlUmF0aW9Bc09mRGF0ZVxuICAgICAgbmF2XG4gICAgICBuYXZBc09mRGF0ZVxuICAgICAgbmV0QXNzZXRzXG4gICAgICBuZXRBc3NldHNBc09mRGF0ZVxuICAgIH1cbiAgfVxufSIsInZhcmlhYmxlcyI6bnVsbH0%3D"&gt;Data Explorer&lt;/a&gt; (no signup needed)&lt;/p&gt;

&lt;p&gt;Let us know what you think! We're excited to hear your feedback!&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>webdev</category>
      <category>api</category>
      <category>etf</category>
    </item>
    <item>
      <title>Video: Add a live-updating stock badge to your web (in 5 min)</title>
      <dc:creator>katka</dc:creator>
      <pubDate>Tue, 13 Sep 2022 18:46:47 +0000</pubDate>
      <link>https://dev.to/yuzuapi/video-add-a-live-updating-stock-badge-to-your-web-in-5-min-29ma</link>
      <guid>https://dev.to/yuzuapi/video-add-a-live-updating-stock-badge-to-your-web-in-5-min-29ma</guid>
      <description>&lt;p&gt;Steve explains how to do it using a streaming UI component from 🍋&lt;a href="https://yuzu.dev"&gt;Yuzu API&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📺 &lt;a href="https://www.youtube.com/watch?v=dysUZlh33JM"&gt;Watch our step-by-step tutorial on YouTube&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us know what you think! 🤓&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>webdev</category>
      <category>lowcode</category>
      <category>webcomponents</category>
    </item>
    <item>
      <title>What's your favorite way of learning?</title>
      <dc:creator>katka</dc:creator>
      <pubDate>Fri, 09 Sep 2022 18:47:37 +0000</pubDate>
      <link>https://dev.to/katka/whats-your-favorite-way-of-learning-3lbm</link>
      <guid>https://dev.to/katka/whats-your-favorite-way-of-learning-3lbm</guid>
      <description>&lt;ol&gt;
&lt;li&gt;🎥 Watching videos&lt;/li&gt;
&lt;li&gt;📖 Reading docs / guides &lt;/li&gt;
&lt;li&gt;💻 Reading code examples &lt;/li&gt;
&lt;li&gt;🗣 Talking with someone live&lt;/li&gt;
&lt;li&gt;❓Something else!&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>productivity</category>
      <category>learning</category>
    </item>
    <item>
      <title>Build a live-updating stock price badge for your web</title>
      <dc:creator>katka</dc:creator>
      <pubDate>Tue, 06 Sep 2022 19:47:33 +0000</pubDate>
      <link>https://dev.to/katka/build-a-live-updating-stock-price-badge-for-your-web-dd7</link>
      <guid>https://dev.to/katka/build-a-live-updating-stock-price-badge-for-your-web-dd7</guid>
      <description>&lt;p&gt;&lt;a href="https://yuzu.dev"&gt;Yuzu API&lt;/a&gt; is a free market data API that can power UIs of any size: from huge sprawling webapps to drop-in UI components. &lt;/p&gt;

&lt;p&gt;In this example we'll focus on powering something on the small scale: a portable web component that renders a badge with live-updating stock prices, like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u0xPMQJp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqrrndlutyg3traylpv0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u0xPMQJp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqrrndlutyg3traylpv0.gif" alt="Live badge example" width="880" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you'd rather skip to the good part, my friend Steve created a &lt;a href="https://github.com/yuzu-hq/stock-price-badge"&gt;GitHub Repo with our demo code&lt;/a&gt;. You can drop it right into your existing page!&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Since we want this component to be fully portable and framework-agnostic, we'll be using &lt;a href="https://lit.dev/"&gt;Lit&lt;/a&gt; + Typescript to create a native Web Component. This guide assumes you have the following tools installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js&lt;/li&gt;
&lt;li&gt;Yarn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get started, we'll use yarn to create a project for us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn create vite yuzu-stock-price-badge --template lit-ts
$ cd yuzu-stock-price-badge
$ yarn install`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The code above creates a new project folder using &lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt; as the build tool, then moves into the directory and installs dependencies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once we're in our new project and have run a fresh &lt;code&gt;yarn install&lt;/code&gt;, let's do a few things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Vite has created one component for us at &lt;code&gt;src/my-element.ts&lt;/code&gt;. Let's rename it to &lt;code&gt;yuzu-price-badge.ts&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In &lt;code&gt;src/yuzu-price-badge.ts&lt;/code&gt;, let's replace all occurences of &lt;code&gt;my-element&lt;/code&gt; with &lt;code&gt;yuzu-price-badge&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In &lt;code&gt;package.json&lt;/code&gt;, &lt;code&gt;index.html&lt;/code&gt;, and &lt;code&gt;vite.config.ts&lt;/code&gt;, go ahead and do the same thing, replacing all usages of &lt;code&gt;my-element&lt;/code&gt; with &lt;code&gt;yuzu-price-badge&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;yarn build&lt;/code&gt; and make sure everything looks ok!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;If that sounds like a lot of work, you can just run these commands in your terminal instead:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv src/my-element.ts src/yuzu-price-badge.ts
sed -i '' 's/my-element/yuzu-price-badge/g' vite.config.ts \
  src/yuzu-price-badge.ts \
  package.json \
  index.html
sed -i '' 's/MyElement/YuzuPriceBadge/g' src/yuzu-price-badge.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let's clean out all the boilerplate from &lt;code&gt;src/yuzu-stock-price-badge.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The file should look about this this when you're done:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;src/yuzu-price-badge.ts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { html, css, LitElement } from 'lit'
import { customElement, property, state } from 'lit/decorators.js'

/**
 * Yuzu stock price badge
 */
@customElement('yuzu-price-badge')
export class YuzuPriceBadge extends LitElement {
  static styles = css`
    :host {
    }
  `

  render() {
    return html``
  }
}

declare global {
  interface HTMLElementTagNameMap {
    'yuzu-price-badge': YuzuPriceBadge
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, now that we're at a good baseline, let's add some properties to our new component, just above our &lt;code&gt;render&lt;/code&gt; method:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;src/yuzu-price-badge.ts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  /**
   * Your Yuzu API key, exposed in HTML as "api-key"
   */
  @property({ type: String, attribute: "api-key" })
  apiKey = "";

  /**
   * The symbol to render
   * E.g. AAPL, MSFT, BRK.A
   */
  @property({ type: String })
  symbol = "";

  /**
   * Hold the last price of our stock
   */
  @state()
  private lastPrice: number = 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our two new properties, &lt;code&gt;apiKey&lt;/code&gt; and &lt;code&gt;symbol&lt;/code&gt; will be exposed in HTML to change what's rendered in this badge. The third property, &lt;code&gt;lastPrice&lt;/code&gt; is a bit of internal state that will hold the last known price of our stock. Let's go to &lt;code&gt;index.html&lt;/code&gt; and update our component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;index.html&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;body&amp;gt;
    &amp;lt;!-- Replace "demo" with your own API key --&amp;gt;
    &amp;lt;yuzu-price-badge api-key="demo" symbol="BYND"&amp;gt;
    &amp;lt;/yuzu-price-badge&amp;gt;
  &amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! Now, we need to fetch the last price of our stock when the component loads. We can override the &lt;code&gt;connectedCallback&lt;/code&gt;function from &lt;code&gt;LitElement&lt;/code&gt; to do that. Let's put our &lt;code&gt;connectedCallback&lt;/code&gt; between our new properties and the &lt;code&gt;render&lt;/code&gt;method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;src/yuzu-price-badge.ts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  async connectedCallback() {
    super.connectedCallback();
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we're going to do two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make a GraphQL request to grab the last price of the stock.&lt;/li&gt;
&lt;li&gt;Subscribe to the live price stream for our stock, and update our internal state when the price changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Because Yuzu's streaming APIs only returns data on stocks during market hours, it's good practice to use the GraphQL API to fetch any data you need to render your UI, and then subscribe to subsequent updates.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's add the following code to our &lt;code&gt;connectedCallback&lt;/code&gt; to make the GraphQL request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async connectedCallback() {
    super.connectedCallback();

    // Visit https://graph.yuzu.dev/graphql to see docs on the whole graph
    const query = `query {
      securities(input: { symbols: ["${this.symbol}"] }) {
        lastTrade {
          price
        }
      }
    }`

    const graphQlResult = await fetch("https://graph.yuzu.dev/graphql", {
      method: "POST",
      body: JSON.stringify({
        query
      }),
      headers: {
        'Authorization': `Bearer ${this.apiKey}`,
        'Content-Type': "application/json",
      }
    });
    const { data } = await graphQlResult.json();

    this.lastPrice = parseFloat(data.securities[0].lastTrade.price);
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! Here's a quick breakdown of what's happening above:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Construct the body of our GraphQL query, requesting securities matching our symbol, and on that object, the &lt;code&gt;price&lt;/code&gt; field of that security's last trade.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using the Fetch API to make the request, parsing the result, and assigning the value to &lt;code&gt;this.lastPrice&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One last step before we can see the fruits of our work: rendering &lt;code&gt;lastPrice&lt;/code&gt;. Let's modify &lt;code&gt;render()&lt;/code&gt; to show our symbol and the saved price.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  render() {
    return html`
    &amp;lt;p&amp;gt;${this.symbol}&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;$${this.lastPrice.toFixed(2)}&amp;lt;/p&amp;gt;
    `
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, run &lt;code&gt;yarn dev&lt;/code&gt; in your terminal and open up &lt;code&gt;localhost:3000&lt;/code&gt; in your browser. You should see the last price of BYND.&lt;/p&gt;

&lt;p&gt;All we need to do now is add some liveness! Thankfully this is trivial using Yuzu streams and the &lt;code&gt;EventSource&lt;/code&gt; API. Let's add the following code to the bottom of &lt;code&gt;connectedCallback()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async connectedCallback() {
    /*
    ... Our GraphQL querying code
    */

    const stream = `S:T:${this.symbol}`;
    const url = `https://sse.yuzu.dev/sse?streams=${stream}&amp;amp;token=${this.apiKey}`;
    const tradeStream = new EventSource(url);
    tradeStream.addEventListener("message", (message) =&amp;gt; {
      this.lastPrice = parseFloat(JSON.parse(message.data).price);
    });
  } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is just a few lines of code, but there's a lot of power behind them. Here's what's happening:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We construct a URL pointing at &lt;a href="https://docs.yuzu.dev/live-streaming/server-sent-events"&gt;Yuzu's server-sent events API&lt;/a&gt;, including our API token and the stream name &lt;code&gt;S:T:BYND&lt;/code&gt;, which asks for every trade of the Security &lt;code&gt;BYND&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add an event listener to the &lt;code&gt;EventSource&lt;/code&gt; which parses each message, and assigns the value of &lt;code&gt;price&lt;/code&gt; to our internal state, causing the component to re-render.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, if you go back to your browser, you'll see the price updating in real-time as long as the markets are open.&lt;/p&gt;

&lt;p&gt;Now, all that's left to do is add some styling!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static styles = css`
    :host {
      padding: 0.3rem 0.5rem;
      display: inline-flex;
      flex-direction: row;
      gap: 0.5rem;
      border: 2px solid black;
      border-radius: 99rem;
      background-color: gainsboro;

      font-family: sans-serif;
      font-weight: bold;
      font-size: 1rem;
    }

    p {
      margin: 0;
    }
  `
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there have it! &lt;a href="https://github.com/yuzu-hq/stock-price-badge"&gt;Check out our example repo&lt;/a&gt; for a ready-made version you can drop right into your existing page.&lt;/p&gt;

</description>
      <category>webcomponents</category>
      <category>tutorial</category>
      <category>node</category>
      <category>stocks</category>
    </item>
  </channel>
</rss>
