mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-20 15:24:21 +01:00
examples.rest: create public and auth examples
This commit is contained in:
59
bfxapi/examples/rest/get_authenticated_data.py
Normal file
59
bfxapi/examples/rest/get_authenticated_data.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
import time
|
||||
sys.path.append('../')
|
||||
|
||||
from bfxapi import Client
|
||||
|
||||
API_KEY=os.getenv("BFX_KEY")
|
||||
API_SECRET=os.getenv("BFX_SECRET")
|
||||
|
||||
bfx = Client(
|
||||
API_KEY=API_KEY,
|
||||
API_SECRET=API_SECRET,
|
||||
logLevel='DEBUG',
|
||||
rest_host='https://test.bitfinex.com/v2'
|
||||
)
|
||||
|
||||
async def log_wallets():
|
||||
wallets = await bfx.rest.get_wallets()
|
||||
print ("Wallets:")
|
||||
[ print (w) for w in wallets ]
|
||||
|
||||
async def log_active_orders():
|
||||
orders = await bfx.rest.get_active_orders('tBTCUSD')
|
||||
print ("Orders:")
|
||||
[ print (o) for o in orders ]
|
||||
|
||||
async def log_orders_history():
|
||||
now = int(round(time.time() * 1000))
|
||||
then = now - (1000 * 60 * 60 * 24 * 10) # 10 days ago
|
||||
|
||||
orders = await bfx.rest.get_order_history('tBTCUSD', 0, then)
|
||||
print ("Orders:")
|
||||
[ print (o) for o in orders ]
|
||||
|
||||
async def log_active_positions():
|
||||
positions = await bfx.rest.get_active_position()
|
||||
print ("Positions:")
|
||||
[ print (p) for p in positions ]
|
||||
|
||||
async def log_trades():
|
||||
now = int(round(time.time() * 1000))
|
||||
then = now - (1000 * 60 * 60 * 24 * 10) # 10 days ago
|
||||
|
||||
trades = await bfx.rest.get_trades('tBTCUSD', 0, then)
|
||||
print ("Trades")
|
||||
[ print (t) for t in trades]
|
||||
|
||||
async def run():
|
||||
await log_wallets()
|
||||
await log_active_orders()
|
||||
await log_orders_history()
|
||||
await log_active_positions()
|
||||
await log_trades()
|
||||
|
||||
|
||||
t = asyncio.ensure_future(run())
|
||||
asyncio.get_event_loop().run_until_complete(t)
|
||||
44
bfxapi/examples/rest/get_public_data.py
Normal file
44
bfxapi/examples/rest/get_public_data.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
import time
|
||||
sys.path.append('../')
|
||||
|
||||
from bfxapi import Client
|
||||
|
||||
bfx = Client(
|
||||
logLevel='DEBUG',
|
||||
rest_host='https://test.bitfinex.com/v2'
|
||||
)
|
||||
|
||||
now = int(round(time.time() * 1000))
|
||||
then = now - (1000 * 60 * 60 * 24 * 10) # 10 days ago
|
||||
|
||||
async def log_historical_candles():
|
||||
candles = await bfx.rest.get_public_candles('tBTCUSD', 0, then)
|
||||
print ("Candles:")
|
||||
[ print (c) for c in candles ]
|
||||
|
||||
async def log_historical_trades():
|
||||
trades = await bfx.rest.get_public_trades('tBTCUSD', 0, then)
|
||||
print ("Trades:")
|
||||
[ print (t) for t in trades ]
|
||||
|
||||
async def log_books():
|
||||
orders = await bfx.rest.get_public_books('tBTCUSD')
|
||||
print ("Order book:")
|
||||
[ print (o) for o in orders ]
|
||||
|
||||
async def log_ticker():
|
||||
ticker = await bfx.rest.get_public_ticker('tBTCUSD')
|
||||
print ("Ticker:")
|
||||
print (ticker)
|
||||
|
||||
async def run():
|
||||
await log_historical_candles()
|
||||
await log_historical_trades()
|
||||
await log_books()
|
||||
await log_ticker()
|
||||
|
||||
t = asyncio.ensure_future(run())
|
||||
asyncio.get_event_loop().run_until_complete(t)
|
||||
@@ -1,23 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
sys.path.append('../')
|
||||
|
||||
from bfxapi import Client
|
||||
|
||||
API_KEY=os.getenv("BFX_KEY")
|
||||
API_SECRET=os.getenv("BFX_SECRET")
|
||||
|
||||
bfx = Client(
|
||||
API_KEY='zxXi3z6eMnRuW2mjvJSlJ08aqlHDCZbcKlqXWnzdXtF',
|
||||
API_SECRET='WL6hp6eVboiTW0dYfvIpTrX8HFPioumBoJ1w1FbAEgF',
|
||||
logLevel='DEBUG',
|
||||
rest_host='https://test.bitfinex.com/v2'
|
||||
)
|
||||
|
||||
async def log_wallets():
|
||||
wallets = await bfx.rest.get_wallets()
|
||||
print (wallets)
|
||||
|
||||
t = asyncio.ensure_future(log_wallets())
|
||||
asyncio.get_event_loop().run_until_complete(t)
|
||||
Reference in New Issue
Block a user