Skip to content

Commit

Permalink
Added TIF options for Alpaca
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Jun 16, 2024
1 parent f7d0731 commit 59a1c74
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,4 @@ internal object Alpaca {
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ import net.jacobpeterson.alpaca.openapi.trader.model.TimeInForce as OrderTimeInF
*/
internal class AlpaceOrderPlacer(private val alpacaAPI: AlpacaAPI, private val extendedHours: Boolean = false) {


fun cancelOrder(cancellation: CancelOrder) {
val orderId = UUID.fromString(cancellation.id)
alpacaAPI.trader().orders().deleteOrderByOrderID(orderId)
}



private fun TimeInForce.toOrderTimeInForce(): OrderTimeInForce {

return when (this) {
is GTC -> OrderTimeInForce.GTC
is DAY -> OrderTimeInForce.DAY
is IOC -> OrderTimeInForce.IOC
is FOK -> OrderTimeInForce.FOK
else -> throw UnsupportedException("unsupported tif=${this}")
}
}
Expand Down Expand Up @@ -104,6 +104,4 @@ internal class AlpaceOrderPlacer(private val alpacaAPI: AlpacaAPI, private val e
}




}
3 changes: 3 additions & 0 deletions roboquant-avro/src/main/kotlin/org/roboquant/avro/AvroFeed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class AvroFeed(private val path: Path, private val template: Asset = Asset("TEMP

val arraySchema = Schema.createArray(Schema.create(Schema.Type.DOUBLE))
val enumSchema = Schema.createArray(Schema.create(Schema.Type.STRING))
var count = 0L
try {
val record = GenericData.Record(schema)
val serializer = PriceItemSerializer()
Expand All @@ -236,6 +237,7 @@ class AvroFeed(private val path: Path, private val template: Asset = Asset("TEMP

record.put(4, serialization.meta)
dataFileWriter.append(record)
count++
}

}
Expand All @@ -247,6 +249,7 @@ class AvroFeed(private val path: Path, private val template: Asset = Asset("TEMP
if (job.isActive) job.cancel()
dataFileWriter.sync()
dataFileWriter.close()
logger.info { "wrote $count records to file $file" }
}
}

Expand Down
5 changes: 3 additions & 2 deletions roboquant/src/main/kotlin/org/roboquant/brokers/Broker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.roboquant.brokers

import org.roboquant.feeds.Event
import org.roboquant.orders.Order
import java.time.Instant

/**
* Interface for any broker implementation, used for both simulated and real brokers.
Expand All @@ -31,9 +32,9 @@ interface Broker {
* trades, cash and buying power.
*
* Optionally an [event] can be provided, although normally only the SimBroker requires this to simulate
* trade executions. If no event is provided, an empty event will be used instead.
* trade executions.
*
* A sync will result in a new instance of the account object.
* A sync will return an instance of the account object.
*/
fun sync(event: Event? = null) : Account

Expand Down

0 comments on commit 59a1c74

Please sign in to comment.