MCPcopy Create free account
hub / github.com/ccxt/ccxt / example_3

Function example_3

examples/py/bybit-updated.py:88–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86
87# Example 3 :: USDC Swap : fetch balance, open a position and close it
88async def example_3():
89 exchange.options['defaultType'] = 'swap'; # very important set swap as default type
90 markets = await exchange.load_markets(True)
91
92 # fetch USDC swap balance
93 # when no symbol is available we can show our intent
94 # of using USDC endpoints by either using defaultSettle in options or
95 # settle in params
96 # Using Options: exchange.options['defaultSettle'] = 'USDC';
97 # Using params:
98 balanceParams = {
99 'settle': 'USDC'
100 }
101 balance = await exchange.fetch_balance(balanceParams)
102 print(balance)
103
104 # create order and open position
105 # taking into consideration that USDC markets do not support
106 # market orders
107 symbol = 'BTC/USD:USDC'
108 type = 'limit'
109 side = 'buy'
110 amount = 0.1
111 price = 15000 # adjust this accordingly
112 create_order = await exchange.create_order(symbol, type, side, amount, price)
113 print('Create order id:', create_order['id'])
114
115 # check if the order was filled and the position opened
116 symbols = [ symbol ]
117 positions = await exchange.fetch_positions(symbols)
118 print(positions)
119
120 # Close position (assuming it was already opened) by issuing an order in the opposite direction
121 side = 'sell'
122 params = {
123 'reduce_only': True
124 }
125 close_position_order = await exchange.createOrder(symbol, type, side, amount, price, params)
126 print(close_position_order)
127
128# -------------------------------------------------------------------------------------------
129

Callers 1

mainFunction · 0.85

Calls 5

load_marketsMethod · 0.45
fetch_balanceMethod · 0.45
create_orderMethod · 0.45
fetch_positionsMethod · 0.45
createOrderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…