gleam-spacetraders-sdk/src/models/market_transaction.gleam
Lily Rose cc8edbed02
Some checks are pending
test / test (push) Waiting to run
Add functioning sdk
2025-06-17 01:43:06 +10:00

42 lines
1.2 KiB
Gleam

import gleam/dynamic/decode.{type Decoder}
import models/ship_symbol.{type ShipSymbol}
import models/trade_symbol.{type TradeSymbol}
import models/transaction_type.{type TransactionType}
import models/waypoint_symbol.{type WaypointSymbol}
pub type MarketTransaction {
MarketTransaction(
waypoint_symbol: WaypointSymbol,
ship_symbol: ShipSymbol,
trade_symbol: TradeSymbol,
type_: TransactionType,
units: Int,
price_per_unit: Int,
total_price: Int,
timestamp: String,
)
}
pub fn decoder() -> Decoder(MarketTransaction) {
use waypoint_symbol <- decode.field(
"waypointSymbol",
waypoint_symbol.decoder(),
)
use ship_symbol <- decode.field("shipSymbol", decode.string)
use trade_symbol <- decode.field("tradeSymbol", trade_symbol.decoder())
use type_ <- decode.field("type", transaction_type.decoder())
use units <- decode.field("units", decode.int)
use price_per_unit <- decode.field("pricePerUnit", decode.int)
use total_price <- decode.field("totalPrice", decode.int)
use timestamp <- decode.field("timestamp", decode.string)
decode.success(MarketTransaction(
waypoint_symbol:,
ship_symbol:,
trade_symbol:,
type_:,
units:,
price_per_unit:,
total_price:,
timestamp:,
))
}