def test_get_mid_price_orderbooks(self): binance = Binance() products = ['BTC_USDT', 'ETH_USDT'] orderbooks = binance.get_mid_price_orderbooks(products) self.assertEqual(len(orderbooks), len(products)) self.assertIn(orderbooks[0].product, products) self.assertIn(orderbooks[1].product, products)
def main(args): with open(args.credentials_path, 'r') as rfile: credentials = json.load(rfile) binance = Binance(api_key=credentials['BINANCE_API_KEY'], secret_key=credentials['BINANCE_API_SECRET']) if args.q == 'get_open_orders': print(*binance.client.get_open_orders(symbol=args.symbol), sep='\n') return if args.q == 'cancel': print(binance.client.cancel_order( symbol=args.symbol, orderId=args.order_id)) return assert args.q == 'create' exchange_info = binance.client.get_exchange_info() for _symbol in exchange_info['symbols']: if _symbol['symbol'] == args.symbol: filt = _symbol['filters'][0] if args.action == 'SELL': price = filt['maxPrice'] else: price = filt['minPrice'] order_response = binance.client.create_order( symbol=args.symbol, side=args.action, quantity=Decimal(args.quantity), price=price, type='LIMIT_MAKER') print(f'create order response {order_response}') orderId = order_response['orderId'] order_response = binance.client.get_order( symbol=args.symbol, orderId=orderId) print(f'get order response {order_response}')
def test_get_orderbooks(self): binance = Binance() products = ['BTC_USDT', 'ETH_USDT'] orderbooks = binance.get_orderbooks(products) self.assertEqual(len(orderbooks), len(products)) self.assertIn(orderbooks[0].product, products) self.assertIn(orderbooks[1].product, products) self.assertLess(orderbooks[0].wall_bid, orderbooks[0].wall_ask) self.assertLess(orderbooks[1].wall_bid, orderbooks[1].wall_ask)
def __init__(self): self.exchange = Binance() self.chart = chart() self.param = [{ "col_name": "4_ema", "color": 'green', "name": "4_ema" }, { "col_name": "9_ema", "color": 'yellow', "name": "9_ema" }, { "col_name": "18_ema", "color": "red", "name": "18_ema" }] self.buy_signals = [] self.sell_signals = []
def get_exchange(self, type: ExchangeType) -> Exchange: if type == ExchangeType.Binance: return Binance() else: return Others()