-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathinstrument.py
More file actions
1255 lines (988 loc) · 35.3 KB
/
instrument.py
File metadata and controls
1255 lines (988 loc) · 35.3 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ujson as json
from v20.base_entity import BaseEntity
from v20.base_entity import EntityDict
from v20.request import Request
from v20 import spec_properties
class Candlestick(BaseEntity):
"""
The Candlestick representation
"""
#
# Format string used when generating a summary for this object
#
_summary_format = ""
#
# Format string used when generating a name for this object
#
_name_format = ""
#
# Property metadata for this object
#
_properties = spec_properties.instrument_Candlestick
def __init__(self, **kwargs):
"""
Create a new Candlestick instance
"""
super(Candlestick, self).__init__()
#
# The start time of the candlestick
#
self.time = kwargs.get("time")
#
# The candlestick data based on bids. Only provided if bid-based
# candles were requested.
#
self.bid = kwargs.get("bid")
#
# The candlestick data based on asks. Only provided if ask-based
# candles were requested.
#
self.ask = kwargs.get("ask")
#
# The candlestick data based on midpoints. Only provided if midpoint-
# based candles were requested.
#
self.mid = kwargs.get("mid")
#
# The number of prices created during the time-range represented by the
# candlestick.
#
self.volume = kwargs.get("volume")
#
# A flag indicating if the candlestick is complete. A complete
# candlestick is one whose ending time is not in the future.
#
self.complete = kwargs.get("complete")
@staticmethod
def from_dict(data, ctx):
"""
Instantiate a new Candlestick from a dict (generally from loading a
JSON response). The data used to instantiate the Candlestick is a
shallow copy of the dict passed in, with any complex child types
instantiated appropriately.
"""
data = data.copy()
if data.get('bid') is not None:
data['bid'] = \
ctx.instrument.CandlestickData.from_dict(
data['bid'], ctx
)
if data.get('ask') is not None:
data['ask'] = \
ctx.instrument.CandlestickData.from_dict(
data['ask'], ctx
)
if data.get('mid') is not None:
data['mid'] = \
ctx.instrument.CandlestickData.from_dict(
data['mid'], ctx
)
return Candlestick(**data)
class CandlestickData(BaseEntity):
"""
The price data (open, high, low, close) for the Candlestick representation.
"""
#
# Format string used when generating a summary for this object
#
_summary_format = ""
#
# Format string used when generating a name for this object
#
_name_format = ""
#
# Property metadata for this object
#
_properties = spec_properties.instrument_CandlestickData
def __init__(self, **kwargs):
"""
Create a new CandlestickData instance
"""
super(CandlestickData, self).__init__()
#
# The first (open) price in the time-range represented by the
# candlestick.
#
self.o = kwargs.get("o")
#
# The highest price in the time-range represented by the candlestick.
#
self.h = kwargs.get("h")
#
# The lowest price in the time-range represented by the candlestick.
#
self.l = kwargs.get("l")
#
# The last (closing) price in the time-range represented by the
# candlestick.
#
self.c = kwargs.get("c")
@staticmethod
def from_dict(data, ctx):
"""
Instantiate a new CandlestickData from a dict (generally from loading a
JSON response). The data used to instantiate the CandlestickData is a
shallow copy of the dict passed in, with any complex child types
instantiated appropriately.
"""
data = data.copy()
if data.get('o') is not None:
data['o'] = ctx.convert_decimal_number(
data.get('o')
)
if data.get('h') is not None:
data['h'] = ctx.convert_decimal_number(
data.get('h')
)
if data.get('l') is not None:
data['l'] = ctx.convert_decimal_number(
data.get('l')
)
if data.get('c') is not None:
data['c'] = ctx.convert_decimal_number(
data.get('c')
)
return CandlestickData(**data)
class OrderBook(BaseEntity):
"""
The representation of an instrument's order book at a point in time
"""
#
# Format string used when generating a summary for this object
#
_summary_format = ""
#
# Format string used when generating a name for this object
#
_name_format = ""
#
# Property metadata for this object
#
_properties = spec_properties.instrument_OrderBook
def __init__(self, **kwargs):
"""
Create a new OrderBook instance
"""
super(OrderBook, self).__init__()
#
# The order book's instrument
#
self.instrument = kwargs.get("instrument")
#
# The time when the order book snapshot was created.
#
self.time = kwargs.get("time")
#
# The price (midpoint) for the order book's instrument at the time of
# the order book snapshot
#
self.price = kwargs.get("price")
#
# The price width for each bucket. Each bucket covers the price range
# from the bucket's price to the bucket's price + bucketWidth.
#
self.bucketWidth = kwargs.get("bucketWidth")
#
# The partitioned order book, divided into buckets using a default
# bucket width. These buckets are only provided for price ranges which
# actually contain order or position data.
#
self.buckets = kwargs.get("buckets")
@staticmethod
def from_dict(data, ctx):
"""
Instantiate a new OrderBook from a dict (generally from loading a JSON
response). The data used to instantiate the OrderBook is a shallow copy
of the dict passed in, with any complex child types instantiated
appropriately.
"""
data = data.copy()
if data.get('price') is not None:
data['price'] = ctx.convert_decimal_number(
data.get('price')
)
if data.get('bucketWidth') is not None:
data['bucketWidth'] = ctx.convert_decimal_number(
data.get('bucketWidth')
)
if data.get('buckets') is not None:
data['buckets'] = [
ctx.instrument.OrderBookBucket.from_dict(d, ctx)
for d in data.get('buckets')
]
return OrderBook(**data)
class OrderBookBucket(BaseEntity):
"""
The order book data for a partition of the instrument's prices.
"""
#
# Format string used when generating a summary for this object
#
_summary_format = ""
#
# Format string used when generating a name for this object
#
_name_format = ""
#
# Property metadata for this object
#
_properties = spec_properties.instrument_OrderBookBucket
def __init__(self, **kwargs):
"""
Create a new OrderBookBucket instance
"""
super(OrderBookBucket, self).__init__()
#
# The lowest price (inclusive) covered by the bucket. The bucket covers
# the price range from the price to price + the order book's
# bucketWidth.
#
self.price = kwargs.get("price")
#
# The percentage of the total number of orders represented by the long
# orders found in this bucket.
#
self.longCountPercent = kwargs.get("longCountPercent")
#
# The percentage of the total number of orders represented by the short
# orders found in this bucket.
#
self.shortCountPercent = kwargs.get("shortCountPercent")
@staticmethod
def from_dict(data, ctx):
"""
Instantiate a new OrderBookBucket from a dict (generally from loading a
JSON response). The data used to instantiate the OrderBookBucket is a
shallow copy of the dict passed in, with any complex child types
instantiated appropriately.
"""
data = data.copy()
if data.get('price') is not None:
data['price'] = ctx.convert_decimal_number(
data.get('price')
)
if data.get('longCountPercent') is not None:
data['longCountPercent'] = ctx.convert_decimal_number(
data.get('longCountPercent')
)
if data.get('shortCountPercent') is not None:
data['shortCountPercent'] = ctx.convert_decimal_number(
data.get('shortCountPercent')
)
return OrderBookBucket(**data)
class PositionBook(BaseEntity):
"""
The representation of an instrument's position book at a point in time
"""
#
# Format string used when generating a summary for this object
#
_summary_format = ""
#
# Format string used when generating a name for this object
#
_name_format = ""
#
# Property metadata for this object
#
_properties = spec_properties.instrument_PositionBook
def __init__(self, **kwargs):
"""
Create a new PositionBook instance
"""
super(PositionBook, self).__init__()
#
# The position book's instrument
#
self.instrument = kwargs.get("instrument")
#
# The time when the position book snapshot was created
#
self.time = kwargs.get("time")
#
# The price (midpoint) for the position book's instrument at the time
# of the position book snapshot
#
self.price = kwargs.get("price")
#
# The price width for each bucket. Each bucket covers the price range
# from the bucket's price to the bucket's price + bucketWidth.
#
self.bucketWidth = kwargs.get("bucketWidth")
#
# The partitioned position book, divided into buckets using a default
# bucket width. These buckets are only provided for price ranges which
# actually contain order or position data.
#
self.buckets = kwargs.get("buckets")
@staticmethod
def from_dict(data, ctx):
"""
Instantiate a new PositionBook from a dict (generally from loading a
JSON response). The data used to instantiate the PositionBook is a
shallow copy of the dict passed in, with any complex child types
instantiated appropriately.
"""
data = data.copy()
if data.get('price') is not None:
data['price'] = ctx.convert_decimal_number(
data.get('price')
)
if data.get('bucketWidth') is not None:
data['bucketWidth'] = ctx.convert_decimal_number(
data.get('bucketWidth')
)
if data.get('buckets') is not None:
data['buckets'] = [
ctx.instrument.PositionBookBucket.from_dict(d, ctx)
for d in data.get('buckets')
]
return PositionBook(**data)
class PositionBookBucket(BaseEntity):
"""
The position book data for a partition of the instrument's prices.
"""
#
# Format string used when generating a summary for this object
#
_summary_format = ""
#
# Format string used when generating a name for this object
#
_name_format = ""
#
# Property metadata for this object
#
_properties = spec_properties.instrument_PositionBookBucket
def __init__(self, **kwargs):
"""
Create a new PositionBookBucket instance
"""
super(PositionBookBucket, self).__init__()
#
# The lowest price (inclusive) covered by the bucket. The bucket covers
# the price range from the price to price + the position book's
# bucketWidth.
#
self.price = kwargs.get("price")
#
# The percentage of the total number of positions represented by the
# long positions found in this bucket.
#
self.longCountPercent = kwargs.get("longCountPercent")
#
# The percentage of the total number of positions represented by the
# short positions found in this bucket.
#
self.shortCountPercent = kwargs.get("shortCountPercent")
@staticmethod
def from_dict(data, ctx):
"""
Instantiate a new PositionBookBucket from a dict (generally from
loading a JSON response). The data used to instantiate the
PositionBookBucket is a shallow copy of the dict passed in, with any
complex child types instantiated appropriately.
"""
data = data.copy()
if data.get('price') is not None:
data['price'] = ctx.convert_decimal_number(
data.get('price')
)
if data.get('longCountPercent') is not None:
data['longCountPercent'] = ctx.convert_decimal_number(
data.get('longCountPercent')
)
if data.get('shortCountPercent') is not None:
data['shortCountPercent'] = ctx.convert_decimal_number(
data.get('shortCountPercent')
)
return PositionBookBucket(**data)
class EntitySpec(object):
"""
The instrument.EntitySpec wraps the instrument module's type definitions
and API methods so they can be easily accessed through an instance of a v20
Context.
"""
Candlestick = Candlestick
CandlestickData = CandlestickData
OrderBook = OrderBook
OrderBookBucket = OrderBookBucket
PositionBook = PositionBook
PositionBookBucket = PositionBookBucket
def __init__(self, ctx):
self.ctx = ctx
def candles(
self,
instrument,
**kwargs
):
"""
Fetch candlestick data for an instrument.
Args:
instrument:
Name of the Instrument
price:
The Price component(s) to get candlestick data for. Can contain
any combination of the characters "M" (midpoint candles) "B"
(bid candles) and "A" (ask candles).
granularity:
The granularity of the candlesticks to fetch
count:
The number of candlesticks to return in the reponse. Count
should not be specified if both the start and end parameters
are provided, as the time range combined with the graularity
will determine the number of candlesticks to return.
fromTime:
The start of the time range to fetch candlesticks for.
toTime:
The end of the time range to fetch candlesticks for.
smooth:
A flag that controls whether the candlestick is "smoothed" or
not. A smoothed candlestick uses the previous candle's close
price as its open price, while an unsmoothed candlestick uses
the first price from its time range as its open price.
includeFirst:
A flag that controls whether the candlestick that is covered by
the from time should be included in the results. This flag
enables clients to use the timestamp of the last completed
candlestick received to poll for future candlesticks but avoid
receiving the previous candlestick repeatedly.
dailyAlignment:
The hour of the day (in the specified timezone) to use for
granularities that have daily alignments.
alignmentTimezone:
The timezone to use for the dailyAlignment parameter.
Candlesticks with daily alignment will be aligned to the
dailyAlignment hour within the alignmentTimezone. Note that
the returned times will still be represented in UTC.
weeklyAlignment:
The day of the week used for granularities that have weekly
alignment.
Returns:
v20.response.Response containing the results from submitting the
request
"""
request = Request(
'GET',
'/v3/instruments/{instrument}/candles'
)
request.set_path_param(
'instrument',
instrument
)
request.set_param(
'price',
kwargs.get('price')
)
request.set_param(
'granularity',
kwargs.get('granularity')
)
request.set_param(
'count',
kwargs.get('count')
)
request.set_param(
'from',
kwargs.get('fromTime')
)
request.set_param(
'to',
kwargs.get('toTime')
)
request.set_param(
'smooth',
kwargs.get('smooth')
)
request.set_param(
'includeFirst',
kwargs.get('includeFirst')
)
request.set_param(
'dailyAlignment',
kwargs.get('dailyAlignment')
)
request.set_param(
'alignmentTimezone',
kwargs.get('alignmentTimezone')
)
request.set_param(
'weeklyAlignment',
kwargs.get('weeklyAlignment')
)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
#
# Parse responses as defined by the API specification
#
if str(response.status) == "200":
if jbody.get('instrument') is not None:
parsed_body['instrument'] = \
jbody.get('instrument')
if jbody.get('granularity') is not None:
parsed_body['granularity'] = \
jbody.get('granularity')
if jbody.get('candles') is not None:
parsed_body['candles'] = [
self.ctx.instrument.Candlestick.from_dict(d, self.ctx)
for d in jbody.get('candles')
]
elif str(response.status) == "400":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "404":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
#
# Unexpected response status
#
else:
parsed_body = jbody
response.body = parsed_body
return response
def price(
self,
instrument,
**kwargs
):
"""
Fetch a price for an instrument. Accounts are not associated in any way
with this endpoint.
Args:
instrument:
Name of the Instrument
time:
The time at which the desired price is in effect. The current
price is returned if no time is provided.
Returns:
v20.response.Response containing the results from submitting the
request
"""
request = Request(
'GET',
'/v3/instruments/{instrument}/price'
)
request.set_path_param(
'instrument',
instrument
)
request.set_param(
'time',
kwargs.get('time')
)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
#
# Parse responses as defined by the API specification
#
if str(response.status) == "200":
if jbody.get('price') is not None:
parsed_body['price'] = \
self.ctx.pricing_common.Price.from_dict(
jbody['price'],
self.ctx
)
elif str(response.status) == "400":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "404":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
#
# Unexpected response status
#
else:
parsed_body = jbody
response.body = parsed_body
return response
def prices(
self,
instrument,
**kwargs
):
"""
Fetch a range of prices for an instrument. Accounts are not associated
in any way with this endpoint.
Args:
instrument:
Name of the Instrument
fromTime:
The start of the time range to fetch prices for.
toTime:
The end of the time range to fetch prices for. The current time
is used if this parameter is not provided.
Returns:
v20.response.Response containing the results from submitting the
request
"""
request = Request(
'GET',
'/v3/instruments/{instrument}/price/range'
)
request.set_path_param(
'instrument',
instrument
)
request.set_param(
'from',
kwargs.get('fromTime')
)
request.set_param(
'to',
kwargs.get('toTime')
)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
#
# Parse responses as defined by the API specification
#
if str(response.status) == "200":
if jbody.get('prices') is not None:
parsed_body['prices'] = [
self.ctx.pricing_common.Price.from_dict(d, self.ctx)
for d in jbody.get('prices')
]
elif str(response.status) == "400":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "404":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
#
# Unexpected response status
#
else:
parsed_body = jbody
response.body = parsed_body
return response
def order_book(
self,
instrument,
**kwargs
):
"""
Fetch an order book for an instrument.
Args:
instrument:
Name of the Instrument
time:
The time of the snapshot to fetch. If not specified, then the
most recent snapshot is fetched.
Returns:
v20.response.Response containing the results from submitting the
request
"""
request = Request(
'GET',
'/v3/instruments/{instrument}/orderBook'
)
request.set_path_param(
'instrument',
instrument
)
request.set_param(
'time',
kwargs.get('time')
)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
#
# Parse responses as defined by the API specification
#
if str(response.status) == "200":
if jbody.get('orderBook') is not None:
parsed_body['orderBook'] = \
self.ctx.instrument.OrderBook.from_dict(
jbody['orderBook'],
self.ctx
)
elif str(response.status) == "400":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
elif str(response.status) == "401":