Coder Social home page Coder Social logo

chetanmehra / the-gateway-code-samples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hftstrat/the-gateway-code-samples

0.0 1.0 0.0 106 KB

Code samples for The Gateway.

Home Page: http://thegateway.hftstrat.com

License: MIT License

Python 100.00%

the-gateway-code-samples's Introduction

What is The Gateway?

The code samples here lets you trade futures, by using The Gateway.

Download The Gateway for free at https://scctrader.herodevice.com/the-gateway.

The Gateway simply extends CTS T4 (a futures trading platform) with a socket interface, allowing other programming languages such as Python to collect data and send orders.

  • The examples folder contain Python scripts to test The Gateway.
  • The classes folder contains required classes to run the examples.

All scripts tested with Python 2.7.

alt text

Requirements

  1. A CTS-enabled futures trading account, or a simulator account. Sign up for a free simulator account at https://cts.sim.t4login.com/register?ref=CTS-footer.
  2. The Gateway installed, with the indicated port opened.
  3. Your scripts with socket connections to The Gateway using the port and IP address.

Getting started

  • Open The Gateway and log in to your T4 account.
  • Make a note of the IP address and port number displayed on The Gateway.
  • Ensure that the port number is open and available when running over a network.
  • When working with contract_id, use the Search contract tool in The Gateway and look for the desired Alias ID.

Streaming market data

1. Importing the classes

In your Python script, import the required classes:

from classes.socket_client import SocketClient
from classes.gateway_interface import GatewayInterface

Ensure your Python script lies in the same directory or in the examples directory within the source file directory.

2. Set up the interface

Create an instance of SocketClient with your IP address and port number.

Then create an instance of GatewayInterface, which requires the instance of SocketClient.

socket_client = SocketClient("localhost", 4000)
gateway = GatewayInterface(socket_client)

3. Request data

The list of public methods can be found at https://scctrader.herodevice.com/the-gateway/code-samples.

For example, to stream market data, define a function to handle the event:

def on_market_data(market_data):
    print market_data

Then, tell The Gateway to use this function for market data updates:

gateway.set_data_handlers(market_data=on_market_data)

Now that our script can handle data updates, let's request for Emini Dow June 15 contract quotes:

gateway.request_market_data("XCME_E YM (M15)")

4. Keep the application active

Keep the socket connection running with an infinite loop:

socket_client.loop()

Press Ctrl+Z or similar to terminate the process.

Sending a market order

First, import the required classes and set up the interface in the same manner.

from classes.socket_client import SocketClient
from classes.gateway_interface import GatewayInterface

socket_client = SocketClient("localhost", 4000)
gateway = GatewayInterface(socket_client)

To send a sell order of a Emini Nasdaq-100 June 15 contract at the market price:

gateway.send_market_order("XCME_Eq NQ (M15)", False, 1)

Documentation

Further information can be found at https://scctrader.herodevice.com/the-gateway/code-samples.

Disclaimer

Use The Gateway and all script files at your own risk! We at HFTStrat and all other third-party application providers are not responsible for losses or damages that may result from its use.

The Gateway is not affliated with CTS in any circumstances.

Futures and options trading involves substantial risk of loss and is not suitable for all investors. Clients may lose more than their initial investment. Past performance of actual trades or strategies cited herein is not necessarily indicative of future performance.

the-gateway-code-samples's People

Contributors

jamesmawm avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.