Esempio n. 1
0
def order_type(**kwargs):
    def check(params, kwarg_params):
        for param in params:
            if param not in kwarg_params:
                print("Missing params: {0}".format(param))
                return False
            else:
                pass
        return True

    """
    :param kwargs:
    type : ["limit", "market"]
    order : ["BUY", "SELL"]
    quantity : amount, int
    limit : limit amount, int
    """
    if 'type' in kwargs:
        if kwargs['type'] == 'limit':
            params = ['order', 'quantity', 'limit']
            if check(params, kwargs):
                return OrderSamples.LimitOrder(kwargs['order'],
                                               kwargs['quantity'],
                                               kwargs['limit'])

        elif kwargs['type'] == 'market':
            params = ['order', 'quantity']
            if check(params, kwargs):
                return OrderSamples.MarketOrder(kwargs['order'],
                                                kwargs['quantity'])
    else:
        print('Missing param: type')
Esempio n. 2
0
 def nextValidId(self, orderId:int):
     print("setting nextValidOrderId: %d", orderId)
     self.nextValidOrderId = orderId
     #here is where you start using api
     contract = Contract()
     contract.symbol = self.stock_symbol
     contract.secType = "STK"
     contract.currency = "USD"
     contract.exchange = "SMART"
     contract.primaryExchange = 'NASDAQ'
     self.reqMarketDataType(4)
     self.reqMktData(1002, contract, "", False, False, [])
     self.placeOrder(self.nextValidOrderId, contract, OrderSamples.MarketOrder("BUY", 100))
Esempio n. 3
0
def main():

    stock_contract = Contract()
    stock_contract.symbol = 'SPY'
    stock_contract.secType = 'STK'
    stock_contract.exchange = 'SMART'
    stock_contract.currency = 'USD'
    stock_contract.primaryExchange = 'NASDAQ'

    app = TestApp('SPY')
    app.connect("localhost", 7497, clientId=105)
    print("serverVersion:%s connectionTime:%s" %
          (app.serverVersion(), app.twsConnectionTime()))
    #app.reqContractDetails(1101+1, stock_contract)
    app.placeOrder(1101 + 14, stock_contract,
                   OrderSamples.LimitOrder("BUY", 100, 271))
    app.run()
    dolla = app.print_bank()
    return dolla
    app.disconnect()
def placeOneOrder(self):
    #self.simplePlaceOid = self.nextOrderId()
    faOrderOneAccount = OrderSamples.MarketOrder("BUY", 100)
    faOrderOneAccount.account = "DU2324971"
    self.placeOrder(self.nextOrderId(), ContractSamples.USStock(),
                    faOrderOneAccount)