繁体   English   中英

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

[英]AWS chalice local works but not chalice deploy

我对编码和 aws chalice 还是很陌生。 我尝试编写一个从交易视图获取消息并根据信号执行订单的代码。 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”检查了我的设置,它们很好。 一开始的索引 function 也有效,所以我的代码应该有问题吗? 我更改了一些值并删除了一些函数和策略部分,但代码看起来有点像这样:

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"}

我用 Insomnia 在本地对其进行了测试,并尝试了 Rest API 链接和我的浏览器,两者都显示相同的错误消息。 我的测试方法是错误的还是代码? 但即便如此,当我再次从头开始包含索引 function 时,为什么 Rest API 链接不起作用? 如果我从头开始尝试索引 function ,我会得到{"message": "Internal server error"} 这可能是一个非常基本的问题,但我在网上找不到答案。 任何帮助,将不胜感激!

我不太确定这是否对您有帮助,因为我不太了解您的问题,但是:

您正在使用一个POST-request ,该请求不会通过打开 URL 来执行。

尝试类似@app.route('/test123', methods=['POST', 'GET'])这样如果你只是打开URL,它将执行一个GET-request

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

暂无
暂无

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

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