Skip to main content

This is a library that works as a connector to Apifiny OPEN API.

Project description

Apifiny OPEN API Connector Python

GitHub issues GitHub forks GitHub stars GitHub license contributors PyPI PyPI - Python Version Downloads

This is a library that works as a connector to APIFINY OPEN API

  • Supported APIs:
  • REST trading/market API
  • WebSocket trading/market API

OPEN API Documentation

https://doc.apifiny.com/connect/#introduction

Install

pip3 install apifiny

Use windows, installing quickfix fails,Please use the link to download the file and install locally. https://www.lfd.uci.edu/~gohlke/pythonlibs/#quickfix

RESTful APIs

Usage examples:

Get all supported exchanges

from apifiny.rest_api import API as Client

client = Client()
print(client.list_venue())

Get Market Data

from apifiny.rest_market import MarketData as MD_Client

md_client = MD_Client()
# Get BINANCE orderbook of BTCUSDT
print(md_client.market_order_book("BINANCE", "BTCUSDT"))
# Get BINANCE klines of BTCUSDT at 1m interval
print(md_client.market_kline("BINANCE", "BTC", "USDT", "1m"))

Create Order

from apifiny.rest_api import API as Client
from apifiny.lib import venue_list

client = Client(venue_list.BINANCE)

# Get server timestamp
print(client.server_time())

# api_key_id/secret_key are required for trade endpoints
client = Client(venue="BINANCE", key='<api_key_id>', secret='<secret_key>')

# Post a new order
params = {
    "accountId": '<account_id>',
    "venue": "BINANCE",
    "orderId": "",
    "orderInfo": {
        "limitPrice": "30000",
        "orderSide": "BUY",
        "orderType": "LIMIT",
        "quantity": "0.0001",
        "symbol": "BTCUSDT",
        "timeInForce": 1,
    }
}

response = client.new_order(**params)
print(response)

Access sandbox environment

from apifiny.rest_api import API as Client

client = Client(test=True)
print(client.list_venue())

WebSocket APIs

Usage examples:

Subscribe Market Data

from apifiny.ac_websocket import ACSpotApi as Client

# Get BINANCE orderbook of BTCUSDT
msg = {"channel": "orderbook", "symbol": 'BTCUSDT', "venues": ["BINANCE"], "action": "sub"}
# Get BINANCE klines of BTCUSDT at 1m interval
# msg = {"channel": "kline_1m", "symbol": "BTCUSDT", "venues": ["BINANCE"], "action": "sub"}
# client = Client(test=True) # test=True,Access sandbox environment
client = Client()
client.connect(md=True)
client.send_msg(msg)

Create Order

from apifiny.ac_websocket import ACSpotApi as Client

# Post a new order
params = {
    "accountId": '<account_id>',
    "venue": "BINANCE",
    "orderId": "",
    "orderInfo": {
        "limitPrice": "30000",
        "orderSide": "BUY",
        "orderType": "LIMIT",
        "quantity": "0.0001",
        "symbol": "BTCUSDT",
        "timeInForce": 1,
    }
}
# api_key_id/secret_key are required for trade endpoints
client = Client(venue="BINANCE")
client.connect()
client.login(api_key_id, secret_key)
client.new_order(**params)
# client.close()

Please find examples folder to check for more endpoints.

Contributing

Contributions are welcome.
If you've found a bug within this project, please open an issue to discuss what you would like to change.
If it's an issue with the API, please report any new issues at apifiny-connector-python issues

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

apifiny-1.2.1-py3-none-any.whl (10.8 kB view hashes)

Uploaded Python 3

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