BlockRazor
Go to website
繁体中文
繁体中文
  • 👉关于BlockRazor
  • 👨‍💻用户案例
    • 钱包
    • 去中心化交易所
    • Trading Bot
    • Searcher
    • 量化交易系统
  • 💸Solana
    • 总览
    • Authentication
    • APIs
      • sendTransaction
      • getTransactionFee
      • Sandwich Detector
  • 🖥️BSC
    • Authentication
    • Dedicate Node
      • 創建Dedicate Node
      • 使用Dedicate Node
    • 高性能網絡
      • Proto
      • Subscribe NewTxs
      • Subscribe NewBlocks
      • Send RawTx
      • Send RawTxBatch
      • 全節點同步
    • Block Builder
      • Send Bundle
      • Send PrivateTransaction
      • Call Bundle
      • Trace Bundle
    • APIs
      • GetGasPriceStream
      • GetAllGasPriceStream
      • Sandwich Detector
  • 🛡️Scutum(ETH & BSC)
    • 总览
    • New to MEV
    • 項目專屬RPC
    • 錢包用戶通用RPC
    • Searcher
      • Authentication
      • Subscribe Bundle
      • Send Bundle
  • 📄声明
    • 隱私聲明
Powered by GitBook
On this page
  • 介紹
  • 限流
  • 請求參數
  • 請求示例
  • Proto
  • 返回示例
  1. BSC
  2. APIs

GetAllGasPriceStream

PreviousGetGasPriceStreamNextSandwich Detector

Last updated 1 month ago

介紹

GetAllGasPriceStream 供BSC交易gas price訂閱服務,基於gRPC流按百分位向用戶推送BSC交易在最近上鏈區塊中的gas price,端點域名:

限流

Tier 4
Tier 3
Tier 2
Tier 1
Tier 0

Streams

-

-

-

-

10

請求參數

字段
必選
格式
示例
備注

blockRange

是

int

20

統計最近N個區塊中交易的gas price,N取值範圍1-20

請求示例

package main

import (
	"context"
	"crypto/tls"
	"log"

	pb "fee-test/bscfeepb"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
)

const (
	gRPCEndpoint = "grpc.bsc-fee.blockrazor.xyz:443"
	auth         = "your_auth"
)

func main() {
	conn, err := grpc.Dial(
		gRPCEndpoint,
		grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
		grpc.WithPerRPCCredentials(&Authentication{auth}),
	)
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	client := pb.NewServerClient(conn)

	req := &pb.BlockRange{
		BlockRange: 5,
	}
	stream, err := client.GetAllGasPriceStream(context.Background(), req)
	if err != nil {
		panic(err)
	}

	for {
		message, err := stream.Recv()
		if err != nil {
			log.Printf("Failed to receive message: %v", err)
			break
		}
		log.Printf("Received Time: %s\n", message.Time.AsTime().Format("2006-01-02 15:04:05"))
		for _, gasPrice := range message.AllGasPrice {
			log.Printf("Received message percentile: %d\n", gasPrice.Percentile)
			log.Printf("Received message value: %s\n", gasPrice.Value)
		}
	}
}

type Authentication struct {
	auth string
}

func (a *Authentication) GetRequestMetadata(context.Context, ...string) (map[string]string, error) {
	return map[string]string{"apiKey": a.auth}, nil
}

func (a *Authentication) RequireTransportSecurity() bool {
	return false
}

Proto

syntax = "proto3";

package bscfeepb;

import "google/protobuf/timestamp.proto";

option go_package = "./pb/bscfeepb";

service Server {
    rpc GetAllGasPriceStream(BlockRange) returns(stream AllGasPriceStreamResponse) {};
}

message FeeValue {
    int32 percentile = 1;
    string value = 2;
}

message BlockRange {
    int32 blockRange = 2;
}

message AllGasPriceStreamResponse {
    repeated FeeValue allGasPrice = 1;
    google.protobuf.Timestamp time = 2;
}

返回示例

2025/04/08 10:18:21 Received Time: 2025-04-08 02:18:21
2025/04/08 10:18:21 Received message percentile: 25
2025/04/08 10:18:21 Received message value: 1000000000
2025/04/08 10:18:21 Received message percentile: 50
2025/04/08 10:18:21 Received message value: 1100000000
2025/04/08 10:18:21 Received message percentile: 75
2025/04/08 10:18:21 Received message value: 2020000000
2025/04/08 10:18:21 Received message percentile: 95
2025/04/08 10:18:21 Received message value: 5000000000
2025/04/08 10:18:21 Received message percentile: 99
2025/04/08 10:18:21 Received message value: 20000000000

🖥️
grpc.bsc-fee.blockrazor.xyz:443