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.

14 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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

  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. With the recent collapse of FTX COIN and owners losing their coins or couldn’t access their wallets, I was devastated and confused because i recently bought thousands of dollars of FTX COIN as i was told it was the future coin. I tried severally on how to access my coins, while searching i came across a post on this site from a lady testifying about a hacker who helped her recovered her Bitcoin after a fake trading. I contacted them on (cybergenieintercontinental@proton.me) OR WhatsApp (+1-252-512-0391) and the rest is story, I was able to had access to my coins and i quickly exchanged it to another coin as advised by this hacker…

    ReplyDelete
  13. ^^^^^^^^^^^^TAKE A MINUTE OF YOUR TIME TO READ THIS. This is my story, and how one person changed my life for good.
    I lost my job and there was no hope for me. I suffered looking for a job and luckily I came across
    Mr Bernie DOran on a review about Forex, NFT, Binary, and Crypto trade. I borrowed
    $500 from a colleague to invest with Mr Bernie, thank goodness I made a profit of $4000 on the first week,
    reinvested 1500, and cashed out the remaining balance directly to my bank account. I. was able to pay my friend,
    and convinced him to invest as well. all this happens within a week. I'm very grateful to him for helping me
    manage my trading account. I will advise all of you who want to invest for the future and a better tomorrow
    should start with Mr Bernie DOran. Some might think this is a joke, but a trial won't hurt. give
    this a try and come back to thank me after.
    Contact him via:
    WhatsApp:+1 (424) 285-0682
    Gmail: Bernie.doranfx01@gmail.com

    ReplyDelete