Before you begin writing a scraper, please check if the exchange offers integration through WebSockets. If it does, implement the scraper using the WebSocket protocol instead of a RESTful API.To scrape data from an exchange data source, called “MySource” for instance, follow these steps:
pkg/dia/scraper/exchange-scrapers/
with the filename MySourceScraper.go
.NewMySourceScraper(exchangeName string) *MySourceScraper
. We suggest that this function calls a mainLoop()
method in a go routine, constantly receiving trade information through the trade channel of MySourceScraper as long as the channel is open.In order to implement the interface, it is necessary to include the ScrapePair
method, which returns a MySourcePairScraper for a specific pair, so our main collection method can iterate over all possible trading pairs. Note that MySourcePairScraper should respect and implement the PairScraper
interfaceAlso, to ensure proper error handling and cleanup, it is recommended to include a method Error()
, which returns an error as soon as the scraper’s channel closes. Additionally, Close()
and cleanup()
methods should be included to handle the closing and shutting down of channels.
For a better understanding of how to set up a scraper, you can refer to the CoinBaseScraper.go
file, as it provides an example of an existing exchange scraper and its overall structure and logic.
Config.go
in the dia package:pkg/dia/scraper/exchange-scrapers/APIScraper.go
file:config/MySourceExchange.json
config:build/Dockerfile-genericCollector
and build/Dockerfile-pairDiscoveryService
files and add the following two lines before the RUN go mod tidy
step:mysource.yaml
file. You can refer to existing files for guidance or use the following template:go mod tidy -go=1.16 && go mod tidy -go=1.17 && go install && collector -exchange=Bitfinex -mode=current -pairsfile=true
go mod tidy -go=1.16 && go mod tidy -go=1.17 && go install && collector -exchange=Bittrex -mode=current -pairsfile=true
go mod tidy -go=1.16 && go mod tidy -go=1.17 && go install && collector -exchange=CoinBase -mode=current -pairsfile=true
go mod tidy -go=1.16 && go mod tidy -go=1.17 && go install && collector -exchange=MEXC -mode=current -pairsfile=true
go mod tidy -go=1.16 && go mod tidy -go=1.17 && go install && SOLANA_URI_REST=https://try-rpc.mainnet.solana.blockdaemon.tech/ collector -exchange=Orca -mode=current -pairsfile=true