我使用Python 3.9和Python - Binance API,版本Python - Binance ==1.0.15。在他们的测试环境中,我像这样下购买订单
order=self._get_auth_client(account).order_limit_buy(symbol=formatted_name,
quantity=amount,
price=fiat_price)
返回以下JSON
{'symbol': 'ETHUSDT', 'orderId': 2603582, 'orderListId': -1, 'clientOrderId': 'Ru4Vv2jmxHIfGI21vIMtjD', 'transactTime': 1650828003836, 'price': '2915.16000000', 'origQty': '0.34303000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'fills': []}
使用"orderId"字段,检查订单的状态,然后返回结果
{'symbol': 'ETHUSDT', 'orderId': 2603582, 'orderListId': -1, 'clientOrderId': 'Ru4Vv2jmxHIfGI21vIMtjD', 'price': '2915.16000000', 'origQty': '0.34303000', 'executedQty': '0.08067000', 'cummulativeQuoteQty': '235.16595720', 'status': 'PARTIALLY_FILLED', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'stopPrice': '0.00000000', 'icebergQty': '0.00000000', 'time': 1650828003836, 'updateTime': 1650828050722, 'isWorking': True, 'origQuoteOrderQty': '0.00000000'}
状态表示部分填充。我想知道是否有一种方法来指定我的购买订单,这样它要么完全填充,要么根本不填充。我在他们的文档中没有看到任何指定,但是它们有点稀疏。
部分填充顺序似乎是Reddit上讨论过的一个常见问题。
以下是与您正在执行的order_limit_buy
相关的API文档。
order_limit_buy(timeInForce='GTC', **params)[source]
发送新的限价买单
任何带有iceberqty的订单必须将timeInForce设置为GTC。
参数:
- 符号(str) - required
- 数量(十进制)-所需
- price (str) - required
- timeInForce (str) -默认有效,直到取消
- newClientOrderId (str) -订单的唯一id。未发送时自动生成
- 停止价格(十进制)-用于停止订单
- icebergQty(十进制)-与冰山顺序 一起使用
- newOrderRespType (str) -设置响应JSON。ACK、RESULT或FULL;默认值:结果。
- recvWindow (int) -请求在 内有效的毫秒数
的回报:。API响应
完整响应选项见订单端点
提出:
- BinanceRequestException
- BinanceAPIException
- BinanceOrderException
- BinanceOrderMinAmountException
- BinanceOrderMinPriceException
- BinanceOrderMinTotalException
- BinanceOrderUnknownSymbolException
- BinanceOrderInactiveSymbolException
下面是order_limit_buy函数
的源代码def order_limit_buy(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
"""Send in a new limit buy order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({
'side': self.SIDE_BUY,
})
return self.order_limit(timeInForce=timeInForce, **params)
无论是API参数还是Pythonorder_limit_buy
函数都没有明确如何防止部分填充顺序问题。
这是你的买单:
order=self._get_auth_client(account).order_limit_buy(symbol=formatted_name,
quantity=amount,
price=fiat_price)
您的订单有API文档中所述的3个必需参数:
- 符号(str) - required
- 数量(十进制)-所需
- price (str) - required
我找到了文章什么是限价单?在币安学院网站上。文章是这样说的:
如果你担心你的订单只能部分完成,考虑一下使用填充或删除
基于此语句,我开始查看API文档和源代码,以了解如何设置FILL
或KILL
顺序。
我注意到Pythonorder_limit_buy
函数有这个参数:
:param timeInForce: default Good till cancelled
:type timeInForce: str
默认值为Good till cancelled
或GTC
。
timeInForce
参数有3个可能的值:
TIME_IN_FORCE_GTC = 'GTC' # Good till cancelled
TIME_IN_FORCE_IOC = 'IOC' # Immediate or cancel
TIME_IN_FORCE_FOK = 'FOK' # Fill or kill
注意TIME_IN_FORCE_FOK
或FOK
。
以下是GitHub上的Binance API文档:
生效时间(timeInForce):
设置订单在到期前的有效时间。
状态 | 描述 |
---|---|
GTC | Good Till cancelled 除非订单被取消,否则订单将被记录在账簿上。 |
IOC | 立即或取消 一个订单将尝试在订单到期之前尽可能多地完成订单。 |
FOK | Fill or Kill 如果在执行时不能完成完整的订单,则订单将过期 |
我认为这不可能。这是由于交易所订单匹配系统的性质。当您向发送订单时,请购买0.34303ETH @2915.16,交易所寻找想要卖出的人ETH @2915.16,即。交易对手。然而,他们想要出售的数量很少恰好是0.34303ETH。它可以大于或小于这个量。这就是为什么当市场在规定的价格水平附近大幅波动时,你可以得到部分填补。