Skip to main content

Python wrapper for Bitfinex API v1 and v2

Project description

pyfinex

Python wrapper for Bitfinex API.

Dependencies

Requests library is required.

Usage

Include the pyfinex module and use it as a toolbox. For trading, a key and a secret key must be provided.

import pyfinex

API_KEY = 'insert key'
API_SECRET = 'insert secret'

resp = pyfinex.v1.positions.active(key=API_KEY, secret_key=API_SECRET)
resp = pyfinex.v1.public.ticker(symbol='btcusd')

Function names are organized for better coding

Function names are referred in part to the api doc's html, which you can see Bitfinex API web page. Required params to build the request's url are coded in the function's args, other query params are to be added acording to api doc

BEWARE: some inputs varies from v1 to v2. Example: v1>> 'BTCUSD' v2>> 'tBTCUSD'

All documented API calls are implemented!

Examples

Get the latest BTCUSD price

resp = pyfinex.v1.public.ticker(symbol='btcusd')

View your active orders

resp = pyfinex.v1.positions.active(API_KEY,API_SECRET)

Get the BTCUSD order book

resp = pyfinex.v1.public.order_book(symbol='btcusd')

Get the last BTCUSD 1m candle

resp = pyfinex.v2.public.candles(Symbol='tBTCUSD', TimeFrame='1m', Section='last')

Note: in v2 the parameters are capital case.

Submit a new order

For example, if you'd like to buy 0.001 BTC as 0.01 BTC/USD, you need to specify the parameters acording to the api doc. You may parse the response to get the order id for future use.

resp = pyfinex.v1.orders.new(symbol="BTCUSD", amount=0.001, price=0.01, side='buy', type='market')

In case there is a new call you can do it yourself!:

pyfinex.api.request(authenticate=True, 
    key=API_KEY, 
    secret_key=API_SECRET, 
    version=1, 
    endpoint='new/api/call/here', 
    method='POST', 
    body_params={}, 
    query_params={})

Test

  1. Replace your keys in .env.example file, and rename it to .env
  2. Include your unit tests as functions in a test_vX_*.py file
    def test_ticker():
        resp = pyfinex.v1.public.ticker(symbol='btcusd')
        resp['mid']
    
  3. Run the tests using pytest

Known Issues

  • No

TODO

  • Test every endpoint

Contributing

  1. Create an issue and discuss.
  2. Create a feature branch containing only your fix or feature.
  3. Add tests, please!!
  4. Create a pull request.
  5. Thanks!

References

Licence

The MIT License (MIT)

Copyright (c) 2018 faberquisque

See LICENSE.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfinex-1.0.3.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

pyfinex-1.0.3-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file pyfinex-1.0.3.tar.gz.

File metadata

  • Download URL: pyfinex-1.0.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for pyfinex-1.0.3.tar.gz
Algorithm Hash digest
SHA256 18c47120993c215120507443f8f11a6508e2717dfd6c74e0cb891961dc3974eb
MD5 765c1d42bf464640c54861f9d29e733e
BLAKE2b-256 58df68f55ead0dfddccd71a937ef9a42b8c725a8c8bfd4d30cdaa3f1b48d1c06

See more details on using hashes here.

File details

Details for the file pyfinex-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyfinex-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for pyfinex-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a94de96c998923ed119819607b5795983c23fbca4b193770e2a6270c2839531a
MD5 3d8c0ebbc2ff60048ae074c14f02bbe4
BLAKE2b-256 3847552ca6a09a9623ee6a719089c7b4b234e66de0dd3b9788f5245e33940a25

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page