https://github.com/fang2hou/markets
Local high performance cryptocurrency price data provider.
https://github.com/fang2hou/markets
cryptocurrency cryptocurrency-api cryptocurrency-exchanges cryptocurrency-prices
Last synced: about 1 month ago
JSON representation
Local high performance cryptocurrency price data provider.
- Host: GitHub
- URL: https://github.com/fang2hou/markets
- Owner: fang2hou
- License: lgpl-3.0
- Created: 2022-02-20T17:40:56.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-26T00:39:52.000Z (over 1 year ago)
- Last Synced: 2025-03-19T20:42:14.329Z (about 1 month ago)
- Topics: cryptocurrency, cryptocurrency-api, cryptocurrency-exchanges, cryptocurrency-prices
- Language: Go
- Homepage:
- Size: 108 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
README
# markets
## Introduction
This project is used to build a real-time cross-exchange price database. In addition to the prices, the program also automatically stores the commission information obtained through the exchange API. Based on the information in the database, you can set up strategies to trade robotically.
It's a free work for everyone, but if you use this library, the code you write need to be open source.
```
LICENSE: LGPL version 3
```## Features
1. Support WebSocket API of various exchanges with very high performance.
2. Support for using both Rest API and WebSocket API in a single thread.
3. Multiple exchanges can be polled at the same time.
4. It is easy to extend the program to support more exchanges.## Storage
The program only provides two types of storage:
1. Simply save in memory.
2. RedisThe other databases are also supported, but you need to write a connector for them in golang.
Check the files in `pkg/database` if you want to know how to create a connector.## Usage
Here is the sample code, just set your API token in the `config.yaml` file, and then run the program.
```go
package mainimport (
"os""github.com/go-redis/redis/v8"
"markets/internal/pkg/config"
"markets/pkg/database"
"markets/pkg/exchange"
)func pollExchange(e exchange.Exchanger) {
forever := make(chan bool)if err := e.Start(); err != nil {
panic(err)
}defer func() {
if err := e.Stop(); err != nil {
panic(err)
}
}()<-forever
}func main() {
dataBytes, err := os.ReadFile("configs/config.yaml")
if err != nil {
panic(err)
}cfg := config.Config{}
if err := cfg.Load(dataBytes); err != nil {
panic(err)
}var currencies []string
if value, err := cfg.GetCurrenciesSetting(); err != nil {
panic(err)
} else {
currencies = value
}if setting, err := cfg.GetExchangeSetting("okx"); err != nil {
panic(err)
} else {
e := exchange.NewOkx(
setting,
currencies,
database.NewInteractor(database.NewRedisConnector(&redis.Options{
Addr: "localhost:6379",
})),
)go pollExchange(e)
}if setting, err := cfg.GetExchangeSetting("gateio"); err != nil {
panic(err)
} else {
e := exchange.NewGateio(
setting,
currencies,
database.NewInteractor(database.NewRedisConnector(&redis.Options{
Addr: "localhost:6379",
})),
)go pollExchange(e)
}forever := make(chan bool)
<-forever
}```