-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstrument.py
65 lines (53 loc) · 1.75 KB
/
instrument.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
import pandas as pd
import utils
class Instrument():
def __init__(self, ob):
self.name = ob['name']
self.ins_type = ob['type']
self.displayName = ob['displayName']
self.pipLocation = pow(10, ob['pipLocation']) # -4 -> 0.0001
self.marginRate = ob['marginRate']
def __repr__(self):
return str(vars(self))
@classmethod
def get_instruments_df(cls):
return pd.read_pickle(utils.get_instruments_data_filename())
@classmethod
def get_instruments_list(cls):
df = cls.get_instruments_df()
return [Instrument(x) for x in df.to_dict(orient='records')]
'''
dict to access instruments by pair name
instrument_dict =
{
"EUR_USD" : Instrument(),
"EUR_GBP" : Instrument(),
"..." : Instrument(),
}
our_instrument = instrument_dict["EUR_USD"]
'''
@classmethod
def get_instruments_dict(cls):
i_list = cls.get_instruments_list()
i_keys = [x.name for x in i_list]
return { k:v for (k,v) in zip(i_keys, i_list) }
@classmethod
def get_instrument_by_name(cls, pairname):
d = cls.get_instruments_dict()
if pairname in d:
return d[pairname]
else:
return None
@classmethod
def get_pairs_from_string(cls, pair_str):
existing_pairs = cls.get_instruments_dict().keys()
pairs = pair_str.split(",")
pair_list = []
for p1 in pairs:
for p2 in pairs:
p = f"{p1}_{p2}"
if p in existing_pairs:
pair_list.append(p)
return pair_list
if __name__ == "__main__":
print(Instrument.get_test_pairs("GBP,EUR,USD,CAD,JPY,NZD,CHF"))