Giter Club home page Giter Club logo

golang-forex-quotes's Introduction

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.

golang-forex-quotes's People

Contributors

aditi-mi avatar bricktownseo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

golang-forex-quotes's Issues

Unexpected JSON responses unhandled

If the server returns an un-expected JSON response, its not properly unmarshaled. An example of such response:

{"error":true,"message":"We are unable to convert the price for the given currencies. If you need help, please email [email protected]"}

Incorrect URL in RestClient

Using the package as is the URL in the RestClient is http://forex.1forge.com/1.0.3/, this does not work for me, shouldn't it be https://api.1forge.com/?

No support for checking quota

Because quota_remaining is sometimes an integer (eg: 1,000) and sometimes a string (eg: "unlimited") I am unsure how to unmarshal it properly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.