mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-24 01:04:22 +01:00
Rewrite all rest examples according to v3.0.0b3's changes.
This commit is contained in:
@@ -2,18 +2,18 @@
|
||||
|
||||
import os
|
||||
|
||||
from bfxapi import Client, REST_HOST
|
||||
|
||||
from bfxapi import Client
|
||||
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)
|
||||
notification: Notification[PositionClaim] = bfx.rest.auth.claim_position(
|
||||
position.position_id
|
||||
)
|
||||
claim: PositionClaim = notification.data
|
||||
print(f"Position: {position} | PositionClaim: {claim}")
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
# python -c "import examples.rest.auth.get_wallets"
|
||||
|
||||
import os
|
||||
|
||||
from typing import List
|
||||
|
||||
from bfxapi import Client, REST_HOST
|
||||
|
||||
from bfxapi.types import Wallet, Transfer, DepositAddress, \
|
||||
LightningNetworkInvoice, Withdrawal, Notification
|
||||
from bfxapi import Client
|
||||
from bfxapi.types import (
|
||||
DepositAddress,
|
||||
LightningNetworkInvoice,
|
||||
Notification,
|
||||
Transfer,
|
||||
Wallet,
|
||||
Withdrawal,
|
||||
)
|
||||
|
||||
bfx = Client(
|
||||
rest_host=REST_HOST,
|
||||
api_key=os.getenv("BFX_API_KEY"),
|
||||
api_secret=os.getenv("BFX_API_SECRET")
|
||||
)
|
||||
@@ -20,26 +23,35 @@ 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)
|
||||
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)
|
||||
wallet="exchange", method="bitcoin", op_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)
|
||||
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
|
||||
# Withdraws 1.0 UST from user's exchange wallet to address 0x742d35...
|
||||
D: Notification[Withdrawal] = bfx.rest.auth.submit_wallet_withdrawal(
|
||||
wallet="exchange", method="tetheruse", address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
||||
amount=1.0)
|
||||
wallet="exchange",
|
||||
method="tetheruse",
|
||||
address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
||||
amount=1.0,
|
||||
)
|
||||
|
||||
print("Withdrawal:", D.data)
|
||||
|
||||
@@ -1,36 +1,39 @@
|
||||
# python -c "import examples.rest.auth.set_derivatives_position_collateral"
|
||||
# python -c "import examples.rest.auth.set_derivative_position_collateral"
|
||||
|
||||
import os
|
||||
|
||||
from bfxapi import Client, REST_HOST
|
||||
|
||||
from bfxapi.types import DerivativePositionCollateral, DerivativePositionCollateralLimits
|
||||
from bfxapi import Client
|
||||
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
|
||||
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)
|
||||
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 = \
|
||||
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}")
|
||||
print(
|
||||
f"Minimum collateral: {derivative_position_collateral_limits.min_collateral} | "
|
||||
f"Maximum collateral: {derivative_position_collateral_limits.max_collateral}"
|
||||
)
|
||||
|
||||
@@ -2,24 +2,17 @@
|
||||
|
||||
import os
|
||||
|
||||
from bfxapi import Client, REST_HOST
|
||||
from bfxapi.types import Notification, FundingOffer
|
||||
from bfxapi.enums import FundingOfferType, Flag
|
||||
from bfxapi import Client
|
||||
from bfxapi.types import FundingOffer, Notification
|
||||
|
||||
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
|
||||
type="LIMIT", symbol="fUSD", amount=123.45, rate=0.001, period=2
|
||||
)
|
||||
|
||||
print("Funding Offer notification:", notification)
|
||||
|
||||
@@ -2,23 +2,17 @@
|
||||
|
||||
import os
|
||||
|
||||
from bfxapi import Client, REST_HOST
|
||||
from bfxapi import Client
|
||||
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
|
||||
type="EXCHANGE LIMIT", symbol="tBTCUST", amount=0.015, price=10000
|
||||
)
|
||||
|
||||
print("Submit order notification:", submit_order_notification)
|
||||
@@ -27,16 +21,12 @@ 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
|
||||
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
|
||||
)
|
||||
cancel_order_notification: Notification[Order] = bfx.rest.auth.cancel_order(id=order.id)
|
||||
|
||||
print("Cancel order notification:", cancel_order_notification)
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
# python -c "import examples.rest.auth.toggle_keep_funding"
|
||||
|
||||
import os
|
||||
|
||||
from typing import List
|
||||
|
||||
from bfxapi import Client, REST_HOST
|
||||
|
||||
from bfxapi import Client
|
||||
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")
|
||||
)
|
||||
@@ -18,9 +15,7 @@ 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 }
|
||||
type="loan", ids=[loan.id for loan in loans], changes={loan.id: 2 for loan in loans}
|
||||
)
|
||||
|
||||
print("Toggle keep funding notification:", notification)
|
||||
|
||||
Reference in New Issue
Block a user