def xud_list_pairs(): global channel if channel is None: return stub = xudrpc_pb2_grpc.XudStub(channel) request = xudrpc_pb2.ListPairsRequest() response = stub.ListPairs(request) print('Currency Pairs: %s' % (', '.join(response.pairs)))
def subscribe_swaps(): global channel try: stub = xudrpc_pb2_grpc.XudStub(channel) request = xudrpc_pb2.SubscribeSwapsRequest() # print('[XUD]SubscribeSwaps') for response in stub.SubscribeSwaps(request): print("------------SWAPS------------") print(response) handle_xud_swap(response) except: print('Failed to subscribe swaps') traceback.print_exc()
def subscribe_removed_orders(): global channel try: stub = xudrpc_pb2_grpc.XudStub(channel) request = xudrpc_pb2.SubscribeRemovedOrdersRequest() # print('[XUD]SubscribeRemovedOrders') for response in stub.SubscribeRemovedOrders(request): #print("-----------REMOVED-----------") #print(response) cancel_xud_order(response.order_id) except: print('Failed to subscribe removed orders') traceback.print_exc()
def xud_get_info(): global channel if channel is None: return stub = xudrpc_pb2_grpc.XudStub(channel) request = xudrpc_pb2.GetInfoRequest() response = stub.GetInfo(request) # print(response) print('Connected to xud %s pub_key: %s\n' % (response.version, response.node_pub_key)) xud_list_pairs() print('\nBTC Lightning Channels: %s' % (response.lndbtc.channels.active)) print('LTC Lightning Channels: %s' % (response.lndltc.channels.active))
def xud_execute_swap(order_id, peer_pub_key, quantity): global channel, Q, P if channel is None: # print("xud is not connected!") return stub = xudrpc_pb2_grpc.XudStub(channel) request = xudrpc_pb2.ExecuteSwapRequest(pair_id='%s/%s' % (Q, P), order_id=order_id, peer_pub_key=peer_pub_key, quantity=quantity) print('[XUD]ExecuteSwap: order_id=%s, peer_pub_key=%s, quantity=%s' % (order_id, peer_pub_key, quantity)) response = stub.ExecuteSwap(request) print("--------------SWAP--------------") print(response)
def xud_place_order(order_id, side, quantity, price): global channel, Q, P, boot_timestamp if channel is None: # print("xud is not connected!") return stub = xudrpc_pb2_grpc.XudStub(channel) xud_side = xudrpc_pb2.BUY if side == 'buy' else xudrpc_pb2.SELL request = xudrpc_pb2.PlaceOrderRequest(price=price, quantity=quantity, pair_id='%s/%s' % (Q, P), order_id='test-%s-%s' % (boot_timestamp, order_id), side=xud_side) # print('[XUD]PlaceOrder: order_id=%s, side=%s, quantity=%s, price=%s' % (order_id, side, quantity, price)) for response in stub.PlaceOrder(request): print(response)
def subscribe_added_orders(): global channel try: stub = xudrpc_pb2_grpc.XudStub(channel) request = xudrpc_pb2.SubscribeAddedOrdersRequest(existing=True) # print('[XUD]SubscribeAddedOrders') for response in stub.SubscribeAddedOrders(request): #print("------------ADDED------------") #print(response) if not response.is_own_order: qq = round(response.quantity, 4) place_xud_order( str(qq), str(response.price), response.id, 'sell' if response.side == xudrpc_pb2.SELL else 'buy', response.peer_pub_key, response.created_at) except: print('Failed to subscribe added orders') traceback.print_exc()