@imbingox/acex 0.2.0 → 0.3.0-beta.0

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/README.md CHANGED
@@ -29,7 +29,9 @@ const book = client.market.getL1Book({
29
29
  exchange: "binance",
30
30
  symbol: "BTC/USDT:USDT",
31
31
  });
32
+ const books = client.market.getL1Books("BTC/USDT:USDT");
32
33
  console.log(`bid=${book?.bidPrice.toFixed()} ask=${book?.askPrice.toFixed()}`);
34
+ console.log(`venues=${books.length}`);
33
35
  console.log(`book freshness=${book?.status.freshness}`);
34
36
 
35
37
  await client.market.subscribeFundingRate({
@@ -41,7 +43,9 @@ const funding = client.market.getFundingRate({
41
43
  exchange: "binance",
42
44
  symbol: "BTC/USDT:USDT",
43
45
  });
46
+ const fundingRates = client.market.getFundingRates("BTC/USDT:USDT");
44
47
  console.log(`funding=${funding?.fundingRate.toFixed()}`);
48
+ console.log(`funding venues=${fundingRates.length}`);
45
49
 
46
50
  for await (const event of client.market.events.l1BookUpdates({
47
51
  exchange: "binance",
@@ -141,7 +145,7 @@ bun run test:live:order:soak
141
145
 
142
146
  覆盖内容:
143
147
 
144
- - `market`:`loadMarkets()`、`subscribeL1Book()`、`subscribeFundingRate()`、`getL1Book()` / `getFundingRate()`、对应事件流和可选断线重连(`--disconnect-target funding` 可单独验证资金费率重连)
148
+ - `market`:`loadMarkets()`、`subscribeL1Book()`、`subscribeFundingRate()`、`getL1Book()` / `getL1Books()`、`getFundingRate()` / `getFundingRates()`、对应事件流和可选断线重连(`--disconnect-target funding` 可单独验证资金费率重连)
145
149
  - `account`:Binance PAPI UM 账户 bootstrap、余额/仓位/风险投影、private stream 更新和可选重连
146
150
  - `order`:open orders bootstrap、`subscribeOrders()`、订单事件投影和可选重连
147
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imbingox/acex",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-beta.0",
4
4
  "description": "Multi-exchange trading SDK for market data, account, and order management",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,13 +43,13 @@ interface BinanceMarkPriceMessage {
43
43
  T?: number;
44
44
  }
45
45
 
46
- const BINANCE_USDM_WS_BASE_URL = "wss://fstream.binance.com/ws";
46
+ const BINANCE_USDM_MARKET_WS_BASE_URL = "wss://fstream.binance.com/market/ws";
47
47
  const BINANCE_COINM_WS_BASE_URL = "wss://dstream.binance.com/ws";
48
48
 
49
49
  function getWsBaseUrl(market: BinanceMarketDefinition): string {
50
50
  switch (market.family) {
51
51
  case "usdm":
52
- return BINANCE_USDM_WS_BASE_URL;
52
+ return BINANCE_USDM_MARKET_WS_BASE_URL;
53
53
  case "coinm":
54
54
  return BINANCE_COINM_WS_BASE_URL;
55
55
  case "spot":
@@ -60,7 +60,7 @@ function getWsBaseUrl(market: BinanceMarketDefinition): string {
60
60
  }
61
61
 
62
62
  function buildMarkPriceUrl(market: BinanceMarketDefinition): string {
63
- return `${getWsBaseUrl(market)}/${market.id.toLowerCase()}@markPrice@1s`;
63
+ return `${getWsBaseUrl(market)}/${market.id.toLowerCase()}@markPrice`;
64
64
  }
65
65
 
66
66
  function parseMarkPriceMessage(
@@ -224,9 +224,10 @@ export class MarketManagerImpl
224
224
  return market ? cloneMarketDefinition(market) : undefined;
225
225
  }
226
226
 
227
- findMarkets(symbol: string): MarketDefinition[] {
227
+ getMarkets(symbol: string): MarketDefinition[] {
228
228
  return [...this.definitions.values()]
229
229
  .filter((market) => market.symbol === symbol)
230
+ .sort((left, right) => left.exchange.localeCompare(right.exchange))
230
231
  .map((market) => cloneMarketDefinition(market));
231
232
  }
232
233
 
@@ -245,11 +246,33 @@ export class MarketManagerImpl
245
246
  return book ? cloneL1Book(book) : undefined;
246
247
  }
247
248
 
249
+ getL1Books(symbol: string): L1Book[] {
250
+ return [...this.records.values()]
251
+ .filter(
252
+ (record): record is MarketRecord & { l1Book: L1Book } =>
253
+ record.symbol === symbol && Boolean(record.l1Book),
254
+ )
255
+ .map((record) => cloneL1Book(record.l1Book))
256
+ .sort((left, right) => left.exchange.localeCompare(right.exchange));
257
+ }
258
+
248
259
  getFundingRate(key: MarketKeyInput): FundingRateSnapshot | undefined {
249
260
  const fundingRate = this.records.get(marketKey(key))?.fundingRate;
250
261
  return fundingRate ? cloneFundingRate(fundingRate) : undefined;
251
262
  }
252
263
 
264
+ getFundingRates(symbol: string): FundingRateSnapshot[] {
265
+ return [...this.records.values()]
266
+ .filter(
267
+ (
268
+ record,
269
+ ): record is MarketRecord & { fundingRate: FundingRateSnapshot } =>
270
+ record.symbol === symbol && Boolean(record.fundingRate),
271
+ )
272
+ .map((record) => cloneFundingRate(record.fundingRate))
273
+ .sort((left, right) => left.exchange.localeCompare(right.exchange));
274
+ }
275
+
253
276
  getMarketStatus(key: MarketKeyInput): MarketDataStatus | undefined {
254
277
  const status = this.records.get(marketKey(key))?.status;
255
278
  return status ? cloneMarketStatus(status) : undefined;
@@ -142,9 +142,11 @@ export interface MarketManager {
142
142
  unsubscribeFundingRate(input: SubscribeFundingRateInput): Promise<void>;
143
143
 
144
144
  getMarket(exchange: Exchange, symbol: string): MarketDefinition | undefined;
145
- findMarkets(symbol: string): MarketDefinition[];
145
+ getMarkets(symbol: string): MarketDefinition[];
146
146
  listMarkets(exchange?: Exchange): MarketDefinition[];
147
147
  getL1Book(key: MarketKeyInput): L1Book | undefined;
148
+ getL1Books(symbol: string): L1Book[];
148
149
  getFundingRate(key: MarketKeyInput): FundingRateSnapshot | undefined;
150
+ getFundingRates(symbol: string): FundingRateSnapshot[];
149
151
  getMarketStatus(key: MarketKeyInput): MarketDataStatus | undefined;
150
152
  }