Merge bfxapi.rest.types and bfxapi.websocket.types in bfxapi.tests sub-package.

This commit is contained in:
Davide Casale
2023-04-20 03:44:13 +02:00
parent 34a1b0099e
commit 0f9fa1bf6a
32 changed files with 164 additions and 759 deletions

View File

@@ -0,0 +1,19 @@
# python -c "import examples.rest.authenticated.claim_position"
import os
from bfxapi import Client, REST_HOST
from bfxapi.types import Notification, PositionClaim
bfx = Client(
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
# Claims all active positions
for position in bfx.rest.auth.get_positions():
notification: Notification[PositionClaim] = bfx.rest.auth.claim_position(position.position_id)
claim: PositionClaim = notification.data
print(f"Position: {position} | PositionClaim: {claim}")

View File

@@ -0,0 +1,45 @@
# python -c "import examples.rest.authenticated.get_wallets"
import os
from typing import List
from bfxapi import Client, REST_HOST
from bfxapi.types import Wallet, Transfer, DepositAddress, \
LightningNetworkInvoice, Withdrawal, Notification
bfx = Client(
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
# Gets all user's available wallets
wallets: List[Wallet] = bfx.rest.auth.get_wallets()
# Transfers funds (0.001 ETH) from exchange wallet to funding wallet
A: Notification[Transfer] = bfx.rest.auth.transfer_between_wallets(
from_wallet="exchange", to_wallet="funding", currency="ETH",
currency_to="ETH", amount=0.001)
print("Transfer:", A.data)
# Retrieves the deposit address for bitcoin currency in exchange wallet.
B: Notification[DepositAddress] = bfx.rest.auth.get_deposit_address(
wallet="exchange", method="bitcoin", renew=False)
print("Deposit address:", B.data)
# Generates a lightning network deposit invoice
C: Notification[LightningNetworkInvoice] = bfx.rest.auth.generate_deposit_invoice(
wallet="funding", currency="LNX", amount=0.001)
print("Lightning network invoice:", C.data)
# Withdraws 1.0 UST from user's exchange wallet to address 0x742d35Cc6634C0532925a3b844Bc454e4438f44e
D: Notification[Withdrawal] = bfx.rest.auth.submit_wallet_withdrawal(
wallet="exchange", method="tetheruse", address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
amount=1.0)
print("Withdrawal:", D.data)

View File

@@ -0,0 +1,36 @@
# python -c "import examples.rest.authenticated.set_derivatives_position_collateral"
import os
from bfxapi import Client, REST_HOST
from bfxapi.types import DerivativePositionCollateral, DerivativePositionCollateralLimits
bfx = Client(
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
submit_order_notification = bfx.rest.auth.submit_order(
type="LIMIT",
symbol="tBTCF0:USTF0",
amount="0.015",
price="16700",
lev=10
)
print("New Order:", submit_order_notification.data)
# Update the amount of collateral for tBTCF0:USTF0 derivative position
derivative_position_collateral: DerivativePositionCollateral = \
bfx.rest.auth.set_derivative_position_collateral(symbol="tBTCF0:USTF0", collateral=50.0)
print("Status:", bool(derivative_position_collateral.status))
# Calculate the minimum and maximum collateral that can be assigned to tBTCF0:USTF0.
derivative_position_collateral_limits: DerivativePositionCollateralLimits = \
bfx.rest.auth.get_derivative_position_collateral_limits(symbol="tBTCF0:USTF0")
print(f"Minimum collateral: {derivative_position_collateral_limits.min_collateral} | " \
f"Maximum collateral: {derivative_position_collateral_limits.max_collateral}")

View File

@@ -0,0 +1,30 @@
# python -c "import examples.rest.authenticated.submit_funding_offer"
import os
from bfxapi import Client, REST_HOST
from bfxapi.types import Notification, FundingOffer
from bfxapi.enums import FundingOfferType, Flag
bfx = Client(
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
# Submit a new funding offer
notification: Notification[FundingOffer] = bfx.rest.auth.submit_funding_offer(
type=FundingOfferType.LIMIT,
symbol="fUSD",
amount=123.45,
rate=0.001,
period=2,
flags=Flag.HIDDEN
)
print("Funding Offer notification:", notification)
# Get all fUSD active funding offers
offers = bfx.rest.auth.get_funding_offers(symbol="fUSD")
print("Offers (fUSD):", offers)

View File

@@ -0,0 +1,42 @@
# python -c "import examples.rest.authenticated.submit_order"
import os
from bfxapi import Client, REST_HOST
from bfxapi.types import Notification, Order
from bfxapi.enums import OrderType, Flag
bfx = Client(
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
# Submit a new order
submit_order_notification: Notification[Order] = bfx.rest.auth.submit_order(
type=OrderType.EXCHANGE_LIMIT,
symbol="tBTCUST",
amount=0.015,
price=10000,
flags=Flag.HIDDEN + Flag.OCO + Flag.CLOSE
)
print("Submit order notification:", submit_order_notification)
order: Order = submit_order_notification.data
# Update its amount and its price
update_order_notification: Notification[Order] = bfx.rest.auth.update_order(
id=order.id,
amount=0.020,
price=10150
)
print("Update order notification:", update_order_notification)
# Cancel it by its ID
cancel_order_notification: Notification[Order] = bfx.rest.auth.cancel_order(
id=order.id
)
print("Cancel order notification:", cancel_order_notification)

View File

@@ -0,0 +1,26 @@
# python -c "import examples.rest.authenticated.toggle_keep_funding"
import os
from typing import List
from bfxapi import Client, REST_HOST
from bfxapi.types import FundingLoan, Notification
bfx = Client(
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
loans: List[FundingLoan] = bfx.rest.auth.get_funding_loans(symbol="fUSD")
# Set every loan's keep funding status to <off> (1: <on>, 2: <off>)
notification: Notification[None] = bfx.rest.auth.toggle_keep_funding(
type="loan",
ids=[ loan.id for loan in loans ],
changes={ loan.id: 2 for loan in loans }
)
print("Toggle keep funding notification:", notification)