Coder Social home page Coder Social logo

encryptman / definance Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 10 KB

DeFinance is a Python library designed to abstract exchange APIs and simplify fetching cryptocurrency market data. It currently supports fetching spot prices from Binance, Bitget, and OKX exchange.

License: MIT License

Python 100.00%
api binance bitget crypto cryptocurrency defi exchange finance okx python

definance's Introduction

DeFinance

DeFinance is a Python library designed to abstract the APIs of various cryptocurrency exchanges and fetch cryptocurrency market data. Currently, it supports spot prices in Binance, Bitget, and OKX exchanges. This library simplifies the process of retrieving cryptocurrency price data by providing a unified interface.

Features

  • Fetch spot price data from Binance, Bitget, and OKX.
  • Unified interface to handle data retrieval from multiple exchanges.
  • Automatic fallback mechanism to fetch data from other exchanges if the symbol is not found in one of the exchange.

Installation

To install DeFinance, you can use pip:

pip install definance

Usage

Here's a quick example of how to use DeFinance to fetch cryptocurrency price data:

Importing the Library

from definance import fetch_price_data, Exchange

Fetching Price Data from a Specific Exchange

To fetch price data from a specific exchange, you can specify the exchange as an argument:

price_data = fetch_price_data('BTC/USDT', Exchange.BINANCE)
print(price_data)

Fetching Price Data from Any Exchange

If you do not specify an exchange, DeFinance will attempt to fetch the data from all supported exchanges in the following order: Binance, Bitget, and OKX.

price_data = fetch_price_data('BTC/USDT')
print(price_data)

Handling Symbol Not Found

If the symbol is not found in any of the exchanges, an exception will be raised:

from definance.exceptions import SymbolNotFound

try:
    price_data = fetch_price_data('INVALID_SYMBOL')
except SymbolNotFound as e:
    print(e)

API Reference

fetch_price_data(symbol: str, exchange: Exchange = None) -> PriceData

Fetches the cryptocurrency price data from the specified exchange or from all exchanges if none is specified.

Arguments

  • symbol (str): The symbol of the cryptocurrency. Example: 'BTC/USDT', 'ETH/BTC', 'BTC'.
  • exchange (Exchange, optional): The exchange to fetch the data from. If None, the function will try to fetch the data from all exchanges.

Returns

  • PriceData: The price data object containing the fetched price data.

Supported Exchanges

  • Exchange.BINANCE
  • Exchange.BITGET
  • Exchange.OKX

Contributing

Contributions are welcome! If you'd like to contribute to DeFinance, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Make your changes.
  4. Submit a pull request.

License

DeFinance is released under the MIT License. See the LICENSE file for more details.

Contact

For any questions or inquiries, please contact [email protected].

definance's People

Contributors

encryptman avatar

Stargazers

 avatar

Watchers

 avatar

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.