()
| 19 | |
| 20 | |
| 21 | def main(): |
| 22 | |
| 23 | # the exchange instance has to be reused |
| 24 | # do not recreate the exchange before each call! |
| 25 | |
| 26 | exchange = ccxt.binance({ |
| 27 | |
| 28 | 'apiKey': 'YOUR_API_KEY', |
| 29 | 'secret': 'YOUR_API_SECRET', |
| 30 | |
| 31 | # 'uid': 'YOUR_UID', # some exchanges require this |
| 32 | # 'password': 'YOUR_API_PASSWORD', # some exchanges require this |
| 33 | |
| 34 | # if you do not rate-limit your requests the exchange can ban you! |
| 35 | 'enableRateLimit': False, # https://github.com/ccxt/ccxt/wiki/Manual#rate-limit |
| 36 | |
| 37 | }) |
| 38 | |
| 39 | exchange.load_markets() # https://github.com/ccxt/ccxt/wiki/Manual#loading-markets |
| 40 | |
| 41 | # exchange.verbose = True # uncomment for debugging purposes if needed |
| 42 | |
| 43 | symbol = 'BTC/USDC' |
| 44 | market = exchange.market(symbol) |
| 45 | ticker = exchange.fetch_ticker(symbol) |
| 46 | |
| 47 | amount = market['limits']['amount']['min'] |
| 48 | |
| 49 | # we will place limit buy order at 3/4 of the price to make sure they're not triggered |
| 50 | |
| 51 | price = ticker['last'] * 0.8 |
| 52 | amount = round(market['limits']['cost']['min'] / price, 4) |
| 53 | |
| 54 | results = [] |
| 55 | |
| 56 | for i in range(0, 10): |
| 57 | started = exchange.milliseconds() |
| 58 | order = exchange.create_order(symbol, 'limit', 'buy', amount, price) |
| 59 | ended = exchange.milliseconds() |
| 60 | elapsed = ended - started |
| 61 | results.append(elapsed) |
| 62 | exchange.cancel_order(order['id'], order['symbol']) |
| 63 | pprint(order) |
| 64 | pprint(results) |
| 65 | |
| 66 | |
| 67 | rtt = int(sum(results) / len(results)) |
| 68 | print('Successfully tested 10 orders, the average round-trip time per order is', rtt, 'milliseconds') |
| 69 | |
| 70 | |
| 71 | main() |
no test coverage detected
searching dependent graphs…