@tradejs/connectors 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1607,6 +1607,12 @@ var ByBitConnectorCreator = async (config) => {
1607
1607
  // src/Binance/index.ts
1608
1608
  var import_http = require("@tradejs/infra/http");
1609
1609
  var import_types2 = require("@tradejs/types");
1610
+
1611
+ // src/shared/binancePublicApi.ts
1612
+ var DEFAULT_BINANCE_PUBLIC_API_URL = "https://data-api.binance.vision";
1613
+ var getBinancePublicApiUrl = () => process.env.BINANCE_BASE_URL?.trim() || DEFAULT_BINANCE_PUBLIC_API_URL;
1614
+
1615
+ // src/Binance/index.ts
1610
1616
  var INTERVAL_MAP = {
1611
1617
  "1": "1m",
1612
1618
  "3": "3m",
@@ -1666,7 +1672,7 @@ var BinanceConnectorCreator = async (config) => {
1666
1672
  if (!intervalToken) return [];
1667
1673
  const intervalMs = INTERVAL_MS[String(interval)] ?? 9e5;
1668
1674
  const normalizedEnd = end ?? Date.now();
1669
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1675
+ const baseUrl = getBinancePublicApiUrl();
1670
1676
  let cursor = start ?? Math.max(0, normalizedEnd - intervalMs * 1e3);
1671
1677
  const rows = [];
1672
1678
  while (cursor <= normalizedEnd) {
@@ -1716,11 +1722,15 @@ var BinanceConnectorCreator = async (config) => {
1716
1722
  return rows;
1717
1723
  };
1718
1724
  const loadTickers = async () => {
1719
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1725
+ const baseUrl = getBinancePublicApiUrl();
1720
1726
  const response = await (0, import_http.fetchWithRetry)(`${baseUrl}/api/v3/ticker/24hr`, {
1721
1727
  headers: { "User-Agent": "tradejs/binance-connector" }
1722
1728
  });
1723
- if (!response.ok) return [];
1729
+ if (!response.ok) {
1730
+ throw new Error(
1731
+ `Binance ticker request failed with HTTP ${response.status || "unknown"}`
1732
+ );
1733
+ }
1724
1734
  const payload = await response.json();
1725
1735
  if (!Array.isArray(payload)) return [];
1726
1736
  return payload.map((row) => {
@@ -1796,7 +1806,7 @@ var BinanceConnectorCreator = async (config) => {
1796
1806
  getTopOfBookTicker: async (symbol) => {
1797
1807
  const normalizedSymbol = String(symbol || "").trim().toUpperCase();
1798
1808
  if (!normalizedSymbol) return null;
1799
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1809
+ const baseUrl = getBinancePublicApiUrl();
1800
1810
  const url = new URL(`${baseUrl}/api/v3/ticker/bookTicker`);
1801
1811
  url.searchParams.set("symbol", normalizedSymbol);
1802
1812
  const response = await (0, import_http.fetchWithRetry)(url.toString(), {
@@ -1817,7 +1827,7 @@ var BinanceConnectorCreator = async (config) => {
1817
1827
  const normalizedSymbol = String(symbol || "").trim().toUpperCase();
1818
1828
  if (!normalizedSymbol) return [];
1819
1829
  const safeLimit = Math.min(Math.max(Math.floor(limit), 1), 1e3);
1820
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1830
+ const baseUrl = getBinancePublicApiUrl();
1821
1831
  const url = new URL(`${baseUrl}/api/v3/aggTrades`);
1822
1832
  url.searchParams.set("symbol", normalizedSymbol);
1823
1833
  url.searchParams.set("startTime", String(Math.floor(startTime)));
@@ -1846,7 +1856,7 @@ var BinanceConnectorCreator = async (config) => {
1846
1856
  if (!normalizedSymbol) return null;
1847
1857
  const allowedLimits = [5, 10, 20, 50, 100, 500, 1e3, 5e3];
1848
1858
  const safeLimit = allowedLimits.includes(limit) ? limit : 100;
1849
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1859
+ const baseUrl = getBinancePublicApiUrl();
1850
1860
  const url = new URL(`${baseUrl}/api/v3/depth`);
1851
1861
  url.searchParams.set("symbol", normalizedSymbol);
1852
1862
  url.searchParams.set("limit", String(safeLimit));
@@ -2149,7 +2159,7 @@ var spotKlineProviders = {
2149
2159
  binance: {
2150
2160
  kline: async ({ symbol, interval, start, end }) => {
2151
2161
  const token = toIntervalToken(interval);
2152
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
2162
+ const baseUrl = getBinancePublicApiUrl();
2153
2163
  const url = new URL(`${baseUrl}/api/v3/klines`);
2154
2164
  url.searchParams.set("symbol", symbol);
2155
2165
  url.searchParams.set("interval", token);
package/dist/index.mjs CHANGED
@@ -1566,6 +1566,12 @@ import { fetchWithRetry } from "@tradejs/infra/http";
1566
1566
  import {
1567
1567
  resolveConnectorUniverse as resolveConnectorUniverse2
1568
1568
  } from "@tradejs/types";
1569
+
1570
+ // src/shared/binancePublicApi.ts
1571
+ var DEFAULT_BINANCE_PUBLIC_API_URL = "https://data-api.binance.vision";
1572
+ var getBinancePublicApiUrl = () => process.env.BINANCE_BASE_URL?.trim() || DEFAULT_BINANCE_PUBLIC_API_URL;
1573
+
1574
+ // src/Binance/index.ts
1569
1575
  var INTERVAL_MAP = {
1570
1576
  "1": "1m",
1571
1577
  "3": "3m",
@@ -1625,7 +1631,7 @@ var BinanceConnectorCreator = async (config) => {
1625
1631
  if (!intervalToken) return [];
1626
1632
  const intervalMs = INTERVAL_MS[String(interval)] ?? 9e5;
1627
1633
  const normalizedEnd = end ?? Date.now();
1628
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1634
+ const baseUrl = getBinancePublicApiUrl();
1629
1635
  let cursor = start ?? Math.max(0, normalizedEnd - intervalMs * 1e3);
1630
1636
  const rows = [];
1631
1637
  while (cursor <= normalizedEnd) {
@@ -1675,11 +1681,15 @@ var BinanceConnectorCreator = async (config) => {
1675
1681
  return rows;
1676
1682
  };
1677
1683
  const loadTickers = async () => {
1678
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1684
+ const baseUrl = getBinancePublicApiUrl();
1679
1685
  const response = await fetchWithRetry(`${baseUrl}/api/v3/ticker/24hr`, {
1680
1686
  headers: { "User-Agent": "tradejs/binance-connector" }
1681
1687
  });
1682
- if (!response.ok) return [];
1688
+ if (!response.ok) {
1689
+ throw new Error(
1690
+ `Binance ticker request failed with HTTP ${response.status || "unknown"}`
1691
+ );
1692
+ }
1683
1693
  const payload = await response.json();
1684
1694
  if (!Array.isArray(payload)) return [];
1685
1695
  return payload.map((row) => {
@@ -1755,7 +1765,7 @@ var BinanceConnectorCreator = async (config) => {
1755
1765
  getTopOfBookTicker: async (symbol) => {
1756
1766
  const normalizedSymbol = String(symbol || "").trim().toUpperCase();
1757
1767
  if (!normalizedSymbol) return null;
1758
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1768
+ const baseUrl = getBinancePublicApiUrl();
1759
1769
  const url = new URL(`${baseUrl}/api/v3/ticker/bookTicker`);
1760
1770
  url.searchParams.set("symbol", normalizedSymbol);
1761
1771
  const response = await fetchWithRetry(url.toString(), {
@@ -1776,7 +1786,7 @@ var BinanceConnectorCreator = async (config) => {
1776
1786
  const normalizedSymbol = String(symbol || "").trim().toUpperCase();
1777
1787
  if (!normalizedSymbol) return [];
1778
1788
  const safeLimit = Math.min(Math.max(Math.floor(limit), 1), 1e3);
1779
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1789
+ const baseUrl = getBinancePublicApiUrl();
1780
1790
  const url = new URL(`${baseUrl}/api/v3/aggTrades`);
1781
1791
  url.searchParams.set("symbol", normalizedSymbol);
1782
1792
  url.searchParams.set("startTime", String(Math.floor(startTime)));
@@ -1805,7 +1815,7 @@ var BinanceConnectorCreator = async (config) => {
1805
1815
  if (!normalizedSymbol) return null;
1806
1816
  const allowedLimits = [5, 10, 20, 50, 100, 500, 1e3, 5e3];
1807
1817
  const safeLimit = allowedLimits.includes(limit) ? limit : 100;
1808
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
1818
+ const baseUrl = getBinancePublicApiUrl();
1809
1819
  const url = new URL(`${baseUrl}/api/v3/depth`);
1810
1820
  url.searchParams.set("symbol", normalizedSymbol);
1811
1821
  url.searchParams.set("limit", String(safeLimit));
@@ -2110,7 +2120,7 @@ var spotKlineProviders = {
2110
2120
  binance: {
2111
2121
  kline: async ({ symbol, interval, start, end }) => {
2112
2122
  const token = toIntervalToken(interval);
2113
- const baseUrl = process.env.BINANCE_BASE_URL?.trim() || "https://api.binance.com";
2123
+ const baseUrl = getBinancePublicApiUrl();
2114
2124
  const url = new URL(`${baseUrl}/api/v3/klines`);
2115
2125
  url.searchParams.set("symbol", symbol);
2116
2126
  url.searchParams.set("interval", token);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/connectors",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Built-in exchange connectors and market data providers for the TradeJS open-source framework.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -33,10 +33,10 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@tradejs/core": "^1.0.10",
37
- "@tradejs/infra": "^1.0.10",
38
- "@tradejs/node": "^1.0.10",
39
- "@tradejs/types": "^1.0.10",
36
+ "@tradejs/core": "^1.0.11",
37
+ "@tradejs/infra": "^1.0.11",
38
+ "@tradejs/node": "^1.0.11",
39
+ "@tradejs/types": "^1.0.11",
40
40
  "bybit-api": "^4.6.2",
41
41
  "chalk": "4.1.2",
42
42
  "lodash": "^4.18.1"