Пример #1
0
class TestSubjectGetWithDefault(TestCase):
    def setUp(self):
        self.subject = Subject(
            (
                ("AssetClass", "Future"),
                ("Exchange", "BMF"),
                ("Level", "1"),
                ("Source", "Reuters"),
                ("Symbol", "DDIF6"),
            )
        )

    def test_first_component_value(self):
        self.assertEqual(self.subject.get("AssetClass", "DEFAULT"), "Future")

    def test_level(self):
        self.assertEqual(self.subject.get("Level", "DEFAULT"), "1")

    def test_exchange(self):
        self.assertEqual(self.subject.get("Exchange", "DEFAULT"), "BMF")

    def test_last_component_value(self):
        self.assertEqual(self.subject.get("Symbol", "DEFAULT"), "DDIF6")

    def test_missing_component_returns_None(self):
        self.assertEqual(self.subject.get("Quantity", "DEFAULT"), "DEFAULT")
Пример #2
0
 def setUp(self):
     self.subject = Subject(
         (
             ("AssetClass", "Future"),
             ("Exchange", "BMF"),
             ("Level", "1"),
             ("Source", "Reuters"),
             ("Symbol", "DDIF6"),
         )
     )
Пример #3
0
 def test_parsed_subject(self):
     subject = Subject.parse_string(
         "AssetClass=Fx,Currency=GBP,Quantity=10000.00,Symbol=GBPJPY"
     )
     self.assertEqual(len(subject), 4)
     self.assertEqual(subject["AssetClass"], "Fx")
     self.assertEqual(subject["Symbol"], "GBPJPY")
Пример #4
0
 def setUp(self):
     self.component_map = {
         "Level": "1",
         "Exchange": "LSE",
         "AssetClass": "Equity",
         "Symbol": "BARC",
     }
     self.subject = Subject.from_dict(self.component_map)
Пример #5
0
 def setUp(self):
     self.subject = Subject(
         (
             ("AssetClass", "Fx"),
             ("Currency", "CHF"),
             ("Quantity", "1000.00"),
             ("Symbol", "CHFUSD"),
         )
     )
Пример #6
0
 def test_length_of_4_part_subject_is_4(self):
     subject = Subject(
         (
             ("AssetClass", "Fx"),
             ("Currency", "GBP"),
             ("Quantity", "1000.00"),
             ("Symbol", "GBPUSD"),
         )
     )
     self.assertEqual(len(subject), 4)
Пример #7
0
 def test_dict_conversion_with_sorting(self):
     subject = Subject.from_dict(
         {
             "Currency": "EUR",
             "Quantity": "10000.00",
             "AssetClass": "Fx",
             "Symbol": "EURUSD",
         }
     )
     self.assertEqual(
         str(subject), "AssetClass=Fx,Currency=EUR,Quantity=10000.00,Symbol=EURUSD"
     )
Пример #8
0
 def test_GBPJPY_subject_to_string(self):
     subject = Subject(
         (
             ("AssetClass", "Fx"),
             ("Currency", "GBP"),
             ("Quantity", "10000.00"),
             ("Symbol", "GBPJPY"),
         )
     )
     self.assertEqual(
         str(subject), "AssetClass=Fx,Currency=GBP,Quantity=10000.00,Symbol=GBPJPY"
     )
Пример #9
0
 def test_dict_conversion(self):
     subject = Subject(
         (
             ("AssetClass", "Fx"),
             ("Currency", "EUR"),
             ("Quantity", "10000.00"),
             ("Symbol", "EURUSD"),
         )
     )
     self.assertEqual(
         str(subject), "AssetClass=Fx,Currency=EUR,Quantity=10000.00,Symbol=EURUSD"
     )
Пример #10
0
 def test_EURUSD_subject_repr(self):
     subject = Subject(
         (
             ("AssetClass", "Fx"),
             ("Currency", "EUR"),
             ("Quantity", "10000.00"),
             ("Symbol", "EURUSD"),
         )
     )
     self.assertEqual(
         repr(subject),
         "Subject(AssetClass=Fx,Currency=EUR,Quantity=10000.00,Symbol=EURUSD)",
     )
