Skip to content

Commit d48c71b

Browse files
harveyyuejackwener
andauthored
feat(binance): depth shows both bids and asks (#1019)
* feat(binance): depth shows both bids and asks * test(pipeline): cover root data access after inline select * fix(binance): preserve map select context and register manifest entries --------- Co-authored-by: jackwener <jakevingoo@gmail.com>
1 parent 6fbeda9 commit d48c71b

6 files changed

Lines changed: 376 additions & 16 deletions

File tree

cli-manifest.json

Lines changed: 344 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,342 @@
16071607
"modulePath": "bilibili/user-videos.js",
16081608
"sourceFile": "bilibili/user-videos.js"
16091609
},
1610+
{
1611+
"site": "binance",
1612+
"name": "asks",
1613+
"description": "Order book ask prices for a trading pair",
1614+
"domain": "data-api.binance.vision",
1615+
"strategy": "public",
1616+
"browser": false,
1617+
"args": [
1618+
{
1619+
"name": "symbol",
1620+
"type": "str",
1621+
"required": true,
1622+
"positional": true,
1623+
"help": "Trading pair symbol (e.g. BTCUSDT, ETHUSDT)"
1624+
},
1625+
{
1626+
"name": "limit",
1627+
"type": "int",
1628+
"default": 10,
1629+
"required": false,
1630+
"help": "Number of price levels (5, 10, 20, 50, 100)"
1631+
}
1632+
],
1633+
"columns": [
1634+
"rank",
1635+
"ask_price",
1636+
"ask_qty"
1637+
],
1638+
"type": "js",
1639+
"modulePath": "binance/asks.js",
1640+
"sourceFile": "binance/asks.js"
1641+
},
1642+
{
1643+
"site": "binance",
1644+
"name": "depth",
1645+
"description": "Order book bid and ask prices for a trading pair",
1646+
"domain": "data-api.binance.vision",
1647+
"strategy": "public",
1648+
"browser": false,
1649+
"args": [
1650+
{
1651+
"name": "symbol",
1652+
"type": "str",
1653+
"required": true,
1654+
"positional": true,
1655+
"help": "Trading pair symbol (e.g. BTCUSDT, ETHUSDT)"
1656+
},
1657+
{
1658+
"name": "limit",
1659+
"type": "int",
1660+
"default": 10,
1661+
"required": false,
1662+
"help": "Number of price levels (5, 10, 20, 50, 100)"
1663+
}
1664+
],
1665+
"columns": [
1666+
"rank",
1667+
"bid_price",
1668+
"bid_qty",
1669+
"ask_price",
1670+
"ask_qty"
1671+
],
1672+
"type": "js",
1673+
"modulePath": "binance/depth.js",
1674+
"sourceFile": "binance/depth.js"
1675+
},
1676+
{
1677+
"site": "binance",
1678+
"name": "gainers",
1679+
"description": "Top gaining trading pairs by 24h price change",
1680+
"domain": "data-api.binance.vision",
1681+
"strategy": "public",
1682+
"browser": false,
1683+
"args": [
1684+
{
1685+
"name": "limit",
1686+
"type": "int",
1687+
"default": 10,
1688+
"required": false,
1689+
"help": "Number of trading pairs"
1690+
}
1691+
],
1692+
"columns": [
1693+
"rank",
1694+
"symbol",
1695+
"price",
1696+
"change_24h",
1697+
"volume"
1698+
],
1699+
"type": "js",
1700+
"modulePath": "binance/gainers.js",
1701+
"sourceFile": "binance/gainers.js"
1702+
},
1703+
{
1704+
"site": "binance",
1705+
"name": "klines",
1706+
"description": "Candlestick/kline data for a trading pair",
1707+
"domain": "data-api.binance.vision",
1708+
"strategy": "public",
1709+
"browser": false,
1710+
"args": [
1711+
{
1712+
"name": "symbol",
1713+
"type": "str",
1714+
"required": true,
1715+
"positional": true,
1716+
"help": "Trading pair symbol (e.g. BTCUSDT, ETHUSDT)"
1717+
},
1718+
{
1719+
"name": "interval",
1720+
"type": "str",
1721+
"default": "1d",
1722+
"required": false,
1723+
"help": "Kline interval (1m, 5m, 15m, 1h, 4h, 1d, 1w, 1M)"
1724+
},
1725+
{
1726+
"name": "limit",
1727+
"type": "int",
1728+
"default": 10,
1729+
"required": false,
1730+
"help": "Number of klines (max 1000)"
1731+
}
1732+
],
1733+
"columns": [
1734+
"open",
1735+
"high",
1736+
"low",
1737+
"close",
1738+
"volume"
1739+
],
1740+
"type": "js",
1741+
"modulePath": "binance/klines.js",
1742+
"sourceFile": "binance/klines.js"
1743+
},
1744+
{
1745+
"site": "binance",
1746+
"name": "losers",
1747+
"description": "Top losing trading pairs by 24h price change",
1748+
"domain": "data-api.binance.vision",
1749+
"strategy": "public",
1750+
"browser": false,
1751+
"args": [
1752+
{
1753+
"name": "limit",
1754+
"type": "int",
1755+
"default": 10,
1756+
"required": false,
1757+
"help": "Number of trading pairs"
1758+
}
1759+
],
1760+
"columns": [
1761+
"rank",
1762+
"symbol",
1763+
"price",
1764+
"change_24h",
1765+
"volume"
1766+
],
1767+
"type": "js",
1768+
"modulePath": "binance/losers.js",
1769+
"sourceFile": "binance/losers.js"
1770+
},
1771+
{
1772+
"site": "binance",
1773+
"name": "pairs",
1774+
"description": "List active trading pairs on Binance",
1775+
"domain": "data-api.binance.vision",
1776+
"strategy": "public",
1777+
"browser": false,
1778+
"args": [
1779+
{
1780+
"name": "limit",
1781+
"type": "int",
1782+
"default": 20,
1783+
"required": false,
1784+
"help": "Number of trading pairs"
1785+
}
1786+
],
1787+
"columns": [
1788+
"symbol",
1789+
"base",
1790+
"quote",
1791+
"status"
1792+
],
1793+
"type": "js",
1794+
"modulePath": "binance/pairs.js",
1795+
"sourceFile": "binance/pairs.js"
1796+
},
1797+
{
1798+
"site": "binance",
1799+
"name": "price",
1800+
"description": "Quick price check for a trading pair",
1801+
"domain": "data-api.binance.vision",
1802+
"strategy": "public",
1803+
"browser": false,
1804+
"args": [
1805+
{
1806+
"name": "symbol",
1807+
"type": "str",
1808+
"required": true,
1809+
"positional": true,
1810+
"help": "Trading pair symbol (e.g. BTCUSDT, ETHUSDT)"
1811+
}
1812+
],
1813+
"columns": [
1814+
"symbol",
1815+
"price",
1816+
"change",
1817+
"change_pct",
1818+
"high",
1819+
"low",
1820+
"volume",
1821+
"quote_volume",
1822+
"trades"
1823+
],
1824+
"type": "js",
1825+
"modulePath": "binance/price.js",
1826+
"sourceFile": "binance/price.js"
1827+
},
1828+
{
1829+
"site": "binance",
1830+
"name": "prices",
1831+
"description": "Latest prices for all trading pairs",
1832+
"domain": "data-api.binance.vision",
1833+
"strategy": "public",
1834+
"browser": false,
1835+
"args": [
1836+
{
1837+
"name": "limit",
1838+
"type": "int",
1839+
"default": 20,
1840+
"required": false,
1841+
"help": "Number of prices"
1842+
}
1843+
],
1844+
"columns": [
1845+
"rank",
1846+
"symbol",
1847+
"price"
1848+
],
1849+
"type": "js",
1850+
"modulePath": "binance/prices.js",
1851+
"sourceFile": "binance/prices.js"
1852+
},
1853+
{
1854+
"site": "binance",
1855+
"name": "ticker",
1856+
"description": "24h ticker statistics for top trading pairs by volume",
1857+
"domain": "data-api.binance.vision",
1858+
"strategy": "public",
1859+
"browser": false,
1860+
"args": [
1861+
{
1862+
"name": "limit",
1863+
"type": "int",
1864+
"default": 20,
1865+
"required": false,
1866+
"help": "Number of tickers"
1867+
}
1868+
],
1869+
"columns": [
1870+
"symbol",
1871+
"price",
1872+
"change_pct",
1873+
"high",
1874+
"low",
1875+
"volume",
1876+
"quote_vol",
1877+
"trades"
1878+
],
1879+
"type": "js",
1880+
"modulePath": "binance/ticker.js",
1881+
"sourceFile": "binance/ticker.js"
1882+
},
1883+
{
1884+
"site": "binance",
1885+
"name": "top",
1886+
"description": "Top trading pairs by 24h volume on Binance",
1887+
"domain": "data-api.binance.vision",
1888+
"strategy": "public",
1889+
"browser": false,
1890+
"args": [
1891+
{
1892+
"name": "limit",
1893+
"type": "int",
1894+
"default": 20,
1895+
"required": false,
1896+
"help": "Number of trading pairs"
1897+
}
1898+
],
1899+
"columns": [
1900+
"rank",
1901+
"symbol",
1902+
"price",
1903+
"change_24h",
1904+
"high",
1905+
"low",
1906+
"volume"
1907+
],
1908+
"type": "js",
1909+
"modulePath": "binance/top.js",
1910+
"sourceFile": "binance/top.js"
1911+
},
1912+
{
1913+
"site": "binance",
1914+
"name": "trades",
1915+
"description": "Recent trades for a trading pair",
1916+
"domain": "data-api.binance.vision",
1917+
"strategy": "public",
1918+
"browser": false,
1919+
"args": [
1920+
{
1921+
"name": "symbol",
1922+
"type": "str",
1923+
"required": true,
1924+
"positional": true,
1925+
"help": "Trading pair symbol (e.g. BTCUSDT, ETHUSDT)"
1926+
},
1927+
{
1928+
"name": "limit",
1929+
"type": "int",
1930+
"default": 20,
1931+
"required": false,
1932+
"help": "Number of trades (max 1000)"
1933+
}
1934+
],
1935+
"columns": [
1936+
"id",
1937+
"price",
1938+
"qty",
1939+
"quote_qty",
1940+
"buyer_maker"
1941+
],
1942+
"type": "js",
1943+
"modulePath": "binance/trades.js",
1944+
"sourceFile": "binance/trades.js"
1945+
},
16101946
{
16111947
"site": "bloomberg",
16121948
"name": "businessweek",
@@ -13280,14 +13616,14 @@
1328013616
"help": ""
1328113617
}
1328213618
],
13283-
"columns": [
13284-
"author",
13285-
"text",
13286-
"likes",
13287-
"retweets",
13288-
"bookmarks",
13289-
"url"
13290-
],
13619+
"columns": [
13620+
"author",
13621+
"text",
13622+
"likes",
13623+
"retweets",
13624+
"bookmarks",
13625+
"url"
13626+
],
1329113627
"type": "js",
1329213628
"modulePath": "twitter/bookmarks.js",
1329313629
"sourceFile": "twitter/bookmarks.js"

