Skip to content

State Bank of Pakistan Exchange Rates

State Bank of Pakistan Exchange Rates

Test Lint

Overview

The State Bank of Pakistan (SBP) publishes exchange rates for various currencies against the Pakistani Rupee (PKR) on a daily basis. They publish the exchange rates on the internet in PDF format at a deterministic URL for each day. This library provides an interface to fetch and/or download the exchange rates for any given date.

Example Rate Sheets

:::caution[Important] These rates will almost always differ from google rates (e.g. rates from google search). :::

Installation

Terminal window
go get github.com/mistermoe/sbpfx

Quick Start

package main
import (
"context"
"fmt"
"log"
"github.com/mistermoe/sbpfx"
)
func main() {
client := sbpfx.New()
rate, err := client.GetExchangeRate(context.Background(), sbpfx.USD)
if err != nil {
log.Fatalf("failed to get exchange rate: %v", err)
}
fmt.Printf("USD to PKR: %s\n", rate.GetSpotRate())
}

Features

  • πŸ“ˆ Current Exchange Rates: Get today’s rates with no configuration
  • πŸ“… Historical Data: Fetch rates for any specific date
  • πŸ’Ύ PDF Download: Download original PDF rate sheets
  • πŸ”— URL Generation: Get direct links to rate sheet PDFs
  • 🌍 Multiple Currencies: Support for USD, EUR, GBP, JPY, and 25+ other currencies
  • ⚑ Human-Friendly API: Use simple date strings like β€œ2025-08-27”
  • πŸ§ͺ Well Tested: Comprehensive test suite with VCR for reliable testing
  • πŸ“¦ Zero Dependencies: Minimal external dependencies for easy integration