Get the App
SLTechnology News&Howtos  ›  Development  › 

The solution to the failure of hanging order before opening in VNPY

Shulou Source: shulou.com Published: 2022-06-02 08:06:48 09月18日 Update

This article will explain in detail the solutions to the failure of hanging orders before the opening of VNPY. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

In VNPY quantitative trading platform, hanging stop order (STOP Order) is a common way to initiate a transaction. A stop order does not start a transaction until the price reaches the predetermined point.

Futures trading at 9: 00 in the morning and 9: 00 in the night just opened for 10 minutes, which is often the most volatile period of time, with a lot of trading opportunities. However, the existence of VNPY obviously should have a stop order, but it will not be available at the opening time. It should be at the opening time that all pending orders are invalid. Although these pending orders are invalid within VNPY, they will also fail. The specific code has been read for a long time, but still can not find the specific reason.

A temporary fix is provided here.

Define a global policy variable stopOpenOrder, with a default value of False

Define a global variable status, with the default value of NA, and put it in the policy judgment transaction code. Once the order is triggered, update this to the hanging order direction.

Finally, the stop order price is also set as a global variable.

two。 Override stops single push function. Once billed, the stopOpenOrder becomes True.

Def onStopOrder (self, so):

"" stop single push ""

Self.writeCtaLog (blocked% s, variety:% s, status:% s, direction:% s, price:% s% (self.name, so.vtSymbol, so.status, so.orderType, so.price))

If so.offset = = OFFSET_OPEN:

Self.stopOpenOrder = True

Self.putEvent ()

3. Override OnTick function. If pos is empty and stopOpenOrder = = False, if status is buy or short, hang the order accordingly.

Def onTick (self, tick):

"" receive quotation TICK push (must be inherited by the user) ""

If self.pos = 0 and self.stopOpenOrder = = False:

If self.status = = "buy":

Self.buy (self.buyPrice, self.fixedSize, True)

Elif self.status = = "short":

Self.short (self.shortPrice, self.fixedSize, True)

Self.bg.updateTick (tick)

In the actual test, if the hanging order condition is met, but no hanging order is issued, the order will be hung automatically when the first tick arrives.

The solution to the failure of hanging orders before the opening of VNPY is shared here. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Transaction method global variable time push code price content article direction is in more knowledge strategy article good maximum trading platform price Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Shulou Technology Docker Microsoft