-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinm_example.py
More file actions
68 lines (53 loc) · 1.83 KB
/
coinm_example.py
File metadata and controls
68 lines (53 loc) · 1.83 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
"""
Coin-M Perpetual Futures Example
Demonstrates Coin-M (crypto-margined) futures trading.
"""
from bingx import BingXClient
from bingx.exceptions import BingXException
# Initialize client
client = BingXClient(
api_key="your_api_key_here",
api_secret="your_api_secret_here"
)
try:
# Get Coin-M contracts
contracts = client.coinm().market().get_contracts()
print(f"Coin-M Contracts: {contracts}")
# Get ticker for BTC-USD
ticker = client.coinm().market().get_ticker("BTC-USD")
print(f"BTC-USD Ticker: {ticker}")
# Get order book
depth = client.coinm().market().get_depth("BTC-USD", 20)
print(f"Depth: {depth}")
# Get candlesticks
klines = client.coinm().market().get_klines("BTC-USD", "1h", 10)
print(f"Klines: {klines}")
# Get open interest
open_interest = client.coinm().market().get_open_interest("BTC-USD")
print(f"Open Interest: {open_interest}")
# Get funding rate
funding_rate = client.coinm().market().get_funding_rate("BTC-USD")
print(f"Funding Rate: {funding_rate}")
# Get balance
balance = client.coinm().trade().get_balance()
print(f"Coin-M Balance: {balance}")
# Get positions
positions = client.coinm().trade().get_positions("BTC-USD")
print(f"Positions: {positions}")
# Set leverage
leverage_result = client.coinm().trade().set_leverage("BTC-USD", "BOTH", 10)
print(f"Leverage set: {leverage_result}")
# Create order
order = client.coinm().trade().create_order({
"symbol": "BTC-USD",
"side": "BUY",
"positionSide": "LONG",
"type": "MARKET",
"quantity": 100
})
print(f"Order created: {order}")
# Get open orders
open_orders = client.coinm().trade().get_open_orders("BTC-USD")
print(f"Open orders: {open_orders}")
except BingXException as e:
print(f"Error: {e}")