mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-18 22:34:21 +01:00
Rewrite all rest examples according to v3.0.0b3's changes.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from typing import TYPE_CHECKING, Optional, Any
|
from typing import TYPE_CHECKING, Optional, Any
|
||||||
|
|
||||||
from enum import Enum
|
from enum import IntEnum
|
||||||
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ from ..._utils.json_decoder import JSONDecoder
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from requests.sessions import _Params
|
from requests.sessions import _Params
|
||||||
|
|
||||||
class _Error(Enum):
|
class _Error(IntEnum):
|
||||||
ERR_UNK = 10000
|
ERR_UNK = 10000
|
||||||
ERR_GENERIC = 10001
|
ERR_GENERIC = 10001
|
||||||
ERR_PARAMS = 10020
|
ERR_PARAMS = 10020
|
||||||
|
|||||||
@@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bfxapi import Client, REST_HOST
|
from bfxapi import Client
|
||||||
|
|
||||||
from bfxapi.types import Notification, PositionClaim
|
from bfxapi.types import Notification, PositionClaim
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
rest_host=REST_HOST,
|
|
||||||
api_key=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
api_secret=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Claims all active positions
|
# Claims all active positions
|
||||||
for position in bfx.rest.auth.get_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
|
claim: PositionClaim = notification.data
|
||||||
print(f"Position: {position} | PositionClaim: {claim}")
|
print(f"Position: {position} | PositionClaim: {claim}")
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
# python -c "import examples.rest.auth.get_wallets"
|
# python -c "import examples.rest.auth.get_wallets"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from bfxapi import Client, REST_HOST
|
from bfxapi import Client
|
||||||
|
from bfxapi.types import (
|
||||||
from bfxapi.types import Wallet, Transfer, DepositAddress, \
|
DepositAddress,
|
||||||
LightningNetworkInvoice, Withdrawal, Notification
|
LightningNetworkInvoice,
|
||||||
|
Notification,
|
||||||
|
Transfer,
|
||||||
|
Wallet,
|
||||||
|
Withdrawal,
|
||||||
|
)
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
rest_host=REST_HOST,
|
|
||||||
api_key=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
api_secret=os.getenv("BFX_API_SECRET")
|
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
|
# Transfers funds (0.001 ETH) from exchange wallet to funding wallet
|
||||||
A: Notification[Transfer] = bfx.rest.auth.transfer_between_wallets(
|
A: Notification[Transfer] = bfx.rest.auth.transfer_between_wallets(
|
||||||
from_wallet="exchange", to_wallet="funding", currency="ETH",
|
from_wallet="exchange",
|
||||||
currency_to="ETH", amount=0.001)
|
to_wallet="funding",
|
||||||
|
currency="ETH",
|
||||||
|
currency_to="ETH",
|
||||||
|
amount=0.001,
|
||||||
|
)
|
||||||
|
|
||||||
print("Transfer:", A.data)
|
print("Transfer:", A.data)
|
||||||
|
|
||||||
# Retrieves the deposit address for bitcoin currency in exchange wallet.
|
# Retrieves the deposit address for bitcoin currency in exchange wallet.
|
||||||
B: Notification[DepositAddress] = bfx.rest.auth.get_deposit_address(
|
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)
|
print("Deposit address:", B.data)
|
||||||
|
|
||||||
# Generates a lightning network deposit invoice
|
# Generates a lightning network deposit invoice
|
||||||
C: Notification[LightningNetworkInvoice] = bfx.rest.auth.generate_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)
|
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(
|
D: Notification[Withdrawal] = bfx.rest.auth.submit_wallet_withdrawal(
|
||||||
wallet="exchange", method="tetheruse", address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
wallet="exchange",
|
||||||
amount=1.0)
|
method="tetheruse",
|
||||||
|
address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
||||||
|
amount=1.0,
|
||||||
|
)
|
||||||
|
|
||||||
print("Withdrawal:", D.data)
|
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
|
import os
|
||||||
|
|
||||||
from bfxapi import Client, REST_HOST
|
from bfxapi import Client
|
||||||
|
from bfxapi.types import (
|
||||||
from bfxapi.types import DerivativePositionCollateral, DerivativePositionCollateralLimits
|
DerivativePositionCollateral,
|
||||||
|
DerivativePositionCollateralLimits,
|
||||||
|
)
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
rest_host=REST_HOST,
|
|
||||||
api_key=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
api_secret=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
submit_order_notification = bfx.rest.auth.submit_order(
|
submit_order_notification = bfx.rest.auth.submit_order(
|
||||||
type="LIMIT",
|
type="LIMIT", symbol="tBTCF0:USTF0", amount="0.015", price="16700", lev=10
|
||||||
symbol="tBTCF0:USTF0",
|
|
||||||
amount="0.015",
|
|
||||||
price="16700",
|
|
||||||
lev=10
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("New Order:", submit_order_notification.data)
|
print("New Order:", submit_order_notification.data)
|
||||||
|
|
||||||
# Update the amount of collateral for tBTCF0:USTF0 derivative position
|
# Update the amount of collateral for tBTCF0:USTF0 derivative position
|
||||||
derivative_position_collateral: DerivativePositionCollateral = \
|
derivative_position_collateral: DerivativePositionCollateral = (
|
||||||
bfx.rest.auth.set_derivative_position_collateral(symbol="tBTCF0:USTF0", collateral=50.0)
|
bfx.rest.auth.set_derivative_position_collateral(
|
||||||
|
symbol="tBTCF0:USTF0", collateral=50.0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
print("Status:", bool(derivative_position_collateral.status))
|
print("Status:", bool(derivative_position_collateral.status))
|
||||||
|
|
||||||
# Calculate the minimum and maximum collateral that can be assigned to tBTCF0:USTF0.
|
# 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")
|
bfx.rest.auth.get_derivative_position_collateral_limits(symbol="tBTCF0:USTF0")
|
||||||
|
)
|
||||||
|
|
||||||
print(f"Minimum collateral: {derivative_position_collateral_limits.min_collateral} | " \
|
print(
|
||||||
f"Maximum collateral: {derivative_position_collateral_limits.max_collateral}")
|
f"Minimum collateral: {derivative_position_collateral_limits.min_collateral} | "
|
||||||
|
f"Maximum collateral: {derivative_position_collateral_limits.max_collateral}"
|
||||||
|
)
|
||||||
|
|||||||
@@ -2,24 +2,17 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bfxapi import Client, REST_HOST
|
from bfxapi import Client
|
||||||
from bfxapi.types import Notification, FundingOffer
|
from bfxapi.types import FundingOffer, Notification
|
||||||
from bfxapi.enums import FundingOfferType, Flag
|
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
rest_host=REST_HOST,
|
|
||||||
api_key=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
api_secret=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Submit a new funding offer
|
# Submit a new funding offer
|
||||||
notification: Notification[FundingOffer] = bfx.rest.auth.submit_funding_offer(
|
notification: Notification[FundingOffer] = bfx.rest.auth.submit_funding_offer(
|
||||||
type=FundingOfferType.LIMIT,
|
type="LIMIT", symbol="fUSD", amount=123.45, rate=0.001, period=2
|
||||||
symbol="fUSD",
|
|
||||||
amount=123.45,
|
|
||||||
rate=0.001,
|
|
||||||
period=2,
|
|
||||||
flags=Flag.HIDDEN
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Funding Offer notification:", notification)
|
print("Funding Offer notification:", notification)
|
||||||
|
|||||||
@@ -2,23 +2,17 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bfxapi import Client, REST_HOST
|
from bfxapi import Client
|
||||||
from bfxapi.types import Notification, Order
|
from bfxapi.types import Notification, Order
|
||||||
from bfxapi.enums import OrderType, Flag
|
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
rest_host=REST_HOST,
|
|
||||||
api_key=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
api_secret=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Submit a new order
|
# Submit a new order
|
||||||
submit_order_notification: Notification[Order] = bfx.rest.auth.submit_order(
|
submit_order_notification: Notification[Order] = bfx.rest.auth.submit_order(
|
||||||
type=OrderType.EXCHANGE_LIMIT,
|
type="EXCHANGE LIMIT", symbol="tBTCUST", amount=0.015, price=10000
|
||||||
symbol="tBTCUST",
|
|
||||||
amount=0.015,
|
|
||||||
price=10000,
|
|
||||||
flags=Flag.HIDDEN + Flag.OCO + Flag.CLOSE
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Submit order notification:", submit_order_notification)
|
print("Submit order notification:", submit_order_notification)
|
||||||
@@ -27,16 +21,12 @@ order: Order = submit_order_notification.data
|
|||||||
|
|
||||||
# Update its amount and its price
|
# Update its amount and its price
|
||||||
update_order_notification: Notification[Order] = bfx.rest.auth.update_order(
|
update_order_notification: Notification[Order] = bfx.rest.auth.update_order(
|
||||||
id=order.id,
|
id=order.id, amount=0.020, price=10150
|
||||||
amount=0.020,
|
|
||||||
price=10150
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Update order notification:", update_order_notification)
|
print("Update order notification:", update_order_notification)
|
||||||
|
|
||||||
# Cancel it by its ID
|
# Cancel it by its ID
|
||||||
cancel_order_notification: Notification[Order] = bfx.rest.auth.cancel_order(
|
cancel_order_notification: Notification[Order] = bfx.rest.auth.cancel_order(id=order.id)
|
||||||
id=order.id
|
|
||||||
)
|
|
||||||
|
|
||||||
print("Cancel order notification:", cancel_order_notification)
|
print("Cancel order notification:", cancel_order_notification)
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
# python -c "import examples.rest.auth.toggle_keep_funding"
|
# python -c "import examples.rest.auth.toggle_keep_funding"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from bfxapi import Client, REST_HOST
|
from bfxapi import Client
|
||||||
|
|
||||||
from bfxapi.types import FundingLoan, Notification
|
from bfxapi.types import FundingLoan, Notification
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
rest_host=REST_HOST,
|
|
||||||
api_key=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
api_secret=os.getenv("BFX_API_SECRET")
|
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>)
|
# Set every loan's keep funding status to <off> (1: <on>, 2: <off>)
|
||||||
notification: Notification[None] = bfx.rest.auth.toggle_keep_funding(
|
notification: Notification[None] = bfx.rest.auth.toggle_keep_funding(
|
||||||
type="loan",
|
type="loan", ids=[loan.id for loan in loans], changes={loan.id: 2 for loan in loans}
|
||||||
ids=[ loan.id for loan in loans ],
|
|
||||||
changes={ loan.id: 2 for loan in loans }
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Toggle keep funding notification:", notification)
|
print("Toggle keep funding notification:", notification)
|
||||||
|
|||||||
@@ -2,27 +2,28 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bfxapi import Client, REST_HOST
|
from bfxapi import Client
|
||||||
|
|
||||||
from bfxapi.rest.enums import MerchantSettingsKey
|
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
rest_host=REST_HOST,
|
|
||||||
api_key=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
api_secret=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
if not bfx.rest.merchant.set_merchant_settings(MerchantSettingsKey.RECOMMEND_STORE, 1):
|
if not bfx.rest.merchant.set_merchant_settings("bfx_pay_recommend_store", 1):
|
||||||
print(f"Cannot set <{MerchantSettingsKey.RECOMMEND_STORE}> to <1>.")
|
print("Cannot set <bfx_pay_recommend_store> to <1>.")
|
||||||
|
|
||||||
print(f"The current <{MerchantSettingsKey.PREFERRED_FIAT}> value is:",
|
print(
|
||||||
bfx.rest.merchant.get_merchant_settings(MerchantSettingsKey.PREFERRED_FIAT))
|
"The current <bfx_pay_preferred_fiat> value is:",
|
||||||
|
bfx.rest.merchant.get_merchant_settings("bfx_pay_preferred_fiat"),
|
||||||
|
)
|
||||||
|
|
||||||
settings = bfx.rest.merchant.list_merchant_settings([
|
settings = bfx.rest.merchant.list_merchant_settings(
|
||||||
MerchantSettingsKey.DUST_BALANCE_UI,
|
[
|
||||||
MerchantSettingsKey.MERCHANT_CUSTOMER_SUPPORT_URL,
|
"bfx_pay_dust_balance_ui",
|
||||||
MerchantSettingsKey.MERCHANT_UNDERPAID_THRESHOLD
|
"bfx_pay_merchant_customer_support_url",
|
||||||
])
|
"bfx_pay_merchant_underpaid_threshold",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
for key, value in settings.items():
|
for key, value in settings.items():
|
||||||
print(f"<{key}>:", value)
|
print(f"<{key}>:", value)
|
||||||
|
|||||||
@@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bfxapi import Client, REST_HOST
|
from bfxapi import Client
|
||||||
|
|
||||||
from bfxapi.types import InvoiceSubmission
|
from bfxapi.types import InvoiceSubmission
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
rest_host=REST_HOST,
|
|
||||||
api_key=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
api_secret=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
@@ -20,7 +18,7 @@ customer_info = {
|
|||||||
"residStreet": "5-6 Leicester Square",
|
"residStreet": "5-6 Leicester Square",
|
||||||
"residBuildingNo": "23 A",
|
"residBuildingNo": "23 A",
|
||||||
"fullName": "John Doe",
|
"fullName": "John Doe",
|
||||||
"email": "john@example.com"
|
"email": "john@example.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
invoice: InvoiceSubmission = bfx.rest.merchant.submit_invoice(
|
invoice: InvoiceSubmission = bfx.rest.merchant.submit_invoice(
|
||||||
@@ -29,17 +27,19 @@ invoice: InvoiceSubmission = bfx.rest.merchant.submit_invoice(
|
|||||||
order_id="test",
|
order_id="test",
|
||||||
customer_info=customer_info,
|
customer_info=customer_info,
|
||||||
pay_currencies=["ETH"],
|
pay_currencies=["ETH"],
|
||||||
duration=86400 * 10
|
duration=86400,
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Invoice submission:", invoice)
|
print("Invoice submission:", invoice)
|
||||||
|
|
||||||
print(bfx.rest.merchant.complete_invoice(
|
print(
|
||||||
id=invoice.id,
|
bfx.rest.merchant.complete_invoice(id=invoice.id, pay_currency="ETH", deposit_id=1)
|
||||||
pay_currency="ETH",
|
)
|
||||||
deposit_id=1
|
|
||||||
))
|
|
||||||
|
|
||||||
print(bfx.rest.merchant.get_invoices(limit=25))
|
print(bfx.rest.merchant.get_invoices(limit=25))
|
||||||
|
|
||||||
print(bfx.rest.merchant.get_invoices_paginated(page=1, page_size=60, sort="asc", sort_field="t"))
|
print(
|
||||||
|
bfx.rest.merchant.get_invoices_paginated(
|
||||||
|
page=1, page_size=60, sort="asc", sort_field="t"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -2,14 +2,19 @@
|
|||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from bfxapi import Client, PUB_REST_HOST
|
from bfxapi import Client
|
||||||
|
from bfxapi.types import (
|
||||||
|
FundingCurrencyBook,
|
||||||
|
FundingCurrencyRawBook,
|
||||||
|
TradingPairBook,
|
||||||
|
TradingPairRawBook,
|
||||||
|
)
|
||||||
|
|
||||||
from bfxapi.types import TradingPairBook, TradingPairRawBook, \
|
bfx = Client()
|
||||||
FundingCurrencyBook, FundingCurrencyRawBook
|
|
||||||
|
|
||||||
bfx = Client(rest_host=PUB_REST_HOST)
|
t_book: List[TradingPairBook] = bfx.rest.public.get_t_book(
|
||||||
|
"tBTCUSD", precision="P0", len=25
|
||||||
t_book: List[TradingPairBook] = bfx.rest.public.get_t_book("tBTCUSD", precision="P0", len=25)
|
)
|
||||||
|
|
||||||
print("25 price points of tBTCUSD order book (with precision P0):", t_book)
|
print("25 price points of tBTCUSD order book (with precision P0):", t_book)
|
||||||
|
|
||||||
@@ -17,7 +22,9 @@ t_raw_book: List[TradingPairRawBook] = bfx.rest.public.get_t_raw_book("tBTCUSD")
|
|||||||
|
|
||||||
print("tBTCUSD raw order book:", t_raw_book)
|
print("tBTCUSD raw order book:", t_raw_book)
|
||||||
|
|
||||||
f_book: List[FundingCurrencyBook] = bfx.rest.public.get_f_book("fUSD", precision="P0", len=25)
|
f_book: List[FundingCurrencyBook] = bfx.rest.public.get_f_book(
|
||||||
|
"fUSD", precision="P0", len=25
|
||||||
|
)
|
||||||
|
|
||||||
print("25 price points of fUSD order book (with precision P0):", f_book)
|
print("25 price points of fUSD order book (with precision P0):", f_book)
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
# python -c "import examples.rest.public.conf"
|
# python -c "import examples.rest.public.conf"
|
||||||
|
|
||||||
from bfxapi import Client, PUB_REST_HOST
|
from bfxapi import Client
|
||||||
|
|
||||||
from bfxapi.rest.enums import Config
|
bfx = Client()
|
||||||
|
|
||||||
bfx = Client(rest_host=PUB_REST_HOST)
|
# Prints a map from symbols to their API symbols
|
||||||
|
print(bfx.rest.public.conf("pub:map:currency:sym"))
|
||||||
|
|
||||||
print("Available configs:", [ config.value for config in Config ])
|
# Prints all the available exchange trading pairs
|
||||||
|
print(bfx.rest.public.conf("pub:list:pair:exchange"))
|
||||||
|
|
||||||
# Prints a map from symbols to their API symbols (pub:map:currency:sym)
|
# Prints all the available funding currencies
|
||||||
print (bfx.rest.public.conf(Config.MAP_CURRENCY_SYM))
|
print(bfx.rest.public.conf("pub:list:currency"))
|
||||||
|
|
||||||
# Prints all the available exchange trading pairs (pub:list:pair:exchange)
|
|
||||||
print(bfx.rest.public.conf(Config.LIST_PAIR_EXCHANGE))
|
|
||||||
|
|
||||||
# Prints all the available funding currencies (pub:list:currency)
|
|
||||||
print(bfx.rest.public.conf(Config.LIST_CURRENCY))
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
# python -c "import examples.rest.public.get_candles_hist"
|
# python -c "import examples.rest.public.get_candles_hist"
|
||||||
|
|
||||||
from bfxapi import Client, PUB_REST_HOST
|
from bfxapi import Client
|
||||||
|
|
||||||
bfx = Client(rest_host=PUB_REST_HOST)
|
bfx = Client()
|
||||||
|
|
||||||
print(f"Candles: {bfx.rest.public.get_candles_hist(symbol='tBTCUSD')}")
|
print(f"Candles: {bfx.rest.public.get_candles_hist(symbol='tBTCUSD')}")
|
||||||
|
|
||||||
# Be sure to specify a period or aggregated period when retrieving funding candles.
|
# Be sure to specify a period or aggregated period when retrieving funding candles.
|
||||||
# If you wish to mimic the candles found in the UI, use the following setup to aggregate all funding candles: a30:p2:p30
|
# If you wish to mimic the candles found in the UI, use the following setup
|
||||||
print(f"Candles: {bfx.rest.public.get_candles_hist(tf='15m', symbol='fUSD:a30:p2:p30')}")
|
# to aggregate all funding candles: a30:p2:p30
|
||||||
|
print(
|
||||||
|
f"Candles: {bfx.rest.public.get_candles_hist(tf='15m', symbol='fUSD:a30:p2:p30')}"
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
# python -c "import examples.rest.public.pulse_endpoints"
|
# python -c "import examples.rest.public.pulse_endpoints"
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from bfxapi import Client, PUB_REST_HOST
|
from bfxapi import Client
|
||||||
|
|
||||||
from bfxapi.types import PulseMessage, PulseProfile
|
from bfxapi.types import PulseMessage, PulseProfile
|
||||||
|
|
||||||
bfx = Client(rest_host=PUB_REST_HOST)
|
bfx = Client()
|
||||||
|
|
||||||
# POSIX timestamp in milliseconds (check https://currentmillis.com/)
|
# POSIX timestamp in milliseconds (check https://currentmillis.com/)
|
||||||
end = datetime.datetime(2020, 5, 2).timestamp() * 1000
|
end = datetime.datetime(2020, 5, 2).timestamp() * 1000
|
||||||
|
|
||||||
# Retrieves 25 pulse messages up to 2020/05/02
|
# Retrieves 25 pulse messages up to 2020/05/02
|
||||||
messages: List[PulseMessage] = bfx.rest.public.get_pulse_message_history(end=end, limit=25)
|
messages: List[PulseMessage] = bfx.rest.public.get_pulse_message_history(
|
||||||
|
end=end, limit=25
|
||||||
|
)
|
||||||
|
|
||||||
for message in messages:
|
for message in messages:
|
||||||
print(f"Message author: {message.profile.nickname} ({message.profile.puid})")
|
print(f"Message author: {message.profile.nickname} ({message.profile.puid})")
|
||||||
@@ -23,4 +23,7 @@ for message in messages:
|
|||||||
|
|
||||||
profile: PulseProfile = bfx.rest.public.get_pulse_profile_details("News")
|
profile: PulseProfile = bfx.rest.public.get_pulse_profile_details("News")
|
||||||
URL = profile.picture.replace("size", "small")
|
URL = profile.picture.replace("size", "small")
|
||||||
print(f"<{profile.nickname}>'s profile picture: https://s3-eu-west-1.amazonaws.com/bfx-pub/{URL}")
|
print(
|
||||||
|
f"<{profile.nickname}>'s profile picture:"
|
||||||
|
f" https://s3-eu-west-1.amazonaws.com/bfx-pub/{URL}"
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
# python -c "import examples.rest.public.rest_calculation_endpoints"
|
# python -c "import examples.rest.public.rest_calculation_endpoints"
|
||||||
|
|
||||||
from bfxapi import Client, PUB_REST_HOST
|
from bfxapi import Client
|
||||||
|
from bfxapi.types import FundingMarketAveragePrice, FxRate, TradingMarketAveragePrice
|
||||||
|
|
||||||
from bfxapi.types import TradingMarketAveragePrice, FundingMarketAveragePrice, FxRate
|
bfx = Client()
|
||||||
|
|
||||||
bfx = Client(rest_host=PUB_REST_HOST)
|
trading_market_average_price: TradingMarketAveragePrice = (
|
||||||
|
bfx.rest.public.get_trading_market_average_price(
|
||||||
trading_market_average_price: TradingMarketAveragePrice = bfx.rest.public.get_trading_market_average_price(
|
symbol="tBTCUSD", amount=-100, price_limit=20000.5
|
||||||
symbol="tBTCUSD",
|
)
|
||||||
amount=-100,
|
|
||||||
price_limit=20000.5
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Average execution price for tBTCUSD:", trading_market_average_price.price_avg)
|
print("Average execution price for tBTCUSD:", trading_market_average_price.price_avg)
|
||||||
|
|
||||||
funding_market_average_price: FundingMarketAveragePrice = bfx.rest.public.get_funding_market_average_price(
|
funding_market_average_price: FundingMarketAveragePrice = (
|
||||||
symbol="fUSD",
|
bfx.rest.public.get_funding_market_average_price(
|
||||||
amount=100,
|
symbol="fUSD", amount=100, period=2, rate_limit=0.00015
|
||||||
period=2,
|
)
|
||||||
rate_limit=0.00015
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Average execution rate for fUSD:", funding_market_average_price.rate_avg)
|
print("Average execution rate for fUSD:", funding_market_average_price.rate_avg)
|
||||||
|
|||||||
@@ -2,18 +2,19 @@
|
|||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from bfxapi import Client, PUB_REST_HOST
|
from bfxapi import Client
|
||||||
from bfxapi.types import TradingPairTrade, FundingCurrencyTrade
|
from bfxapi.types import FundingCurrencyTrade, TradingPairTrade
|
||||||
from bfxapi.rest.enums import Sort
|
|
||||||
|
|
||||||
bfx = Client(rest_host=PUB_REST_HOST)
|
bfx = Client()
|
||||||
|
|
||||||
t_trades: List[TradingPairTrade] = bfx.rest.public.get_t_trades("tBTCUSD", \
|
t_trades: List[TradingPairTrade] = bfx.rest.public.get_t_trades(
|
||||||
limit=15, sort=Sort.ASCENDING)
|
"tBTCUSD", limit=15, sort=+1
|
||||||
|
)
|
||||||
|
|
||||||
print("Latest 15 trades for tBTCUSD (in ascending order):", t_trades)
|
print("Latest 15 trades for tBTCUSD (in ascending order):", t_trades)
|
||||||
|
|
||||||
f_trades: List[FundingCurrencyTrade] = bfx.rest.public.get_f_trades("fUSD", \
|
f_trades: List[FundingCurrencyTrade] = bfx.rest.public.get_f_trades(
|
||||||
limit=15, sort=Sort.DESCENDING)
|
"fUSD", limit=15, sort=-1
|
||||||
|
)
|
||||||
|
|
||||||
print("Latest 15 trades for fUSD (in descending order):", f_trades)
|
print("Latest 15 trades for fUSD (in descending order):", f_trades)
|
||||||
|
|||||||
Reference in New Issue
Block a user