Giter Club home page Giter Club logo

alpaca-swift-old's Introduction

Alpaca Trade API for Swift

https://alpaca.markets/docs/

Alpaca is a type-safe Swift client for the Alpaca trade API.

Currently a work in progress. The currently implemented methods and types are documented on the Wiki.

Usage

Alpaca defaults to paper trading mode.

let alpaca = Alpaca(key: Alpaca.Key(key: "[YOUR-API-KEY]", secret: "[YOUR-API-SECRET]"))

Placing an order

Alpaca is primarily a closure-based API, and provides a Result type for API responses:

let order = OrderRequest(
    symbol: "AAPL",
    qty: 1,
    side: .buy,
    type: .limit,
    timeInForce: .day,
    limitPrice: 320,
    extendedHours: false
)

alpaca.place(order: order) { result in
    switch result {
    case .success(let placedOrder):
        print(placedOrder)
    case .failure(let error):
        print(error)
    }
}

Placing an order using the Combine interface

Alpaca also offers a Combine interface:

var bag = Set<AnyCancellable>()

alpaca.place(order: order).sink(
    receiveCompletion: { _ in },
    receiveValue: { placedOrder in
        print(placedOrder)
    }
).store(in: &bag)

alpaca-swift-old's People

Contributors

hallee avatar mjkosmic 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.