-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
88 lines (68 loc) · 3.08 KB
/
basic_usage.py
File metadata and controls
88 lines (68 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Basic usage of the Dimes Multiply Python SDK.
This example shows how to connect to the Multiply API,
browse prediction markets, and manage leveraged positions.
Run: python examples/basic_usage.py
"""
import os
from multiply import MultiplyClient
def main():
# Initialize the client with your API key
client = MultiplyClient(api_key=os.environ["DIMES_API_KEY"])
# ── Browse markets ────────────────────────────────────────
markets = client.get_markets(
platform="polymarket",
status="active",
min_leverage=3,
min_liquidity=10_000,
limit=5,
)
print(f"Found {markets.total} markets with 3x+ leverage\n")
for market in markets.data:
print(f"{market['title']}")
print(f" Max leverage: {market['max_leverage']}x")
print(f" Liquidity: ${market['liquidity_usdc']:,.0f}")
for outcome in market["outcomes"]:
print(f" {outcome['label']}: {outcome['price'] * 100:.1f}%")
print()
# ── Check leverage tiers ──────────────────────────────────
if markets.data:
market_id = markets.data[0]["id"]
leverage_info = client.get_leverage(market_id)
print(f"Leverage tiers for: {markets.data[0]['title']}")
for tier in leverage_info.tiers:
print(
f" {tier.leverage}x — "
f"initial margin: {tier.initial_margin:.0%}, "
f"max size: ${tier.max_position_usdc:,.0f}"
)
print(f" Funding rate: {leverage_info.funding_rate_annualized}% annualized\n")
# ── Open a position ───────────────────────────────────────
if markets.data:
market = markets.data[0]
outcome = market["outcomes"][0]
result = client.create_position(
market_id=market["id"],
outcome_id=outcome["id"],
side="long",
collateral_usdc=50,
leverage=3,
max_slippage=0.01,
)
pos = result.position
print(f"Opened position: {pos.id}")
print(f" {pos.leverage}x {pos.side} on '{pos.market_title}'")
print(f" Collateral: ${pos.collateral_usdc}")
print(f" Notional: ${pos.notional_usdc}")
print(f" Entry: {pos.entry_price:.4f}")
print(f" Liquidation: {pos.liquidation_price:.4f}")
print(f" Tx: {result.transaction.tx_hash}\n")
# ── Check account ─────────────────────────────────────────
account = client.get_account()
print("Account summary:")
print(f" Balance: ${account.balance_usdc:,.2f}")
print(f" Locked collateral: ${account.locked_collateral_usdc:,.2f}")
print(f" Unrealized PnL: ${account.total_unrealized_pnl_usdc:,.2f}")
print(f" Health factor: {account.health_factor:.2f}")
if __name__ == "__main__":
main()