-
Notifications
You must be signed in to change notification settings - Fork 0
Adding a Market
Every board tgju server-renders uses the same table markup, so adding one is a registration plus a fixture. This is the whole procedure.
curl -sL -A "Mozilla/5.0" https://www.tgju.org/<page> | grep -c 'market-table'Zero means the table is built by JavaScript and this project cannot read it. That is why there is no crypto market.
In market.go:
const (
Currency Market = "currency"
Gold Market = "gold"
Coin Market = "coin"
Stock Market = "stock" // new
)
var sources = map[Market]source{
Currency: {path: "/currency", label: "ارز"},
Gold: {path: "/gold-chart", label: "طلا و نقره"},
Coin: {path: "/coin", label: "سکه"},
Stock: {path: "/stock", label: "بورس"}, // new
}Then add the aliases people will actually type, in ParseMarket:
case "stock", "stocks", "بورس":
return Stock, nilMarkets() reads the registry, so the CLI, /v1/markets, FetchAll and Item all pick
the new board up with no further changes.
In internal/cmd/fixtures/main.go:
var files = map[tgju.Market]string{
// ...
tgju.Stock: "stock.html",
}and in internal/fixture/fixture.go:
var Paths = map[string]string{
// ...
"/stock": "testdata/stock.html",
}Then:
make fixturesAt minimum, extend the table in TestFetchParsesEveryBoard (client_test.go) and
TestTablesOnSavedPages (internal/scrape/scrape_test.go) with the new board, a known
key and its title.
TestMarkets will fail until you add the market to its expected list — that failure is
the point: the ordering of Markets() is part of the API.
-
server/openapi.yaml— theMarketschema'senum. -
docs/index.html— the markets table. -
wiki/Instrument-Keys.md— a few of the new keys. -
CHANGELOG.md— underUnreleased.
make ci runs checkspec, which will tell you if the OpenAPI document has drifted, and
TestOpenAPICoversEveryRoute fails if a new route is undescribed.
/api/price/* exists to be byte-compatible with the Python service. Do not add a new
market there unless the shape genuinely fits — /api/price/coin was added because coins
group into categories exactly like gold does. New boards belong under /v1.