Pages

Thursday, January 7, 2016

Streaming OANDA with python and ZeroMQ

I have been looking at its REST API for OANDA, for potential use with an FX trading system I developed.

The API has two streaming endpoints, one for prices and one for account events such as trades opening and stuff like that.  

Asynchronous IO is always a bit fiddly, and I wanted separate processes for incoming tick data and events. This enables them to be managed separately, and generally makes handling disconnects or other errors a bit cleaner.

If you try and mash your various feeds, trade identification, trade management, logging, accounting etc all into one big process it gets a bit messy and convoluted. Sometimes you don’t have a choice due to the API available, but thankfully in this case it’s easy to separate everything out.

Details


I use the requests library for streaming from OANDA, and ZeroMQ endpoints with the pub/sub pattern for passing data to the client(s).

Conceptually, it looks like this:



The prices feed connects to the OANDA prices endpoint, and publishes what it receives to a ZeroMQ socket. Likewise, the events feed does the same, publishing to another zmq socket.

The client connects to the respective sockets and subscribes to its feeds, and can do whatever is required with the data it receives. You are not limited to one client subscriber either.

I use JSON as the serialization format, as it arrives from OANDA. No real point in deserializing JSON to an object, then immediately serializing that with pickle or something for transport with zeromq. Your needs may differ of course.  

All up, a pretty painless process.

Code


The single file of code (here) is the prices feed, events feed and client that just prints out what it receives. Just run it separately three times, passing either prices, events or client as a single argument. You will also need to fill in your OANDA details as well.

I use a 10 second timeout for the prices feed, and a 20 second timeout for the events feed, as per OANDAs recommendations. The feed streams will print heartbeats but not publish them to clients.

Thanks for reading and let me know how you go.

