Hi,
I'm building an auto trading bot and I'm using Bet Angel to handle the actual betting/trading part.
I'm able to communicate with the Bet Angel Api from my host machine via "http://localhost:9000" but from within a Container localhost would be the Containers address, to access the host machines address I would need to use it's IP address.
For example a query that'd go to:
http://localhost:9000/api/markets/v1.0/getMarkets
Would now need to go to:
http://192.168.0.69:9000/api/markets/v1.0/getMarkets
Unfortunately doing so results in an error:
"HTTP Error 400. The request hostname is invalid"
How can I access the Bet Angel Api from within a Container?
Any assistance would be greatly appreciated!
Accessing Bet Angel Api from a Container (Docker)
Could you possibly edit \etc\hosts to point localhost at the container IP ? On the proviso that it may screw up anything else you have that references localhost
i.e
localhost 192.168.0.69
From memory, you may need a reboot post edit to pick up the hosts file change
i.e
localhost 192.168.0.69
From memory, you may need a reboot post edit to pick up the hosts file change
We've been testing remote connections to the API this morning and think we have a solution. It'll need a few lines of extra code in Bet Angel, you have to open the port on the PC hosting Bet Angel using a Windows firewall rule, and there's command to run using netsh, but it does seem to work. We were able to communicate with the API running on a different PC & IP address.
We'll make the changes ready for the next beta of Bet Angel.
We'll make the changes ready for the next beta of Bet Angel.
This is helpful to know. I've been grappling with the same problem as OP on and off for a few weeks.
Thanks!
A basic "reverse proxy" running alongside Bet Angel (i.e. not in a Docker container) might be a viable workaround for now. Have it listen on, say, port 9001 and send its requests on to the Bet Angel API port (I think 9000 by default, so http://localhost:9000). Then in your Docker container, send your requests to http://host.docker.internal:9001, which resolves to the internal IP address of the host [EDIT TO ADD: this assumes that you're running Docker Desktop and Bet Angel on the same machine]. Happy to be corrected by anyone who knows more about this than I do, though
Not really in my wheelhouse, but based on this the code below looks like it should do what we need. I threw it together fairly quickly and haven't tested it yet, so use it at your own risk, etc.
Code: Select all
from flask import Flask, request, Response
import requests
app = Flask(__name__)
@app.route("/")
def index():
return "Flask is running!"
@app.route("/<path:path>", methods=["POST"])
def proxy(path):
resp = requests.post(f"http://localhost:9000/{path}", json=request.get_json())
response = Response(resp.content, resp.status_code, resp.raw.headers.items())
return response
if __name__ == "__main__":
app.run(debug=False, port=9001)
The changes to support remote connection are in the beta released today. viewtopic.php?p=333758
Instructions as to how to reserve the URL and configure the Windows firewall are in the updated API docs.