Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ranjanrak/orderbookstore
Go package to store daily end-of-the-day complete order book to clickhouse DB and generate queries based on them.
https://github.com/ranjanrak/orderbookstore
clickhouse stock-data
Last synced: 3 days ago
JSON representation
Go package to store daily end-of-the-day complete order book to clickhouse DB and generate queries based on them.
- Host: GitHub
- URL: https://github.com/ranjanrak/orderbookstore
- Owner: ranjanrak
- License: mit
- Created: 2021-06-23T08:46:35.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-10T08:00:09.000Z (over 2 years ago)
- Last Synced: 2024-06-20T17:48:28.484Z (5 months ago)
- Topics: clickhouse, stock-data
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# orderbookstore
A package to store daily end-of-the-day complete order book to clickhouse DB. This can be use to fetch historical order book data to calculate p&l related values.
## Installation
```
go get -u github.com/ranjanrak/orderbookstore
```## Usage
```go
package mainimport (
"github.com/ranjanrak/orderbookstore"
)func main() {
// Create new orderbook instance
client := orderbookstore.New(orderbookstore.ClientParam{
// Send DSN as per your clickhouse DB setup.
// visit https://github.com/ClickHouse/clickhouse-go#dsn to know more
DBSource: "dsn_address",
ApiKey: "your api key",
AccessToken: "your access token",
})// Store current orderbook data to clickhouse DB
client.DataLoad()// Fetch all historical order's for the symbol
symbolBook := client.QuerySymbol("SBIN")
fmt.Printf("%+v\n", symbolBook)startTime := time.Date(2021, 6, 29, 9, 41, 0, 0, time.UTC)
endTime := time.Date(2021, 8, 3, 15, 05, 0, 0, time.UTC)// Fetch average buy and sell price for the mentioned symbol and period
avgBook := client.QueryAvgPrice("IOC", startTime, endTime)
fmt.Printf("%+v\n", avgBook)// Fetch complete tradebook between start and end date
tradeBook := client.TradeBook(startTime, endTime)
fmt.Printf("%+v\n", tradeBook)}
```## Response
1> Response for `client.QuerySymbol("SBIN")`:
```
[{Exchange:NSE Symbol:SBIN OrderID:210629000202833 OrderTimestamp:2021-06-29T14:45:24+05:30
AveragePrice:426.65 TransactionType:BUY} {Exchange:NSE Symbol:SBIN OrderID:210629002938256
OrderTimestamp:2021-06-29T18:50:27+05:30 AveragePrice:424.05 TransactionType:SELL}
{Exchange:BSE Symbol:SBIN OrderID:210629002940618 OrderTimestamp:2021-06-29T18:50:54+05:30
AveragePrice:423.95 TransactionType:SELL}]
```2> Response for `client.QueryAvgPrice("IOC", startTime, endTime)`:
```
{Symbol:IOC BuyAvg:107.41 BuyQty:39 SellAvg:107.61 SellQty:17 RealizedPnl:-22.9}
```3> Response for `client.TradeBook(startTime, endTime)`:
```
[{OrderTimestamp:2021-06-29T14:45:11+05:30 Exchange:BSE TradingSymbol:IOC
AveragePrice:111.05 TransactionType:BUY}
{OrderTimestamp:2021-06-29T14:45:11+05:30 Exchange:NSE TradingSymbol:IOC
AveragePrice:111.1 TransactionType:SELL}]
```### Run unit tests
```
go test -v
```