clis/binance/depth.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ import { cli, Strategy } from '@jackwener/opencli/registry';
33
cli({
44
site: 'binance',
55
name: 'depth',
6-
description: 'Order book bid prices for a trading pair',
6+
description: 'Order book bid and ask prices for a trading pair',
77
domain: 'data-api.binance.vision',
88
strategy: Strategy.PUBLIC,
99
browser: false,
1010
args: [
1111
{ name: 'symbol', type: 'str', required: true, positional: true, help: 'Trading pair symbol (e.g. BTCUSDT, ETHUSDT)' },
1212
{ name: 'limit', type: 'int', default: 10, help: 'Number of price levels (5, 10, 20, 50, 100)' },
1313
],
14-
columns: ['rank', 'bid_price', 'bid_qty'],
14+
columns: ['rank', 'bid_price', 'bid_qty', 'ask_price', 'ask_qty'],
1515
pipeline: [
1616
{ fetch: { url: 'https://data-api.binance.vision/api/v3/depth?symbol=${{ args.symbol }}&limit=${{ args.limit }}' } },
17-
{ select: 'bids' },
18-
{ map: { rank: '${{ index + 1 }}', bid_price: '${{ item.0 }}', bid_qty: '${{ item.1 }}' } },
17+
{ map: { select: 'bids', rank: '${{ index + 1 }}', bid_price: '${{ item[0] }}', bid_qty: '${{ item[1] }}', ask_price: '${{ root.asks[index]?.[0] ?? "" }}', ask_qty: '${{ root.asks[index]?.[1] ?? "" }}' } },
1918
{ limit: '${{ args.limit }}' },
2019
],
2120
});

src/pipeline/steps/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function stepMap(_page: IPage | null, params: unknown, data: unknow
4141
const row: Record<string, unknown> = {};
4242
for (const [key, template] of Object.entries(templateParams)) {
4343
if (key === 'select') continue;
44-
row[key] = render(template, { args, data: source, item, index: i });
44+
row[key] = render(template, { args, data: source, root: data, item, index: i });
4545
}
4646
result.push(row);
4747
}

0 commit comments

Comments
 (0)