Skip to content

hedisam/shrimpygo

Repository files navigation

shrimpygo

Golang Shrimpy client

It's still under development, so things might change.

What is Shrimpy?

Shrimpy provides real-time & historical (and more) crypto data

Coverage

  • Websocket subscriptions
    • BBO (Best Bid Offer) channel
    • Order book channel
    • Trades channel
    • Orders channel
  • Rest API
    • Public endpoints
    • Market-Data endpoints
    • Historical-Data endpoints

Todo

  • unit tests
  • implementing the remaining rest api
  • ...

Install

go get github.com/hedisam/shrimpygo

Usage

Check out the examples to see more.

package main

import (
  "context"
  "fmt"
  "github.com/hedisam/shrimpygo"
  "log"
  "time"
)

func main() {
  cfg := shrimpygo.Config{
    PublicKey:  "my API key",
    PrivateKey: "my secret key",
  }
  client, err := shrimpygo.NewClient(cfg)
  if err != nil {
    log.Fatal(err)
  }

  // receive data for 5 seconds, unless there's an error.
  ctx, cancel := context.WithTimeout(
    context.Background(),
    time.Second*5,
  )
  defer cancel()

  // you can specify the stream's throughput (the data channel's capacity)
  // by setting throughput as the the second parameter.
  ws, err := client.Websocket(ctx, 0)
  if err != nil {
    log.Fatal(err)
  }

  // subscribing to the order-book channel.  
  // check the examples to see how you can subscribe to other channels.
  ws.Subscribe(
    shrimpygo.OrderBookSubs("coinbasepro", "btc-usd"),
  )

  // reading the stream which can push any type of data from the supported
  // ws channels (bbo, trades, etc); depends on how many different channels 
  // you have subscribed on the same ws connection.
  for iData := range ws.Stream() {
    fmt.Println("============================")
    switch data := iData.(type) {
    case *shrimpygo.OrderBookInfo:
      fmt.Printf("OrderBook: %v\n", data)
    case error:
      fmt.Printf("shrimpy error: %+v\n", data)
      return
    default:
      fmt.Printf("unknown/unwanted data received from the stream: %v\n", data)
    }
  }
}

Releases

No releases published

Packages

No packages published

Languages