Пример #11
0
 def test_flatten(self):
     self.assertListEqual(
         [
             "AssetClass",
             "Fx",
             "Currency",
             "GBP",
             "Quantity",
             "10000.00",
             "Symbol",
             "GBPJPY",
         ],
         Subject.parse_string(
             "AssetClass=Fx,Currency=GBP,Quantity=10000.00,Symbol=GBPJPY"
         ).flatten(),
     )
Пример #12
0
 def test_length_of_1_part_subject_is_1(self):
     subject = Subject((("Symbol", "GBPUSD"),))
     self.assertEqual(len(subject), 1)
Пример #13
0
 def test_subject_matches_subject_parsed_from_its_string(self):
     subject2 = Subject.parse_string(str(self.subject))
     self.assertTrue(self.subject == subject2)
Пример #14
0
 def test_subject_does_not_matches_different_subject(self):
     subject2 = Subject.parse_string(
         "AssetClass=Fx,Currency=GBP,Quantity=10000.00,Symbol=GBPJPY"
     )
     self.assertFalse(self.subject == subject2)
Пример #15
0
 def test_subject_matches_its_clone(self):
     subject2 = Subject.from_dict(self.component_map)
     self.assertTrue(self.subject == subject2)
Пример #16
0
from unittest import TestCase

from bidfx import Subject
from bidfx.pricing._pixie.subscription_register import SubscriptionRegister

SUBJECT1 = Subject.parse_string("Source=A,Symbol=EURGBP")
SUBJECT2 = Subject.parse_string("Source=A,Symbol=GBPAUD")
SUBJECT3 = Subject.parse_string("Source=A,Symbol=GBPUSD")
SUBJECT4 = Subject.parse_string("Source=A,Symbol=GBPNZD")
SUBJECT5 = Subject.parse_string("Source=A,Symbol=USDCAD")


class TestCurrentSubscriptionSet(TestCase):
    def setUp(self):
        self.register = SubscriptionRegister()

    def test_zero_subscribe(self):
        self.assertEqual(None, self.register.subscription_sync(),
                         "No change to be synced")

    def test_single_subscribe(self):
        self.register.subscribe(SUBJECT1)
        self.assertListEqual([SUBJECT1],
                             self.register.subscription_sync().subjects)

    def test_sequence_of_subscribes(self):
        self.register.subscribe(SUBJECT1)
        self.register.subscribe(SUBJECT2)
        self.register.subscribe(SUBJECT3)
        self.assertListEqual([SUBJECT1, SUBJECT2, SUBJECT3],
                             self.register.subscription_sync().subjects)
Пример #17
0
 def test_parsed_subject_to_string_gives_back_equivalent_string(self):
     s = "AssetClass=Fx,Currency=GBP,Quantity=10000.00,Symbol=GBPJPY"
     subject = Subject.parse_string(s)
     self.assertEqual(str(subject), s)
Пример #18
0
from unittest import TestCase

from bidfx import Subject
from bidfx.pricing import (
    PriceEvent,
    SubscriptionEvent,
    SubscriptionStatus,
    ProviderEvent,
    ProviderStatus,
)

PROVIDER = "Pixie-3"
SUBJECT = Subject.parse_string(
    "AssetClass=Fx,Currency=EUR,Quantity=10000.00,Symbol=EURUSD"
)
PRICE = {
    "AskSize": "1000000.0",
    "BidSize": "1000000.0",
    "Ask": "1.109271",
    "Bid": "1.107795",
}


class TestPriceEvent(TestCase):
    def test_get_subject(self):
        self.assertEqual(SUBJECT, PriceEvent(SUBJECT, PRICE, True).subject)

    def test_get_price(self):
        self.assertDictEqual(PRICE, PriceEvent(SUBJECT, PRICE, True).price)

    def test_get_price_is_true_when_there_are_fields(self):
Пример #19
0
 def test_length_of_empty_subject_is_0(self):
     subject = Subject((),)
     self.assertEqual(len(subject), 0)