This is a library that works as a connector to Apifiny OPEN API.
Project description
Apifiny OPEN API Connector Python
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
Built Distribution
File details
Details for the file apifiny-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: apifiny-1.2.1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.26.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 590f833e9fa533f0b78308977f7055341ffc2d738402fa35aeb9935414a89e4b |
|
MD5 | 791c0c0aa117b643a67c7146ad75c830 |
|
BLAKE2b-256 | 69d5001cd68edee7cb3f7efcb93de5440813a5e60e5354567e65a151c0dbbe8d |