-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSprites.py
95 lines (85 loc) · 2.7 KB
/
Sprites.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from threading import *
class Sprite:
def __init__(self, instrument, origin):
self.instrument = instrument
self.origin: Grid = origin
self.exchange = self.instrument.exchange
self.symbol = self.instrument.symbol
self.instrument.create_sprite(self)
self.new_quote_flag = Event()
self.quote = 0
self.thread = Thread(target=self.feed, daemon=True)
def quote_update(self, quote):
self.quote = quote
self.new_quote_flag.set()
def feed(self):
while self.new_quote_flag.wait():
self.new_quote_flag.clear()
def kill(self):
self.instrument.kill_sprite(self)
@staticmethod
def get_ltp(quote):
return quote['last_price']
@staticmethod
def get_timestamp(quote):
return quote['timestamp']
@staticmethod
def get_volume(quote):
return quote['volume']
@staticmethod
def get_oi(quote):
return quote['oi']
# class PriceAbove(Sprite):
# def __init__(self, instrument, origin, id, price, event_handler):
# super().__init__(instrument, origin)
# self.price = price
# self.event_handler = event_handler
# self.id = id
#
# def feed(self, quote):
# quote = float(quote['ltp'])
# if quote > self.price:
# self.event_handler(self.id)
# self.kill()
#
#
# class PriceAboveOrEqual(Sprite):
# def __init__(self, instrument, origin, id, price, event_handler):
# super().__init__(instrument, origin)
# self.price = price
# self.event_handler = event_handler
# self.id = id
#
# def feed(self, quote):
# quote = float(quote['ltp'])
# if quote >= self.price:
# self.event_handler(self.id)
# self.kill()
#
#
# class PriceBelow(Sprite):
# def __init__(self, instrument, origin, id, price, event_handler):
# super().__init__(instrument, origin)
# self.price = price
# self.event_handler = event_handler
# self.id = id
#
# def feed(self, quote):
# quote = float(quote['ltp'])
# if quote < self.price:
# self.event_handler(self.id)
# self.kill()
#
#
# class PriceBelowOrEqual(Sprite):
# def __init__(self, instrument, origin, id, price, event_handler):
# super().__init__(instrument, origin)
# self.price = price
# self.event_handler = event_handler
# self.id = id
#
# def feed(self, quote):
# quote = float(quote['ltp'])
# if quote <= self.price:
# self.event_handler(self.id)
# self.kill()