US Congress Stock Trading API examples & templates
Use these vals as a playground to view and fork US Congress Stock Trading API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
yysofiyan
savvyTomatoToad
HTTP
This is an edit to the existing code to convert it to a Val Town HTTP val. Changes required: Remove Express and CORS dependencies Convert to native Deno/Val Town HTTP handler Use standard Response objects Remove PORT configuration Simplify server setup Use esm.sh for any required imports I've made several key modifications to adapt the code to Val Town: Converted from Express to a native Deno HTTP handler Added two API endpoints: /api/authors: Returns all authors /api/author/:sintaID : Returns a specific author by Sinta ID Added CORS headers to allow cross-origin requests Included a simple React frontend with a view source link Implemented error handling for non-existent routes Used Val Town's recommended import and rendering strategies The val now provides a flexible API for retrieving author information with both a JSON endpoint and a basic web interface.
0
xkonti
computeScheduleSegment
Script
computeScheduleSegment function Calculates the on/off time spans for a given schedule segment based on the duty cycle. Parameters: segment -A ScheduleSegment object describing the schedule. Returns: An array of TimeSpan objects representing the on times. TimeSpan type Represents a span of time with a starting point and a duration in minutes. DutyCycle type Represents the "on" state scheduling pattern for a device. It's similar to the concept of Pulse-Width Modulation (PWM). ScheduleSegment type A part of a complete schedule, describing a time frame with a specified duty cycle.
0
jamiedubs
nftMetadata
HTTP
use by copying web API endpoint and appending "?contractAddress=...&tokenId..." - here's an example: https://jamiedubs-nftmetadata.web.val.run/?contractAddress=0x3769c5700Da07Fe5b8eee86be97e061F961Ae340&tokenId=666 uses Alchemy for indexed NFT data, via my other jamiedubs/alchemyClient val plus it's using my personal API key. don't abuse this or I'll disable it! yeesh
1
fal
sdxl
Script
SDXL (fastest) https://www.fal.ai/models/stable-diffusion-xl link to val - https://www.val.town/v/fal/sdxl import * as fal from "npm:@fal-ai/serverless-client";
const result = await fal.subscribe("fal-ai/fast-sdxl", {
input: {
prompt: "photo of a rhino dressed suit and tie sitting at a table in a bar with a bar stools, award winning photography, Elke vogelsang"
},
logs: true,
onQueueUpdate: (update) => {
if (update.status === "IN_PROGRESS") {
update.logs.map((log) => log.message).forEach(console.log);
}
},
});
0
postpostscript
reactiveStateBlob
Script
reactiveStateBlob: wrap blob state in a proxy to autosave it on changes Examples (full example at @postpostscript/reactiveStateBlobExample ) import { reactiveStateBlob } from "https://esm.town/v/postpostscript/reactiveStateBlob"
using state = await reactiveStateBlob({
viewCount: 0,
rows: [] as {
x: number;
y: number;
}[],
});
state.viewCount += 1;
state.rows.push({
x: Math.random(),
y: Math.random(),
}); This infers the key from the name of the val that uses it. To specify it, pass the key option: using state = await reactiveStateBlob({
viewCount: 0,
rows: [] as {
x: number;
y: number;
}[],
}, {
key: 'reactiveStateBlobExample.state',
}); Updating Schema If you want to update the schema, or always verify the state that is pulled from the job, pass a function as the first argument: using state = await reactiveStateBlob((existingState) => {
return {
viewCount: (existingState.viewCount ?? 0) as number,
rows: (existingState.rows ?? []) as {
x: number;
y: number;
}[],
someNewField: (existingState.someNewField ?? "") as string,
}
}) Options using state = await reactiveStateBlob<{
value: number;
}>({
value: 0,
}, {
log: true, // log when saving
key: "blobKey", // blob key to fetch/save to
timeout: 100, // ms, defaults to 10
lock: true, // or LockOptions (see https://www.val.town/v/postpostscript/lock#options)
}) See Also @postpostscript/counter (example at @postpostscript/counterExample )
0