Accessing Bet Angel Api from a Container (Docker)

The Bet Angel API makes it easy for you to further enhance your betting and trading by integrating your own code into Bet Angel
Post Reply
Medz89
Posts: 8
Joined: Fri Jun 02, 2023 4:50 pm

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!
Bet Angel
Bet Angel
Bet Angel
Posts: 4001
Joined: Tue Apr 14, 2009 3:47 pm

The hostname of the request does need to be localhost, so maybe you'll need to run Bet Angel and your trading bot both inside the same virtual machine rather than using a docker container.
sniffer66
Posts: 1681
Joined: Thu May 02, 2019 8:37 am

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
Bet Angel
Bet Angel
Bet Angel
Posts: 4001
Joined: Tue Apr 14, 2009 3:47 pm

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.
Medz89
Posts: 8
Joined: Fri Jun 02, 2023 4:50 pm

Awesome! Thank you very much! Please let us know when the changes are out!
whte_rbt
Posts: 3
Joined: Wed Nov 30, 2022 2:17 pm

Bet Angel wrote:
Mon Jul 17, 2023 2:10 pm
The hostname of the request does need to be localhost
This is helpful to know. I've been grappling with the same problem as OP on and off for a few weeks.

Bet Angel wrote:
Tue Jul 18, 2023 2:52 pm
We'll make the changes ready for the next beta of Bet Angel.
Thanks!

Medz89 wrote:
Mon Jul 17, 2023 1:54 pm
How can I access the Bet Angel Api from within a Container?
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 :lol: :lol:

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)
Bet Angel
Bet Angel
Bet Angel
Posts: 4001
Joined: Tue Apr 14, 2009 3:47 pm

Medz89 wrote:
Tue Jul 18, 2023 4:25 pm
Awesome! Thank you very much! Please let us know when the changes are out!
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.
Post Reply

Return to “Bet Angel - API”