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

Function example_2

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

Source from the content-addressed store, hash-verified

53
54# Example 2 :: Swap : fetch balance, open a position and close it
55async def example_2():
56 exchange.options['defaultType'] = 'swap'; # very important set swap as default type
57 markets = await exchange.load_markets(True)
58
59 # fetch swap balance
60 balance = await exchange.fetch_balance()
61 print(balance)
62
63 # create market order and open position
64 symbol = 'LTC/USDT:USDT'
65 type = 'market'
66 side = 'buy'
67 amount = 0.1
68 price = None
69 create_order = await exchange.create_order(symbol, type, side, amount, price)
70 print('Create order id:', create_order['id'])
71
72 # check opened position
73 symbols = [ symbol ]
74 positions = await exchange.fetch_positions(symbols)
75 print(positions)
76
77 # Close position by issuing a order in the opposite direction
78 side = 'sell'
79 params = {
80 'reduce_only': True
81 }
82 close_position_order = await exchange.createOrder(symbol, type, side, amount, price, params)
83 print(close_position_order)
84
85# -------------------------------------------------------------------------------------------
86

Callers 1

mainFunction · 0.70

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…