Migrating to BinomoAPI 2.x
Version 2 renamed the trading and balance methods, added typed return values and replaced generic errors with specific exceptions. Old method names still work, so you can migrate one call at a time.
- Upgrade
- Method renames
- Creating the client
- Exceptions
- Assets without logging in
- Deprecation timeline
Upgrade
pip install --upgrade BinomoAPI
Method renames
| Before | After |
|---|---|
await api.Call(ric, duration, amount, is_demo) | await api.place_call_option(ric, duration, amount, use_demo=is_demo) |
await api.Put(ric, duration, amount, is_demo) | await api.place_put_option(ric, duration, amount, use_demo=is_demo) |
await api.Getbalance() | await api.get_balance() |
Return values changed
get_balance()returns aBalanceobject withamountin major units (e.g.1000.00).Getbalance()returned a bare number in minor units (100000), orNone.place_call_option()andplace_put_option()return a receipt dict.Call()andPut()returnedNone.
# Before
cents = await api.Getbalance()
print(cents / 100)
# After
balance = await api.get_balance()
print(balance.amount, balance.currency)
Creating the client
Build the client from the login response so the authenticated session is reused:
# Before
login = BinomoAPI.login(email, password)
api = BinomoAPI(auth_token=login.authtoken, device_id=DEVICE_ID, demo=True)
# After
login = BinomoAPI.login(email, password)
async with BinomoAPI.create_from_login(login, demo=True) as api:
...
Exceptions
Catch specific errors instead of Exception:
# Before
try:
await api.Call("EURO", 60, 100, True)
except Exception as e:
print(e)
# After
from BinomoAPI import TradeError, InvalidParameterError
try:
await api.place_call_option("EURO", 60, 100, use_demo=True)
except InvalidParameterError as e:
print("Fix your input:", e)
except TradeError as e:
print("Order failed:", e)
See Error Handling for the full hierarchy.
Assets without logging in
New in 2.x: list assets and RIC codes without creating a client.
BinomoAPI.get_assets()
BinomoAPI.get_otc_assets()
Deprecation timeline
Call, Put and Getbalance remain available in 2.x and may be removed in a future major release. Migrate when you can.