简体   繁体   English

AWS 圣杯本地工作,但不是圣杯部署

[英]AWS chalice local works but not chalice deploy

I am pretty new to coding and aws chalice.我对编码和 aws chalice 还是很陌生。 I tried writing a code that gets messages from trading-view and executes orders depending on the signals.我尝试编写一个从交易视图获取消息并根据信号执行订单的代码。 I tested the code locally and everything worked fine, but when I test the Rest API I get the following error: {"message":"Missing Authentication Token"} I set up my credentials via "aws configure" as explained here: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html I also created a config.txt file in my aws folder and checked my settings via "aws configure get" and they were fine. I tested the code locally and everything worked fine, but when I test the Rest API I get the following error: {"message":"Missing Authentication Token"} I set up my credentials via "aws configure" as explained here: https: //docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html我还在我的aws文件夹中创建了一个config.txt文件,并通过“aws configure get”检查了我的设置,它们很好。 The index function in the beginning worked too, so there should be a problem within my code?一开始的索引 function 也有效,所以我的代码应该有问题吗? I changed some values and cut some functions and the strategy part out, but the code looks somewhat like this:我更改了一些值并删除了一些函数和策略部分,但代码看起来有点像这样:

from chalice import Chalice
from datetime import datetime
from binance.client import Client
from binance.enums import *
import ccxt


exchange = ccxt.binance({
    'apiKey': 'KEY',
    'secret': 'SECRET',
    'enableRateLimit': True,
    'options': {
        'defaultType': 'future',
    },
})

def buy_order(quantity, symbol, order_type = ORDER_TYPE_MARKET,side=SIDE_BUY,recvWindow=5000):
try:
    print("sending order")
    order = client.futures_create_order(symbol = symbol, type = order_type, side = side, quantity = quantity,recvWindow=recvWindow)
    print(order)
except Exception as e:
    print("an exception occured - {}".format(e))
    return False

return True

app = Chalice(app_name='tradingview-webhook-alert')
indicator1 = "x"
indicator2 = "y"
TRADE_SYMBOL = "Test123"
in_position = False

def diff_time(time1, time2):
    fmt = '%Y-%m-%dT%H:%M:%SZ'
    tstamp1 = datetime.strptime(time1, fmt)
    tstamp2 = datetime.strptime(time2, fmt)
    if tstamp1 > tstamp2:
        td = tstamp1 - tstamp2
    else:
        td = tstamp2 - tstamp1
    td_mins = int(round(td.total_seconds() / 60))
    return td_mins

@app.route('/test123', methods=['POST'])
def test123():
    global indicator1, indicator2
    request = app.current_request
    message = request.json_body
    indicator = message["indicator"]
    price = message["price"]
    value = message["value"]
    if indicator == "indicator1":
        indicator1 = value
    if indicator == "indicator2":
        indicator2 = value
    if in_position == False:
        if (indicator1 >123) & (indicator2 < 321):
            balance = exchange.fetch_free_balance()
            usd = float(balance['USDT'])
            TRADE_QUANTITY = (usd / price)*0.1
            order_succeeded = buy_order(TRADE_QUANTITY, TRADE_SYMBOL)
            if order_succeeded:
                in_position = True
return {"test": "123"}

I tested it locally with Insomnia and tried the Rest API link there and in my browser, both with the same error message.我用 Insomnia 在本地对其进行了测试,并尝试了 Rest API 链接和我的浏览器,两者都显示相同的错误消息。 Is my testing method wrong or is it the code?我的测试方法是错误的还是代码? But even then, why isn't the Rest API link working, when I include the index function from the beginning again?但即便如此,当我再次从头开始包含索引 function 时,为什么 Rest API 链接不起作用? If I try the index function from the beginning, I get the {"message": "Internal server error"} .如果我从头开始尝试索引 function ,我会得到{"message": "Internal server error"} This is probably a very very basic question but I couldn't find an answer online.这可能是一个非常基本的问题,但我在网上找不到答案。 Any help would be appreciated!任何帮助,将不胜感激!

I am not pretty sure if that helps you because I don't really understand your question but:我不太确定这是否对您有帮助,因为我不太了解您的问题,但是:

You are using a POST-request which will not be executed by opening a URL.您正在使用一个POST-request ,该请求不会通过打开 URL 来执行。

Try something like @app.route('/test123', methods=['POST', 'GET']) so that if you just open the URL, it will execute a GET-request尝试类似@app.route('/test123', methods=['POST', 'GET'])这样如果你只是打开URL,它将执行一个GET-request

Some more information: https://www.w3schools.com/tags/ref_httpmethods.asp更多信息: https://www.w3schools.com/tags/ref_httpmethods.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM