async def test(): exchange = ccxt.bitstamp({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', }) response = None try: await exchange.load_markets() # force-preload markets first exchange.verbose = True # this is for debugging symbol = 'BTC/USD' # change for your symbol amount = 1.0 # change the amount price = 6000.00 # change the price try: response = await exchange.create_limit_buy_order( symbol, amount, price) except Exception as e: print('Failed to create order with', exchange.id, type(e).__name__, str(e)) except Exception as e: print('Failed to load markets from', exchange.id, type(e).__name__, str(e)) await exchange.close() return response
async def test(): exchange = ccxt.bitstamp({ # "verbose": True, # useful for debugging purposes, uncomment if needed 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', 'uid': 'YOUR_UID', # i'm adding a CORS proxy here, because my country is blocked by bitstamp # you don't need this, so it's safe to comment it out # "proxy": "https://cors-anywhere.herokuapp.com/", # "origin": "bitstamp" }) print(await exchange.fetch_balance()) await exchange.close() # don't forget to close it when you're done return True
async def main(): exchange = ccxt.bitstamp({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', 'uid': 'YOUR_UID', }) markets = await exchange.load_markets() exchange.verbose = True # enable verbose mode after loading the markets print( '-------------------------------------------------------------------') try: balance = await exchange.fetch_balance() pprint(balance) except Exception as e: print('Failed to fetch the balance') print(type(e).__name__, str(e)) order = None print( '-------------------------------------------------------------------') try: symbol = 'BTC/USDT' market = exchange.market(symbol) base = market['base'] quote = market['quote'] pprint(balance[base]) pprint(balance[quote]) amount = 0.001 price = 40000 order_type = 'limit' side = 'sell' order = await exchange.create_order(symbol, order_type, side, amount, price) pprint(order) except Exception as e: print('Failed to place', symbol, 'order') print(type(e).__name__, str(e)) print( '-------------------------------------------------------------------') if order is not None: try: response = await exchange.cancel_order(order['id'], order['symbol']) pprint(response) except Exception as e: print('Failed to cancel', symbol, 'order') print(type(e).__name__, str(e)) print( '-------------------------------------------------------------------') await exchange.close()