-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpips_to_price_to_pips.py
153 lines (147 loc) · 2.75 KB
/
pips_to_price_to_pips.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def pips_to_price(instrument, pips):
"""
Given an instrument and price, convert price to pips
Examples:
pips_to_price('USD_JPY', 100) == 1
Returns: decimal or None
"""
if instrument in currency_pair_conversions:
return (currency_pair_conversions[instrument] * pips);
else:
return None
def price_to_pips(instrument, price):
"""
"""
if not instrument in currency_pair_conversions:
return None
else:
# TODO Why the check for zero?
if price != 0:
return (price / currency_pair_conversions[instrument])
return 0
currency_pair_conversions = {
'AU200_AUD':0.1
,'AUD_CAD':0.0001
,'AUD_CHF':0.0001
,'AUD_HKD':0.0001
,'AUD_JPY':0.01
,'AUD_NZD':0.0001
,'AUD_SGD':0.0001
,'AUD_USD':0.0001
,'BCO_USD':0.01
,'CAD_CHF':0.0001
,'CAD_HKD':0.0001
,'CAD_JPY':0.01
,'CAD_SGD':0.0001
,'CH20_CHF':0.1
,'CHF_HKD':0.0001
,'CHF_JPY':0.01
,'CHF_ZAR':0.0001
,'CORN_USD':0.01
,'DE10YB_EUR':0.01
,'DE30_EUR':0.1
,'EU50_EUR':0.1
,'EUR_AUD':0.0001
,'EUR_CAD':0.0001
,'EUR_CHF':0.0001
,'EUR_CZK':0.0001
,'EUR_DKK':0.0001
,'EUR_GBP':0.0001
,'EUR_HKD':0.0001
,'EUR_HUF':0.01
,'EUR_JPY':0.01
,'EUR_NOK':0.0001
,'EUR_NZD':0.0001
,'EUR_PLN':0.0001
,'EUR_SEK':0.0001
,'EUR_SGD':0.0001
,'EUR_TRY':0.0001
,'EUR_USD':0.0001
,'EUR_ZAR':0.0001
,'FR40_EUR':0.1
,'GBP_AUD':0.0001
,'GBP_CAD':0.0001
,'GBP_CHF':0.0001
,'GBP_HKD':0.0001
,'GBP_JPY':0.01
,'GBP_NZD':0.0001
,'GBP_PLN':0.0001
,'GBP_SGD':0.0001
,'GBP_USD':0.0001
,'GBP_ZAR':0.0001
,'HK33_HKD':0.1
,'HKD_JPY':0.0001
,'JP225_USD':0.1
,'NAS100_USD':0.1
,'NATGAS_USD':0.01
,'NL25_EUR':0.01
,'NZD_CAD':0.0001
,'NZD_CHF':0.0001
,'NZD_HKD':0.0001
,'NZD_JPY':0.01
,'NZD_SGD':0.0001
,'NZD_USD':0.0001
,'SG30_SGD':0.1
,'SGD_CHF':0.0001
,'SGD_HKD':0.0001
,'SGD_JPY':0.01
,'SOYBN_USD':0.01
,'SPX500_USD':0.1
,'SUGAR_USD':0.0001
,'TRY_JPY':0.01
,'UK100_GBP':0.1
,'UK10YB_GBP':0.01
,'US2000_USD':0.01
,'US30_USD':0.1
,'USB02Y_USD':0.01
,'USB05Y_USD':0.01
,'USB10Y_USD':0.01
,'USB30Y_USD':0.01
,'USD_CAD':0.0001
,'USD_CHF':0.0001
,'USD_CNH':0.0001
,'USD_CNY':0.0001
,'USD_CZK':0.0001
,'USD_DKK':0.0001
,'USD_HKD':0.0001
,'USD_HUF':0.01
,'USD_INR':0.01
,'USD_JPY':0.01
,'USD_MXN':0.0001
,'USD_NOK':0.0001
,'USD_PLN':0.0001
,'USD_SAR':0.0001
,'USD_SEK':0.0001
,'USD_SGD':0.0001
,'USD_THB':0.01
,'USD_TRY':0.0001
,'USD_TWD':0.0001
,'USD_ZAR':0.0001
,'WHEAT_USD':0.01
,'WTICO_USD':0.01
,'XAG_AUD':0.0001
,'XAG_CAD':0.0001
,'XAG_CHF':0.0001
,'XAG_EUR':0.0001
,'XAG_GBP':0.0001
,'XAG_HKD':0.0001
,'XAG_JPY':0.1
,'XAG_NZD':0.0001
,'XAG_SGD':0.0001
,'XAG_USD':0.0001
,'XAU_AUD':0.01
,'XAU_CAD':0.01
,'XAU_CHF':0.01
,'XAU_EUR':0.01
,'XAU_GBP':0.01
,'XAU_HKD':0.01
,'XAU_JPY':10
,'XAU_NZD':0.01
,'XAU_SGD':0.01
,'XAU_USD':0.01
,'XAU_XAG':0.01
,'XCU_USD':0.0001
,'XPD_USD':0.01
,'XPT_USD':0.01
,'ZAR_JPY':0.01
}