Skip to content

Commit

Permalink
HitBTC examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nardew committed Aug 30, 2020
1 parent ed7cfa6 commit 5e0c41a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 84 deletions.
82 changes: 8 additions & 74 deletions examples/hitbtc_rest_apy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from cryptoxlib.CryptoXLib import CryptoXLib
from cryptoxlib.Pair import Pair
from cryptoxlib.clients.bitpanda.exceptions import BitpandaException
from cryptoxlib.clients.bitpanda.enums import OrderSide, TimeUnit

LOG = logging.getLogger("cryptoxlib")
LOG.setLevel(logging.DEBUG)
Expand All @@ -19,83 +17,19 @@ async def order_book_update(response: dict) -> None:
print(f"Callback order_book_update: [{response}]")

async def run():
api_key = os.environ['BITPANDAAPIKEY']
api_key = os.environ['HITBTCAPIKEY']
sec_key = os.environ['HITBTCSECKEY']

client = CryptoXLib.create_bitpanda_client(api_key)

print("Time:")
response = await client.get_time()
print(f"Headers: {response['headers']}")
client = CryptoXLib.create_hitbtc_client(api_key, sec_key)

print("Account balance:")
await client.get_account_balances()

print("Account orders:")
await client.get_account_orders()

print("Account order:")
try:
await client.get_account_order("1")
except BitpandaException as e:
print(e)

print("Create market order:")
try:
await client.create_market_order(Pair("BTC", "EUR"), OrderSide.BUY, "10000")
except BitpandaException as e:
print(e)

print("Create limit order:")
try:
await client.create_limit_order(Pair("BTC", "EUR"), OrderSide.BUY, "10000", "1")
except BitpandaException as e:
print(e)

print("Create stop loss order:")
try:
await client.create_stop_limit_order(Pair("BTC", "EUR"), OrderSide.BUY, "10000", "1", "1")
except BitpandaException as e:
print(e)

print("Delete order:")
try:
await client.delete_account_order("1")
except BitpandaException as e:
print(e)

print("Order trades:")
try:
await client.get_account_order_trades("1")
except BitpandaException as e:
print(e)

print("Trades:")
await client.get_account_trades()

print("Trade:")
try:
await client.get_account_trade("1")
except BitpandaException as e:
print(e)

print("Trading volume:")
await client.get_account_trading_volume()

print("Currencies:")
await client.get_currencies()

print("Candlesticks:")
await client.get_candlesticks(Pair("BTC", "EUR"), TimeUnit.DAYS, "1",
datetime.datetime.now() - datetime.timedelta(days = 7), datetime.datetime.now())

print("Fees:")
await client.get_account_fees()
await client.get_balance()

print("Instruments:")
await client.get_instruments()
print("Symbols:")
await client.get_symbols()

print("Order book:")
await client.get_order_book(Pair("BTC", "EUR"))
print("Orderbook:")
await client.get_order_book(pair = Pair("ETH", "BTC"), limit = 2)

await client.close()

Expand Down
24 changes: 14 additions & 10 deletions examples/hitbtc_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

from cryptoxlib.CryptoXLib import CryptoXLib
from cryptoxlib.Pair import Pair
from cryptoxlib.clients.bitpanda.enums import TimeUnit
from cryptoxlib.clients.bitpanda.BitpandaWebsocket import AccountSubscription, PricesSubscription, \
OrderbookSubscription, CandlesticksSubscription, CandlesticksSubscriptionParams, MarketTickerSubscription
from cryptoxlib.clients.hitbtc.HitbtcWebsocket import TickerSubscription, OrderbookSubscription, TradesSubscription, \
AccountSubscription

LOG = logging.getLogger("cryptoxlib")
LOG.setLevel(logging.DEBUG)
Expand All @@ -18,24 +17,29 @@
async def order_book_update(response: dict) -> None:
print(f"Callback order_book_update: [{response}]")

async def ticker_update(response: dict) -> None:
print(f"Callback ticker_update: [{response}]")

async def trade_update(response: dict) -> None:
print(f"Callback trade_update: [{response}]")


async def run():
api_key = os.environ['BITPANDAAPIKEY']
api_key = os.environ['HITBTCAPIKEY']
sec_key = os.environ['HITBTCSECKEY']

client = CryptoXLib.create_bitpanda_client(api_key)
client = CryptoXLib.create_hitbtc_client(api_key, sec_key)

# Bundle several subscriptions into a single websocket
client.compose_subscriptions([
AccountSubscription(),
PricesSubscription([Pair("BTC", "EUR")]),
OrderbookSubscription([Pair("BTC", "EUR")], "50", callbacks = [order_book_update]),
CandlesticksSubscription([CandlesticksSubscriptionParams(Pair("BTC", "EUR"), TimeUnit.MINUTES, 1)]),
MarketTickerSubscription([Pair("BTC", "EUR")])
OrderbookSubscription(pair = Pair("BTC", "USD"), callbacks = [order_book_update]),
TickerSubscription(pair = Pair("BTC", "USD"), callbacks = [ticker_update])
])

# Bundle another subscriptions into a separate websocket
client.compose_subscriptions([
OrderbookSubscription([Pair("ETH", "EUR")], "3", callbacks = [order_book_update]),
TradesSubscription(pair = Pair("ETH", "BTC"), limit = 5,callbacks = [trade_update])
])

# Execute all websockets asynchronously
Expand Down

0 comments on commit 5e0c41a

Please sign in to comment.