Skip to main content
Version: 2.6

Stock Price Reaktor

This example demonstrates how to wrap an external REST call in an aktor and expose it through a reaktor. The full implementation lives in operaide-apps/apps/op-demo-stock-example/src/Stock.reaktor.ts.

Create an async aktor

import { createAktorFunctionAsync } from '@operaide/aktor';
import axios from 'axios';

const aktorGetStock = createAktorFunctionAsync('aktorGetStock', async ({ symbol }: { symbol: string }) => {
// Twelve Data provides a free demo endpoint. The demo key is rate limited.
const url = `https://api.twelvedata.com/price?symbol=${symbol}&apikey=demo`;
const response = await axios.get(url);
return response.data;
});

Register the reaktor

import { z } from 'zod';
import { registerReaktorDefinition } from '@operaide/aktor';

registerReaktorDefinition({
reaktorDefinitionId: 'stock-example',
label: 'Get Stock Price by Symbol (default Apple)',
description: 'Gets the stock price of a symbol via Twelve Data',
inputSchema: z.object({
symbol: z.string().openapi({ example: 'APPL' }),
}),
outputSchema: z.object({ price: z.string() }),
createReaktor({ symbol }) {
return aktorGetStock({ symbol });
},
});

Try it out

Deploy the app and send a request similar to the bundled src/Stock.http:

POST http://localhost:8811/api/v1/aktor/stock-example/run
Content-Type: application/json

{
"symbol": "APPL"
}

The response contains the JSON payload returned by Twelve Data.