Professional Python client for Binomo trading platform
Project description
BinomoAPI - Professional Python Client
A comprehensive, production-ready Python client for the Binomo trading platform API. This library provides a clean, type-safe interface for authentication, account management, and binary options trading.
Support
donate in paypal: Paypal.me
help us in patreon: Patreon
๐ Join us on Discord
Get our services here
Let us create your bot here
Contact us in Telegram
๐ Features
- Professional Authentication: Secure login with comprehensive error handling
- Type Safety: Full type hints and data validation using dataclasses
- Async/Await Support: Modern Python async programming patterns
- Context Manager: Automatic resource cleanup and connection management
- Comprehensive Error Handling: Custom exceptions for different error scenarios
- Logging Support: Configurable logging for debugging and monitoring
- Balance Management: Real-time account balance checking
- Asset Management: Asset discovery and RIC code resolution
- Binary Options Trading: CALL and PUT options with validation
- Demo & Live Trading: Support for both demo and real accounts
๐ฆ Installation
pip install -r requirements.txt
๐ง Quick Start
Basic Authentication and Setup
import asyncio
from BinomoAPI.api import BinomoAPI
from BinomoAPI.exceptions import AuthenticationError
async def main():
try:
# Authenticate
login_response = BinomoAPI.login("your_email@example.com", "your_password")
# Create API client
async with BinomoAPI(
auth_token=login_response.authtoken,
device_id="your_device_id",
demo=True, # Use demo account
enable_logging=True
) as api:
# Check balance
balance = await api.get_balance()
print(f"Balance: ${balance.amount:.2f}")
# Place a trade
result = await api.place_call_option(
asset="EUR/USD",
duration_seconds=60,
amount=1.0
)
print(f"Trade result: {result}")
except AuthenticationError as e:
print(f"Login failed: {e}")
# Run the example
asyncio.run(main())
๐ Comprehensive Usage Guide
1. Authentication
from BinomoAPI.api import BinomoAPI
from BinomoAPI.exceptions import AuthenticationError, ConnectionError
try:
# Login with email and password
login_response = BinomoAPI.login(
email="your_email@example.com",
password="your_password",
device_id="optional_custom_device_id" # Uses default if not provided
)
print(f"Auth Token: {login_response.authtoken}")
print(f"User ID: {login_response.user_id}")
except AuthenticationError as e:
print(f"Invalid credentials: {e}")
except ConnectionError as e:
print(f"Network error: {e}")
2. API Client Initialization
# Recommended: Using context manager (automatic cleanup)
async with BinomoAPI(
auth_token=login_response.authtoken,
device_id="your_device_id",
demo=True, # False for real trading
enable_logging=True,
log_level=logging.INFO
) as api:
# Your trading code here
pass
# Alternative: Manual management
api = BinomoAPI(auth_token=token, device_id=device_id, demo=True)
try:
# Your trading code here
pass
finally:
api.close() # Important: Always close connections
3. Account Balance Management
# Get current account balance
balance = await api.get_balance()
print(f"Amount: ${balance.amount:.2f}")
print(f"Currency: {balance.currency}")
print(f"Account Type: {balance.account_type}")
# Check specific account type
demo_balance = await api.get_balance("demo")
real_balance = await api.get_balance("real")
4. Asset Management
# Get all available assets
assets = api.get_available_assets()
for asset in assets:
print(f"Name: {asset.name}, RIC: {asset.ric}, Active: {asset.is_active}")
# Get RIC code for an asset
ric = api.get_asset_ric("EUR/USD")
print(f"EUR/USD RIC: {ric}")
5. Binary Options Trading
from BinomoAPI.exceptions import InsufficientBalanceError, TradeError
try:
# Place CALL option
call_result = await api.place_call_option(
asset="EUR/USD", # Asset name or RIC
duration_seconds=60, # Duration in seconds
amount=5.0, # Investment amount in USD
use_demo=True # Optional: override account type
)
# Place PUT option
put_result = await api.place_put_option(
asset="GBP/USD",
duration_seconds=120,
amount=10.0
)
print(f"CALL trade: {call_result}")
print(f"PUT trade: {put_result}")
except InsufficientBalanceError as e:
print(f"Not enough funds: {e}")
except TradeError as e:
print(f"Trade failed: {e}")
๐ Error Handling
The API uses custom exceptions for different error scenarios:
from BinomoAPI.exceptions import (
BinomoAPIException, # Base exception
AuthenticationError, # Login/auth failures
ConnectionError, # Network issues
InvalidParameterError, # Bad parameters
TradeError, # Trade execution issues
InsufficientBalanceError # Low balance
)
try:
# Your API calls here
pass
except AuthenticationError:
print("Check your credentials")
except ConnectionError:
print("Check your internet connection")
except InvalidParameterError:
print("Check your input parameters")
except InsufficientBalanceError:
print("Add funds to your account")
except TradeError:
print("Trade execution failed")
except BinomoAPIException as e:
print(f"General API error: {e}")
๐ Data Models
The API uses structured data models for type safety:
LoginResponse
@dataclass
class LoginResponse:
authtoken: str
user_id: str
Asset
@dataclass
class Asset:
name: str
ric: str
is_active: bool = True
Balance
@dataclass
class Balance:
amount: float
currency: str
account_type: str
๐ง Configuration
Logging Configuration
import logging
# Enable detailed logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
# Create API with logging
async with BinomoAPI(
auth_token=token,
device_id=device_id,
enable_logging=True,
log_level=logging.DEBUG
) as api:
# All API calls will be logged
pass
Custom Device ID
# Use your own device ID for consistency
DEVICE_ID = "your-custom-device-id-12345"
login_response = BinomoAPI.login(email, password, DEVICE_ID)
api = BinomoAPI(auth_token=token, device_id=DEVICE_ID)
๐ Legacy Compatibility
For backward compatibility with older code:
# Legacy methods still work but are deprecated
balance = await api.Getbalance() # Use get_balance() instead
await api.Call("EUR", 60, 1.0, True) # Use place_call_option() instead
await api.Put("EUR", 60, 1.0, True) # Use place_put_option() instead
๐ก๏ธ Best Practices
- Always use context managers for automatic cleanup
- Handle exceptions properly for robust applications
- Use demo accounts for testing and development
- Enable logging for debugging and monitoring
- Validate inputs before making API calls
- Check balances before placing trades
- Use type hints for better code quality
๐ Project Structure
BinomoAPI/
โโโ __init__.py
โโโ api.py # Main API client
โโโ exceptions.py # Custom exceptions
โโโ constants.py # API constants
โโโ models.py # Data models
โโโ assets.json # Available assets
โโโ config/
โ โโโ __init__.py
โ โโโ conf.py # Configuration
โโโ wss/
โโโ __init__.py
โโโ client.py # WebSocket client
๐ API Reference
Static Methods
BinomoAPI.login(email, password, device_id=None) -> LoginResponse
Instance Methods
get_balance(account_type=None) -> Balanceget_asset_ric(asset_name) -> Optional[str]get_available_assets() -> List[Asset]place_call_option(asset, duration_seconds, amount, use_demo=None) -> Dictplace_put_option(asset, duration_seconds, amount, use_demo=None) -> Dictconnect() -> Noneclose() -> None
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
โ ๏ธ Disclaimer
This library is for educational and development purposes. Binary options trading involves financial risk. Always test with demo accounts before using real money. The authors are not responsible for any financial losses.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ Support
For support and questions, please open an issue on the GitHub repository. BinomoAPI is the api for the binomo trading platform
Talk to us
๐ Join us on Discord
Reference
Inspired by this project: https://github.com/hert0t/Binomo-API
Support us
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file binomoapi-2.0.1.tar.gz.
File metadata
- Download URL: binomoapi-2.0.1.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f7a26dcdd6ee660b38a8244e48e9e97945cdd3e04c16c18f79e4da30ab379cf
|
|
| MD5 |
ceacbf07595e1e647dcba6e0fa860b51
|
|
| BLAKE2b-256 |
87a3b58b55e816b56e342d882a72e6d4e48dedfc2e5d342238a0f1f8e5c4031e
|
File details
Details for the file binomoapi-2.0.1-py3-none-any.whl.
File metadata
- Download URL: binomoapi-2.0.1-py3-none-any.whl
- Upload date:
- Size: 27.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
716394233ab22671988969d58c74810fd4021cc9b5bfe313e4278b0f917f87e9
|
|
| MD5 |
389045de58f128371a59ec96c83d30c7
|
|
| BLAKE2b-256 |
fb43c623a823cf86b451ef1bfe4d4c2e6f6b878de010729af8a73dcf47ba1153
|