17 comments:

  1. Hello everyone, Are you looking for a professional trader, forex and binary manager who will help you trade and manager your account with good and massive amount of profit in return. you can contact Mr. Anderson for your investment plan, for he helped me earned 12,000usd with little investment funds. Mr Anderson you're the best trader I can recommend for anyone who wants to invest and trade with a genuine trader, he also helps in recovery of loss funds..you can contact him on his whatsapp: (+447883246472) Email:(tdameritrade077@gmail.com)I advice you shouldn't hesitate He's great.

    ReplyDelete
    Replies
    1. LEGIT FULLZ & TOOLS STORE

      Hello to All !

      We are offering all types of tools & Fullz on discounted price.
      If you are in search of anything regarding fullz, tools, tutorials, Hack Pack, etc
      Feel Free to contact

      ***CONTACT 24/7***
      **Telegram > @leadsupplier
      **ICQ > 752822040
      **Skype > Peeterhacks
      **Wicker me > peeterhacks

      "SSN LEADS/FULLZ AVAILABLE"
      "TOOLS & TUTORIALS AVAILABLE FOR HACKING, SPAMMING,
      CARDING, CASHOUT, CLONING, SCRIPTING ETC"

      **************************************
      "Fresh Spammed SSN Fullz info included"
      >>SSN FULLZ with complete info
      >>CC With CVV (vbv & non vbv) Fullz USA
      >>FULLZ FOR SBA, PUA & TAX RETURN FILLING
      >>USA I.D Photos Front & Back
      >>High Credit Score fullz (700+ Scores)
      >>DL number, Employee Details, Bank Details Included
      >>Complete Premium Info with Relative Info

      ***************************************
      COMPLETE GUIDE FOR TUTORIALS & TOOLS

      "SPAMMING" "HACKING" "CARDING" "CASH OUT"
      "KALI LINUX" "BLOCKCHAIN BLUE PRINTS" "SCRIPTING"
      "FRAUD BIBLE"

      "TOOLS & TUTORIALS LIST"
      =>Ethical Hacking Ebooks, Tools & Tutorials
      =>Bitcoin Hacking
      =>Kali Linux
      =>Fraud Bible
      =>RAT
      =>Keylogger & Keystroke Logger
      =>Whatsapp Hacking & Hacked Version of Whatsapp
      =>Facebook & Google Hacking
      =>Bitcoin Flasher
      =>SQL Injector
      =>Premium Logs (PayPal/Amazon/Coinbase/Netflix/FedEx/Banks)
      =>Bitcoin Cracker
      =>SMTP Linux Root
      =>Shell Scripting
      =>DUMPS with pins track 1 and 2 with & without pin
      =>SMTP's, Safe Socks, Rdp's brute
      =>PHP mailer
      =>SMS Sender & Email Blaster
      =>Cpanel
      =>Server I.P's & Proxies
      =>Viruses & VPN's
      =>HQ Email Combo (Gmail, Yahoo, Hotmail, MSN, AOL, etc.)

      *Serious buyers will always welcome
      *Price will be reduce in bulk order
      *Discount offers will give to serious buyers
      *Hope we do a great business together

      ===>Contact 24/7<===
      ==>Telegram > @leadsupplier
      ==>ICQ > 752822040
      ==>Skype > Peeterhacks
      ==>Wicker me > peeterhacks

      Delete
  2. I have read Your Article and Learn a lot from it. I can Imagine the time it took to get all this expertise exposed . You can also look here to see where to easily get a FAKE BANK STATEMENT I've bookmark your site and furthermore include RSS. keep us refreshed all the time.

    While doing more research , I fell on this EXPERTS TELEGRAM GROUP which helped me to obtain a statement for Wells Fargo of which my loan was approved with ease . I was amazed so I decided to share the platform for everyone to enjoy their services.

    ReplyDelete
  3. We have specially programmed ATMs that can be used to withdraw money at ATMs, shops and points of sale. We sell these cards to all our customers and interested buyers all over the world, the cards have a withdrawal limit every week.The programmed ATM card withdraw money from each ATM but have a withdrawal limit every week, only your PIN code is in it, it is a high-tech card system. The PROGRAMMED ATM card works on all card-based ATMs, anywhere in the world.
    -hack into any kind of phone
    _Increase Credit Scores
    _western union, bitcoin and money gram hacking
    _criminal records deletion_BLANK ATM/CREDIT CARDS
    _Hacking of phones(that of your spouse, boss, friends, and see whatever is being discussed behind your back)
    _Security system hacking...and so much more. Contact us now and get whatever you want at
    Email:creditcards.creditscoreupgrade@gmail.com
    whatsapp:+1785 279 3047

    ReplyDelete
  4. My name is Mohammed Ahsan I'm a financial Consultant of a reputable firm Operating out of the United Kingdom
    we provide Discrete Financial, Services for High Net Worth CEO's/Executives of Corporation & Senior Government Officials globally.
    What we do is Legal & within the ambit of the law but following the Leakage of the Infamous United Kingdom
    Papers & subsequent threat by the International Consortium of Investigative Journalists (ICIJ)
    International Criminal Court (ICC)
    Below is what my Sender can offer.
    1, MT103 gpi automatic
    2, MT103 wire transfer
    3, MT103 TT
    4, MT103/202 manual download
    5, SBLC lease and Purchase

    All bank instrument will be done via bank officer to bank officer, Receiver has to provide bank officer details
    on DOA all brokers are welcome and guarantee of there payment after successful deal
    kindly send me a message via email and WhatsApp.


    Email: mohammedahsan877@gmail.com

    WhatsApp- +19893413179

    ReplyDelete
  5. I am Larry Baier. I can never stop thanking Dr Graceondu for transforming my life, i have been playing lottery games for a very long time and i have never one day win any game, i met a friend whom i complained to about my inability to win and he introduced me to Dr Graceondu whom helped him by praying for him and giving him a game that he played and he won $150,000
    so i contacted him through his email and he assured me that i will win big. he asked me to give him two day so he can make some prayers on my behalf so that the winning numbers will be revealed to him, so i waited for two days the second day he sent me the number to play, so i play the game i never had it in my mind that i was going to win such amount of money, so on that faithful day i went to check the game on April 16, 2021 and behold i got the biggest shock of my life i won $2,000,000 and from that moment my life changed.
    all thanks to Dr Graceondu, i want to also advice everyone out there to also contact him if you have been playing lottery and you have never won.
    You can reach him via his email, drgraceondu12@gmail.com or WhatsApp him +15204677763, you can also visit his Website. https://drgraceonduadodo.com

    ReplyDelete
  6. RECOVER YOUR FUNDS FROM FAKE INVESTMENT COMPANY, FAKE BINARY OPTION ETC.
    Have you been ripped by scammers online, have you invested your funds in the wrong investment companies? You do not need to worry any more as we provide you with an answer which is GETTING BACK WHAT YOU HAVE LOST. We at CRYPTOREFUNDER360(AT)GMAIL(DOT)COM provide Btc recovery services. It does not matter how mush you have been ripped off or when it happened, provided we have the right and necessary informations, then we can assure you of a quick and safe recovery. We have testimonies flowing daily on lost funds being recovered safely. You may not be in need of this but tell a friend who is. You can contact us by mail @ Cryptorefunder360(at)gmail(dot)com.

    ReplyDelete
  7. Borrow money here today at 3% interest rate. Sawda Capital Finance offers all kinds of financial services of all sizes ranging from individuals, companies, and traders globally./Our services are 100% guaranteed and risk-free.

    We build just the right financing for each client, with simple paperwork, quick approvals, and flexible payment schedules. For further details, Kindly contact us via email At sawda.finance@gmail.com

    Intermediaries/Consultants/Brokers are welcome to bring their clients and are 100% protected. In complete confidence, we will work together for the benefits of all parties involved, Looking forward to rendering the best of our services to all esteemed clientele globally.

    ReplyDelete
  8. Few Months ago, I felt so depressed, got frustrated dealing with bad credits, but reaching out to HACK VANISH via Phone: +1 (747) 293-8514 and Email: HACK VANISH (@) GMAIL. COM gave my life a new meaning, after I found him credible through positive reviews read on some credit blogs, in a twinkle of an eye, this great hacker restored my credit score from 509 to 784 across all 3 major credit bureaus, evictions and repossession cleared, my LexisNexis and Chex system fixed respectively, some days later, I received an E-mail confirming the approval of my home loan, it was quite amazing because I never thought it was possible. Today, I can confidently say 2021 was an exceptional year for my husband and I as we now own a new home and a brand-new SUV courtesy HACK VANISH, I would definitely recommend him to anyone in need of a genuine Hacker.

    ReplyDelete

  9. Richmond super are just very terrible set of professionals who seem to bed very goo good at what they do.
    I did a due diligence test before investing with Richmond but guess what ?
    I ended up getting burned. This is to create awareness, not everybody can be as lucky as I was.
    if claimpayback.com had not taken my case and reclaim my loses, i would never have understood Richmonds modus operandi.
    not even only Richmond, but Etoro, 500 investment and all. they are all scammers please don't fall for it.
    i was scammed of over 220,000Aud after their compliance lady promised me high yield returns. i didn't have a problem with the money at all.
    i started smelling fowl play when i tried withdrawing some money to purchase a tractor for my farm.
    that i discovered i was not able to make any withdrawals.i sent several mails to their compliance lady to know avail.
    I managed to find reviews on how thehackerspro.com have assisted victims recover their investment
    from Richmond super so I followed through with it and today I was given withdrawal access to the funds in my account.
    All I wanted to do was invest for a rainy day but Richmond super was willing to abscond with my investment. How Pathetic!
    i later realized it is a coordinated scam Richmond Super is under the jurisdiction of the courts of St. Vincent & Grenadines.
    It is now clear the broker is registered offshore and traders funds are not protected by any proper regulator.

    ReplyDelete
  10. HOW I CLEARED MY DEBT IN HOURS .

    If you are in any debt and you need money to clear your debt and you need money to pay off those bills i will advise you contact DARK WEB CYBER HACKERS to get a bank transfer hack or blank atm card because I just get paid $50,00 for their service and I got my blank atm card of $90,000 delivered to my destination after 24hours of payment i trust their service and they are reliable and trustworthy don't SEARCH no more contact them today and get paid without the fear of being ripped off your money okay

    Visit their company website at

    https://darkwebcycberhackers.com/

    For quick and direct response email them at

    darkwebcyberhackers@gmail.com OR darkwebcyberhackers@yahoo.com

    Text & Call or WhatsApp: +18033921735

    Contact them and get paid.

    ReplyDelete
  11. I bring you all the good news... it’s really a testimony for me...I never knew my partner was cheating on me until I came across an online Wizard who help me hack his phone got me access to it without any physical contact with his phone... I could access his chats text messages and all.. from there I know another woman got pregnant for him.. he even got the woman a house where he goes to sleep whenever he told me he’s on night duty... after that I confronted him.. he wanted to lie so I show him all the proof which he can not deny... big thanks to. WIZARD BRIXTON WIZARDBRIXTON AT GMAIL DOT COM though it wasn’t easy cause it’s heartbreak but I thank god I'm able to know and find out the truth. God bless America. God bless women out here … contact him for a HACKING JOB: WIZARDBRIXTON AT GMAIL DOT COM, WHAT-APP : (+) 1807234 0428

    ReplyDelete
  12. CONTACT US FOR ALL KINDS OF HACKING JOBs @ We offer professional hacking services,we offer the following services;
    -University grades changing
    -Bank accounts hack
    -Erase criminal records hack
    -Facebook hack
    -Twitters hack
    -email accounts hack
    -Grade Changes hack
    Contact us on whatsapp + 1 681 532 3704
    Email- n17833408@gmail.com

    ReplyDelete
  13. LEGIT FULLZ & TOOLS STORE

    Hello to All !

    We are offering all types of tools & Fullz on discounted price.
    If you are in search of anything regarding fullz, tools, tutorials, Hack Pack, etc
    Feel Free to contact

    ***CONTACT 24/7***
    **Telegram > @leadsupplier
    **ICQ > 752822040
    **Skype > Peeterhacks
    **Wicker me > peeterhacks

    "SSN LEADS/FULLZ AVAILABLE"
    "TOOLS & TUTORIALS AVAILABLE FOR HACKING, SPAMMING,
    CARDING, CASHOUT, CLONING, SCRIPTING ETC"

    **************************************
    "Fresh Spammed SSN Fullz info included"
    >>SSN FULLZ with complete info
    >>CC With CVV (vbv & non vbv) Fullz USA
    >>FULLZ FOR SBA, PUA & TAX RETURN FILLING
    >>USA I.D Photos Front & Back
    >>High Credit Score fullz (700+ Scores)
    >>DL number, Employee Details, Bank Details Included
    >>Complete Premium Info with Relative Info

    ***************************************
    COMPLETE GUIDE FOR TUTORIALS & TOOLS

    "SPAMMING" "HACKING" "CARDING" "CASH OUT"
    "KALI LINUX" "BLOCKCHAIN BLUE PRINTS" "SCRIPTING"
    "FRAUD BIBLE"

    "TOOLS & TUTORIALS LIST"
    =>Ethical Hacking Ebooks, Tools & Tutorials
    =>Bitcoin Hacking
    =>Kali Linux
    =>Fraud Bible
    =>RAT
    =>Keylogger & Keystroke Logger
    =>Whatsapp Hacking & Hacked Version of Whatsapp
    =>Facebook & Google Hacking
    =>Bitcoin Flasher
    =>SQL Injector
    =>Premium Logs (PayPal/Amazon/Coinbase/Netflix/FedEx/Banks)
    =>Bitcoin Cracker
    =>SMTP Linux Root
    =>Shell Scripting
    =>DUMPS with pins track 1 and 2 with & without pin
    =>SMTP's, Safe Socks, Rdp's brute
    =>PHP mailer
    =>SMS Sender & Email Blaster
    =>Cpanel
    =>Server I.P's & Proxies
    =>Viruses & VPN's
    =>HQ Email Combo (Gmail, Yahoo, Hotmail, MSN, AOL, etc.)

    *Serious buyers will always welcome
    *Price will be reduce in bulk order
    *Discount offers will give to serious buyers
    *Hope we do a great business together

    ===>Contact 24/7<===
    ==>Telegram > @leadsupplier
    ==>ICQ > 752822040
    ==>Skype > Peeterhacks
    ==>Wicker me > peeterhacks

    ReplyDelete
  14. The world is filled with uncertainties, but obtaining a fake UK passport online is not one of them. 5 SIMPLE TECHNIQUES TO OBTAIN A VALID UK PASSPORT FOR TRAVEL PURPOSES Passports are important as they serve as a means of identification and also help you travel out of the country free from immigration restrictions.We have been online for a numerous years to help the movement between one country to another especially UK as most loved by many.

    ReplyDelete
  15. It’s my pleasure to read this blog post. This is amazing and very informative. I appreciate your efforts to write this and I am thankful to you for adding some value to my knowledge.
    I am excited to share this with my friends because they will also get something from it surely and will be thankful for yours. Keep sharing your thoughts MALTA CITIZENSHIP

    ReplyDelete