简体   繁体   English

如何使用FOR循环在python中以逐渐降低的价格向binance发送多个订单

[英]How to send multiple orders to binance at incrementally decreasing prices in python using FOR loop

I am using python-binance to connect to binance cryptocurrency exchange.我正在使用 python-binance 连接到币安加密货币交易所。 I am able to send orders simply using this code:我只需使用此代码即可发送订单:

client.create_margin_order(
                symbol =           'BTCUSDT',
                side =             Client.SIDE_BUY,
                type =             Client.ORDER_TYPE_LIMIT,
                timeInForce =      Client.TIME_IN_FORCE_GTC,
                quantity =         100,
                price =            10000
                recvWindow =       5000,
                timestamp =        time.time_ns())

I am able to get a FOR loop to send the correct number of orders but i need each order in the range to send an order at 5% below the last order.我能够得到一个 FOR 循环来发送正确数量的订单,但我需要该范围内的每个订单以低于最后一个订单 5% 的价格发送订单。 How can I achieve this?我怎样才能做到这一点?

My current idea looks like this, however it sends all 10 orders at 5% below the bid price as opposed to 5% below each previous order.我目前的想法是这样的,但是它以低于投标价 5% 的价格发送所有 10 个订单,而不是低于每个先前订单的 5%。

for x in range(10):
            client.create_margin_order(
                symbol =           'BTCUSDT',
                side =             Client.SIDE_BUY,
                type =             Client.ORDER_TYPE_LIMIT,
                timeInForce =      Client.TIME_IN_FORCE_GTC,
                quantity =         100,
                price =            d.Decimal(bidprice) * d.Decimal(0.95), #????????
                recvWindow =       5000,
                timestamp =        time.time_ns())

Thank you for your suggestions!谢谢你的建议!

Just need to update the price after the API call.只需要在 API 调用后更新价格。

price=10000
for x in range(10):
    print(price)
    price *= .95

Output输出

10000
9500.0
9025.0
8573.75
8145.0625
7737.809375
7350.918906249999
6983.372960937499
6634.204312890623
6302.494097246092

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

相关问题 如何以不同的价格向 FTX 或 binace 发送多个订单 - How to send multiple orders to FTX or binace in different prices 如何使用币安 API 获取所有价格历史记录,以使用 Python 进行加密? - How do I get all the prices history with binance API for a crypto using Python? 如何在精确时间在 Python 中获取 Binance API 价格? - How do I get Binance API prices in Python at a precise time? Python Binance - 如何使用 websocket 获取期货交易的最后价格? - Python Binance - How to get the last PRICES traded in futures with websocket? 如何在 python 的 for 循环中使用数字递增地分配变量名称? - How to incrementally assign variable names using numbers inside a for loop in python? 如何在 binance 中异步创建多个 api 密钥的订单? - How to create orders for multiple api keys asynchronously in binance? 如何使用 Binance API 和 Python-CCXT 下百分比订单? - How to place percentage orders with Binance API and Python-CCXT? 如何使用 websocket python-binance 获得未结订单? - How to get open orders with websocket python-binance? 如何使用 Python netCDF4 增量保存多个变量? - How to incrementally save multiple variables using Python netCDF4? Python:从 Binance API 获取加密货币对价格,从文件循环对 - Python: get crypto pair prices from Binance API, loop pairs from file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM