Skip to main content

purpleflea

Python SDK for the Purple Flea Casino, Trading & Wallet APIs.

Installation

pip install purpleflea

Quick Start

Casino

from purpleflea import CasinoClient

# Defaults to http://80.78.27.26:3000
casino = CasinoClient("your-api-key")

# Register a new account
casino.register("alice", "alice@example.com")

# Deposit funds
casino.deposit(100.0, currency="USDC")

# List available games
games = casino.list_games()

# Play a round
result = casino.play("dice", bet_amount=5.0)

# Check balance & withdraw
balance = casino.get_balance()
casino.withdraw(50.0)

# Referrals
ref = casino.create_referral()
casino.redeem_referral("REF123")

casino.close()

Trading

from purpleflea import TradingClient

# Defaults to http://80.78.27.26:3003
trading = TradingClient("your-api-key")

# Register a new account
trading.register("bob", "bob@example.com")

# Browse markets
markets = trading.list_markets()
btc = trading.get_market("BTC-USD")
book = trading.get_orderbook("BTC-USD")

# Open a long position
pos = trading.open_position("BTC-USD", side="long", size=0.5)

# Check position and close
details = trading.get_position(pos["position_id"])
trading.close_position(pos["position_id"])

# Referrals
trading.create_referral()
trading.redeem_referral("TREF1")

trading.close()

Wallet

from purpleflea import WalletClient

# Defaults to http://80.78.27.26:3000
wallet = WalletClient("your-api-key")

# Get balance
balance = wallet.get_balance()

# Get deposit address for BTC
addr = wallet.get_address("BTC")

# Deposit USDC
wallet.deposit(500.0, currency="USDC")

# Withdraw to external address
wallet.withdraw(100.0, address="0xYourAddress", currency="USDC")

# Transaction history
txns = wallet.list_transactions(limit=20)

# Transfer between accounts
wallet.transfer(to_account="carol", amount=25.0)

wallet.close()

Context Manager

All clients support context managers for automatic cleanup:

from purpleflea import CasinoClient

with CasinoClient("your-api-key") as casino:
    casino.deposit(50.0)
    result = casino.play("dice", bet_amount=10.0)

Custom Base URL

from purpleflea import CasinoClient, TradingClient

casino = CasinoClient("your-api-key", base_url="http://80.78.27.26:3000")
trading = TradingClient("your-api-key", base_url="http://80.78.27.26:3003")

Error Handling

from purpleflea import CasinoClient, APIError

try:
    with CasinoClient("your-api-key") as casino:
        casino.play("invalid-game", bet_amount=10.0)
except APIError as e:
    print(f"API error {e.status_code}: {e.message}")

API Reference

CasinoClient(api_key, base_url=None, timeout=30.0)

Default base URL: http://80.78.27.26:3000. Routes use the /api/v1/ prefix.

Method Description
register(username, email) Register a new player
get_account() Get account details
deposit(amount, currency="USDC") Deposit funds
withdraw(amount, currency="USDC") Withdraw funds
get_balance() Get wallet balance
list_games() List available games
get_game(game_id) Get game details
play(game_id, bet_amount) Play a round
get_game_history() Get past results
create_referral() Generate referral code
list_referrals() List referrals
redeem_referral(code) Redeem a referral code

TradingClient(api_key, base_url=None, timeout=30.0)

Default base URL: http://80.78.27.26:3003. Routes use the /v1/ prefix.

Method Description
register(username, email) Register a new trader
get_account() Get account details
list_markets() List available markets
get_market(market_id) Get market details
get_orderbook(market_id) Get order book
open_position(market_id, side, size) Open a position
close_position(position_id) Close a position
get_position(position_id) Get position details
list_positions() List open positions
create_referral() Generate referral code
list_referrals() List referrals
redeem_referral(code) Redeem a referral code

WalletClient(api_key, base_url=None, timeout=30.0)

Default base URL: http://80.78.27.26:3000. Routes use the /api/v1/wallet/ prefix.

Method Description
get_balance() Get balance across all currencies
get_address(currency) Get deposit address for a currency
deposit(amount, currency="USDC") Initiate a deposit
get_deposit(deposit_id) Get deposit status
list_deposits() List all deposits
withdraw(amount, address, currency="USDC") Withdraw to external address
get_withdrawal(withdrawal_id) Get withdrawal status
list_withdrawals() List all withdrawals
list_transactions(limit=50) List all transactions
get_transaction(transaction_id) Get transaction details
transfer(to_account, amount, currency="USDC") Transfer to another account

Changelog

0.2.1

0.2.0

  • Added WalletClient with full deposit/withdrawal/transfer support
  • Set correct default base URLs: casino http://80.78.27.26:3000, trading http://80.78.27.26:3003
  • Promoted to Beta status

0.1.0

  • Initial release with CasinoClient and TradingClient

Development

git clone https://github.com/purple-flea/purpleflea-py.git
cd purpleflea-py
pip install -e ".[dev]"
pytest

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

purpleflea-0.2.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

purpleflea-0.2.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file purpleflea-0.2.1.tar.gz.

File metadata

  • Download URL: purpleflea-0.2.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for purpleflea-0.2.1.tar.gz
Algorithm Hash digest
SHA256 25d022a97f7c0be3dd68c19778adc95d33518787e022c620d68c4a54b315ea91
MD5 1411d09cf2269f22f7c9e8a1fd8854ec
BLAKE2b-256 ee762066f37318391281ba20aa5d1273c27323b0217ec0885ff8905335ff148c

See more details on using hashes here.

File details

Details for the file purpleflea-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: purpleflea-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for purpleflea-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f890a5d37d3816b4416c91555ebdcff16883b9dde5db0097b84db1345011ef9c
MD5 34830f6af69db3cf52e1888710af60e9
BLAKE2b-256 e4eb500b61564a043298ec6853a348651bdc96704176e71e77729d1e4ba698c6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page