Query Account With Time Lags

To track positions timely, I’m checking positions whenever there’s a trade done via onTrade() method from PythonGo. However there’s a threshold on how frequent you could query the account, and you might receive warning from the broker if you query too often.

The solution to this issue is to place a time lag from current query to the next, and we would use the cached positions. At time T, before we query account, we would check Redis if the Position-Key has value, if so, we will use the cached positions; if not, then we have to query account to have a list of positions, which would be saved to Redis under Position-Key, and such key would expire in N seconds.

Related redis commands as following.

SET mkey "hello"
GET mkey
EXPIRE mkey 10
TTL mkey
GET mkey
import redis
r=redis.Redis(host='localhost',port=6379,db=0)
r.set("mkey","hello")
r.get("mkey")
r.expire("mkey")
r.ttl("mkey")
r.get("mkey")

Published by

wofong

三千娑婆世界,三千难忘遗憾;回头乃是岸,此岸在何方;堪忍不能忍,万般看不穿;何时放得下,始得自在心。 I'm a programmer, a quantitative analyst, a photography hobbyist, a traveler, a runner, and a nature lover.

Leave a comment