()
| 86 | |
| 87 | # Example 3 :: USDC Swap : fetch balance, open a position and close it |
| 88 | async 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 |
no test coverage detected
searching dependent graphs…