Skip to content

1Forge/golang-forex-quotes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang-forex-quotes

golang-forex-quotes is a Golang library for fetching realtime forex quotes. Any contributions or issues opened are greatly appreciated.

1Forge Data

Table of Contents

Requirements

Known Issues

Please see the list of known issues here: Issues

Installation

go get github.com/1Forge/golang-forex-quotes

Usage

Initialize the client

import (
	Forex "github.com/1Forge/golang-forex-quotes"
)

WebSocket API

func main() {
    client := Forex.CreateForgeClient("YOUR_API_KEY")

    symbols := []string{"BTC/JPY", "AUD/JPY", "GBP/CHF"}

    // Specify the update handler
    client.OnUpdate(func(q Forex.Quote) {
        fmt.Println(q)
    })

    // Specify the message handler
    client.OnMessage(func(m string) {
        fmt.Println(m)
    })

    // Specify the disconnection handler
    client.OnDisconnection(func() {
        fmt.Println("Disconnected")
    })

    // Specify the login success handler
    client.OnLoginSuccess(func() {
        fmt.Println("Successfully logged in")

        // Subscribe to some symbols
        client.SubscribeTo(symbols)

        // Subscribe to all symbols
        client.SubscribeToAll()
    })

    // Specify the connection handler
    client.OnConnection(func() {
        fmt.Println("Connected")
    })

    // Connect to the socket server
    client.Connect()

    // Wait 25 seconds
    time.Sleep(25 * time.Second)

    // Unsubscribe from some symbols
    client.UnsubscribeFrom(symbols)

    // Unsubscribe from all symbols
    client.UnsubscribeFromAll()

    // Disconnect
    client.Disconnect()
}

RESTful API

func main() {
    client := Forex.CreateClient("YOUR_API_KEY")

    // Get the list of symbols
    symbols, e := client.GetSymbols()

    if e != nil {
        log.Fatal(e)
    }

    // Gets quotes
    quotes, e := client.GetQuotes(symbols)

    if e != nil {
        log.Fatal(e)
    }

    fmt.Println(quotes)

    // Convert currencies
    conversion, e := client.Convert("EUR", "USD", 100)
    if e != nil {
        log.Fatal(e)
    }

    fmt.Println(conversion.Value)
    fmt.Println(conversion.Text)
    fmt.Println(conversion.Timestamp)

    // Get the market status
    marketStatus, e := client.GetMarketStatus()

    if e != nil {
        log.Fatal(e)
    }

    fmt.Println("Is the market open?", marketStatus.MarketIsOpen)

    // Get current quota
    quota, e := client.GetQuota()

    if e != nil {
        log.Fatal(e)
    }

    fmt.Println("Quota used", quota.QuotaUsed)
    fmt.Println("Quota limit", quota.QuotaLimit)
    fmt.Println("Quota remaining", quota.QuotaRemaining)
    fmt.Println("Hours until reset", quota.HoursUntilReset)
}

Support and Contact

Please contact me at [email protected] if you have any questions or requests.

License and Terms

This library is provided without warranty under the MIT license.